diff --git a/modules/ibc-hooks/wasm_hook.go b/modules/ibc-hooks/wasm_hook.go index 0aef149b..4233f28e 100644 --- a/modules/ibc-hooks/wasm_hook.go +++ b/modules/ibc-hooks/wasm_hook.go @@ -159,11 +159,7 @@ func jsonStringHasKey(memo, key string) (found bool, jsonObject map[string]inter // If the key doesn't exist, there's nothing to do on this hook. Continue by passing the packet // down the stack _, ok := jsonObject[key] - if !ok { - return false, jsonObject - } - - return true, jsonObject + return ok, jsonObject } func ValidateAndParseMemo(memo string, receiver string) (isWasmRouted bool, contractAddr sdk.AccAddress, msgBytes []byte, err error) { @@ -181,7 +177,6 @@ func ValidateAndParseMemo(memo string, receiver string) (isWasmRouted bool, cont fmt.Errorf(types.ErrBadMetadataFormatMsg, memo, "wasm metadata is not a valid JSON map object") } - // Get the contract contract, ok := wasm["contract"].(string) if !ok { // The tokens will be returned @@ -195,19 +190,16 @@ func ValidateAndParseMemo(memo string, receiver string) (isWasmRouted bool, cont fmt.Errorf(types.ErrBadMetadataFormatMsg, memo, `wasm["contract"] is not a valid bech32 address`) } - // The contract and the receiver should be the same for the packet to be valid if contract != receiver { return isWasmRouted, sdk.AccAddress{}, nil, fmt.Errorf(types.ErrBadMetadataFormatMsg, memo, `wasm["contract"] should be the same as the receiver of the packet`) } - // Ensure the message key is provided if wasm["msg"] == nil { return isWasmRouted, sdk.AccAddress{}, nil, fmt.Errorf(types.ErrBadMetadataFormatMsg, memo, `Could not find key wasm["msg"]`) } - // Make sure the msg key is a map. If it isn't, return an error _, ok = wasm["msg"].(map[string]interface{}) if !ok { return isWasmRouted, sdk.AccAddress{}, nil, @@ -236,7 +228,8 @@ func (h WasmHooks) SendPacketOverride(i ICS4Middleware, ctx sdk.Context, chanCap return i.channel.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) // continue } - // We remove the callback metadata from the memo as it has already been processed. + // We remove the meta.callback provides instructions for post-send processing. This instruction are saved + // in the keepr (at the end of this function), and at the end - it is set as as it has already been processed. // If the only available key in the memo is the callback, we should remove the memo // from the data completely so the packet is sent without it. @@ -411,9 +404,9 @@ func MustExtractDenomFromPacketOnRecv(packet ibcexported.PacketI) string { var denom string if transfertypes.ReceiverChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom) { - // remove prefix added by sender chain + // if we receive back a token, that was originally sent from "this" chain, then we need to remove + // prefix added by the sender chain: port/channel/base_denom -> base_denom. voucherPrefix := transfertypes.GetDenomPrefix(packet.GetSourcePort(), packet.GetSourceChannel()) - unprefixedDenom := data.Denom[len(voucherPrefix):] // coin denomination used in sending from the escrow address @@ -422,7 +415,7 @@ func MustExtractDenomFromPacketOnRecv(packet ibcexported.PacketI) string { // The denomination used to send the coins is either the native denom or the hash of the path // if the denomination is not native. denomTrace := transfertypes.ParseDenomTrace(unprefixedDenom) - if denomTrace.Path != "" { + if !denomTrace.IsNativeDenom() { denom = denomTrace.IBCDenom() } } else {