-
Notifications
You must be signed in to change notification settings - Fork 751
Modify UnmarshalPacketData interface to allow additional args #6341
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
Changes from 4 commits
9a3a0d5
09d1a10
fcfe4b5
9eadd72
1528eda
e5c0de5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1573,7 +1573,7 @@ func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterface() { | |
| feeModule, ok := cbs.(porttypes.PacketDataUnmarshaler) | ||
| suite.Require().True(ok) | ||
|
|
||
| packetData, err := feeModule.UnmarshalPacketData(ibcmock.MockPacketData) | ||
| packetData, err := feeModule.UnmarshalPacketData(suite.chainA.GetContext(), "", "", ibcmock.MockPacketData) | ||
| suite.Require().NoError(err) | ||
| suite.Require().Equal(ibcmock.MockPacketData, packetData) | ||
| } | ||
|
|
@@ -1582,7 +1582,8 @@ func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterfaceError() { | |
| // test the case when the underlying application cannot be casted to a PacketDataUnmarshaler | ||
| mockFeeMiddleware := ibcfee.NewIBCMiddleware(nil, feekeeper.Keeper{}) | ||
|
|
||
| _, err := mockFeeMiddleware.UnmarshalPacketData(ibcmock.MockPacketData) | ||
| // Context, port identifier, channel identifier are not used in mockFeeMiddleware. | ||
| _, err := mockFeeMiddleware.UnmarshalPacketData(suite.chainA.GetContext(), "", "", ibcmock.MockPacketData) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can add mock values in all of these if people prefer
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think it's fine, we can make sure to add good tests in transfer with the different values instead.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no preference, happy as is |
||
| expError := errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement %T", (*porttypes.PacketDataUnmarshaler)(nil)) | ||
| suite.Require().ErrorIs(err, expError) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ import ( | |
|
|
||
| errorsmod "cosmossdk.io/errors" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
|
||
| channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
| porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" | ||
| ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" | ||
| ) | ||
|
|
@@ -67,35 +70,43 @@ type CallbackData struct { | |
|
|
||
| // GetSourceCallbackData parses the packet data and returns the source callback data. | ||
| func GetSourceCallbackData( | ||
| ctx sdk.Context, | ||
| packetDataUnmarshaler porttypes.PacketDataUnmarshaler, | ||
| data []byte, srcPortID string, remainingGas uint64, maxGas uint64, | ||
| packet channeltypes.Packet, | ||
| maxGas uint64, | ||
| ) (CallbackData, error) { | ||
| return getCallbackData(packetDataUnmarshaler, data, srcPortID, remainingGas, maxGas, SourceCallbackKey) | ||
| packetData, err := packetDataUnmarshaler.UnmarshalPacketData(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetData()) | ||
| if err != nil { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. took liberty of moving these out of |
||
| return CallbackData{}, errorsmod.Wrap(ErrCannotUnmarshalPacketData, err.Error()) | ||
| } | ||
|
|
||
| return getCallbackData(packetData, packet.GetSourcePort(), ctx.GasMeter().GasRemaining(), maxGas, SourceCallbackKey) | ||
| } | ||
|
|
||
| // GetDestCallbackData parses the packet data and returns the destination callback data. | ||
| func GetDestCallbackData( | ||
| ctx sdk.Context, | ||
| packetDataUnmarshaler porttypes.PacketDataUnmarshaler, | ||
| data []byte, srcPortID string, remainingGas, maxGas uint64, | ||
| packet channeltypes.Packet, maxGas uint64, | ||
| ) (CallbackData, error) { | ||
| return getCallbackData(packetDataUnmarshaler, data, srcPortID, remainingGas, maxGas, DestinationCallbackKey) | ||
| packetData, err := packetDataUnmarshaler.UnmarshalPacketData(ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetData()) | ||
| if err != nil { | ||
| return CallbackData{}, errorsmod.Wrap(ErrCannotUnmarshalPacketData, err.Error()) | ||
| } | ||
|
|
||
| return getCallbackData(packetData, packet.GetSourcePort(), ctx.GasMeter().GasRemaining(), maxGas, DestinationCallbackKey) | ||
| } | ||
|
|
||
| // getCallbackData parses the packet data and returns the callback data. | ||
| // It also checks that the remaining gas is greater than the gas limit specified in the packet data. | ||
| // The addressGetter and gasLimitGetter functions are used to retrieve the callback | ||
| // address and gas limit from the callback data. | ||
| func getCallbackData( | ||
| packetDataUnmarshaler porttypes.PacketDataUnmarshaler, | ||
| data []byte, srcPortID string, remainingGas, | ||
| packetData interface{}, | ||
| srcPortID string, | ||
| remainingGas, | ||
| maxGas uint64, callbackKey string, | ||
| ) (CallbackData, error) { | ||
| // unmarshal packet data | ||
| packetData, err := packetDataUnmarshaler.UnmarshalPacketData(data) | ||
| if err != nil { | ||
| return CallbackData{}, errorsmod.Wrap(ErrCannotUnmarshalPacketData, err.Error()) | ||
| } | ||
|
|
||
| packetDataProvider, ok := packetData.(ibcexported.PacketDataProvider) | ||
| if !ok { | ||
| return CallbackData{}, ErrNotPacketDataProvider | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.