Skip to content

Commit 7928ab7

Browse files
damiannolanmergify[bot]
authored andcommitted
feat: adding interchain account address query to controller submodule (#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 # modules/apps/27-interchain-accounts/controller/keeper/grpc_query.go # modules/apps/27-interchain-accounts/controller/keeper/grpc_query_test.go # modules/apps/27-interchain-accounts/controller/types/query.pb.go
1 parent cf2cc50 commit 7928ab7

File tree

10 files changed

+843
-4
lines changed

10 files changed

+843
-4
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
4646

4747
### Features
4848

49+
<<<<<<< HEAD
50+
=======
51+
* (apps/27-interchain-accounts) [\#2147](https://github.com/cosmos/ibc-go/pull/2147) Adding a `SubmitTx` gRPC endpoint for the ICS27 Controller module which allows owners of interchain accounts to submit transactions. This replaces the previously existing need for authentication modules to implement this standard functionality.
52+
* (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.
53+
54+
>>>>>>> e569045 (feat: adding interchain account address query to controller submodule (#2193))
4955
### Bug Fixes
5056

5157
## [v4.0.0](https://github.com/cosmos/ibc-go/releases/tag/v4.0.0) - 2022-08-12

docs/client/swagger-ui/swagger.yaml

+58
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,56 @@ paths:
353353
format: byte
354354
tags:
355355
- Query
356+
'/ibc/apps/interchain_accounts/controller/v1/owners/{owner}/connections/{connection_id}':
357+
get:
358+
summary: >-
359+
InterchainAccount returns the interchain account address for a given
360+
owner address on a given connection
361+
operationId: InterchainAccount
362+
responses:
363+
'200':
364+
description: A successful response.
365+
schema:
366+
type: object
367+
properties:
368+
address:
369+
type: string
370+
description: >-
371+
QueryInterchainAccountResponse the response type for the
372+
Query/InterchainAccount RPC method.
373+
default:
374+
description: An unexpected error response
375+
schema:
376+
type: object
377+
properties:
378+
error:
379+
type: string
380+
code:
381+
type: integer
382+
format: int32
383+
message:
384+
type: string
385+
details:
386+
type: array
387+
items:
388+
type: object
389+
properties:
390+
type_url:
391+
type: string
392+
value:
393+
type: string
394+
format: byte
395+
parameters:
396+
- name: owner
397+
in: path
398+
required: true
399+
type: string
400+
- name: connection_id
401+
in: path
402+
required: true
403+
type: string
404+
tags:
405+
- Query
356406
/ibc/apps/interchain_accounts/controller/v1/params:
357407
get:
358408
summary: Params queries all parameters of the ICA controller submodule.
@@ -13232,6 +13282,14 @@ definitions:
1323213282
description: |-
1323313283
Params defines the set of on-chain interchain accounts parameters.
1323413284
The following parameters may be used to disable the controller submodule.
13285+
ibc.applications.interchain_accounts.controller.v1.QueryInterchainAccountResponse:
13286+
type: object
13287+
properties:
13288+
address:
13289+
type: string
13290+
description: >-
13291+
QueryInterchainAccountResponse the response type for the
13292+
Query/InterchainAccount RPC method.
1323513293
ibc.applications.interchain_accounts.controller.v1.QueryParamsResponse:
1323613294
type: object
1323713295
properties:

docs/ibc/proto-docs.md

+34
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

+1
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

+34
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,40 @@ import (
1111
"github.com/cosmos/ibc-go/v4/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

+31-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,45 @@ 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

10+
<<<<<<< HEAD
811
"github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types"
12+
=======
13+
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
14+
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
15+
>>>>>>> e569045 (feat: adding interchain account address query to controller submodule (#2193))
916
)
1017

1118
var _ types.QueryServer = Keeper{}
1219

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

1847
return &types.QueryParamsResponse{
1948
Params: &params,

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

+73
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,82 @@ package keeper_test
33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55

6+
<<<<<<< HEAD
67
"github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types"
8+
=======
9+
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
10+
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
11+
ibctesting "github.com/cosmos/ibc-go/v5/testing"
12+
>>>>>>> e569045 (feat: adding interchain account address query to controller submodule (#2193))
713
)
814

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

0 commit comments

Comments
 (0)