Skip to content

Commit

Permalink
Adding gRPC query for escrow address (cosmos#1416)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton committed May 30, 2022
1 parent 373e1e6 commit 899f791
Show file tree
Hide file tree
Showing 8 changed files with 772 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (apps/29-fee) [\#1224](https://github.com/cosmos/ibc-go/pull/1224) Adding Query/CounterpartyAddress and CLI to ICS29 fee middleware
* (apps/29-fee) [\#1225](https://github.com/cosmos/ibc-go/pull/1225) Adding Query/FeeEnabledChannel and Query/FeeEnabledChannels with CLIs to ICS29 fee middleware.
* (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.
* (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.

### Bug Fixes

Expand Down
62 changes: 62 additions & 0 deletions docs/client/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,59 @@ info:
description: A REST interface for state queries
version: 1.0.0
paths:
'/ibc/apps/transfer/v1/channels/{channel_id}/ports/{port_id}/escrow_address':
get:
summary: >-
EscrowAddress returns the escrow address for a particular port and
channel id.
operationId: EscrowAddress
responses:
'200':
description: A successful response.
schema:
type: object
properties:
escrow_address:
type: string
title: the escrow account address
description: >-
QueryEscrowAddressResponse is the response type of the
EscrowAddress RPC method.
default:
description: An unexpected error response
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: channel_id
description: unique channel identifier
in: path
required: true
type: string
- name: port_id
description: unique port identifier
in: path
required: true
type: string
tags:
- Query
'/ibc/apps/transfer/v1/denom_hashes/{trace}':
get:
summary: DenomHash queries a denomination hash information.
Expand Down Expand Up @@ -12584,6 +12637,15 @@ definitions:
QueryConnectionsResponse is the response type for the Query/DenomTraces
RPC

method.
ibc.applications.transfer.v1.QueryEscrowAddressResponse:
type: object
properties:
escrow_address:
type: string
title: the escrow account address
description: >-
QueryEscrowAddressResponse is the response type of the EscrowAddress RPC
method.
ibc.applications.transfer.v1.QueryParamsResponse:
type: object
Expand Down
34 changes: 34 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
- [QueryDenomTraceResponse](#ibc.applications.transfer.v1.QueryDenomTraceResponse)
- [QueryDenomTracesRequest](#ibc.applications.transfer.v1.QueryDenomTracesRequest)
- [QueryDenomTracesResponse](#ibc.applications.transfer.v1.QueryDenomTracesResponse)
- [QueryEscrowAddressRequest](#ibc.applications.transfer.v1.QueryEscrowAddressRequest)
- [QueryEscrowAddressResponse](#ibc.applications.transfer.v1.QueryEscrowAddressResponse)
- [QueryParamsRequest](#ibc.applications.transfer.v1.QueryParamsRequest)
- [QueryParamsResponse](#ibc.applications.transfer.v1.QueryParamsResponse)

Expand Down Expand Up @@ -1920,6 +1922,37 @@ method.



<a name="ibc.applications.transfer.v1.QueryEscrowAddressRequest"></a>

### QueryEscrowAddressRequest
QueryEscrowAddressRequest is the request type for the EscrowAddress RPC method.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `port_id` | [string](#string) | | unique port identifier |
| `channel_id` | [string](#string) | | unique channel identifier |






<a name="ibc.applications.transfer.v1.QueryEscrowAddressResponse"></a>

### QueryEscrowAddressResponse
QueryEscrowAddressResponse is the response type of the EscrowAddress RPC method.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `escrow_address` | [string](#string) | | the escrow account address |






<a name="ibc.applications.transfer.v1.QueryParamsRequest"></a>

### QueryParamsRequest
Expand Down Expand Up @@ -1962,6 +1995,7 @@ Query provides defines the gRPC querier service.
| `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|
| `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|
| `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}|
| `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|

<!-- end services -->

Expand Down
13 changes: 13 additions & 0 deletions modules/apps/transfer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,16 @@ func (q Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) (
Hash: denomHash.String(),
}, nil
}

// EscrowAddress implements the EscrowAddress gRPC method
func (q Keeper) EscrowAddress(c context.Context, req *types.QueryEscrowAddressRequest) (*types.QueryEscrowAddressResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

addr := types.GetEscrowAddress(req.PortId, req.ChannelId)

return &types.QueryEscrowAddressResponse{
EscrowAddress: addr.String(),
}, nil
}
43 changes: 43 additions & 0 deletions modules/apps/transfer/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/query"

"github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
)

func (suite *KeeperTestSuite) TestQueryDenomTrace() {
Expand Down Expand Up @@ -220,3 +221,45 @@ func (suite *KeeperTestSuite) TestQueryDenomHash() {
})
}
}

func (suite *KeeperTestSuite) TestEscrowAddress() {
var (
req *types.QueryEscrowAddressRequest
)

testCases := []struct {
msg string
malleate func()
expPass bool
}{
{
"success",
func() {
req = &types.QueryEscrowAddressRequest{
PortId: ibctesting.TransferPort,
ChannelId: ibctesting.FirstChannelID,
}
},
true,
},
}

for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset

tc.malleate()
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())

res, err := suite.queryClient.EscrowAddress(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
expected := types.GetEscrowAddress(ibctesting.TransferPort, ibctesting.FirstChannelID).String()
suite.Require().Equal(expected, res.EscrowAddress)
} else {
suite.Require().Error(err)
}
})
}
}
Loading

0 comments on commit 899f791

Please sign in to comment.