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
package/lib/modules/cdp.js
CHANGED
|
@@ -103,6 +103,7 @@ class CDPModule extends base_1.default {
|
|
|
103
103
|
creator: wallet.bech32Address,
|
|
104
104
|
denom: params.denom,
|
|
105
105
|
amount: params.amount.toString(10),
|
|
106
|
+
debtor: params.debtor,
|
|
106
107
|
});
|
|
107
108
|
return yield wallet.sendTx({
|
|
108
109
|
typeUrl: util_1.CarbonTx.Types.MsgRepayAsset,
|
|
@@ -269,6 +270,7 @@ class CDPModule extends base_1.default {
|
|
|
269
270
|
principalAmount: params.principalAmount.toString(10),
|
|
270
271
|
interestDenom: params.interestDenom,
|
|
271
272
|
interestAmount: params.interestAmount.toString(10),
|
|
273
|
+
debtor: params.debtor,
|
|
272
274
|
});
|
|
273
275
|
return yield wallet.sendTx({
|
|
274
276
|
typeUrl: util_1.CarbonTx.Types.MsgReturnStablecoin,
|
|
@@ -342,6 +344,38 @@ class CDPModule extends base_1.default {
|
|
|
342
344
|
}, opts);
|
|
343
345
|
});
|
|
344
346
|
}
|
|
347
|
+
returnStablecoinWithInterestInCdpTokens(params, opts) {
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
const wallet = this.getWallet();
|
|
350
|
+
const value = tx_1.MsgReturnStablecoinWithInterestInCdpTokens.fromPartial({
|
|
351
|
+
creator: wallet.bech32Address,
|
|
352
|
+
principalAmount: params.principalAmount.toString(10),
|
|
353
|
+
interestCdpDenom: params.interestCdpDenom,
|
|
354
|
+
interestCdpAmount: params.interestCdpAmount.toString(10),
|
|
355
|
+
debtor: params.debtor,
|
|
356
|
+
});
|
|
357
|
+
return yield wallet.sendTx({
|
|
358
|
+
typeUrl: util_1.CarbonTx.Types.MsgReturnStablecoinWithInterestInCdpTokens,
|
|
359
|
+
value,
|
|
360
|
+
}, opts);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
returnStablecoinWithInterestInCollateral(params, opts) {
|
|
364
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
const wallet = this.getWallet();
|
|
366
|
+
const value = tx_1.MsgReturnStablecoinWithInterestInCollateral.fromPartial({
|
|
367
|
+
creator: wallet.bech32Address,
|
|
368
|
+
principalAmount: params.principalAmount.toString(10),
|
|
369
|
+
interestCdpDenom: params.interestCdpDenom,
|
|
370
|
+
interestCdpAmount: params.interestCdpAmount.toString(10),
|
|
371
|
+
debtor: params.debtor,
|
|
372
|
+
});
|
|
373
|
+
return yield wallet.sendTx({
|
|
374
|
+
typeUrl: util_1.CarbonTx.Types.MsgReturnStablecoinWithInterestInCollateral,
|
|
375
|
+
value,
|
|
376
|
+
}, opts);
|
|
377
|
+
});
|
|
378
|
+
}
|
|
345
379
|
// start of cdp calculations
|
|
346
380
|
getAccountData(account) {
|
|
347
381
|
var _a;
|
|
@@ -881,4 +915,3 @@ CDPModule.calculateInterestAPY = (debtInfo, rateStrategy) => {
|
|
|
881
915
|
return vRate.plus(baseVariableBorrowRate);
|
|
882
916
|
}
|
|
883
917
|
};
|
|
884
|
-
;
|
package/lib/util/tx.d.ts
CHANGED
|
@@ -128,6 +128,10 @@ export declare const Types: {
|
|
|
128
128
|
MsgSetStalePriceGracePeriodResponse: string;
|
|
129
129
|
MsgSetCdpPaused: string;
|
|
130
130
|
MsgSetCdpPausedResponse: string;
|
|
131
|
+
MsgReturnStablecoinWithInterestInCollateral: string;
|
|
132
|
+
MsgReturnStablecoinWithInterestInCollateralResponse: string;
|
|
133
|
+
MsgReturnStablecoinWithInterestInCdpTokens: string;
|
|
134
|
+
MsgReturnStablecoinWithInterestInCdpTokensResponse: string;
|
|
131
135
|
MsgSyncGenesis: string;
|
|
132
136
|
MsgSyncGenesisResponse: string;
|
|
133
137
|
MsgSyncHeaders: string;
|
package/package.json
CHANGED
|
@@ -1,117 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -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.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;
|