Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport #1416 to v3.1.x #1496

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -10074,6 +10127,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 @@ -37,6 +37,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 @@ -692,6 +694,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 @@ -734,6 +767,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 @@ -208,3 +209,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