carbon-js-sdk 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/clients/CarbonTendermintClient.d.ts +117 -0
- package/lib/clients/CarbonTendermintClient.js +376 -0
- package/lib/constant/ibc.js +2 -1
- package/lib/util/blockchain.js +1 -1
- package/lib/wallet/CarbonTendermintClient.js +376 -0
- package/package.json +1 -1
- package/lib/codec/bank/tx.d.ts +0 -64
- package/lib/codec/bank/tx.js +0 -236
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Stream } from "xstream";
|
|
2
|
+
import { JsonRpcSuccessResponse } from "@cosmjs/json-rpc/build/types";
|
|
3
|
+
import * as requests from "@cosmjs/tendermint-rpc/build/tendermint34/requests";
|
|
4
|
+
import * as responses from "@cosmjs/tendermint-rpc/build/tendermint34/responses";
|
|
5
|
+
export interface SubscriptionEvent {
|
|
6
|
+
readonly query: string;
|
|
7
|
+
readonly data: {
|
|
8
|
+
readonly type: string;
|
|
9
|
+
readonly value: any;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare type JsonRpcId = number | string;
|
|
13
|
+
export interface JsonRpcRequest {
|
|
14
|
+
readonly jsonrpc: "2.0";
|
|
15
|
+
readonly id: JsonRpcId;
|
|
16
|
+
readonly method: string;
|
|
17
|
+
readonly params: JsonCompatibleArray | JsonCompatibleDictionary;
|
|
18
|
+
}
|
|
19
|
+
export interface JsonCompatibleArray extends ReadonlyArray<JsonCompatibleValue> {
|
|
20
|
+
}
|
|
21
|
+
export interface JsonCompatibleDictionary {
|
|
22
|
+
readonly [key: string]: JsonCompatibleValue | readonly JsonCompatibleValue[];
|
|
23
|
+
}
|
|
24
|
+
export declare type JsonCompatibleValue = JsonCompatibleDictionary | JsonCompatibleArray | string | number | boolean | null;
|
|
25
|
+
export interface RpcClient {
|
|
26
|
+
readonly execute: (request: JsonRpcRequest) => Promise<JsonRpcSuccessResponse>;
|
|
27
|
+
readonly disconnect: () => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function instanceOfRpcStreamingClient(client: RpcClient): client is RpcStreamingClient;
|
|
30
|
+
export interface RpcStreamingClient extends RpcClient {
|
|
31
|
+
readonly listen: (request: JsonRpcRequest) => Stream<SubscriptionEvent>;
|
|
32
|
+
}
|
|
33
|
+
export default class CarbonTendermintClient {
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new Tendermint client for the given endpoint.
|
|
36
|
+
*
|
|
37
|
+
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
|
|
38
|
+
*/
|
|
39
|
+
static connect(endpoint: string): Promise<CarbonTendermintClient>;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new Tendermint client given an RPC client.
|
|
42
|
+
*/
|
|
43
|
+
static create(rpcClient: RpcClient): Promise<CarbonTendermintClient>;
|
|
44
|
+
private static detectVersion;
|
|
45
|
+
private readonly client;
|
|
46
|
+
private readonly p;
|
|
47
|
+
private readonly r;
|
|
48
|
+
/**
|
|
49
|
+
* Use `CarbonTendermintClient.connect` or `CarbonTendermintClient.create` to create an instance.
|
|
50
|
+
*/
|
|
51
|
+
private constructor();
|
|
52
|
+
disconnect(): void;
|
|
53
|
+
abciInfo(): Promise<responses.AbciInfoResponse>;
|
|
54
|
+
abciQuery(params: requests.AbciQueryParams): Promise<responses.AbciQueryResponse>;
|
|
55
|
+
block(height?: number): Promise<responses.BlockResponse>;
|
|
56
|
+
blockResults(height?: number): Promise<responses.BlockResultsResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Search for events that are in a block.
|
|
59
|
+
*
|
|
60
|
+
* NOTE
|
|
61
|
+
* This method will error on any node that is running a Tendermint version lower than 0.34.9.
|
|
62
|
+
*
|
|
63
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/block_search
|
|
64
|
+
*/
|
|
65
|
+
blockSearch(params: requests.BlockSearchParams): Promise<responses.BlockSearchResponse>;
|
|
66
|
+
blockSearchAll(params: requests.BlockSearchParams): Promise<responses.BlockSearchResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Queries block headers filtered by minHeight <= height <= maxHeight.
|
|
69
|
+
*
|
|
70
|
+
* @param minHeight The minimum height to be included in the result. Defaults to 0.
|
|
71
|
+
* @param maxHeight The maximum height to be included in the result. Defaults to infinity.
|
|
72
|
+
*/
|
|
73
|
+
blockchain(minHeight?: number, maxHeight?: number): Promise<responses.BlockchainResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* Broadcast transaction to mempool and wait for response
|
|
76
|
+
*
|
|
77
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync
|
|
78
|
+
*/
|
|
79
|
+
broadcastTxSync(params: requests.BroadcastTxParams): Promise<responses.BroadcastTxSyncResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Broadcast transaction to mempool and do not wait for result
|
|
82
|
+
*
|
|
83
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async
|
|
84
|
+
*/
|
|
85
|
+
broadcastTxAsync(params: requests.BroadcastTxParams): Promise<responses.BroadcastTxAsyncResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Broadcast transaction to mempool and wait for block
|
|
88
|
+
*
|
|
89
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit
|
|
90
|
+
*/
|
|
91
|
+
broadcastTxCommit(params: requests.BroadcastTxParams): Promise<responses.BroadcastTxCommitResponse>;
|
|
92
|
+
commit(height?: number): Promise<responses.CommitResponse>;
|
|
93
|
+
genesis(): Promise<responses.GenesisResponse>;
|
|
94
|
+
health(): Promise<responses.HealthResponse>;
|
|
95
|
+
numUnconfirmedTxs(): Promise<responses.NumUnconfirmedTxsResponse>;
|
|
96
|
+
status(): Promise<responses.StatusResponse>;
|
|
97
|
+
subscribeNewBlock(): Stream<responses.NewBlockEvent>;
|
|
98
|
+
subscribeNewBlockHeader(): Stream<responses.NewBlockHeaderEvent>;
|
|
99
|
+
subscribeTx(query?: string): Stream<responses.TxEvent>;
|
|
100
|
+
/**
|
|
101
|
+
* Get a single transaction by hash
|
|
102
|
+
*
|
|
103
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx
|
|
104
|
+
*/
|
|
105
|
+
tx(params: requests.TxParams): Promise<responses.TxResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Search for transactions that are in a block
|
|
108
|
+
*
|
|
109
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx_search
|
|
110
|
+
*/
|
|
111
|
+
txSearch(params: requests.TxSearchParams): Promise<responses.TxSearchResponse>;
|
|
112
|
+
txSearchAll(params: requests.TxSearchParams): Promise<responses.TxSearchResponse>;
|
|
113
|
+
validators(params: requests.ValidatorsParams): Promise<responses.ValidatorsResponse>;
|
|
114
|
+
validatorsAll(height?: number): Promise<responses.ValidatorsResponse>;
|
|
115
|
+
private doCall;
|
|
116
|
+
private subscribe;
|
|
117
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.instanceOfRpcStreamingClient = void 0;
|
|
32
|
+
const jsonrpc_1 = require("@cosmjs/tendermint-rpc/build/jsonrpc");
|
|
33
|
+
const httpclient_1 = require("@cosmjs/tendermint-rpc/build/rpcclients/httpclient");
|
|
34
|
+
const adaptor_1 = require("@cosmjs/tendermint-rpc/build/tendermint34/adaptor");
|
|
35
|
+
const requests = __importStar(require("@cosmjs/tendermint-rpc/build/tendermint34/requests"));
|
|
36
|
+
function instanceOfRpcStreamingClient(client) {
|
|
37
|
+
return typeof client.listen === "function";
|
|
38
|
+
}
|
|
39
|
+
exports.instanceOfRpcStreamingClient = instanceOfRpcStreamingClient;
|
|
40
|
+
class CarbonTendermintClient {
|
|
41
|
+
/**
|
|
42
|
+
* Use `CarbonTendermintClient.connect` or `CarbonTendermintClient.create` to create an instance.
|
|
43
|
+
*/
|
|
44
|
+
constructor(client) {
|
|
45
|
+
this.client = client;
|
|
46
|
+
this.p = adaptor_1.adaptor34.params;
|
|
47
|
+
this.r = adaptor_1.adaptor34.responses;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new Tendermint client for the given endpoint.
|
|
51
|
+
*
|
|
52
|
+
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
|
|
53
|
+
*/
|
|
54
|
+
static connect(endpoint) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const useHttp = endpoint.startsWith("http://") || endpoint.startsWith("https://");
|
|
57
|
+
if (!useHttp) {
|
|
58
|
+
throw new Error('this client only uses httpClient.');
|
|
59
|
+
}
|
|
60
|
+
const rpcClient = new httpclient_1.HttpClient(endpoint);
|
|
61
|
+
return CarbonTendermintClient.create(rpcClient);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new Tendermint client given an RPC client.
|
|
66
|
+
*/
|
|
67
|
+
static create(rpcClient) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
// For some very strange reason I don't understand, tests start to fail on some systems
|
|
70
|
+
// (our CI) when skipping the status call before doing other queries. Sleeping a little
|
|
71
|
+
// while did not help. Thus we query the version as a way to say "hi" to the backend,
|
|
72
|
+
// even in cases where we don't use the result.
|
|
73
|
+
const _version = yield this.detectVersion(rpcClient);
|
|
74
|
+
return new CarbonTendermintClient(rpcClient);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
static detectVersion(client) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const req = (0, jsonrpc_1.createJsonRpcRequest)(requests.Method.Status);
|
|
80
|
+
const response = yield client.execute(req);
|
|
81
|
+
const result = response.result;
|
|
82
|
+
if (!result || !result.node_info) {
|
|
83
|
+
throw new Error("Unrecognized format for status response");
|
|
84
|
+
}
|
|
85
|
+
const version = result.node_info.version;
|
|
86
|
+
if (typeof version !== "string") {
|
|
87
|
+
throw new Error("Unrecognized version format: must be string");
|
|
88
|
+
}
|
|
89
|
+
return version;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
disconnect() {
|
|
93
|
+
this.client.disconnect();
|
|
94
|
+
}
|
|
95
|
+
abciInfo() {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const query = { method: requests.Method.AbciInfo };
|
|
98
|
+
return this.doCall(query, this.p.encodeAbciInfo, this.r.decodeAbciInfo);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
abciQuery(params) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const query = { params: params, method: requests.Method.AbciQuery };
|
|
104
|
+
return this.doCall(query, this.p.encodeAbciQuery, this.r.decodeAbciQuery);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
block(height) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const query = { method: requests.Method.Block, params: { height: height } };
|
|
110
|
+
return this.doCall(query, this.p.encodeBlock, this.r.decodeBlock);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
blockResults(height) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const query = {
|
|
116
|
+
method: requests.Method.BlockResults,
|
|
117
|
+
params: { height: height },
|
|
118
|
+
};
|
|
119
|
+
return this.doCall(query, this.p.encodeBlockResults, this.r.decodeBlockResults);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Search for events that are in a block.
|
|
124
|
+
*
|
|
125
|
+
* NOTE
|
|
126
|
+
* This method will error on any node that is running a Tendermint version lower than 0.34.9.
|
|
127
|
+
*
|
|
128
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/block_search
|
|
129
|
+
*/
|
|
130
|
+
blockSearch(params) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const query = { params: params, method: requests.Method.BlockSearch };
|
|
133
|
+
const resp = yield this.doCall(query, this.p.encodeBlockSearch, this.r.decodeBlockSearch);
|
|
134
|
+
return Object.assign(Object.assign({}, resp), {
|
|
135
|
+
// make sure we sort by height, as tendermint may be sorting by string value of the height
|
|
136
|
+
blocks: [...resp.blocks].sort((a, b) => a.block.header.height - b.block.header.height) });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// this should paginate through all blockSearch options to ensure it returns all results.
|
|
140
|
+
// starts with page 1 or whatever was provided (eg. to start on page 7)
|
|
141
|
+
//
|
|
142
|
+
// NOTE
|
|
143
|
+
// This method will error on any node that is running a Tendermint version lower than 0.34.9.
|
|
144
|
+
blockSearchAll(params) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
let page = params.page || 1;
|
|
147
|
+
const blocks = [];
|
|
148
|
+
let done = false;
|
|
149
|
+
while (!done) {
|
|
150
|
+
const resp = yield this.blockSearch(Object.assign(Object.assign({}, params), { page: page }));
|
|
151
|
+
blocks.push(...resp.blocks);
|
|
152
|
+
if (blocks.length < resp.totalCount) {
|
|
153
|
+
page++;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
done = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// make sure we sort by height, as tendermint may be sorting by string value of the height
|
|
160
|
+
// and the earlier items may be in a higher page than the later items
|
|
161
|
+
blocks.sort((a, b) => a.block.header.height - b.block.header.height);
|
|
162
|
+
return {
|
|
163
|
+
totalCount: blocks.length,
|
|
164
|
+
blocks: blocks,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Queries block headers filtered by minHeight <= height <= maxHeight.
|
|
170
|
+
*
|
|
171
|
+
* @param minHeight The minimum height to be included in the result. Defaults to 0.
|
|
172
|
+
* @param maxHeight The maximum height to be included in the result. Defaults to infinity.
|
|
173
|
+
*/
|
|
174
|
+
blockchain(minHeight, maxHeight) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const query = {
|
|
177
|
+
method: requests.Method.Blockchain,
|
|
178
|
+
params: {
|
|
179
|
+
minHeight: minHeight,
|
|
180
|
+
maxHeight: maxHeight,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
return this.doCall(query, this.p.encodeBlockchain, this.r.decodeBlockchain);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Broadcast transaction to mempool and wait for response
|
|
188
|
+
*
|
|
189
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync
|
|
190
|
+
*/
|
|
191
|
+
broadcastTxSync(params) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
const query = { params: params, method: requests.Method.BroadcastTxSync };
|
|
194
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxSync);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Broadcast transaction to mempool and do not wait for result
|
|
199
|
+
*
|
|
200
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async
|
|
201
|
+
*/
|
|
202
|
+
broadcastTxAsync(params) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const query = { params: params, method: requests.Method.BroadcastTxAsync };
|
|
205
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxAsync);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Broadcast transaction to mempool and wait for block
|
|
210
|
+
*
|
|
211
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit
|
|
212
|
+
*/
|
|
213
|
+
broadcastTxCommit(params) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
const query = { params: params, method: requests.Method.BroadcastTxCommit };
|
|
216
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxCommit);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
commit(height) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
const query = { method: requests.Method.Commit, params: { height: height } };
|
|
222
|
+
return this.doCall(query, this.p.encodeCommit, this.r.decodeCommit);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
genesis() {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
const query = { method: requests.Method.Genesis };
|
|
228
|
+
return this.doCall(query, this.p.encodeGenesis, this.r.decodeGenesis);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
health() {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
const query = { method: requests.Method.Health };
|
|
234
|
+
return this.doCall(query, this.p.encodeHealth, this.r.decodeHealth);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
numUnconfirmedTxs() {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
const query = { method: requests.Method.NumUnconfirmedTxs };
|
|
240
|
+
return this.doCall(query, this.p.encodeNumUnconfirmedTxs, this.r.decodeNumUnconfirmedTxs);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
status() {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
const query = { method: requests.Method.Status };
|
|
246
|
+
return this.doCall(query, this.p.encodeStatus, this.r.decodeStatus);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
subscribeNewBlock() {
|
|
250
|
+
const request = {
|
|
251
|
+
method: requests.Method.Subscribe,
|
|
252
|
+
query: { type: requests.SubscriptionEventType.NewBlock },
|
|
253
|
+
};
|
|
254
|
+
return this.subscribe(request, this.r.decodeNewBlockEvent);
|
|
255
|
+
}
|
|
256
|
+
subscribeNewBlockHeader() {
|
|
257
|
+
const request = {
|
|
258
|
+
method: requests.Method.Subscribe,
|
|
259
|
+
query: { type: requests.SubscriptionEventType.NewBlockHeader },
|
|
260
|
+
};
|
|
261
|
+
return this.subscribe(request, this.r.decodeNewBlockHeaderEvent);
|
|
262
|
+
}
|
|
263
|
+
subscribeTx(query) {
|
|
264
|
+
const request = {
|
|
265
|
+
method: requests.Method.Subscribe,
|
|
266
|
+
query: {
|
|
267
|
+
type: requests.SubscriptionEventType.Tx,
|
|
268
|
+
raw: query,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
return this.subscribe(request, this.r.decodeTxEvent);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Get a single transaction by hash
|
|
275
|
+
*
|
|
276
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx
|
|
277
|
+
*/
|
|
278
|
+
tx(params) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
const query = { params: params, method: requests.Method.Tx };
|
|
281
|
+
return this.doCall(query, this.p.encodeTx, this.r.decodeTx);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Search for transactions that are in a block
|
|
286
|
+
*
|
|
287
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx_search
|
|
288
|
+
*/
|
|
289
|
+
txSearch(params) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const query = { params: params, method: requests.Method.TxSearch };
|
|
292
|
+
return this.doCall(query, this.p.encodeTxSearch, this.r.decodeTxSearch);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
// this should paginate through all txSearch options to ensure it returns all results.
|
|
296
|
+
// starts with page 1 or whatever was provided (eg. to start on page 7)
|
|
297
|
+
txSearchAll(params) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
let page = params.page || 1;
|
|
300
|
+
const txs = [];
|
|
301
|
+
let done = false;
|
|
302
|
+
while (!done) {
|
|
303
|
+
const resp = yield this.txSearch(Object.assign(Object.assign({}, params), { page: page }));
|
|
304
|
+
txs.push(...resp.txs);
|
|
305
|
+
if (txs.length < resp.totalCount) {
|
|
306
|
+
page++;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
done = true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
totalCount: txs.length,
|
|
314
|
+
txs: txs,
|
|
315
|
+
};
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
validators(params) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
const query = {
|
|
321
|
+
method: requests.Method.Validators,
|
|
322
|
+
params: params,
|
|
323
|
+
};
|
|
324
|
+
return this.doCall(query, this.p.encodeValidators, this.r.decodeValidators);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
validatorsAll(height) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
const validators = [];
|
|
330
|
+
let page = 1;
|
|
331
|
+
let done = false;
|
|
332
|
+
let blockHeight = height;
|
|
333
|
+
while (!done) {
|
|
334
|
+
const response = yield this.validators({
|
|
335
|
+
per_page: 50,
|
|
336
|
+
height: blockHeight,
|
|
337
|
+
page: page,
|
|
338
|
+
});
|
|
339
|
+
validators.push(...response.validators);
|
|
340
|
+
blockHeight = blockHeight || response.blockHeight;
|
|
341
|
+
if (validators.length < response.total) {
|
|
342
|
+
page++;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
done = true;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
// NOTE: Default value is for type safety but this should always be set
|
|
350
|
+
blockHeight: blockHeight !== null && blockHeight !== void 0 ? blockHeight : 0,
|
|
351
|
+
count: validators.length,
|
|
352
|
+
total: validators.length,
|
|
353
|
+
validators: validators,
|
|
354
|
+
};
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
// doCall is a helper to handle the encode/call/decode logic
|
|
358
|
+
doCall(request, encode, decode) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
const req = encode(request);
|
|
361
|
+
const result = yield this.client.execute(req);
|
|
362
|
+
return decode(result);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
subscribe(request, decode) {
|
|
366
|
+
if (!instanceOfRpcStreamingClient(this.client)) {
|
|
367
|
+
throw new Error("This RPC client type cannot subscribe to events");
|
|
368
|
+
}
|
|
369
|
+
const req = this.p.encodeSubscribe(request);
|
|
370
|
+
const eventStream = this.client.listen(req);
|
|
371
|
+
return eventStream.map((event) => {
|
|
372
|
+
return decode(event);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.default = CarbonTendermintClient;
|
package/lib/constant/ibc.js
CHANGED
|
@@ -101,6 +101,7 @@ exports.ibcWhitelist = [
|
|
|
101
101
|
ChainIds.Evmos,
|
|
102
102
|
ChainIds.Axelar,
|
|
103
103
|
ChainIds.Stride,
|
|
104
|
+
ChainIds.Kujira,
|
|
104
105
|
];
|
|
105
106
|
exports.EmbedChainInfosInit = {
|
|
106
107
|
[ChainIds.Osmosis]: {
|
|
@@ -1728,7 +1729,7 @@ exports.swthChannels = {
|
|
|
1728
1729
|
};
|
|
1729
1730
|
exports.ibcTokenRegex = /^ibc\/([a-f\d]+)$/i;
|
|
1730
1731
|
exports.ibcNetworkRegex = /^([a-z\d_-]+)-([\d]+)$/i;
|
|
1731
|
-
exports.ibcDefaultGas =
|
|
1732
|
+
exports.ibcDefaultGas = 200000;
|
|
1732
1733
|
exports.DefaultGasPriceStep = {
|
|
1733
1734
|
low: 0.01,
|
|
1734
1735
|
average: 0.025,
|
package/lib/util/blockchain.js
CHANGED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.CarbonTendermintClient = exports.instanceOfRpcStreamingClient = void 0;
|
|
32
|
+
const jsonrpc_1 = require("../jsonrpc");
|
|
33
|
+
const rpcclients_1 = require("../rpcclients");
|
|
34
|
+
const adaptor_1 = require("./adaptor");
|
|
35
|
+
const requests = __importStar(require("./requests"));
|
|
36
|
+
function instanceOfRpcStreamingClient(client) {
|
|
37
|
+
return typeof client.listen === "function";
|
|
38
|
+
}
|
|
39
|
+
exports.instanceOfRpcStreamingClient = instanceOfRpcStreamingClient;
|
|
40
|
+
class CarbonTendermintClient {
|
|
41
|
+
/**
|
|
42
|
+
* Use `CarbonTendermintClient.connect` or `CarbonTendermintClient.create` to create an instance.
|
|
43
|
+
*/
|
|
44
|
+
constructor(client) {
|
|
45
|
+
this.client = client;
|
|
46
|
+
this.p = adaptor_1.adaptor34.params;
|
|
47
|
+
this.r = adaptor_1.adaptor34.responses;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new Tendermint client for the given endpoint.
|
|
51
|
+
*
|
|
52
|
+
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
|
|
53
|
+
*/
|
|
54
|
+
static connect(endpoint) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const useHttp = endpoint.startsWith("http://") || endpoint.startsWith("https://");
|
|
57
|
+
if (!useHttp) {
|
|
58
|
+
throw new Error('this client only uses httpClient.');
|
|
59
|
+
}
|
|
60
|
+
const rpcClient = new rpcclients_1.HttpClient(endpoint);
|
|
61
|
+
return CarbonTendermintClient.create(rpcClient);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new Tendermint client given an RPC client.
|
|
66
|
+
*/
|
|
67
|
+
static create(rpcClient) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
// For some very strange reason I don't understand, tests start to fail on some systems
|
|
70
|
+
// (our CI) when skipping the status call before doing other queries. Sleeping a little
|
|
71
|
+
// while did not help. Thus we query the version as a way to say "hi" to the backend,
|
|
72
|
+
// even in cases where we don't use the result.
|
|
73
|
+
const _version = yield this.detectVersion(rpcClient);
|
|
74
|
+
return new CarbonTendermintClient(rpcClient);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
static detectVersion(client) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const req = (0, jsonrpc_1.createJsonRpcRequest)(requests.Method.Status);
|
|
80
|
+
const response = yield client.execute(req);
|
|
81
|
+
const result = response.result;
|
|
82
|
+
if (!result || !result.node_info) {
|
|
83
|
+
throw new Error("Unrecognized format for status response");
|
|
84
|
+
}
|
|
85
|
+
const version = result.node_info.version;
|
|
86
|
+
if (typeof version !== "string") {
|
|
87
|
+
throw new Error("Unrecognized version format: must be string");
|
|
88
|
+
}
|
|
89
|
+
return version;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
disconnect() {
|
|
93
|
+
this.client.disconnect();
|
|
94
|
+
}
|
|
95
|
+
abciInfo() {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const query = { method: requests.Method.AbciInfo };
|
|
98
|
+
return this.doCall(query, this.p.encodeAbciInfo, this.r.decodeAbciInfo);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
abciQuery(params) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const query = { params: params, method: requests.Method.AbciQuery };
|
|
104
|
+
return this.doCall(query, this.p.encodeAbciQuery, this.r.decodeAbciQuery);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
block(height) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const query = { method: requests.Method.Block, params: { height: height } };
|
|
110
|
+
return this.doCall(query, this.p.encodeBlock, this.r.decodeBlock);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
blockResults(height) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const query = {
|
|
116
|
+
method: requests.Method.BlockResults,
|
|
117
|
+
params: { height: height },
|
|
118
|
+
};
|
|
119
|
+
return this.doCall(query, this.p.encodeBlockResults, this.r.decodeBlockResults);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Search for events that are in a block.
|
|
124
|
+
*
|
|
125
|
+
* NOTE
|
|
126
|
+
* This method will error on any node that is running a Tendermint version lower than 0.34.9.
|
|
127
|
+
*
|
|
128
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/block_search
|
|
129
|
+
*/
|
|
130
|
+
blockSearch(params) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const query = { params: params, method: requests.Method.BlockSearch };
|
|
133
|
+
const resp = yield this.doCall(query, this.p.encodeBlockSearch, this.r.decodeBlockSearch);
|
|
134
|
+
return Object.assign(Object.assign({}, resp), {
|
|
135
|
+
// make sure we sort by height, as tendermint may be sorting by string value of the height
|
|
136
|
+
blocks: [...resp.blocks].sort((a, b) => a.block.header.height - b.block.header.height) });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// this should paginate through all blockSearch options to ensure it returns all results.
|
|
140
|
+
// starts with page 1 or whatever was provided (eg. to start on page 7)
|
|
141
|
+
//
|
|
142
|
+
// NOTE
|
|
143
|
+
// This method will error on any node that is running a Tendermint version lower than 0.34.9.
|
|
144
|
+
blockSearchAll(params) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
let page = params.page || 1;
|
|
147
|
+
const blocks = [];
|
|
148
|
+
let done = false;
|
|
149
|
+
while (!done) {
|
|
150
|
+
const resp = yield this.blockSearch(Object.assign(Object.assign({}, params), { page: page }));
|
|
151
|
+
blocks.push(...resp.blocks);
|
|
152
|
+
if (blocks.length < resp.totalCount) {
|
|
153
|
+
page++;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
done = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// make sure we sort by height, as tendermint may be sorting by string value of the height
|
|
160
|
+
// and the earlier items may be in a higher page than the later items
|
|
161
|
+
blocks.sort((a, b) => a.block.header.height - b.block.header.height);
|
|
162
|
+
return {
|
|
163
|
+
totalCount: blocks.length,
|
|
164
|
+
blocks: blocks,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Queries block headers filtered by minHeight <= height <= maxHeight.
|
|
170
|
+
*
|
|
171
|
+
* @param minHeight The minimum height to be included in the result. Defaults to 0.
|
|
172
|
+
* @param maxHeight The maximum height to be included in the result. Defaults to infinity.
|
|
173
|
+
*/
|
|
174
|
+
blockchain(minHeight, maxHeight) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const query = {
|
|
177
|
+
method: requests.Method.Blockchain,
|
|
178
|
+
params: {
|
|
179
|
+
minHeight: minHeight,
|
|
180
|
+
maxHeight: maxHeight,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
return this.doCall(query, this.p.encodeBlockchain, this.r.decodeBlockchain);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Broadcast transaction to mempool and wait for response
|
|
188
|
+
*
|
|
189
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync
|
|
190
|
+
*/
|
|
191
|
+
broadcastTxSync(params) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
const query = { params: params, method: requests.Method.BroadcastTxSync };
|
|
194
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxSync);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Broadcast transaction to mempool and do not wait for result
|
|
199
|
+
*
|
|
200
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async
|
|
201
|
+
*/
|
|
202
|
+
broadcastTxAsync(params) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const query = { params: params, method: requests.Method.BroadcastTxAsync };
|
|
205
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxAsync);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Broadcast transaction to mempool and wait for block
|
|
210
|
+
*
|
|
211
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit
|
|
212
|
+
*/
|
|
213
|
+
broadcastTxCommit(params) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
const query = { params: params, method: requests.Method.BroadcastTxCommit };
|
|
216
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxCommit);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
commit(height) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
const query = { method: requests.Method.Commit, params: { height: height } };
|
|
222
|
+
return this.doCall(query, this.p.encodeCommit, this.r.decodeCommit);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
genesis() {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
const query = { method: requests.Method.Genesis };
|
|
228
|
+
return this.doCall(query, this.p.encodeGenesis, this.r.decodeGenesis);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
health() {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
const query = { method: requests.Method.Health };
|
|
234
|
+
return this.doCall(query, this.p.encodeHealth, this.r.decodeHealth);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
numUnconfirmedTxs() {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
const query = { method: requests.Method.NumUnconfirmedTxs };
|
|
240
|
+
return this.doCall(query, this.p.encodeNumUnconfirmedTxs, this.r.decodeNumUnconfirmedTxs);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
status() {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
const query = { method: requests.Method.Status };
|
|
246
|
+
return this.doCall(query, this.p.encodeStatus, this.r.decodeStatus);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
subscribeNewBlock() {
|
|
250
|
+
const request = {
|
|
251
|
+
method: requests.Method.Subscribe,
|
|
252
|
+
query: { type: requests.SubscriptionEventType.NewBlock },
|
|
253
|
+
};
|
|
254
|
+
return this.subscribe(request, this.r.decodeNewBlockEvent);
|
|
255
|
+
}
|
|
256
|
+
subscribeNewBlockHeader() {
|
|
257
|
+
const request = {
|
|
258
|
+
method: requests.Method.Subscribe,
|
|
259
|
+
query: { type: requests.SubscriptionEventType.NewBlockHeader },
|
|
260
|
+
};
|
|
261
|
+
return this.subscribe(request, this.r.decodeNewBlockHeaderEvent);
|
|
262
|
+
}
|
|
263
|
+
subscribeTx(query) {
|
|
264
|
+
const request = {
|
|
265
|
+
method: requests.Method.Subscribe,
|
|
266
|
+
query: {
|
|
267
|
+
type: requests.SubscriptionEventType.Tx,
|
|
268
|
+
raw: query,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
return this.subscribe(request, this.r.decodeTxEvent);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Get a single transaction by hash
|
|
275
|
+
*
|
|
276
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx
|
|
277
|
+
*/
|
|
278
|
+
tx(params) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
const query = { params: params, method: requests.Method.Tx };
|
|
281
|
+
return this.doCall(query, this.p.encodeTx, this.r.decodeTx);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Search for transactions that are in a block
|
|
286
|
+
*
|
|
287
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx_search
|
|
288
|
+
*/
|
|
289
|
+
txSearch(params) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const query = { params: params, method: requests.Method.TxSearch };
|
|
292
|
+
return this.doCall(query, this.p.encodeTxSearch, this.r.decodeTxSearch);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
// this should paginate through all txSearch options to ensure it returns all results.
|
|
296
|
+
// starts with page 1 or whatever was provided (eg. to start on page 7)
|
|
297
|
+
txSearchAll(params) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
let page = params.page || 1;
|
|
300
|
+
const txs = [];
|
|
301
|
+
let done = false;
|
|
302
|
+
while (!done) {
|
|
303
|
+
const resp = yield this.txSearch(Object.assign(Object.assign({}, params), { page: page }));
|
|
304
|
+
txs.push(...resp.txs);
|
|
305
|
+
if (txs.length < resp.totalCount) {
|
|
306
|
+
page++;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
done = true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
totalCount: txs.length,
|
|
314
|
+
txs: txs,
|
|
315
|
+
};
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
validators(params) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
const query = {
|
|
321
|
+
method: requests.Method.Validators,
|
|
322
|
+
params: params,
|
|
323
|
+
};
|
|
324
|
+
return this.doCall(query, this.p.encodeValidators, this.r.decodeValidators);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
validatorsAll(height) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
const validators = [];
|
|
330
|
+
let page = 1;
|
|
331
|
+
let done = false;
|
|
332
|
+
let blockHeight = height;
|
|
333
|
+
while (!done) {
|
|
334
|
+
const response = yield this.validators({
|
|
335
|
+
per_page: 50,
|
|
336
|
+
height: blockHeight,
|
|
337
|
+
page: page,
|
|
338
|
+
});
|
|
339
|
+
validators.push(...response.validators);
|
|
340
|
+
blockHeight = blockHeight || response.blockHeight;
|
|
341
|
+
if (validators.length < response.total) {
|
|
342
|
+
page++;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
done = true;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
// NOTE: Default value is for type safety but this should always be set
|
|
350
|
+
blockHeight: blockHeight !== null && blockHeight !== void 0 ? blockHeight : 0,
|
|
351
|
+
count: validators.length,
|
|
352
|
+
total: validators.length,
|
|
353
|
+
validators: validators,
|
|
354
|
+
};
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
// doCall is a helper to handle the encode/call/decode logic
|
|
358
|
+
doCall(request, encode, decode) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
const req = encode(request);
|
|
361
|
+
const result = yield this.client.execute(req);
|
|
362
|
+
return decode(result);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
subscribe(request, decode) {
|
|
366
|
+
if (!(0, rpcclients_1.instanceOfRpcStreamingClient)(this.client)) {
|
|
367
|
+
throw new Error("This RPC client type cannot subscribe to events");
|
|
368
|
+
}
|
|
369
|
+
const req = this.p.encodeSubscribe(request);
|
|
370
|
+
const eventStream = this.client.listen(req);
|
|
371
|
+
return eventStream.map((event) => {
|
|
372
|
+
return decode(event);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.CarbonTendermintClient = CarbonTendermintClient;
|
package/package.json
CHANGED
package/lib/codec/bank/tx.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import Long from "long";
|
|
2
|
-
import _m0 from "protobufjs/minimal";
|
|
3
|
-
export declare const protobufPackage = "Switcheo.carbon.bank";
|
|
4
|
-
export interface MsgEnableSend {
|
|
5
|
-
creator: string;
|
|
6
|
-
denom: string;
|
|
7
|
-
}
|
|
8
|
-
export interface MsgEnableSendResponse {
|
|
9
|
-
denom: string;
|
|
10
|
-
}
|
|
11
|
-
export interface MsgDisableSend {
|
|
12
|
-
creator: string;
|
|
13
|
-
denom: string;
|
|
14
|
-
}
|
|
15
|
-
export interface MsgDisableSendResponse {
|
|
16
|
-
denom: string;
|
|
17
|
-
}
|
|
18
|
-
export declare const MsgEnableSend: {
|
|
19
|
-
encode(message: MsgEnableSend, writer?: _m0.Writer): _m0.Writer;
|
|
20
|
-
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgEnableSend;
|
|
21
|
-
fromJSON(object: any): MsgEnableSend;
|
|
22
|
-
toJSON(message: MsgEnableSend): unknown;
|
|
23
|
-
fromPartial(object: DeepPartial<MsgEnableSend>): MsgEnableSend;
|
|
24
|
-
};
|
|
25
|
-
export declare const MsgEnableSendResponse: {
|
|
26
|
-
encode(message: MsgEnableSendResponse, writer?: _m0.Writer): _m0.Writer;
|
|
27
|
-
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgEnableSendResponse;
|
|
28
|
-
fromJSON(object: any): MsgEnableSendResponse;
|
|
29
|
-
toJSON(message: MsgEnableSendResponse): unknown;
|
|
30
|
-
fromPartial(object: DeepPartial<MsgEnableSendResponse>): MsgEnableSendResponse;
|
|
31
|
-
};
|
|
32
|
-
export declare const MsgDisableSend: {
|
|
33
|
-
encode(message: MsgDisableSend, writer?: _m0.Writer): _m0.Writer;
|
|
34
|
-
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgDisableSend;
|
|
35
|
-
fromJSON(object: any): MsgDisableSend;
|
|
36
|
-
toJSON(message: MsgDisableSend): unknown;
|
|
37
|
-
fromPartial(object: DeepPartial<MsgDisableSend>): MsgDisableSend;
|
|
38
|
-
};
|
|
39
|
-
export declare const MsgDisableSendResponse: {
|
|
40
|
-
encode(message: MsgDisableSendResponse, writer?: _m0.Writer): _m0.Writer;
|
|
41
|
-
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgDisableSendResponse;
|
|
42
|
-
fromJSON(object: any): MsgDisableSendResponse;
|
|
43
|
-
toJSON(message: MsgDisableSendResponse): unknown;
|
|
44
|
-
fromPartial(object: DeepPartial<MsgDisableSendResponse>): MsgDisableSendResponse;
|
|
45
|
-
};
|
|
46
|
-
/** Msg defines the Msg service. */
|
|
47
|
-
export interface Msg {
|
|
48
|
-
EnableSend(request: MsgEnableSend): Promise<MsgEnableSendResponse>;
|
|
49
|
-
DisableSend(request: MsgDisableSend): Promise<MsgDisableSendResponse>;
|
|
50
|
-
}
|
|
51
|
-
export declare class MsgClientImpl implements Msg {
|
|
52
|
-
private readonly rpc;
|
|
53
|
-
constructor(rpc: Rpc);
|
|
54
|
-
EnableSend(request: MsgEnableSend): Promise<MsgEnableSendResponse>;
|
|
55
|
-
DisableSend(request: MsgDisableSend): Promise<MsgDisableSendResponse>;
|
|
56
|
-
}
|
|
57
|
-
interface Rpc {
|
|
58
|
-
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|
|
59
|
-
}
|
|
60
|
-
declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
61
|
-
export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
62
|
-
[K in keyof T]?: DeepPartial<T[K]>;
|
|
63
|
-
} : Partial<T>;
|
|
64
|
-
export {};
|
package/lib/codec/bank/tx.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MsgClientImpl = exports.MsgDisableSendResponse = exports.MsgDisableSend = exports.MsgEnableSendResponse = exports.MsgEnableSend = exports.protobufPackage = void 0;
|
|
7
|
-
/* eslint-disable */
|
|
8
|
-
const long_1 = __importDefault(require("long"));
|
|
9
|
-
const minimal_1 = __importDefault(require("protobufjs/minimal"));
|
|
10
|
-
exports.protobufPackage = "Switcheo.carbon.bank";
|
|
11
|
-
const baseMsgEnableSend = { creator: "", denom: "" };
|
|
12
|
-
exports.MsgEnableSend = {
|
|
13
|
-
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
14
|
-
if (message.creator !== "") {
|
|
15
|
-
writer.uint32(10).string(message.creator);
|
|
16
|
-
}
|
|
17
|
-
if (message.denom !== "") {
|
|
18
|
-
writer.uint32(18).string(message.denom);
|
|
19
|
-
}
|
|
20
|
-
return writer;
|
|
21
|
-
},
|
|
22
|
-
decode(input, length) {
|
|
23
|
-
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
|
|
24
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
25
|
-
const message = Object.assign({}, baseMsgEnableSend);
|
|
26
|
-
while (reader.pos < end) {
|
|
27
|
-
const tag = reader.uint32();
|
|
28
|
-
switch (tag >>> 3) {
|
|
29
|
-
case 1:
|
|
30
|
-
message.creator = reader.string();
|
|
31
|
-
break;
|
|
32
|
-
case 2:
|
|
33
|
-
message.denom = reader.string();
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
reader.skipType(tag & 7);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return message;
|
|
41
|
-
},
|
|
42
|
-
fromJSON(object) {
|
|
43
|
-
const message = Object.assign({}, baseMsgEnableSend);
|
|
44
|
-
message.creator =
|
|
45
|
-
object.creator !== undefined && object.creator !== null
|
|
46
|
-
? String(object.creator)
|
|
47
|
-
: "";
|
|
48
|
-
message.denom =
|
|
49
|
-
object.denom !== undefined && object.denom !== null
|
|
50
|
-
? String(object.denom)
|
|
51
|
-
: "";
|
|
52
|
-
return message;
|
|
53
|
-
},
|
|
54
|
-
toJSON(message) {
|
|
55
|
-
const obj = {};
|
|
56
|
-
message.creator !== undefined && (obj.creator = message.creator);
|
|
57
|
-
message.denom !== undefined && (obj.denom = message.denom);
|
|
58
|
-
return obj;
|
|
59
|
-
},
|
|
60
|
-
fromPartial(object) {
|
|
61
|
-
var _a, _b;
|
|
62
|
-
const message = Object.assign({}, baseMsgEnableSend);
|
|
63
|
-
message.creator = (_a = object.creator) !== null && _a !== void 0 ? _a : "";
|
|
64
|
-
message.denom = (_b = object.denom) !== null && _b !== void 0 ? _b : "";
|
|
65
|
-
return message;
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
const baseMsgEnableSendResponse = { denom: "" };
|
|
69
|
-
exports.MsgEnableSendResponse = {
|
|
70
|
-
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
71
|
-
if (message.denom !== "") {
|
|
72
|
-
writer.uint32(10).string(message.denom);
|
|
73
|
-
}
|
|
74
|
-
return writer;
|
|
75
|
-
},
|
|
76
|
-
decode(input, length) {
|
|
77
|
-
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
|
|
78
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
79
|
-
const message = Object.assign({}, baseMsgEnableSendResponse);
|
|
80
|
-
while (reader.pos < end) {
|
|
81
|
-
const tag = reader.uint32();
|
|
82
|
-
switch (tag >>> 3) {
|
|
83
|
-
case 1:
|
|
84
|
-
message.denom = reader.string();
|
|
85
|
-
break;
|
|
86
|
-
default:
|
|
87
|
-
reader.skipType(tag & 7);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return message;
|
|
92
|
-
},
|
|
93
|
-
fromJSON(object) {
|
|
94
|
-
const message = Object.assign({}, baseMsgEnableSendResponse);
|
|
95
|
-
message.denom =
|
|
96
|
-
object.denom !== undefined && object.denom !== null
|
|
97
|
-
? String(object.denom)
|
|
98
|
-
: "";
|
|
99
|
-
return message;
|
|
100
|
-
},
|
|
101
|
-
toJSON(message) {
|
|
102
|
-
const obj = {};
|
|
103
|
-
message.denom !== undefined && (obj.denom = message.denom);
|
|
104
|
-
return obj;
|
|
105
|
-
},
|
|
106
|
-
fromPartial(object) {
|
|
107
|
-
var _a;
|
|
108
|
-
const message = Object.assign({}, baseMsgEnableSendResponse);
|
|
109
|
-
message.denom = (_a = object.denom) !== null && _a !== void 0 ? _a : "";
|
|
110
|
-
return message;
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
const baseMsgDisableSend = { creator: "", denom: "" };
|
|
114
|
-
exports.MsgDisableSend = {
|
|
115
|
-
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
116
|
-
if (message.creator !== "") {
|
|
117
|
-
writer.uint32(10).string(message.creator);
|
|
118
|
-
}
|
|
119
|
-
if (message.denom !== "") {
|
|
120
|
-
writer.uint32(18).string(message.denom);
|
|
121
|
-
}
|
|
122
|
-
return writer;
|
|
123
|
-
},
|
|
124
|
-
decode(input, length) {
|
|
125
|
-
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
|
|
126
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
127
|
-
const message = Object.assign({}, baseMsgDisableSend);
|
|
128
|
-
while (reader.pos < end) {
|
|
129
|
-
const tag = reader.uint32();
|
|
130
|
-
switch (tag >>> 3) {
|
|
131
|
-
case 1:
|
|
132
|
-
message.creator = reader.string();
|
|
133
|
-
break;
|
|
134
|
-
case 2:
|
|
135
|
-
message.denom = reader.string();
|
|
136
|
-
break;
|
|
137
|
-
default:
|
|
138
|
-
reader.skipType(tag & 7);
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return message;
|
|
143
|
-
},
|
|
144
|
-
fromJSON(object) {
|
|
145
|
-
const message = Object.assign({}, baseMsgDisableSend);
|
|
146
|
-
message.creator =
|
|
147
|
-
object.creator !== undefined && object.creator !== null
|
|
148
|
-
? String(object.creator)
|
|
149
|
-
: "";
|
|
150
|
-
message.denom =
|
|
151
|
-
object.denom !== undefined && object.denom !== null
|
|
152
|
-
? String(object.denom)
|
|
153
|
-
: "";
|
|
154
|
-
return message;
|
|
155
|
-
},
|
|
156
|
-
toJSON(message) {
|
|
157
|
-
const obj = {};
|
|
158
|
-
message.creator !== undefined && (obj.creator = message.creator);
|
|
159
|
-
message.denom !== undefined && (obj.denom = message.denom);
|
|
160
|
-
return obj;
|
|
161
|
-
},
|
|
162
|
-
fromPartial(object) {
|
|
163
|
-
var _a, _b;
|
|
164
|
-
const message = Object.assign({}, baseMsgDisableSend);
|
|
165
|
-
message.creator = (_a = object.creator) !== null && _a !== void 0 ? _a : "";
|
|
166
|
-
message.denom = (_b = object.denom) !== null && _b !== void 0 ? _b : "";
|
|
167
|
-
return message;
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
const baseMsgDisableSendResponse = { denom: "" };
|
|
171
|
-
exports.MsgDisableSendResponse = {
|
|
172
|
-
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
173
|
-
if (message.denom !== "") {
|
|
174
|
-
writer.uint32(10).string(message.denom);
|
|
175
|
-
}
|
|
176
|
-
return writer;
|
|
177
|
-
},
|
|
178
|
-
decode(input, length) {
|
|
179
|
-
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
|
|
180
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
181
|
-
const message = Object.assign({}, baseMsgDisableSendResponse);
|
|
182
|
-
while (reader.pos < end) {
|
|
183
|
-
const tag = reader.uint32();
|
|
184
|
-
switch (tag >>> 3) {
|
|
185
|
-
case 1:
|
|
186
|
-
message.denom = reader.string();
|
|
187
|
-
break;
|
|
188
|
-
default:
|
|
189
|
-
reader.skipType(tag & 7);
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return message;
|
|
194
|
-
},
|
|
195
|
-
fromJSON(object) {
|
|
196
|
-
const message = Object.assign({}, baseMsgDisableSendResponse);
|
|
197
|
-
message.denom =
|
|
198
|
-
object.denom !== undefined && object.denom !== null
|
|
199
|
-
? String(object.denom)
|
|
200
|
-
: "";
|
|
201
|
-
return message;
|
|
202
|
-
},
|
|
203
|
-
toJSON(message) {
|
|
204
|
-
const obj = {};
|
|
205
|
-
message.denom !== undefined && (obj.denom = message.denom);
|
|
206
|
-
return obj;
|
|
207
|
-
},
|
|
208
|
-
fromPartial(object) {
|
|
209
|
-
var _a;
|
|
210
|
-
const message = Object.assign({}, baseMsgDisableSendResponse);
|
|
211
|
-
message.denom = (_a = object.denom) !== null && _a !== void 0 ? _a : "";
|
|
212
|
-
return message;
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
class MsgClientImpl {
|
|
216
|
-
constructor(rpc) {
|
|
217
|
-
this.rpc = rpc;
|
|
218
|
-
this.EnableSend = this.EnableSend.bind(this);
|
|
219
|
-
this.DisableSend = this.DisableSend.bind(this);
|
|
220
|
-
}
|
|
221
|
-
EnableSend(request) {
|
|
222
|
-
const data = exports.MsgEnableSend.encode(request).finish();
|
|
223
|
-
const promise = this.rpc.request("Switcheo.carbon.bank.Msg", "EnableSend", data);
|
|
224
|
-
return promise.then((data) => exports.MsgEnableSendResponse.decode(new minimal_1.default.Reader(data)));
|
|
225
|
-
}
|
|
226
|
-
DisableSend(request) {
|
|
227
|
-
const data = exports.MsgDisableSend.encode(request).finish();
|
|
228
|
-
const promise = this.rpc.request("Switcheo.carbon.bank.Msg", "DisableSend", data);
|
|
229
|
-
return promise.then((data) => exports.MsgDisableSendResponse.decode(new minimal_1.default.Reader(data)));
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.MsgClientImpl = MsgClientImpl;
|
|
233
|
-
if (minimal_1.default.util.Long !== long_1.default) {
|
|
234
|
-
minimal_1.default.util.Long = long_1.default;
|
|
235
|
-
minimal_1.default.configure();
|
|
236
|
-
}
|