Skip to content

Commit 899f791

Browse files
authored
Adding gRPC query for escrow address (#1416)
1 parent 373e1e6 commit 899f791

File tree

8 files changed

+772
-39
lines changed

8 files changed

+772
-39
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
6868
* (apps/29-fee) [\#1224](https://github.com/cosmos/ibc-go/pull/1224) Adding Query/CounterpartyAddress and CLI to ICS29 fee middleware
6969
* (apps/29-fee) [\#1225](https://github.com/cosmos/ibc-go/pull/1225) Adding Query/FeeEnabledChannel and Query/FeeEnabledChannels with CLIs to ICS29 fee middleware.
7070
* (modules/apps/29-fee) [\#1230](https://github.com/cosmos/ibc-go/pull/1230) Adding CLI command for getting incentivized packets for a specific channel-id.
71+
* (modules/apps/transfer) [\#1416](https://github.com/cosmos/ibc-go/pull/1416) Adding gRPC endpoint for getting an escrow account for a given port-id and channel-id.
7172

7273
### Bug Fixes
7374

docs/client/swagger-ui/swagger.yaml

+62
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,59 @@ info:
44
description: A REST interface for state queries
55
version: 1.0.0
66
paths:
7+
'/ibc/apps/transfer/v1/channels/{channel_id}/ports/{port_id}/escrow_address':
8+
get:
9+
summary: >-
10+
EscrowAddress returns the escrow address for a particular port and
11+
channel id.
12+
operationId: EscrowAddress
13+
responses:
14+
'200':
15+
description: A successful response.
16+
schema:
17+
type: object
18+
properties:
19+
escrow_address:
20+
type: string
21+
title: the escrow account address
22+
description: >-
23+
QueryEscrowAddressResponse is the response type of the
24+
EscrowAddress RPC method.
25+
default:
26+
description: An unexpected error response
27+
schema:
28+
type: object
29+
properties:
30+
error:
31+
type: string
32+
code:
33+
type: integer
34+
format: int32
35+
message:
36+
type: string
37+
details:
38+
type: array
39+
items:
40+
type: object
41+
properties:
42+
type_url:
43+
type: string
44+
value:
45+
type: string
46+
format: byte
47+
parameters:
48+
- name: channel_id
49+
description: unique channel identifier
50+
in: path
51+
required: true
52+
type: string
53+
- name: port_id
54+
description: unique port identifier
55+
in: path
56+
required: true
57+
type: string
58+
tags:
59+
- Query
760
'/ibc/apps/transfer/v1/denom_hashes/{trace}':
861
get:
962
summary: DenomHash queries a denomination hash information.
@@ -12584,6 +12637,15 @@ definitions:
1258412637
QueryConnectionsResponse is the response type for the Query/DenomTraces
1258512638
RPC
1258612639

12640+
method.
12641+
ibc.applications.transfer.v1.QueryEscrowAddressResponse:
12642+
type: object
12643+
properties:
12644+
escrow_address:
12645+
type: string
12646+
title: the escrow account address
12647+
description: >-
12648+
QueryEscrowAddressResponse is the response type of the EscrowAddress RPC
1258712649
method.
1258812650
ibc.applications.transfer.v1.QueryParamsResponse:
1258912651
type: object

docs/ibc/proto-docs.md

+34
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
- [QueryDenomTraceResponse](#ibc.applications.transfer.v1.QueryDenomTraceResponse)
127127
- [QueryDenomTracesRequest](#ibc.applications.transfer.v1.QueryDenomTracesRequest)
128128
- [QueryDenomTracesResponse](#ibc.applications.transfer.v1.QueryDenomTracesResponse)
129+
- [QueryEscrowAddressRequest](#ibc.applications.transfer.v1.QueryEscrowAddressRequest)
130+
- [QueryEscrowAddressResponse](#ibc.applications.transfer.v1.QueryEscrowAddressResponse)
129131
- [QueryParamsRequest](#ibc.applications.transfer.v1.QueryParamsRequest)
130132
- [QueryParamsResponse](#ibc.applications.transfer.v1.QueryParamsResponse)
131133

@@ -1920,6 +1922,37 @@ method.
19201922

19211923

19221924

1925+
<a name="ibc.applications.transfer.v1.QueryEscrowAddressRequest"></a>
1926+
1927+
### QueryEscrowAddressRequest
1928+
QueryEscrowAddressRequest is the request type for the EscrowAddress RPC method.
1929+
1930+
1931+
| Field | Type | Label | Description |
1932+
| ----- | ---- | ----- | ----------- |
1933+
| `port_id` | [string](#string) | | unique port identifier |
1934+
| `channel_id` | [string](#string) | | unique channel identifier |
1935+
1936+
1937+
1938+
1939+
1940+
1941+
<a name="ibc.applications.transfer.v1.QueryEscrowAddressResponse"></a>
1942+
1943+
### QueryEscrowAddressResponse
1944+
QueryEscrowAddressResponse is the response type of the EscrowAddress RPC method.
1945+
1946+
1947+
| Field | Type | Label | Description |
1948+
| ----- | ---- | ----- | ----------- |
1949+
| `escrow_address` | [string](#string) | | the escrow account address |
1950+
1951+
1952+
1953+
1954+
1955+
19231956
<a name="ibc.applications.transfer.v1.QueryParamsRequest"></a>
19241957

19251958
### QueryParamsRequest
@@ -1962,6 +1995,7 @@ Query provides defines the gRPC querier service.
19621995
| `DenomTraces` | [QueryDenomTracesRequest](#ibc.applications.transfer.v1.QueryDenomTracesRequest) | [QueryDenomTracesResponse](#ibc.applications.transfer.v1.QueryDenomTracesResponse) | DenomTraces queries all denomination traces. | GET|/ibc/apps/transfer/v1/denom_traces|
19631996
| `Params` | [QueryParamsRequest](#ibc.applications.transfer.v1.QueryParamsRequest) | [QueryParamsResponse](#ibc.applications.transfer.v1.QueryParamsResponse) | Params queries all parameters of the ibc-transfer module. | GET|/ibc/apps/transfer/v1/params|
19641997
| `DenomHash` | [QueryDenomHashRequest](#ibc.applications.transfer.v1.QueryDenomHashRequest) | [QueryDenomHashResponse](#ibc.applications.transfer.v1.QueryDenomHashResponse) | DenomHash queries a denomination hash information. | GET|/ibc/apps/transfer/v1/denom_hashes/{trace}|
1998+
| `EscrowAddress` | [QueryEscrowAddressRequest](#ibc.applications.transfer.v1.QueryEscrowAddressRequest) | [QueryEscrowAddressResponse](#ibc.applications.transfer.v1.QueryEscrowAddressResponse) | EscrowAddress returns the escrow address for a particular port and channel id. | GET|/ibc/apps/transfer/v1/channels/{channel_id}/ports/{port_id}/escrow_address|
19651999

19662000
<!-- end services -->
19672001

modules/apps/transfer/keeper/grpc_query.go

+13
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,16 @@ func (q Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) (
108108
Hash: denomHash.String(),
109109
}, nil
110110
}
111+
112+
// EscrowAddress implements the EscrowAddress gRPC method
113+
func (q Keeper) EscrowAddress(c context.Context, req *types.QueryEscrowAddressRequest) (*types.QueryEscrowAddressResponse, error) {
114+
if req == nil {
115+
return nil, status.Error(codes.InvalidArgument, "empty request")
116+
}
117+
118+
addr := types.GetEscrowAddress(req.PortId, req.ChannelId)
119+
120+
return &types.QueryEscrowAddressResponse{
121+
EscrowAddress: addr.String(),
122+
}, nil
123+
}

modules/apps/transfer/keeper/grpc_query_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/cosmos/cosmos-sdk/types/query"
88

99
"github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
10+
ibctesting "github.com/cosmos/ibc-go/v3/testing"
1011
)
1112

1213
func (suite *KeeperTestSuite) TestQueryDenomTrace() {
@@ -220,3 +221,45 @@ func (suite *KeeperTestSuite) TestQueryDenomHash() {
220221
})
221222
}
222223
}
224+
225+
func (suite *KeeperTestSuite) TestEscrowAddress() {
226+
var (
227+
req *types.QueryEscrowAddressRequest
228+
)
229+
230+
testCases := []struct {
231+
msg string
232+
malleate func()
233+
expPass bool
234+
}{
235+
{
236+
"success",
237+
func() {
238+
req = &types.QueryEscrowAddressRequest{
239+
PortId: ibctesting.TransferPort,
240+
ChannelId: ibctesting.FirstChannelID,
241+
}
242+
},
243+
true,
244+
},
245+
}
246+
247+
for _, tc := range testCases {
248+
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
249+
suite.SetupTest() // reset
250+
251+
tc.malleate()
252+
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
253+
254+
res, err := suite.queryClient.EscrowAddress(ctx, req)
255+
256+
if tc.expPass {
257+
suite.Require().NoError(err)
258+
expected := types.GetEscrowAddress(ibctesting.TransferPort, ibctesting.FirstChannelID).String()
259+
suite.Require().Equal(expected, res.EscrowAddress)
260+
} else {
261+
suite.Require().Error(err)
262+
}
263+
})
264+
}
265+
}

0 commit comments

Comments
 (0)