Skip to content

Commit d15d8f4

Browse files
colin-axnerAdityaSripalcrodriguezvegaexpertdicerdependabot[bot]
committed
imp: add UnmarshalPacketData interface function (#3353)
* adr 8 with 20/27 implementation * change interface name and register codecs * documentation * add comma before new line * fix return arg and dest for ica * add ica tests * adr 8 callback packet data impl followups (#3325) * remove query client (#3227) * remove query client * merge main * go mod tidy * Rename ``IsBound`` to ``HasCapability`` (#3253) closes: #828 ```bash imp(api!): rename `IsBound` to `HasCapability` for IBC application modules ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [ ] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * chore: add support for tendermint debug log level (#3279) * build(deps): bump cosmossdk.io/math from 1.0.0-beta.6.0.20230216172121-959ce49135e4 to 1.0.0-rc.0 (#3285) Bumps [cosmossdk.io/math](https://github.com/cosmos/cosmos-sdk) from 1.0.0-beta.6.0.20230216172121-959ce49135e4 to 1.0.0-rc.0. <details> <summary>Commits</summary> <ul> <li>See full diff in <a href="https://github.com/cosmos/cosmos-sdk/commits/math/v1.0.0-rc.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=cosmossdk.io/math&package-manager=go_modules&previous-version=1.0.0-beta.6.0.20230216172121-959ce49135e4&new-version=1.0.0-rc.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> * Write docker inspect output to diagnostics (#3291) * chore: fix dead links (#3293) closes: #XXXX ```bash type: commit message ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [x] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * build(deps): bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#3292) * deps: bump SDK v0.47 (#3295) Co-authored-by: Damian Nolan <damiannolan@gmail.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * remove unnecessary import from doc * chore: remove support for v3 (#3294) * build(deps): bump actions/setup-go from 3 to 4 (#3307) * imp: remove unnecessary defer func statements (#3304) * Remove gogoproto yaml tags from proto files (#3290) Refer from original issue, I removed all `yaml` tags in proto files. closes: #3145 ```bash type: commit message ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [ ] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * add reasoning for migration to enable localhost * Support configuration file for e2e tests (#3260) * E2E fzf Test Selection Autocompletion (#3313) * post v7 release chores (#3310) * chore: fix linter warnings (#3311) * ADR 008: IBC Actor Callbacks (#1976) * context and decision * complete adr * Apply suggestions from code review Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * change from caller to generalized actor * Apply suggestions from code review Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * create folder and scaffolded middleware * add error handling and generify packetdata interface * complete renaming * add user defined gas limit and clarify pseudocode * Clarify CallbackPacketData interface imp: Add ADR 008: IBC Actor Callbacks --------- Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * lint: fix spelling * chore: apply self review concerns * chore: rename CallbackPacketDataI to CallbackPacketData * chore: finish applying remaining review suggestions * test: add remaining unit tests for transfer and ica * test: add unmarshaling test * imp: address ADR 8 review suggestions (#3319) --------- Co-authored-by: Damian Nolan <damiannolan@gmail.com> * Bump interchain test (#3314) * fix: remove codec registration * fix: build + linting * Only run e2e on R4R (#3330) * fix fork workflows (#3328) * Revert "Merge branch 'main' of github.com:cosmos/ibc-go into colin/callback-packet-data-impl" This reverts commit 1c6164b, reversing changes made to 6f25b8e. * chore: add optional interface godoc * Apply suggestions from code review Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * chore: use backticks instead of escape characters in testing --------- Co-authored-by: Lặc <67097720+expertdicer@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cian Hatton <cian@interchain.io> Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: Damian Nolan <damiannolan@gmail.com> Co-authored-by: GNaD13 <89174180+GNaD13@users.noreply.github.com> Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Co-authored-by: Aditya <adityasripal@gmail.com> * fix: merge conflicts * chore: nits from self review * imp: add UnmarshalPacketData interface function * test: add tests for ica * test: add remaining tests * adr 8 with 20/27 implementation * change interface name and register codecs * documentation * fix return arg and dest for ica * add ica tests * adr 8 callback packet data impl followups (#3325) * remove query client (#3227) * remove query client * merge main * go mod tidy * Rename ``IsBound`` to ``HasCapability`` (#3253) closes: #828 ```bash imp(api!): rename `IsBound` to `HasCapability` for IBC application modules ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [ ] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * chore: add support for tendermint debug log level (#3279) * build(deps): bump cosmossdk.io/math from 1.0.0-beta.6.0.20230216172121-959ce49135e4 to 1.0.0-rc.0 (#3285) Bumps [cosmossdk.io/math](https://github.com/cosmos/cosmos-sdk) from 1.0.0-beta.6.0.20230216172121-959ce49135e4 to 1.0.0-rc.0. <details> <summary>Commits</summary> <ul> <li>See full diff in <a href="https://github.com/cosmos/cosmos-sdk/commits/math/v1.0.0-rc.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=cosmossdk.io/math&package-manager=go_modules&previous-version=1.0.0-beta.6.0.20230216172121-959ce49135e4&new-version=1.0.0-rc.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> * Write docker inspect output to diagnostics (#3291) * chore: fix dead links (#3293) closes: #XXXX ```bash type: commit message ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [x] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * build(deps): bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#3292) * deps: bump SDK v0.47 (#3295) Co-authored-by: Damian Nolan <damiannolan@gmail.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * remove unnecessary import from doc * chore: remove support for v3 (#3294) * build(deps): bump actions/setup-go from 3 to 4 (#3307) * imp: remove unnecessary defer func statements (#3304) * Remove gogoproto yaml tags from proto files (#3290) Refer from original issue, I removed all `yaml` tags in proto files. closes: #3145 ```bash type: commit message ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [ ] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * add reasoning for migration to enable localhost * Support configuration file for e2e tests (#3260) * E2E fzf Test Selection Autocompletion (#3313) * post v7 release chores (#3310) * chore: fix linter warnings (#3311) * ADR 008: IBC Actor Callbacks (#1976) * context and decision * complete adr * Apply suggestions from code review Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * change from caller to generalized actor * Apply suggestions from code review Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * create folder and scaffolded middleware * add error handling and generify packetdata interface * complete renaming * add user defined gas limit and clarify pseudocode * Clarify CallbackPacketData interface imp: Add ADR 008: IBC Actor Callbacks --------- Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * lint: fix spelling * chore: apply self review concerns * chore: rename CallbackPacketDataI to CallbackPacketData * chore: finish applying remaining review suggestions * test: add remaining unit tests for transfer and ica * test: add unmarshaling test * imp: address ADR 8 review suggestions (#3319) --------- Co-authored-by: Damian Nolan <damiannolan@gmail.com> * Bump interchain test (#3314) * fix: remove codec registration * fix: build + linting * Only run e2e on R4R (#3330) * fix fork workflows (#3328) * Revert "Merge branch 'main' of github.com:cosmos/ibc-go into colin/callback-packet-data-impl" This reverts commit 1c6164b, reversing changes made to 6f25b8e. * chore: add optional interface godoc * Apply suggestions from code review Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * chore: use backticks instead of escape characters in testing --------- Co-authored-by: Lặc <67097720+expertdicer@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cian Hatton <cian@interchain.io> Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: Damian Nolan <damiannolan@gmail.com> Co-authored-by: GNaD13 <89174180+GNaD13@users.noreply.github.com> Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Co-authored-by: Aditya <adityasripal@gmail.com> * fix: merge conflicts * chore: nits from self review * imp: add UnmarshalPacketData interface function * test: add tests for ica * test: add remaining tests --------- Co-authored-by: Aditya Sripal <adityasripal@gmail.com> Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: Lặc <67097720+expertdicer@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cian Hatton <cian@interchain.io> Co-authored-by: Damian Nolan <damiannolan@gmail.com> Co-authored-by: GNaD13 <89174180+GNaD13@users.noreply.github.com> Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com>
1 parent d53ee99 commit d15d8f4

File tree

13 files changed

+164
-8
lines changed

13 files changed

+164
-8
lines changed

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import (
1515
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
1616
)
1717

18-
var _ porttypes.Middleware = &IBCMiddleware{}
18+
var (
19+
_ porttypes.Middleware = &IBCMiddleware{}
20+
_ porttypes.PacketDataUnmarshaler = &IBCMiddleware{}
21+
)
1922

2023
// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the
2124
// ICA controller keeper and the underlying application.
@@ -251,3 +254,15 @@ func (im IBCMiddleware) WriteAcknowledgement(
251254
func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
252255
return im.keeper.GetAppVersion(ctx, portID, channelID)
253256
}
257+
258+
// UnmarshalPacketData attempts to unmarshal the provided packet data bytes
259+
// into an InterchainAccountPacketData. This function implements the optional
260+
// PacketDataUnmarshaler interface required for ADR 008 support.
261+
func (im IBCMiddleware) UnmarshalPacketData(bz []byte) (interface{}, error) {
262+
var packetData icatypes.InterchainAccountPacketData
263+
if err := icatypes.ModuleCdc.UnmarshalJSON(bz, &packetData); err != nil {
264+
return nil, err
265+
}
266+
267+
return packetData, nil
268+
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -921,3 +921,20 @@ func (suite *InterchainAccountsTestSuite) TestClosedChannelReopensWithMsgServer(
921921
err = path.EndpointB.ChanOpenConfirm()
922922
suite.Require().NoError(err)
923923
}
924+
925+
func (suite *InterchainAccountsTestSuite) TestUnmarshalPacketData() {
926+
expPacketData := icatypes.InterchainAccountPacketData{
927+
Type: icatypes.EXECUTE_TX,
928+
Data: []byte("data"),
929+
Memo: `{"callbacks": {"src_callback_address": "testAddr"}}`,
930+
}
931+
932+
packetData, err := controller.IBCMiddleware{}.UnmarshalPacketData(expPacketData.GetBytes())
933+
suite.Require().NoError(err)
934+
suite.Require().Equal(expPacketData, packetData)
935+
936+
invalidPacketData := []byte("invalid packet data")
937+
packetData, err = controller.IBCMiddleware{}.UnmarshalPacketData(invalidPacketData)
938+
suite.Require().Error(err)
939+
suite.Require().Nil(packetData)
940+
}

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

+18
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ import (
99
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
1010
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
1111
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
12+
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
1213
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
1314
)
1415

16+
var (
17+
_ porttypes.IBCModule = &IBCModule{}
18+
_ porttypes.PacketDataUnmarshaler = &IBCModule{}
19+
)
20+
1521
// IBCModule implements the ICS26 interface for interchain accounts host chains
1622
type IBCModule struct {
1723
keeper keeper.Keeper
@@ -140,3 +146,15 @@ func (im IBCModule) OnTimeoutPacket(
140146
) error {
141147
return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "cannot cause a packet timeout on a host channel end, a host chain does not send a packet over the channel")
142148
}
149+
150+
// UnmarshalPacketData attempts to unmarshal the provided packet data bytes
151+
// into an InterchainAccountPacketData. This function implements the optional
152+
// PacketDataUnmarshaler interface required for ADR 008 support.
153+
func (im IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) {
154+
var packetData icatypes.InterchainAccountPacketData
155+
if err := icatypes.ModuleCdc.UnmarshalJSON(bz, &packetData); err != nil {
156+
return nil, err
157+
}
158+
159+
return packetData, nil
160+
}

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

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/cosmos/gogoproto/proto"
1212
"github.com/stretchr/testify/suite"
1313

14+
icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host"
1415
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
1516
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
1617
feetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
@@ -709,6 +710,23 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose()
709710
suite.assertBalance(icaAddr, expBalAfterSecondSend)
710711
}
711712

713+
func (suite *InterchainAccountsTestSuite) TestUnmarshalPacketData() {
714+
expPacketData := icatypes.InterchainAccountPacketData{
715+
Type: icatypes.EXECUTE_TX,
716+
Data: []byte("data"),
717+
Memo: `{"callbacks": {"src_callback_address": "testAddr"}}`,
718+
}
719+
720+
packetData, err := icahost.IBCModule{}.UnmarshalPacketData(expPacketData.GetBytes())
721+
suite.Require().NoError(err)
722+
suite.Require().Equal(expPacketData, packetData)
723+
724+
invalidPacketData := []byte("invalid packet data")
725+
packetData, err = icahost.IBCModule{}.UnmarshalPacketData(invalidPacketData)
726+
suite.Require().Error(err)
727+
suite.Require().Nil(packetData)
728+
}
729+
712730
// assertBalance asserts that the provided address has exactly the expected balance.
713731
// CONTRACT: the expected balance must only contain one coin denom.
714732
func (suite *InterchainAccountsTestSuite) assertBalance(addr sdk.AccAddress, expBalance sdk.Coins) {

modules/apps/27-interchain-accounts/module.go

-4
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,17 @@ import (
1919
controllerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
2020
controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
2121
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
22-
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host"
2322
hostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
2423
hosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
2524
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/simulation"
2625
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
27-
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
2826
ibchost "github.com/cosmos/ibc-go/v7/modules/core/24-host"
2927
)
3028

3129
var (
3230
_ module.AppModule = AppModule{}
3331
_ module.AppModuleBasic = AppModuleBasic{}
3432
_ module.AppModuleSimulation = AppModule{}
35-
36-
_ porttypes.IBCModule = host.IBCModule{}
3733
)
3834

3935
// AppModuleBasic is the IBC interchain accounts AppModuleBasic

modules/apps/29-fee/ibc_middleware.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import (
1515
"github.com/cosmos/ibc-go/v7/modules/core/exported"
1616
)
1717

18-
var _ porttypes.Middleware = &IBCMiddleware{}
18+
var (
19+
_ porttypes.Middleware = &IBCMiddleware{}
20+
_ porttypes.PacketDataUnmarshaler = &IBCMiddleware{}
21+
)
1922

2023
// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the
2124
// fee keeper and the underlying application.
@@ -361,3 +364,15 @@ func (im IBCMiddleware) WriteAcknowledgement(
361364
func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
362365
return im.keeper.GetAppVersion(ctx, portID, channelID)
363366
}
367+
368+
// UnmarshalPacketData attempts to use the underlying app to unmarshal the packet data.
369+
// If the underlying app does not support the PacketDataUnmarshaler interface, an error is returned.
370+
// This function implements the optional PacketDataUnmarshaler interface required for ADR 008 support.
371+
func (im IBCMiddleware) UnmarshalPacketData(bz []byte) (interface{}, error) {
372+
unmarshaler, ok := im.app.(porttypes.PacketDataUnmarshaler)
373+
if !ok {
374+
return nil, errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement PacketDataUnmarshaler")
375+
}
376+
377+
return unmarshaler.UnmarshalPacketData(bz)
378+
}

modules/apps/29-fee/ibc_middleware_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -1078,3 +1078,17 @@ func (suite *FeeTestSuite) TestGetAppVersion() {
10781078
})
10791079
}
10801080
}
1081+
1082+
func (suite *FeeTestSuite) TestUnmarshalPacketData() {
1083+
module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
1084+
suite.Require().NoError(err)
1085+
1086+
cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module)
1087+
suite.Require().True(ok)
1088+
1089+
feeModule := cbs.(fee.IBCMiddleware)
1090+
1091+
packetData, err := feeModule.UnmarshalPacketData(ibcmock.MockPacketData)
1092+
suite.Require().NoError(err)
1093+
suite.Require().Equal(ibcmock.MockPacketData, packetData)
1094+
}

