Skip to content

Commit

Permalink
Added method on rollappPacket to get transferPacketData.
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix committed Mar 3, 2024
1 parent 3eebad7 commit 5adfcad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.3 h1:iAtAivMtJh2Ublnq2Kas
github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.3/go.mod h1:O2J61ZwM0Vdms6pRa1fb43pwmCuNRctro3AB90WlOc0=
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dym-v0.0.1 h1:59ZE3Ocrn04MUpb5VJgfi24eDcnQ9VBfCSw0Mx1n7OI=
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dym-v0.0.1/go.mod h1:2idySYJxP5YfMAEeSeqD8e7fSchfsI4jn7XFHJgNUsM=
github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.3-alpha.1 h1:K0/44d7M+Nv12tn+ZCHImkXHoUMjIq7AjvUP7PVj0k4=
github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.3-alpha.1 h1:ryioCuV8k52MgBdK1BcsbRebFcvfXojfsOHDHg9tnkE=
github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.3-alpha.1/go.mod h1:BHHGzl86byC0sov3EUfTzyDuIsGY//rcrek6gCOa+fw=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
Expand Down
9 changes: 9 additions & 0 deletions x/common/types/rollapp_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
)

const (
Expand All @@ -30,3 +31,11 @@ func (r RollappPacket) GetEvents() []sdk.Attribute {
}
return eventAttributes
}

func (r RollappPacket) GetTransferPacketData() (transfertypes.FungibleTokenPacketData, error) {
var data transfertypes.FungibleTokenPacketData
if err := transfertypes.ModuleCdc.UnmarshalJSON(r.Packet.GetData(), &data); err != nil {
return transfertypes.FungibleTokenPacketData{}, err
}
return data, nil
}
12 changes: 6 additions & 6 deletions x/delayedack/keeper/rollapp_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ func (k Keeper) UpdateRollappPacketTransferAddress(
if rollappPacket.Status != commontypes.Status_PENDING {
return types.ErrCanOnlyUpdatePendingPacket
}
var data transfertypes.FungibleTokenPacketData
if err := transfertypes.ModuleCdc.UnmarshalJSON(rollappPacket.Packet.GetData(), &data); err != nil {
transferPacketData, err := rollappPacket.GetTransferPacketData()
if err != nil {
return err
}
// Set the recipient and sender based on the rollapp packet type
recipient, sender := data.Receiver, data.Sender
recipient, sender := transferPacketData.Receiver, transferPacketData.Sender
if rollappPacket.Type == commontypes.RollappPacket_ON_RECV {
recipient = address
} else if rollappPacket.Type == commontypes.RollappPacket_ON_TIMEOUT {
sender = address
}
newPacketData := transfertypes.NewFungibleTokenPacketData(
data.Denom,
data.Amount,
transferPacketData.Denom,
transferPacketData.Amount,
sender,
recipient,
data.Memo,
transferPacketData.Memo,
)
// Marshall to binary and update the packet with this data
packetBytes := newPacketData.GetBytes()
Expand Down

0 comments on commit 5adfcad

Please sign in to comment.