Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: cleanup wasm_hook.go #165

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions modules/ibc-hooks/wasm_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Reecepbcups marked this conversation as resolved.
Show resolved Hide resolved
contract, ok := wasm["contract"].(string)
if !ok {
// The tokens will be returned
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading