-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathquery.rpc.Service.ts
87 lines (87 loc) · 5.13 KB
/
query.rpc.Service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { TxRpc } from "../../../../types";
import { BinaryReader } from "../../../../binary";
import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate";
import { GetNodeInfoRequest, GetNodeInfoResponse, GetSyncingRequest, GetSyncingResponse, GetLatestBlockRequest, GetLatestBlockResponse, GetBlockByHeightRequest, GetBlockByHeightResponse, GetLatestValidatorSetRequest, GetLatestValidatorSetResponse, GetValidatorSetByHeightRequest, GetValidatorSetByHeightResponse } from "./query";
/** Service defines the gRPC querier service for tendermint queries. */
export interface Service {
/** GetNodeInfo queries the current node info. */
getNodeInfo(request?: GetNodeInfoRequest): Promise<GetNodeInfoResponse>;
/** GetSyncing queries node syncing. */
getSyncing(request?: GetSyncingRequest): Promise<GetSyncingResponse>;
/** GetLatestBlock returns the latest block. */
getLatestBlock(request?: GetLatestBlockRequest): Promise<GetLatestBlockResponse>;
/** GetBlockByHeight queries block for given height. */
getBlockByHeight(request: GetBlockByHeightRequest): Promise<GetBlockByHeightResponse>;
/** GetLatestValidatorSet queries latest validator-set. */
getLatestValidatorSet(request?: GetLatestValidatorSetRequest): Promise<GetLatestValidatorSetResponse>;
/** GetValidatorSetByHeight queries validator-set at a given height. */
getValidatorSetByHeight(request: GetValidatorSetByHeightRequest): Promise<GetValidatorSetByHeightResponse>;
}
export class ServiceClientImpl implements Service {
private readonly rpc: TxRpc;
constructor(rpc: TxRpc) {
this.rpc = rpc;
this.getNodeInfo = this.getNodeInfo.bind(this);
this.getSyncing = this.getSyncing.bind(this);
this.getLatestBlock = this.getLatestBlock.bind(this);
this.getBlockByHeight = this.getBlockByHeight.bind(this);
this.getLatestValidatorSet = this.getLatestValidatorSet.bind(this);
this.getValidatorSetByHeight = this.getValidatorSetByHeight.bind(this);
}
getNodeInfo(request: GetNodeInfoRequest = {}): Promise<GetNodeInfoResponse> {
const data = GetNodeInfoRequest.encode(request).finish();
const promise = this.rpc.request("cosmos.base.tendermint.v1beta1.Service", "GetNodeInfo", data);
return promise.then(data => GetNodeInfoResponse.decode(new BinaryReader(data)));
}
getSyncing(request: GetSyncingRequest = {}): Promise<GetSyncingResponse> {
const data = GetSyncingRequest.encode(request).finish();
const promise = this.rpc.request("cosmos.base.tendermint.v1beta1.Service", "GetSyncing", data);
return promise.then(data => GetSyncingResponse.decode(new BinaryReader(data)));
}
getLatestBlock(request: GetLatestBlockRequest = {}): Promise<GetLatestBlockResponse> {
const data = GetLatestBlockRequest.encode(request).finish();
const promise = this.rpc.request("cosmos.base.tendermint.v1beta1.Service", "GetLatestBlock", data);
return promise.then(data => GetLatestBlockResponse.decode(new BinaryReader(data)));
}
getBlockByHeight(request: GetBlockByHeightRequest): Promise<GetBlockByHeightResponse> {
const data = GetBlockByHeightRequest.encode(request).finish();
const promise = this.rpc.request("cosmos.base.tendermint.v1beta1.Service", "GetBlockByHeight", data);
return promise.then(data => GetBlockByHeightResponse.decode(new BinaryReader(data)));
}
getLatestValidatorSet(request: GetLatestValidatorSetRequest = {
pagination: undefined
}): Promise<GetLatestValidatorSetResponse> {
const data = GetLatestValidatorSetRequest.encode(request).finish();
const promise = this.rpc.request("cosmos.base.tendermint.v1beta1.Service", "GetLatestValidatorSet", data);
return promise.then(data => GetLatestValidatorSetResponse.decode(new BinaryReader(data)));
}
getValidatorSetByHeight(request: GetValidatorSetByHeightRequest): Promise<GetValidatorSetByHeightResponse> {
const data = GetValidatorSetByHeightRequest.encode(request).finish();
const promise = this.rpc.request("cosmos.base.tendermint.v1beta1.Service", "GetValidatorSetByHeight", data);
return promise.then(data => GetValidatorSetByHeightResponse.decode(new BinaryReader(data)));
}
}
export const createRpcQueryExtension = (base: QueryClient) => {
const rpc = createProtobufRpcClient(base);
const queryService = new ServiceClientImpl(rpc);
return {
getNodeInfo(request?: GetNodeInfoRequest): Promise<GetNodeInfoResponse> {
return queryService.getNodeInfo(request);
},
getSyncing(request?: GetSyncingRequest): Promise<GetSyncingResponse> {
return queryService.getSyncing(request);
},
getLatestBlock(request?: GetLatestBlockRequest): Promise<GetLatestBlockResponse> {
return queryService.getLatestBlock(request);
},
getBlockByHeight(request: GetBlockByHeightRequest): Promise<GetBlockByHeightResponse> {
return queryService.getBlockByHeight(request);
},
getLatestValidatorSet(request?: GetLatestValidatorSetRequest): Promise<GetLatestValidatorSetResponse> {
return queryService.getLatestValidatorSet(request);
},
getValidatorSetByHeight(request: GetValidatorSetByHeightRequest): Promise<GetValidatorSetByHeightResponse> {
return queryService.getValidatorSetByHeight(request);
}
};
};