import { Rpc } from "../../../../helpers"; import * as _m0 from "protobufjs/minimal"; import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate"; import { GetNodeInfoRequest, GetNodeInfoResponse, GetSyncingRequest, GetSyncingResponse, GetLatestBlockRequest, GetLatestBlockResponse, GetBlockByHeightRequest, GetBlockByHeightResponse, GetLatestValidatorSetRequest, GetLatestValidatorSetResponse, GetValidatorSetByHeightRequest, GetValidatorSetByHeightResponse, ABCIQueryRequest, ABCIQueryResponse } from "./query"; /** Service defines the gRPC querier service for tendermint queries. */ export interface Service { /** GetNodeInfo queries the current node info. */ getNodeInfo(request?: GetNodeInfoRequest): Promise; /** GetSyncing queries node syncing. */ getSyncing(request?: GetSyncingRequest): Promise; /** GetLatestBlock returns the latest block. */ getLatestBlock(request?: GetLatestBlockRequest): Promise; /** GetBlockByHeight queries block for given height. */ getBlockByHeight(request: GetBlockByHeightRequest): Promise; /** GetLatestValidatorSet queries latest validator-set. */ getLatestValidatorSet(request?: GetLatestValidatorSetRequest): Promise; /** GetValidatorSetByHeight queries validator-set at a given height. */ getValidatorSetByHeight(request: GetValidatorSetByHeightRequest): Promise; /** * ABCIQuery defines a query handler that supports ABCI queries directly to the * application, bypassing Tendermint completely. The ABCI query must contain * a valid and supported path, including app, custom, p2p, and store. * * Since: cosmos-sdk 0.46 */ aBCIQuery(request: ABCIQueryRequest): Promise; } export class ServiceClientImpl implements Service { private readonly rpc: Rpc; constructor(rpc: Rpc) { 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); this.aBCIQuery = this.aBCIQuery.bind(this); } getNodeInfo(request: GetNodeInfoRequest = {}): Promise { 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 _m0.Reader(data))); } getSyncing(request: GetSyncingRequest = {}): Promise { 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 _m0.Reader(data))); } getLatestBlock(request: GetLatestBlockRequest = {}): Promise { 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 _m0.Reader(data))); } getBlockByHeight(request: GetBlockByHeightRequest): Promise { 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 _m0.Reader(data))); } getLatestValidatorSet(request: GetLatestValidatorSetRequest = { pagination: undefined }): Promise { 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 _m0.Reader(data))); } getValidatorSetByHeight(request: GetValidatorSetByHeightRequest): Promise { 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 _m0.Reader(data))); } aBCIQuery(request: ABCIQueryRequest): Promise { const data = ABCIQueryRequest.encode(request).finish(); const promise = this.rpc.request("cosmos.base.tendermint.v1beta1.Service", "ABCIQuery", data); return promise.then(data => ABCIQueryResponse.decode(new _m0.Reader(data))); } } export const createRpcQueryExtension = (base: QueryClient) => { const rpc = createProtobufRpcClient(base); const queryService = new ServiceClientImpl(rpc); return { getNodeInfo(request?: GetNodeInfoRequest): Promise { return queryService.getNodeInfo(request); }, getSyncing(request?: GetSyncingRequest): Promise { return queryService.getSyncing(request); }, getLatestBlock(request?: GetLatestBlockRequest): Promise { return queryService.getLatestBlock(request); }, getBlockByHeight(request: GetBlockByHeightRequest): Promise { return queryService.getBlockByHeight(request); }, getLatestValidatorSet(request?: GetLatestValidatorSetRequest): Promise { return queryService.getLatestValidatorSet(request); }, getValidatorSetByHeight(request: GetValidatorSetByHeightRequest): Promise { return queryService.getValidatorSetByHeight(request); }, aBCIQuery(request: ABCIQueryRequest): Promise { return queryService.aBCIQuery(request); } }; };