carbon-js-sdk 0.3.4 → 0.3.6

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.
Files changed (56) hide show
  1. package/lib/clients/CarbonQueryClient.js +2 -2
  2. package/lib/clients/CarbonTendermintClient.d.ts +117 -0
  3. package/lib/clients/CarbonTendermintClient.js +376 -0
  4. package/lib/clients/ETHClient.js +15 -15
  5. package/lib/clients/HydrogenClient.js +1 -1
  6. package/lib/clients/N3Client.js +3 -2
  7. package/lib/clients/NEOClient.js +8 -7
  8. package/lib/clients/ZILClient.js +16 -16
  9. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  10. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  11. package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
  12. package/lib/constant/address.d.ts +1 -0
  13. package/lib/constant/address.js +2 -1
  14. package/lib/constant/generic.js +1 -1
  15. package/lib/modules/cdp.js +43 -43
  16. package/lib/modules/gov.js +14 -14
  17. package/lib/modules/liquiditypool.js +1 -1
  18. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  19. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  20. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  21. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  22. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  23. package/lib/provider/amino/types/admin.js +30 -30
  24. package/lib/provider/amino/types/bank.js +1 -1
  25. package/lib/provider/amino/types/broker.js +1 -1
  26. package/lib/provider/amino/types/cdp.js +22 -22
  27. package/lib/provider/amino/types/coin.js +2 -2
  28. package/lib/provider/amino/types/gov.js +4 -4
  29. package/lib/provider/amino/types/ibc.js +1 -1
  30. package/lib/provider/amino/types/leverage.js +1 -1
  31. package/lib/provider/amino/types/liquidityPool.js +7 -7
  32. package/lib/provider/amino/types/market.js +1 -1
  33. package/lib/provider/amino/types/oracle.js +1 -1
  34. package/lib/provider/amino/types/order.js +4 -4
  35. package/lib/provider/amino/types/position.js +1 -1
  36. package/lib/provider/amino/types/profile.js +1 -1
  37. package/lib/provider/amino/types/staking.js +4 -4
  38. package/lib/provider/amino/types/subaccount.js +3 -3
  39. package/lib/provider/amino/utils.js +11 -11
  40. package/lib/provider/keplr/KeplrStore.js +1 -1
  41. package/lib/provider/ledger/ledger.js +2 -2
  42. package/lib/provider/metamask/MetaMask.js +1 -1
  43. package/lib/provider/o3/O3Wallet.js +2 -2
  44. package/lib/util/address.js +13 -13
  45. package/lib/util/api.js +4 -4
  46. package/lib/util/fetch.js +1 -1
  47. package/lib/util/generic.js +3 -3
  48. package/lib/util/number.js +5 -5
  49. package/lib/wallet/CarbonSigner.js +2 -2
  50. package/lib/wallet/CarbonSigningClient.js +8 -8
  51. package/lib/wallet/CarbonTendermintClient.js +376 -0
  52. package/lib/wallet/CarbonWallet.js +6 -6
  53. package/lib/websocket/connector.js +3 -3
  54. package/package.json +1 -1
  55. package/lib/codec/bank/tx.d.ts +0 -64
  56. package/lib/codec/bank/tx.js +0 -236
