-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathquery.rpc.Query.ts
149 lines (149 loc) · 7.64 KB
/
query.rpc.Query.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { TxRpc } from '../types';
import { BinaryReader } from '../binary';
import { QueryClient, createProtobufRpcClient } from '@cosmjs/stargate';
import {
QueryExchangeRateRequest,
QueryExchangeRateResponse,
QueryExchangeRatesRequest,
QueryExchangeRatesResponse,
QueryActivesRequest,
QueryActivesResponse,
QueryVoteTargetsRequest,
QueryVoteTargetsResponse,
QueryPriceSnapshotHistoryRequest,
QueryPriceSnapshotHistoryResponse,
QueryTwapsRequest,
QueryTwapsResponse,
QueryFeederDelegationRequest,
QueryFeederDelegationResponse,
QueryVotePenaltyCounterRequest,
QueryVotePenaltyCounterResponse,
QuerySlashWindowRequest,
QuerySlashWindowResponse,
QueryParamsRequest,
QueryParamsResponse
} from './query';
/** Query defines the gRPC querier service. */
export interface Query {
/** ExchangeRate returns exchange rate of a denom */
exchangeRate(request: QueryExchangeRateRequest): Promise<QueryExchangeRateResponse>;
/** ExchangeRates returns exchange rates of all denoms */
exchangeRates(request?: QueryExchangeRatesRequest): Promise<QueryExchangeRatesResponse>;
/** Actives returns all active denoms */
actives(request?: QueryActivesRequest): Promise<QueryActivesResponse>;
/** VoteTargets returns all vote target denoms */
voteTargets(request?: QueryVoteTargetsRequest): Promise<QueryVoteTargetsResponse>;
/** PriceSnapshotHistory returns the history of price snapshots for all assets */
priceSnapshotHistory(request?: QueryPriceSnapshotHistoryRequest): Promise<QueryPriceSnapshotHistoryResponse>;
twaps(request: QueryTwapsRequest): Promise<QueryTwapsResponse>;
/** FeederDelegation returns feeder delegation of a validator */
feederDelegation(request: QueryFeederDelegationRequest): Promise<QueryFeederDelegationResponse>;
/** MissCounter returns oracle miss counter of a validator */
votePenaltyCounter(request: QueryVotePenaltyCounterRequest): Promise<QueryVotePenaltyCounterResponse>;
/** SlashWindow returns slash window information */
slashWindow(request?: QuerySlashWindowRequest): Promise<QuerySlashWindowResponse>;
/** Params queries all parameters. */
params(request?: QueryParamsRequest): Promise<QueryParamsResponse>;
}
export class QueryClientImpl implements Query {
private readonly rpc: TxRpc;
constructor(rpc: TxRpc) {
this.rpc = rpc;
this.exchangeRate = this.exchangeRate.bind(this);
this.exchangeRates = this.exchangeRates.bind(this);
this.actives = this.actives.bind(this);
this.voteTargets = this.voteTargets.bind(this);
this.priceSnapshotHistory = this.priceSnapshotHistory.bind(this);
this.twaps = this.twaps.bind(this);
this.feederDelegation = this.feederDelegation.bind(this);
this.votePenaltyCounter = this.votePenaltyCounter.bind(this);
this.slashWindow = this.slashWindow.bind(this);
this.params = this.params.bind(this);
}
exchangeRate(request: QueryExchangeRateRequest): Promise<QueryExchangeRateResponse> {
const data = QueryExchangeRateRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'ExchangeRate', data);
return promise.then((data) => QueryExchangeRateResponse.decode(new BinaryReader(data)));
}
exchangeRates(request: QueryExchangeRatesRequest = {}): Promise<QueryExchangeRatesResponse> {
const data = QueryExchangeRatesRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'ExchangeRates', data);
return promise.then((data) => QueryExchangeRatesResponse.decode(new BinaryReader(data)));
}
actives(request: QueryActivesRequest = {}): Promise<QueryActivesResponse> {
const data = QueryActivesRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'Actives', data);
return promise.then((data) => QueryActivesResponse.decode(new BinaryReader(data)));
}
voteTargets(request: QueryVoteTargetsRequest = {}): Promise<QueryVoteTargetsResponse> {
const data = QueryVoteTargetsRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'VoteTargets', data);
return promise.then((data) => QueryVoteTargetsResponse.decode(new BinaryReader(data)));
}
priceSnapshotHistory(request: QueryPriceSnapshotHistoryRequest = {}): Promise<QueryPriceSnapshotHistoryResponse> {
const data = QueryPriceSnapshotHistoryRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'PriceSnapshotHistory', data);
return promise.then((data) => QueryPriceSnapshotHistoryResponse.decode(new BinaryReader(data)));
}
twaps(request: QueryTwapsRequest): Promise<QueryTwapsResponse> {
const data = QueryTwapsRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'Twaps', data);
return promise.then((data) => QueryTwapsResponse.decode(new BinaryReader(data)));
}
feederDelegation(request: QueryFeederDelegationRequest): Promise<QueryFeederDelegationResponse> {
const data = QueryFeederDelegationRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'FeederDelegation', data);
return promise.then((data) => QueryFeederDelegationResponse.decode(new BinaryReader(data)));
}
votePenaltyCounter(request: QueryVotePenaltyCounterRequest): Promise<QueryVotePenaltyCounterResponse> {
const data = QueryVotePenaltyCounterRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'VotePenaltyCounter', data);
return promise.then((data) => QueryVotePenaltyCounterResponse.decode(new BinaryReader(data)));
}
slashWindow(request: QuerySlashWindowRequest = {}): Promise<QuerySlashWindowResponse> {
const data = QuerySlashWindowRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'SlashWindow', data);
return promise.then((data) => QuerySlashWindowResponse.decode(new BinaryReader(data)));
}
params(request: QueryParamsRequest = {}): Promise<QueryParamsResponse> {
const data = QueryParamsRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.oracle.Query', 'Params', data);
return promise.then((data) => QueryParamsResponse.decode(new BinaryReader(data)));
}
}
export const createRpcQueryExtension = (base: QueryClient) => {
const rpc = createProtobufRpcClient(base);
const queryService = new QueryClientImpl(rpc);
return {
exchangeRate(request: QueryExchangeRateRequest): Promise<QueryExchangeRateResponse> {
return queryService.exchangeRate(request);
},
exchangeRates(request?: QueryExchangeRatesRequest): Promise<QueryExchangeRatesResponse> {
return queryService.exchangeRates(request);
},
actives(request?: QueryActivesRequest): Promise<QueryActivesResponse> {
return queryService.actives(request);
},
voteTargets(request?: QueryVoteTargetsRequest): Promise<QueryVoteTargetsResponse> {
return queryService.voteTargets(request);
},
priceSnapshotHistory(request?: QueryPriceSnapshotHistoryRequest): Promise<QueryPriceSnapshotHistoryResponse> {
return queryService.priceSnapshotHistory(request);
},
twaps(request: QueryTwapsRequest): Promise<QueryTwapsResponse> {
return queryService.twaps(request);
},
feederDelegation(request: QueryFeederDelegationRequest): Promise<QueryFeederDelegationResponse> {
return queryService.feederDelegation(request);
},
votePenaltyCounter(request: QueryVotePenaltyCounterRequest): Promise<QueryVotePenaltyCounterResponse> {
return queryService.votePenaltyCounter(request);
},
slashWindow(request?: QuerySlashWindowRequest): Promise<QuerySlashWindowResponse> {
return queryService.slashWindow(request);
},
params(request?: QueryParamsRequest): Promise<QueryParamsResponse> {
return queryService.params(request);
}
};
};