Skip to content

Commit 2719dfc

Browse files
committed
api(port)!: Allow passing of context, port and channel identifier to unmarshal packet data interface as disussed.
This allows us to grab the app version in transfer and unmarshal the packet based on that instead of a hacky unmarshal v2 then v1 and whatever happens.
1 parent 0478cb9 commit 2719dfc

File tree

10 files changed

+18
-14
lines changed

10 files changed

+18
-14
lines changed

modules/apps/27-interchain-accounts/controller/ibc_middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string)
340340
// UnmarshalPacketData attempts to unmarshal the provided packet data bytes
341341
// into an InterchainAccountPacketData. This function implements the optional
342342
// PacketDataUnmarshaler interface required for ADR 008 support.
343-
func (IBCMiddleware) UnmarshalPacketData(bz []byte) (interface{}, error) {
343+
func (IBCMiddleware) UnmarshalPacketData(_ sdk.Context, _, _ string, bz []byte) (interface{}, error) {
344344
var data icatypes.InterchainAccountPacketData
345345
err := data.UnmarshalJSON(bz)
346346
if err != nil {

modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,13 +1248,15 @@ func (suite *InterchainAccountsTestSuite) TestPacketDataUnmarshalerInterface() {
12481248
Memo: "",
12491249
}
12501250

1251-
packetData, err := controller.IBCMiddleware{}.UnmarshalPacketData(expPacketData.GetBytes())
1251+
ctx := suite.chainA.GetContext()
1252+
1253+
packetData, err := controller.IBCMiddleware{}.UnmarshalPacketData(ctx, "", "", expPacketData.GetBytes())
12521254
suite.Require().NoError(err)
12531255
suite.Require().Equal(expPacketData, packetData)
12541256

12551257
// test invalid packet data
12561258
invalidPacketData := []byte("invalid packet data")
1257-
packetData, err = controller.IBCMiddleware{}.UnmarshalPacketData(invalidPacketData)
1259+
packetData, err = controller.IBCMiddleware{}.UnmarshalPacketData(ctx, "", "", invalidPacketData)
12581260
suite.Require().Error(err)
12591261
suite.Require().Nil(packetData)
12601262
}

modules/apps/27-interchain-accounts/host/ibc_module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, pr
184184
// UnmarshalPacketData attempts to unmarshal the provided packet data bytes
185185
// into an InterchainAccountPacketData. This function implements the optional
186186
// PacketDataUnmarshaler interface required for ADR 008 support.
187-
func (IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) {
187+
func (IBCModule) UnmarshalPacketData(_ sdk.Context, _, _ string, bz []byte) (interface{}, error) {
188188
var data icatypes.InterchainAccountPacketData
189189
err := data.UnmarshalJSON(bz)
190190
if err != nil {

modules/apps/27-interchain-accounts/host/ibc_module_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,13 +883,15 @@ func (suite *InterchainAccountsTestSuite) TestPacketDataUnmarshalerInterface() {
883883
Memo: "",
884884
}
885885

886-
packetData, err := icahost.IBCModule{}.UnmarshalPacketData(expPacketData.GetBytes())
886+
ctx := suite.chainA.GetContext()
887+
888+
packetData, err := icahost.IBCModule{}.UnmarshalPacketData(ctx, "", "", expPacketData.GetBytes())
887889
suite.Require().NoError(err)
888890
suite.Require().Equal(expPacketData, packetData)
889891

890892
// test invalid packet data
891893
invalidPacketData := []byte("invalid packet data")
892-
packetData, err = icahost.IBCModule{}.UnmarshalPacketData(invalidPacketData)
894+
packetData, err = icahost.IBCModule{}.UnmarshalPacketData(ctx, "", "", invalidPacketData)
893895
suite.Require().Error(err)
894896
suite.Require().Nil(packetData)
895897
}

modules/apps/29-fee/ibc_middleware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,11 @@ func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string)
471471
// UnmarshalPacketData attempts to use the underlying app to unmarshal the packet data.
472472
// If the underlying app does not support the PacketDataUnmarshaler interface, an error is returned.
473473
// This function implements the optional PacketDataUnmarshaler interface required for ADR 008 support.
474-
func (im IBCMiddleware) UnmarshalPacketData(bz []byte) (interface{}, error) {
474+
func (im IBCMiddleware) UnmarshalPacketData(ctx sdk.Context, portID, channelID string, bz []byte) (interface{}, error) {
475475
unmarshaler, ok := im.app.(porttypes.PacketDataUnmarshaler)
476476
if !ok {
477477
return nil, errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement %T", (*porttypes.PacketDataUnmarshaler)(nil))
478478
}
479479

480-
return unmarshaler.UnmarshalPacketData(bz)
480+
return unmarshaler.UnmarshalPacketData(ctx, portID, channelID, bz)
481481
}

modules/apps/29-fee/ibc_middleware_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterface() {
15711571
feeModule, ok := cbs.(porttypes.PacketDataUnmarshaler)
15721572
suite.Require().True(ok)
15731573

1574-
packetData, err := feeModule.UnmarshalPacketData(ibcmock.MockPacketData)
1574+
packetData, err := feeModule.UnmarshalPacketData(suite.chainA.GetContext(), "", "", ibcmock.MockPacketData)
15751575
suite.Require().NoError(err)
15761576
suite.Require().Equal(ibcmock.MockPacketData, packetData)
15771577
}
@@ -1580,7 +1580,7 @@ func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterfaceError() {
15801580
// test the case when the underlying application cannot be casted to a PacketDataUnmarshaler
15811581
mockFeeMiddleware := ibcfee.NewIBCMiddleware(nil, feekeeper.Keeper{})
15821582

1583-
_, err := mockFeeMiddleware.UnmarshalPacketData(ibcmock.MockPacketData)
1583+
_, err := mockFeeMiddleware.UnmarshalPacketData(suite.chainA.GetContext(), "", "", ibcmock.MockPacketData)
15841584
expError := errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement %T", (*porttypes.PacketDataUnmarshaler)(nil))
15851585
suite.Require().ErrorIs(err, expError)
15861586
}

modules/apps/transfer/ibc_module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func (IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, pr
398398
// UnmarshalPacketData attempts to unmarshal the provided packet data bytes
399399
// into a FungibleTokenPacketData. This function implements the optional
400400
// PacketDataUnmarshaler interface required for ADR 008 support.
401-
func (im IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) {
401+
func (im IBCModule) UnmarshalPacketData(_ sdk.Context, _, _ string, bz []byte) (interface{}, error) {
402402
ftpd, err := im.unmarshalPacketDataBytesToICS20V2(bz)
403403
if err != nil {
404404
return nil, err

modules/apps/transfer/ibc_module_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {
595595
suite.Run(tc.name, func() {
596596
tc.malleate()
597597

598-
packetData, err := transfer.IBCModule{}.UnmarshalPacketData(data)
598+
packetData, err := transfer.IBCModule{}.UnmarshalPacketData(suite.chainA.GetContext(), "", "", data)
599599

600600
if tc.expPass {
601601
suite.Require().NoError(err)

modules/core/05-port/types/module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,5 @@ type Middleware interface {
194194
// request the packet data to be unmarshaled by the base application.
195195
type PacketDataUnmarshaler interface {
196196
// UnmarshalPacketData unmarshals the packet data into a concrete type
197-
UnmarshalPacketData([]byte) (interface{}, error)
197+
UnmarshalPacketData(ctx sdk.Context, portID, channelID string, bz []byte) (interface{}, error)
198198
}

testing/mock/ibc_module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (im IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string,
219219

220220
// UnmarshalPacketData returns the MockPacketData. This function implements the optional
221221
// PacketDataUnmarshaler interface required for ADR 008 support.
222-
func (IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) {
222+
func (IBCModule) UnmarshalPacketData(_ sdk.Context, _, _ string, bz []byte) (interface{}, error) {
223223
if reflect.DeepEqual(bz, MockPacketData) {
224224
return MockPacketData, nil
225225
}

0 commit comments

Comments
 (0)