modules/apps/29-fee/types/errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ var (
1616
ErrFeeNotEnabled = sdkerrors.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled")
1717
ErrRelayerNotFoundForAsyncAck = sdkerrors.Register(ModuleName, 10, "relayer address must be stored for async WriteAcknowledgement")
1818
ErrFeeModuleLocked = sdkerrors.Register(ModuleName, 11, "the fee module is currently locked, a severe bug has been detected")
19+
ErrUnsupportedAction = sdkerrors.Register(ModuleName, 12, "unsupported action")
1920
)

modules/apps/transfer/ibc_module.go

+17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import (
1717
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
1818
)
1919

20+
var (
21+
_ porttypes.IBCModule = IBCModule{}
22+
_ porttypes.PacketDataUnmarshaler = IBCModule{}
23+
)
24+
2025
// IBCModule implements the ICS26 interface for transfer given the transfer keeper.
2126
type IBCModule struct {
2227
keeper keeper.Keeper
@@ -294,3 +299,15 @@ func (im IBCModule) OnTimeoutPacket(
294299

295300
return nil
296301
}
302+
303+
// UnmarshalPacketData attempts to unmarshal the provided packet data bytes
304+
// into a FungibleTokenPacketData. This function implements the optional
305+
// PacketDataUnmarshaler interface required for ADR 008 support.
306+
func (im IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) {
307+
var packetData types.FungibleTokenPacketData
308+
if err := types.ModuleCdc.UnmarshalJSON(bz, &packetData); err != nil {
309+
return nil, err
310+
}
311+
312+
return packetData, nil
313+
}

modules/apps/transfer/ibc_module_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package transfer_test
22

33
import (
4+
"fmt"
45
"math"
56

7+
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
8+
sdk "github.com/cosmos/cosmos-sdk/types"
69
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
710

811
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
912
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
1013
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
1114
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
15+
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
1216
ibctesting "github.com/cosmos/ibc-go/v7/testing"
1317
)
1418

@@ -239,3 +243,34 @@ func (suite *TransferTestSuite) TestOnChanOpenAck() {
239243
})
240244
}
241245
}
246+
247+
func (suite *TransferTestSuite) TestUnmarshalPacketData() {
248+
var (
249+
sender = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String()
250+
receiver = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String()
251+
denom = "transfer/channel-0/atom"
252+
amount = "100"
253+
)
254+
255+
expPacketData := types.FungibleTokenPacketData{
256+
Denom: denom,
257+
Amount: amount,
258+
Sender: sender,
259+
Receiver: receiver,
260+
Memo: fmt.Sprintf(`{"callbacks": {"src_callback_address": "%s", "dest_callback_address": "%s"}}`, sender, receiver),
261+
}
262+
263+
packetData, err := transfer.IBCModule{}.UnmarshalPacketData(expPacketData.GetBytes())
264+
suite.Require().NoError(err)
265+
suite.Require().Equal(expPacketData, packetData)
266+
267+
callbackPacketData, ok := packetData.(ibcexported.CallbackPacketData)
268+
suite.Require().True(ok)
269+
suite.Require().Equal(sender, callbackPacketData.GetSourceCallbackAddress(), "incorrect source callback address")
270+
suite.Require().Equal(receiver, callbackPacketData.GetDestCallbackAddress(), "incorrect destination callback address")
271+
272+
invalidPacketData := []byte("invalid packet data")
273+
packetData, err = transfer.IBCModule{}.UnmarshalPacketData(invalidPacketData)
274+
suite.Require().Error(err)
275+
suite.Require().Nil(packetData)
276+
}

