PR Comment: move where truncating address length to 20

This commit is contained in:
Ethan Frey
2021-07-28 10:33:33 +02:00
parent 92850081f0
commit 6f720a4c88

View File

@@ -819,7 +819,9 @@ func BuildContractAddress(codeID, instanceID uint64) sdk.AccAddress {
contractID := make([]byte, 16) contractID := make([]byte, 16)
binary.BigEndian.PutUint64(contractID[:8], codeID) binary.BigEndian.PutUint64(contractID[:8], codeID)
binary.BigEndian.PutUint64(contractID[8:], instanceID) binary.BigEndian.PutUint64(contractID[8:], instanceID)
return Module(types.ModuleName, contractID) // 20 bytes to work with Cosmos SDK 0.42 (0.43 pushes for 32 bytes)
// TODO: remove truncate if we update to 0.43 before wasmd 1.0
return Module(types.ModuleName, contractID)[:20]
} }
// Hash and Module is taken from https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-rc2/types/address/hash.go // Hash and Module is taken from https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-rc2/types/address/hash.go
@@ -838,10 +840,7 @@ func Hash(typ string, key []byte) []byte {
assertNil(err) assertNil(err)
_, err = hasher.Write(key) _, err = hasher.Write(key)
assertNil(err) assertNil(err)
hashed := hasher.Sum(nil) return hasher.Sum(nil)
// 20 bytes to work with Cosmos SDK 0.42 (0.43 pushes for 32 bytes)
// TODO: remove truncate if we update to 0.43 before wasmd 1.0
return hashed[:20]
} }
// Module is a specialized version of a composed address for modules. Each module account // Module is a specialized version of a composed address for modules. Each module account