Skip to content

Commit

Permalink
backport #1416 to v2.3.x (#1495)
Browse files Browse the repository at this point in the history
* backport #1416

* fix go.mod

Co-authored-by: Cian Hatton <[email protected]>
Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
3 people authored Jun 8, 2022
1 parent 7374d31 commit f10135d
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (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

* (modules/core/04-channel) [\#1130](https://github.com/cosmos/ibc-go/pull/1130) Call `packet.GetSequence()` rather than passing func in `WriteAcknowledgement` log output
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 @@ -9975,6 +10028,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 @@ -18,6 +18,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 @@ -445,6 +447,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 @@ -487,6 +520,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 @@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v2/testing"
)

func (suite *KeeperTestSuite) TestQueryDenomTrace() {
Expand Down Expand Up @@ -207,3 +208,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 f10135d

Please sign in to comment.