package/lib/util/api.js CHANGED
@@ -84,7 +84,7 @@ class HTTP {
84
84
  * Executes HTTP GET request with fetch
85
85
  */
86
86
  this.get = ({ url, headers }) => {
87
- return fetch_1.fetch(url, {
87
+ return (0, fetch_1.fetch)(url, {
88
88
  method: 'GET',
89
89
  headers,
90
90
  });
@@ -93,7 +93,7 @@ class HTTP {
93
93
  * Executes HTTP POST request with fetch
94
94
  */
95
95
  this.post = (options) => {
96
- return fetch_1.fetch(options.url, {
96
+ return (0, fetch_1.fetch)(options.url, {
97
97
  method: 'POST',
98
98
  headers: Object.assign({ 'Content-Type': options.content_type || 'application/json' }, options.headers),
99
99
  body: JSON.stringify(options.body),
@@ -103,7 +103,7 @@ class HTTP {
103
103
  * Executes HTTP DELETE request with fetch
104
104
  */
105
105
  this.del = (options) => {
106
- return fetch_1.fetch(options.url, {
106
+ return (0, fetch_1.fetch)(options.url, {
107
107
  method: 'DELETE',
108
108
  headers: Object.assign({ 'Content-Type': options.content_type || 'application/json' }, options.headers),
109
109
  body: JSON.stringify(options.body),
@@ -114,7 +114,7 @@ class HTTP {
114
114
  */
115
115
  this.raw = (options) => {
116
116
  const { url } = options, otherOpts = __rest(options, ["url"]);
117
- return fetch_1.fetch(url, otherOpts);
117
+ return (0, fetch_1.fetch)(url, otherOpts);
118
118
  };
119
119
  this.apiPrefix = apiPrefix;
120
120
  this.apiEndpoints = apiEndpoints;
package/lib/util/fetch.js CHANGED
@@ -10,7 +10,7 @@ function fetch(url, init) {
10
10
  return window.fetch(url, Object.assign({}, init));
11
11
  }
12
12
  else {
13
- return node_fetch_1.default(url, init);
13
+ return (0, node_fetch_1.default)(url, init);
14
14
  }
15
15
  }
16
16
  exports.fetch = fetch;
@@ -22,7 +22,7 @@ const overrideConfig = (defaults, override) => {
22
22
  continue;
23
23
  if (typeof member === "object") {
24
24
  // @ts-ignore
25
- result[key] = exports.overrideConfig(result[key], member);
25
+ result[key] = (0, exports.overrideConfig)(result[key], member);
26
26
  }
27
27
  else {
28
28
  // @ts-ignore
@@ -41,7 +41,7 @@ const sortObject = (input) => {
41
41
  Object.keys(input)
42
42
  .sort()
43
43
  // @ts-ignore noImplicitAny
44
- .forEach((key) => (output[key] = exports.sortObject(input[key])));
44
+ .forEach((key) => (output[key] = (0, exports.sortObject)(input[key])));
45
45
  return output;
46
46
  };
47
47
  exports.sortObject = sortObject;
@@ -56,7 +56,7 @@ exports.appendHexPrefix = appendHexPrefix;
56
56
  const computeTxHash = (bytes) => {
57
57
  if (!bytes)
58
58
  return bytes;
59
- return exports.toTxHash(crypto_1.sha256(bytes));
59
+ return (0, exports.toTxHash)((0, crypto_1.sha256)(bytes));
60
60
  };
61
61
  exports.computeTxHash = computeTxHash;
62
62
  const toTxHash = (bytes) => {
@@ -18,26 +18,26 @@ const parseBN = (input, defaultValue) => {
18
18
  };
19
19
  exports.parseBN = parseBN;
20
20
  const bnOrZero = (input, defaultValue = exports.BN_ZERO) => {
21
- return exports.parseBN(input, defaultValue);
21
+ return (0, exports.parseBN)(input, defaultValue);
22
22
  };
23
23
  exports.bnOrZero = bnOrZero;
24
24
  const toHuman = (value, decimals) => {
25
25
  if (value === undefined || value === null)
26
26
  return undefined;
27
- const valueBN = exports.bnOrZero(value);
27
+ const valueBN = (0, exports.bnOrZero)(value);
28
28
  if (!decimals)
29
29
  return valueBN; // decimals = 0 or nullish
30
- const decimalsBN = exports.bnOrZero(decimals);
30
+ const decimalsBN = (0, exports.bnOrZero)(decimals);
31
31
  return valueBN.shiftedBy(decimalsBN.negated().toNumber());
32
32
  };
33
33
  exports.toHuman = toHuman;
34
34
  const toUnitless = (value, decimals) => {
35
35
  if (value === undefined || value === null)
36
36
  return undefined;
37
- const valueBN = exports.bnOrZero(value);
37
+ const valueBN = (0, exports.bnOrZero)(value);
38
38
  if (!decimals)
39
39
  return valueBN; // decimals = 0 or nullish
40
- const decimalsBN = exports.bnOrZero(decimals);
40
+ const decimalsBN = (0, exports.bnOrZero)(decimals);
41
41
  return valueBN.shiftedBy(decimalsBN.toNumber());
42
42
  };
43
43
  exports.toUnitless = toUnitless;
@@ -106,9 +106,9 @@ class CarbonLedgerSigner {
106
106
  return __awaiter(this, void 0, void 0, function* () {
107
107
  const account = yield this.retrieveAccount();
108
108
  const { pubkey } = account;
109
- const msg = JSON.stringify(generic_1.sortObject(doc));
109
+ const msg = JSON.stringify((0, generic_1.sortObject)(doc));
110
110
  const signBytes = yield this.ledger.sign(msg);
111
- const signature = amino_1.encodeSecp256k1Signature(pubkey, signBytes);
111
+ const signature = (0, amino_1.encodeSecp256k1Signature)(pubkey, signBytes);
112
112
  return {
113
113
  signed: doc,
114
114
  signature,
@@ -87,7 +87,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
87
87
  */
88
88
  sign(signerAddress, messages, fee, memo, signerData) {
89
89
  return __awaiter(this, void 0, void 0, function* () {
90
- return proto_signing_1.isOfflineDirectSigner(this.signer)
90
+ return (0, proto_signing_1.isOfflineDirectSigner)(this.signer)
91
91
  ? this.signDirect(signerAddress, messages, fee, memo, signerData)
92
92
  : this.signAmino(signerAddress, messages, fee, memo, signerData);
93
93
  });
@@ -99,7 +99,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
99
99
  if (!accountFromSigner) {
100
100
  throw new Error("Failed to retrieve account from signer");
101
101
  }
102
- const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
102
+ const pubkey = (0, proto_signing_1.encodePubkey)((0, amino_1.encodeSecp256k1Pubkey)(accountFromSigner.pubkey));
103
103
  const txBodyEncodeObject = {
104
104
  typeUrl: "/cosmos.tx.v1beta1.TxBody",
105
105
  value: Object.assign({ messages: messages, memo: memo }, timeoutHeight && {
@@ -108,13 +108,13 @@ class CarbonSigningClient extends stargate_1.StargateClient {
108
108
  };
109
109
  const txBodyBytes = this.registry.encode(txBodyEncodeObject);
110
110
  const gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
111
- const authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence }], fee.amount, gasLimit);
112
- const signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
111
+ const authInfoBytes = (0, proto_signing_1.makeAuthInfoBytes)([{ pubkey, sequence }], fee.amount, gasLimit);
112
+ const signDoc = (0, proto_signing_1.makeSignDoc)(txBodyBytes, authInfoBytes, chainId, accountNumber);
113
113
  const { signature, signed } = yield signer.signDirect(signerAddress, signDoc);
114
114
  return tx_1.TxRaw.fromPartial({
115
115
  bodyBytes: signed.bodyBytes,
116
116
  authInfoBytes: signed.authInfoBytes,
117
- signatures: [encoding_1.fromBase64(signature.signature)],
117
+ signatures: [(0, encoding_1.fromBase64)(signature.signature)],
118
118
  });
119
119
  });
120
120
  }
@@ -125,7 +125,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
125
125
  if (!accountFromSigner) {
126
126
  throw new Error("Failed to retrieve account from signer");
127
127
  }
128
- const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
128
+ const pubkey = (0, proto_signing_1.encodePubkey)((0, amino_1.encodeSecp256k1Pubkey)(accountFromSigner.pubkey));
129
129
  const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
130
130
  const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
131
131
  const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight !== null && timeoutHeight !== void 0 ? timeoutHeight : 0);
@@ -140,11 +140,11 @@ class CarbonSigningClient extends stargate_1.StargateClient {
140
140
  const signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
141
141
  const signedGasLimit = math_1.Int53.fromString(signed.fee.gas).toNumber();
142
142
  const signedSequence = math_1.Int53.fromString(signed.sequence).toNumber();
143
- const signedAuthInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signMode);
143
+ const signedAuthInfoBytes = (0, proto_signing_1.makeAuthInfoBytes)([{ pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signMode);
144
144
  return tx_1.TxRaw.fromPartial({
145
145
  bodyBytes: signedTxBodyBytes,
146
146
  authInfoBytes: signedAuthInfoBytes,
147
- signatures: [encoding_1.fromBase64(signature.signature)],
147
+ signatures: [(0, encoding_1.fromBase64)(signature.signature)],
148
148
  });
149
149
  });
150
150
  }
@@ -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;
@@ -148,7 +148,7 @@ class CarbonWallet {
148
148
  const signerData = Object.assign({ accountNumber: this.accountInfo.accountNumber, chainId: this.getChainId(), sequence }, explicitSignerData);
149
149
  const fee = (_a = opts === null || opts === void 0 ? void 0 : opts.fee) !== null && _a !== void 0 ? _a : this.estimateTxFee(messages, feeDenom);
150
150
  const txRaw = yield signingClient.sign(signerAddress, messages, fee, memo, signerData);
151
- signature = amino_1.encodeSecp256k1Signature(account.pubkey, txRaw.signatures[0]);
151
+ signature = (0, amino_1.encodeSecp256k1Signature)(account.pubkey, txRaw.signatures[0]);
152
152
  return txRaw;
153
153
  }
154
154
  finally {
@@ -166,7 +166,7 @@ class CarbonWallet {
166
166
  const tx = CarbonWallet.TxRaw.encode(txRaw).finish();
167
167
  const carbonClient = this.getSigningClient();
168
168
  const response = yield carbonClient.broadcastTx(tx, timeoutMs, pollIntervalMs);
169
- if (stargate_1.isDeliverTxFailure(response)) {
169
+ if ((0, stargate_1.isDeliverTxFailure)(response)) {
170
170
  // tx failed
171
171
  throw new tx_1.CarbonTxError(`[${response.code}] ${response.rawLog}`, response);
172
172
  }
@@ -205,9 +205,9 @@ class CarbonWallet {
205
205
  try {
206
206
  if (!this.accountInfo || this.sequenceInvalidated)
207
207
  yield this.reloadAccountSequence();
208
- const heightResponse = yield fetch_1.fetch(`${this.networkConfig.tmRpcUrl}/blockchain?cache=${new Date().getTime()}`);
208
+ const heightResponse = yield (0, fetch_1.fetch)(`${this.networkConfig.tmRpcUrl}/blockchain?cache=${new Date().getTime()}`);
209
209
  const heightRes = yield heightResponse.json();
210
- const height = number_1.bnOrZero((_a = heightRes.result) === null || _a === void 0 ? void 0 : _a.last_height);
210
+ const height = (0, number_1.bnOrZero)((_a = heightRes.result) === null || _a === void 0 ? void 0 : _a.last_height);
211
211
  const timeoutHeight = height.isZero() ? undefined : height.toNumber() + this.defaultTimeoutBlocks;
212
212
  const sequence = this.accountInfo.sequence;
213
213
  this.accountInfo = Object.assign(Object.assign({}, this.accountInfo), { sequence: sequence + 1 });
@@ -341,12 +341,12 @@ class CarbonWallet {
341
341
  const queryClient = this.getQueryClient();
342
342
  const { msgGasCosts } = yield queryClient.fee.MsgGasCostAll({});
343
343
  this.txGasCosts = msgGasCosts.reduce((result, item) => {
344
- result[item.msgType] = number_1.bnOrZero(item.gasCost);
344
+ result[item.msgType] = (0, number_1.bnOrZero)(item.gasCost);
345
345
  return result;
346
346
  }, {});
347
347
  const { minGasPrices } = yield queryClient.fee.MinGasPriceAll({});
348
348
  this.txGasPrices = minGasPrices.reduce((result, item) => {
349
- result[item.denom] = number_1.bnOrZero(item.gasPrice).shiftedBy(-18); // sdk.Dec shifting
349
+ result[item.denom] = (0, number_1.bnOrZero)(item.gasPrice).shiftedBy(-18); // sdk.Dec shifting
350
350
  return result;
351
351
  }, {});
352
352
  if (!this.txGasPrices[this.defaultFeeDenom]) {
@@ -171,7 +171,7 @@ class WSConnector {
171
171
  params = [params]; // eslint-disable-line no-param-reassign
172
172
  }
173
173
  for (const param of params) {
174
- const channelId = channel_1.generateChannelId(param);
174
+ const channelId = (0, channel_1.generateChannelId)(param);
175
175
  const shouldSubscribe = this.channelHandlers[channelId] === undefined;
176
176
  this.channelHandlers[channelId] = handler;
177
177
  if (shouldSubscribe) {
@@ -193,7 +193,7 @@ class WSConnector {
193
193
  }
194
194
  const channelIds = [];
195
195
  for (const param of params) {
196
- const channelId = channel_1.generateChannelId(param);
196
+ const channelId = (0, channel_1.generateChannelId)(param);
197
197
  delete this.channelHandlers[channelId];
198
198
  }
199
199
  this.send('unsubscribe', {
@@ -279,7 +279,7 @@ class WSConnector {
279
279
  if (!channelHandler) {
280
280
  this.debugLog(`handler not found for channel: ${message.channel}`);
281
281
  try {
282
- const params = channel_1.parseChannelId(message.channel);
282
+ const params = (0, channel_1.parseChannelId)(message.channel);
283
283
  this.unsubscribe({ channel: params.channel });
284
284
  }
285
285
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",