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

feat: add new query for pending nonces using chain id #1131

Merged
merged 7 commits into from
Sep 20, 2023
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
25 changes: 25 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27213,6 +27213,26 @@ paths:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/crosschain/pendingNonces/{chain_id}:
get:
operationId: Query_PendingNoncesByChain
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/crosschainQueryPendingNoncesByChainResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: chain_id
in: path
required: true
type: string
format: uint64
tags:
- Query
/zeta-chain/crosschain/protocolFee:
get:
operationId: Query_ProtocolFee
Expand Down Expand Up @@ -50660,6 +50680,11 @@ definitions:
properties:
feeInZeta:
type: string
crosschainQueryPendingNoncesByChainResponse:
type: object
properties:
pending_nonces:
$ref: '#/definitions/crosschainPendingNonces'
crosschainQueryTssHistoryResponse:
type: object
properties:
Expand Down
12 changes: 12 additions & 0 deletions proto/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ service Query {
option (google.api.http).get = "/zeta-chain/crosschain/pendingNonces";
}

rpc PendingNoncesByChain(QueryPendingNoncesByChainRequest) returns (QueryPendingNoncesByChainResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/pendingNonces/{chain_id}";
}

// Queries a lastBlockHeight by index.
rpc LastBlockHeight(QueryGetLastBlockHeightRequest) returns (QueryGetLastBlockHeightResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/lastBlockHeight/{index}";
Expand Down Expand Up @@ -253,6 +257,14 @@ message QueryAllPendingNoncesResponse {
repeated PendingNonces pending_nonces = 1;
}

message QueryPendingNoncesByChainRequest {
uint64 chain_id = 1;
}

message QueryPendingNoncesByChainResponse {
PendingNonces pending_nonces = 1 [(gogoproto.nullable) = false];
}

Comment on lines +260 to +267
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a very big deal but maybe we might want to keep the same order for message definitions as rpc endpoint definitions above

message QueryGetLastBlockHeightRequest {
string index = 1;
}
Expand Down
20 changes: 20 additions & 0 deletions x/crosschain/keeper/keeper_pending_nonces.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,23 @@ func (k Keeper) PendingNoncesAll(c context.Context, req *types.QueryAllPendingNo
PendingNonces: list,
}, nil
}

func (k Keeper) PendingNoncesByChain(c context.Context, req *types.QueryPendingNoncesByChainRequest) (*types.QueryPendingNoncesByChainResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(c)
tss, found := k.GetTSS(ctx)
if !found {
return nil, status.Error(codes.NotFound, "tss not found")
}
list, found := k.GetPendingNonces(ctx, tss.TssPubkey, req.ChainId)
if !found {
return nil, status.Error(codes.NotFound, fmt.Sprintf("pending nonces not found for chain id : %d", req.ChainId))
}

return &types.QueryPendingNoncesByChainResponse{
PendingNonces: list,
}, nil
}
Loading
Loading