Skip to content

Commit

Permalink
fix to encode intermediate sender changed packet with counterparty po…
Browse files Browse the repository at this point in the history
…rt consideration
  • Loading branch information
beer-1 committed Aug 12, 2024
1 parent d488e00 commit 77b7801
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
13 changes: 2 additions & 11 deletions x/ibc-hooks/move-hooks/receive.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package move_hooks

import (
"encoding/json"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -51,11 +50,7 @@ func (h MoveHooks) onRecvIcs20Packet(
//
// If that succeeds, we make the contract call
data.Receiver = intermediateSender
bz, err := json.Marshal(data)
if err != nil {
return newEmitErrorAcknowledgement(err)
}
packet.Data = bz
packet.Data = data.GetBytes()

ack := im.App.OnRecvPacket(ctx, packet, relayer)
if !ack.Success() {
Expand Down Expand Up @@ -107,11 +102,7 @@ func (h MoveHooks) onRecvIcs721Packet(
//
// If that succeeds, we make the contract call
data.Receiver = intermediateSender
bz, err := json.Marshal(data)
if err != nil {
return newEmitErrorAcknowledgement(err)
}
packet.Data = bz
packet.Data = data.GetBytes(packet.GetDestChannel())

ack := im.App.OnRecvPacket(ctx, packet, relayer)
if !ack.Success() {
Expand Down
4 changes: 2 additions & 2 deletions x/ibc-hooks/move-hooks/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func isIcs20Packet(packetData []byte) (isIcs20 bool, ics20data transfertypes.Fun
return true, data
}

func isIcs721Packet(packetData []byte, counterPartyPort string) (isIcs721 bool, ics721data nfttransfertypes.NonFungibleTokenPacketData) {
if data, err := nfttransfertypes.DecodePacketData(packetData, counterPartyPort); err != nil {
func isIcs721Packet(packetData []byte, counterpartyPort string) (isIcs721 bool, ics721data nfttransfertypes.NonFungibleTokenPacketData) {
if data, err := nfttransfertypes.DecodePacketData(packetData, counterpartyPort); err != nil {
return false, data
} else {
return true, data
Expand Down
8 changes: 4 additions & 4 deletions x/ibc/nft-transfer/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ func (nftpd NonFungibleTokenPacketData) ValidateBasic() error {
}

// GetBytes is a helper for serializing
func (nftpd NonFungibleTokenPacketData) GetBytes(counterPartyPort string) []byte {
func (nftpd NonFungibleTokenPacketData) GetBytes(counterpartyPort string) []byte {
var bz []byte
var err error
if isWasmPacket(counterPartyPort) {
if isWasmPacket(counterpartyPort) {
bz, err = json.Marshal(nftpd.ToWasmData())
} else {
bz, err = json.Marshal(nftpd)
Expand All @@ -87,11 +87,11 @@ func (nftpd NonFungibleTokenPacketData) GetBytes(counterPartyPort string) []byte
}

// decode packet data to NonFungibleTokenPacketData
func DecodePacketData(packetData []byte, counterPartyPort string) (NonFungibleTokenPacketData, error) {
func DecodePacketData(packetData []byte, counterpartyPort string) (NonFungibleTokenPacketData, error) {
decoder := json.NewDecoder(strings.NewReader(string(packetData)))
decoder.DisallowUnknownFields()

if isWasmPacket(counterPartyPort) {
if isWasmPacket(counterpartyPort) {
var wasmData NonFungibleTokenPacketDataWasm
if err := decoder.Decode(&wasmData); err != nil {
return NonFungibleTokenPacketData{}, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
Expand Down

0 comments on commit 77b7801

Please sign in to comment.