@xchainjs/xchain-thorchain 0.20.0 → 0.20.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v0.20.1 (2022-01-11)
2
+
3
+ ## Fix
4
+
5
+ - Get chain ID from THORNode before posting to deposit handler.
6
+
1
7
  # v.0.20.0 (2021-12-29)
2
8
 
3
9
  ## Breaking change
package/lib/index.esm.js CHANGED
@@ -200,9 +200,20 @@ var getPrefix = function (network) {
200
200
  /**
201
201
  * Get the chain id.
202
202
  *
203
+ * @param {Network} network
203
204
  * @returns {string} The chain id based on the network.
205
+ *
204
206
  */
205
- var getChainId = function () { return 'thorchain'; };
207
+ var getChainId = function (network) {
208
+ switch (network) {
209
+ case Network.Mainnet:
210
+ return 'thorchain';
211
+ case Network.Stagenet:
212
+ return 'thorchain-stagenet';
213
+ case Network.Testnet:
214
+ return 'thorchain';
215
+ }
216
+ };
206
217
  /**
207
218
  * Register Codecs based on the prefix.
208
219
  *
@@ -286,19 +297,25 @@ var getTxType = function (txData, encoding) {
286
297
  * @throws {"Invalid client url"} Thrown if the client url is an invalid one.
287
298
  */
288
299
  var buildDepositTx = function (msgNativeTx, nodeUrl) { return __awaiter(void 0, void 0, void 0, function () {
289
- var response, fee, unsignedStdTx;
300
+ var data, chainId, response, fee, unsignedStdTx;
290
301
  var _a, _b;
291
302
  return __generator(this, function (_c) {
292
303
  switch (_c.label) {
293
- case 0: return [4 /*yield*/, axios.post(nodeUrl + "/thorchain/deposit", {
294
- coins: msgNativeTx.coins,
295
- memo: msgNativeTx.memo,
296
- base_req: {
297
- chain_id: getChainId(),
298
- from: msgNativeTx.signer,
299
- },
300
- })];
304
+ case 0: return [4 /*yield*/, axios.get(nodeUrl + "/cosmos/base/tendermint/v1beta1/node_info")];
301
305
  case 1:
306
+ data = (_c.sent()).data;
307
+ chainId = data.default_node_info.network;
308
+ if (!chainId || !(chainId == 'thorchain' || chainId == 'thorchain-stagenet'))
309
+ throw new Error('invalid network');
310
+ return [4 /*yield*/, axios.post(nodeUrl + "/thorchain/deposit", {
311
+ coins: msgNativeTx.coins,
312
+ memo: msgNativeTx.memo,
313
+ base_req: {
314
+ chain_id: chainId,
315
+ from: msgNativeTx.signer,
316
+ },
317
+ })];
318
+ case 2:
302
319
  response = (_c.sent()).data;
303
320
  if (!response || !response.value)
304
321
  throw new Error('Invalid client url');
@@ -541,7 +558,7 @@ var Client = /** @class */ (function () {
541
558
  this.rootDerivationPaths = rootDerivationPaths;
542
559
  this.cosmosClient = new CosmosSDKClient({
543
560
  server: this.getClientUrl().node,
544
- chainId: getChainId(),
561
+ chainId: getChainId(this.network),
545
562
  prefix: getPrefix(this.network),
546
563
  });
547
564
  if (phrase)
package/lib/index.js CHANGED
@@ -208,9 +208,20 @@ var getPrefix = function (network) {
208
208
  /**
209
209
  * Get the chain id.
210
210
  *
211
+ * @param {Network} network
211
212
  * @returns {string} The chain id based on the network.
213
+ *
212
214
  */
213
- var getChainId = function () { return 'thorchain'; };
215
+ var getChainId = function (network) {
216
+ switch (network) {
217
+ case xchainClient.Network.Mainnet:
218
+ return 'thorchain';
219
+ case xchainClient.Network.Stagenet:
220
+ return 'thorchain-stagenet';
221
+ case xchainClient.Network.Testnet:
222
+ return 'thorchain';
223
+ }
224
+ };
214
225
  /**
215
226
  * Register Codecs based on the prefix.
216
227
  *
@@ -294,19 +305,25 @@ var getTxType = function (txData, encoding) {
294
305
  * @throws {"Invalid client url"} Thrown if the client url is an invalid one.
295
306
  */
296
307
  var buildDepositTx = function (msgNativeTx, nodeUrl) { return __awaiter(void 0, void 0, void 0, function () {
297
- var response, fee, unsignedStdTx;
308
+ var data, chainId, response, fee, unsignedStdTx;
298
309
  var _a, _b;
299
310
  return __generator(this, function (_c) {
300
311
  switch (_c.label) {
301
- case 0: return [4 /*yield*/, axios__default['default'].post(nodeUrl + "/thorchain/deposit", {
302
- coins: msgNativeTx.coins,
303
- memo: msgNativeTx.memo,
304
- base_req: {
305
- chain_id: getChainId(),
306
- from: msgNativeTx.signer,
307
- },
308
- })];
312
+ case 0: return [4 /*yield*/, axios__default['default'].get(nodeUrl + "/cosmos/base/tendermint/v1beta1/node_info")];
309
313
  case 1:
314
+ data = (_c.sent()).data;
315
+ chainId = data.default_node_info.network;
316
+ if (!chainId || !(chainId == 'thorchain' || chainId == 'thorchain-stagenet'))
317
+ throw new Error('invalid network');
318
+ return [4 /*yield*/, axios__default['default'].post(nodeUrl + "/thorchain/deposit", {
319
+ coins: msgNativeTx.coins,
320
+ memo: msgNativeTx.memo,
321
+ base_req: {
322
+ chain_id: chainId,
323
+ from: msgNativeTx.signer,
324
+ },
325
+ })];
326
+ case 2:
310
327
  response = (_c.sent()).data;
311
328
  if (!response || !response.value)
312
329
  throw new Error('Invalid client url');
@@ -549,7 +566,7 @@ var Client = /** @class */ (function () {
549
566
  this.rootDerivationPaths = rootDerivationPaths;
550
567
  this.cosmosClient = new xchainCosmos.CosmosSDKClient({
551
568
  server: this.getClientUrl().node,
552
- chainId: getChainId(),
569
+ chainId: getChainId(this.network),
553
570
  prefix: getPrefix(this.network),
554
571
  });
555
572
  if (phrase)
package/lib/util.d.ts CHANGED
@@ -63,9 +63,11 @@ export declare const getPrefix: (network: Network) => "thor" | "sthor" | "tthor"
63
63
  /**
64
64
  * Get the chain id.
65
65
  *
66
+ * @param {Network} network
66
67
  * @returns {string} The chain id based on the network.
68
+ *
67
69
  */
68
- export declare const getChainId: () => string;
70
+ export declare const getChainId: (network: Network) => "thorchain" | "thorchain-stagenet";
69
71
  /**
70
72
  * Register Codecs based on the prefix.
71
73
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "Custom Thorchain client and utilities used by XChainJS clients",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -52,4 +52,4 @@
52
52
  "axios": "^0.21.0",
53
53
  "cosmos-client": "0.39.2"
54
54
  }
55
- }
55
+ }