modules/apps/transfer/module.go

-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ import (
1919
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
2020
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/simulation"
2121
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
22-
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
2322
)
2423

2524
var (
2625
_ module.AppModule = AppModule{}
2726
_ module.AppModuleBasic = AppModuleBasic{}
28-
_ porttypes.IBCModule = IBCModule{}
2927
)
3028

3129
// AppModuleBasic is the IBC Transfer AppModuleBasic

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

+6
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,9 @@ type Middleware interface {
138138
IBCModule
139139
ICS4Wrapper
140140
}
141+
142+
// PacketDataUnmarshaler defines an optional interface which allows a middleware to
143+
// request the packet data to be unmarshaled by the base application.
144+
type PacketDataUnmarshaler interface {
145+
UnmarshalPacketData([]byte) (interface{}, error)
146+
}

testing/mock/ibc_module.go

+6
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ func (im IBCModule) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet,
162162
return nil
163163
}
164164

165+
// UnmarshalPacketData returns the MockPacketData. This function implements the optional
166+
// PacketDataUnmarshaler interface required for ADR 008 support.
167+
func (im IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) {
168+
return MockPacketData, nil
169+
}
170+
165171
// GetMockRecvCanaryCapabilityName generates a capability name for testing OnRecvPacket functionality.
166172
func GetMockRecvCanaryCapabilityName(packet channeltypes.Packet) string {
167173
return fmt.Sprintf("%s%s%s%s", MockRecvCanaryCapabilityName, packet.GetDestPort(), packet.GetDestChannel(), strconv.Itoa(int(packet.GetSequence())))

0 commit comments

Comments
 (0)