Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: Cian Hatton <[email protected]>
  • Loading branch information
2 people authored and dudong2 committed Jan 19, 2023
1 parent ddd5986 commit 7984678
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 0 deletions.
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 @@ -10173,6 +10226,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 @@ -110,3 +110,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/line/lbm-sdk/types/query"

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

func (suite *KeeperTestSuite) TestQueryDenomTrace() {
Expand Down Expand Up @@ -221,3 +222,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)
}
})
}
}
19 changes: 19 additions & 0 deletions proto/ibc/applications/transfer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ service Query {
rpc DenomHash(QueryDenomHashRequest) returns (QueryDenomHashResponse) {
option (google.api.http).get = "/ibc/apps/transfer/v1/denom_hashes/{trace}";
}

// EscrowAddress returns the escrow address for a particular port and channel id.
rpc EscrowAddress(QueryEscrowAddressRequest) returns (QueryEscrowAddressResponse) {
option (google.api.http).get = "/ibc/apps/transfer/v1/channels/{channel_id}/ports/{port_id}/escrow_address";
}
}

// QueryDenomTraceRequest is the request type for the Query/DenomTrace RPC
Expand Down Expand Up @@ -84,3 +89,17 @@ message QueryDenomHashResponse {
// hash (in hex format) of the denomination trace information.
string hash = 1;
}

// QueryEscrowAddressRequest is the request type for the EscrowAddress RPC method.
message QueryEscrowAddressRequest {
// unique port identifier
string port_id = 1;
// unique channel identifier
string channel_id = 2;
}

// QueryEscrowAddressResponse is the response type of the EscrowAddress RPC method.
message QueryEscrowAddressResponse {
// the escrow account address
string escrow_address = 1;
}

0 comments on commit 7984678

Please sign in to comment.