Skip to content

Commit 06510a5

Browse files
feat: adding interchain account address query to controller submodule (backport cosmos#2193) (cosmos#2228)
* feat: adding interchain account address query to controller submodule (cosmos#2193) * adding interchain account address query to ica controller * adding basic cli query * satisfy linter, aligning recvr var naming * Apply suggestions from code review Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * reordering cli args * regenerate protobufs and swagger docs post review suggestions * adding changelog * Update modules/apps/27-interchain-accounts/controller/client/cli/query.go Co-authored-by: Carlos Rodriguez <carlos@interchain.io> (cherry picked from commit e569045) # Conflicts: # CHANGELOG.md * resolving conflicts Co-authored-by: Damian Nolan <damiannolan@gmail.com>
1 parent a6adf67 commit 06510a5

11 files changed

Lines changed: 831 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
5959

6060
### Features
6161

62+
* (apps/27-interchain-accounts) [\#2193](https://github.com/cosmos/ibc-go/pull/2193) Adding `InterchainAccount` gRPC query endpont to ICS27 `controller` submodule to allow users to retrieve registered interchain account addresses.
63+
6264
### Bug Fixes
6365

6466
* (makefile) [\#1785](https://github.com/cosmos/ibc-go/pull/1785) Fetch the correct versions of protocol buffers dependencies from tendermint, cosmos-sdk, and ics23.

docs/client/swagger-ui/swagger.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,56 @@ paths:
365365
format: byte
366366
tags:
367367
- Query
368+
'/ibc/apps/interchain_accounts/controller/v1/owners/{owner}/connections/{connection_id}':
369+
get:
370+
summary: >-
371+
InterchainAccount returns the interchain account address for a given
372+
owner address on a given connection
373+
operationId: InterchainAccount
374+
responses:
375+
'200':
376+
description: A successful response.
377+
schema:
378+
type: object
379+
properties:
380+
address:
381+
type: string
382+
description: >-
383+
QueryInterchainAccountResponse the response type for the
384+
Query/InterchainAccount RPC method.
385+
default:
386+
description: An unexpected error response
387+
schema:
388+
type: object
389+
properties:
390+
error:
391+
type: string
392+
code:
393+
type: integer
394+
format: int32
395+
message:
396+
type: string
397+
details:
398+
type: array
399+
items:
400+
type: object
401+
properties:
402+
type_url:
403+
type: string
404+
value:
405+
type: string
406+
format: byte
407+
parameters:
408+
- name: owner
409+
in: path
410+
required: true
411+
type: string
412+
- name: connection_id
413+
in: path
414+
required: true
415+
type: string
416+
tags:
417+
- Query
368418
/ibc/apps/interchain_accounts/controller/v1/params:
369419
get:
370420
summary: Params queries all parameters of the ICA controller submodule.
@@ -13384,6 +13434,14 @@ definitions:
1338413434
description: |-
1338513435
Params defines the set of on-chain interchain accounts parameters.
1338613436
The following parameters may be used to disable the controller submodule.
13437+
ibc.applications.interchain_accounts.controller.v1.QueryInterchainAccountResponse:
13438+
type: object
13439+
properties:
13440+
address:
13441+
type: string
13442+
description: >-
13443+
QueryInterchainAccountResponse the response type for the
13444+
Query/InterchainAccount RPC method.
1338713445
ibc.applications.interchain_accounts.controller.v1.QueryParamsResponse:
1338813446
type: object
1338913447
properties:

docs/ibc/proto-docs.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
- [Params](#ibc.applications.interchain_accounts.controller.v1.Params)
8585

8686
- [ibc/applications/interchain_accounts/controller/v1/query.proto](#ibc/applications/interchain_accounts/controller/v1/query.proto)
87+
- [QueryInterchainAccountRequest](#ibc.applications.interchain_accounts.controller.v1.QueryInterchainAccountRequest)
88+
- [QueryInterchainAccountResponse](#ibc.applications.interchain_accounts.controller.v1.QueryInterchainAccountResponse)
8789
- [QueryParamsRequest](#ibc.applications.interchain_accounts.controller.v1.QueryParamsRequest)
8890
- [QueryParamsResponse](#ibc.applications.interchain_accounts.controller.v1.QueryParamsResponse)
8991

@@ -1460,6 +1462,37 @@ The following parameters may be used to disable the controller submodule.
14601462

14611463

14621464

1465+
<a name="ibc.applications.interchain_accounts.controller.v1.QueryInterchainAccountRequest"></a>
1466+
1467+
### QueryInterchainAccountRequest
1468+
QueryInterchainAccountRequest is the request type for the Query/InterchainAccount RPC method.
1469+
1470+
1471+
| Field | Type | Label | Description |
1472+
| ----- | ---- | ----- | ----------- |
1473+
| `owner` | [string](#string) | | |
1474+
| `connection_id` | [string](#string) | | |
1475+
1476+
1477+
1478+
1479+
1480+
1481+
<a name="ibc.applications.interchain_accounts.controller.v1.QueryInterchainAccountResponse"></a>
1482+
1483+
### QueryInterchainAccountResponse
1484+
QueryInterchainAccountResponse the response type for the Query/InterchainAccount RPC method.
1485+
1486+
1487+
| Field | Type | Label | Description |
1488+
| ----- | ---- | ----- | ----------- |
1489+
| `address` | [string](#string) | | |
1490+
1491+
1492+
1493+
1494+
1495+
14631496
<a name="ibc.applications.interchain_accounts.controller.v1.QueryParamsRequest"></a>
14641497

14651498
### QueryParamsRequest
@@ -1498,6 +1531,7 @@ Query provides defines the gRPC querier service.
14981531

14991532
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
15001533
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
1534+
| `InterchainAccount` | [QueryInterchainAccountRequest](#ibc.applications.interchain_accounts.controller.v1.QueryInterchainAccountRequest) | [QueryInterchainAccountResponse](#ibc.applications.interchain_accounts.controller.v1.QueryInterchainAccountResponse) | InterchainAccount returns the interchain account address for a given owner address on a given connection | GET|/ibc/apps/interchain_accounts/controller/v1/owners/{owner}/connections/{connection_id}|
15011535
| `Params` | [QueryParamsRequest](#ibc.applications.interchain_accounts.controller.v1.QueryParamsRequest) | [QueryParamsResponse](#ibc.applications.interchain_accounts.controller.v1.QueryParamsResponse) | Params queries all parameters of the ICA controller submodule. | GET|/ibc/apps/interchain_accounts/controller/v1/params|
15021536

15031537
<!-- end services -->

modules/apps/27-interchain-accounts/controller/client/cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func GetQueryCmd() *cobra.Command {
1414
}
1515

1616
queryCmd.AddCommand(
17+
GetCmdQueryInterchainAccount(),
1718
GetCmdParams(),
1819
)
1920

modules/apps/27-interchain-accounts/controller/client/cli/query.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,40 @@ import (
1111
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
1212
)
1313

14+
// GetCmdQueryInterchainAccount returns the command handler for the controller submodule parameter querying.
15+
func GetCmdQueryInterchainAccount() *cobra.Command {
16+
cmd := &cobra.Command{
17+
Use: "interchain-account [owner] [connection-id]",
18+
Short: "Query the interchain account address for a given owner on a particular connection",
19+
Long: "Query the controller submodule for the interchain account address for a given owner on a particular connection",
20+
Args: cobra.ExactArgs(2),
21+
Example: fmt.Sprintf("%s query interchain-accounts controller interchain-account cosmos1layxcsmyye0dc0har9sdfzwckaz8sjwlfsj8zs connection-0", version.AppName),
22+
RunE: func(cmd *cobra.Command, args []string) error {
23+
clientCtx, err := client.GetClientQueryContext(cmd)
24+
if err != nil {
25+
return err
26+
}
27+
28+
queryClient := types.NewQueryClient(clientCtx)
29+
req := &types.QueryInterchainAccountRequest{
30+
Owner: args[0],
31+
ConnectionId: args[1],
32+
}
33+
34+
res, err := queryClient.InterchainAccount(cmd.Context(), req)
35+
if err != nil {
36+
return err
37+
}
38+
39+
return clientCtx.PrintProto(res)
40+
},
41+
}
42+
43+
flags.AddQueryFlagsToCmd(cmd)
44+
45+
return cmd
46+
}
47+
1448
// GetCmdParams returns the command handler for the controller submodule parameter querying.
1549
func GetCmdParams() *cobra.Command {
1650
cmd := &cobra.Command{

modules/apps/27-interchain-accounts/controller/keeper/grpc_query.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,41 @@ import (
44
"context"
55

66
sdk "github.com/cosmos/cosmos-sdk/types"
7+
"google.golang.org/grpc/codes"
8+
"google.golang.org/grpc/status"
79

810
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
11+
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
912
)
1013

1114
var _ types.QueryServer = Keeper{}
1215

16+
// InterchainAccount implements the Query/InterchainAccount gRPC method
17+
func (k Keeper) InterchainAccount(goCtx context.Context, req *types.QueryInterchainAccountRequest) (*types.QueryInterchainAccountResponse, error) {
18+
if req == nil {
19+
return nil, status.Error(codes.InvalidArgument, "empty request")
20+
}
21+
22+
portID, err := icatypes.NewControllerPortID(req.Owner)
23+
if err != nil {
24+
return nil, status.Errorf(codes.InvalidArgument, "failed to generate portID from owner address: %s", err)
25+
}
26+
27+
ctx := sdk.UnwrapSDKContext(goCtx)
28+
addr, found := k.GetInterchainAccountAddress(ctx, req.ConnectionId, portID)
29+
if !found {
30+
return nil, status.Errorf(codes.NotFound, "failed to retrieve account address for %s on connection %s", portID, req.ConnectionId)
31+
}
32+
33+
return &types.QueryInterchainAccountResponse{
34+
Address: addr,
35+
}, nil
36+
}
37+
1338
// Params implements the Query/Params gRPC method
14-
func (q Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
39+
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
1540
ctx := sdk.UnwrapSDKContext(c)
16-
params := q.GetParams(ctx)
41+
params := k.GetParams(ctx)
1742

1843
return &types.QueryParamsResponse{
1944
Params: &params,

modules/apps/27-interchain-accounts/controller/keeper/grpc_query_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,77 @@ import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55

66
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
7+
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
8+
ibctesting "github.com/cosmos/ibc-go/v5/testing"
79
)
810

11+
func (suite *KeeperTestSuite) TestQueryInterchainAccount() {
12+
var req *types.QueryInterchainAccountRequest
13+
14+
testCases := []struct {
15+
name string
16+
malleate func()
17+
expPass bool
18+
}{
19+
{
20+
"success",
21+
func() {},
22+
true,
23+
},
24+
{
25+
"empty request",
26+
func() {
27+
req = nil
28+
},
29+
false,
30+
},
31+
{
32+
"empty owner address",
33+
func() {
34+
req.Owner = ""
35+
},
36+
false,
37+
},
38+
{
39+
"invalid connection, account address not found",
40+
func() {
41+
req.ConnectionId = "invalid-connection-id"
42+
},
43+
false,
44+
},
45+
}
46+
47+
for _, tc := range testCases {
48+
suite.Run(tc.name, func() {
49+
suite.SetupTest()
50+
51+
path := NewICAPath(suite.chainA, suite.chainB)
52+
suite.coordinator.SetupConnections(path)
53+
54+
err := SetupICAPath(path, ibctesting.TestAccAddress)
55+
suite.Require().NoError(err)
56+
57+
req = &types.QueryInterchainAccountRequest{
58+
ConnectionId: ibctesting.FirstConnectionID,
59+
Owner: ibctesting.TestAccAddress,
60+
}
61+
62+
tc.malleate()
63+
64+
res, err := suite.chainA.GetSimApp().ICAControllerKeeper.InterchainAccount(sdk.WrapSDKContext(suite.chainA.GetContext()), req)
65+
66+
if tc.expPass {
67+
expAddress := icatypes.GenerateAddress(suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(icatypes.ModuleName), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
68+
69+
suite.Require().NoError(err)
70+
suite.Require().Equal(expAddress.String(), res.Address)
71+
} else {
72+
suite.Require().Error(err)
73+
}
74+
})
75+
}
76+
}
77+
978
func (suite *KeeperTestSuite) TestQueryParams() {
1079
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
1180
expParams := types.DefaultParams()

0 commit comments

Comments
 (0)