carbon-js-sdk 0.3.13 → 0.3.14
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/codec/bank/tx.d.ts +64 -0
- package/lib/codec/bank/tx.js +236 -0
- package/lib/codec/cdp/tx.d.ts +53 -1
- package/lib/codec/cdp/tx.js +318 -4
- package/lib/codec/index.d.ts +5 -1
- package/lib/codec/index.js +23 -11
- package/lib/modules/cdp.d.ts +16 -0
- package/lib/modules/cdp.js +34 -1
- package/lib/util/tx.d.ts +4 -0
- package/package.json +1 -1
- package/lib/clients/CarbonTendermintClient.d.ts +0 -117
- package/lib/clients/CarbonTendermintClient.js +0 -376
- package/lib/wallet/CarbonTendermintClient.js +0 -376
|
@@ -1,376 +0,0 @@
|
|
|
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;
|