@xchainjs/xchain-thorchain 0.28.1 → 0.28.3

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/client.d.ts CHANGED
@@ -165,13 +165,19 @@ declare class Client extends BaseXChainClient implements ThorchainClient, XChain
165
165
  getTransactions: (params?: (TxHistoryParams & {
166
166
  filterFn?: ((tx: RPCTxResult) => boolean) | undefined;
167
167
  }) | undefined) => Promise<TxsPage>;
168
+ /**
169
+ *
170
+ * @param txId - tx hash
171
+ * @returns txResponse
172
+ */
173
+ fetchTransaction(txId: string): Promise<import("@xchainjs/xchain-cosmos").TxResponse | null>;
168
174
  /**
169
175
  * Get the transaction details of a given transaction id.
170
176
  *
171
177
  * @param {string} txId The transaction id.
172
178
  * @returns {Tx} The transaction details of the given transaction id.
173
179
  */
174
- getTransactionData(txId: string, address: Address): Promise<Tx>;
180
+ getTransactionData(txId: string, address?: Address): Promise<Tx>;
175
181
  /** This function is used when in bound or outbound tx is not of thorchain
176
182
  *
177
183
  * @param txId - transaction hash
package/lib/const.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Asset } from '@xchainjs/xchain-util/lib';
2
2
  import { ExplorerUrls } from './types';
3
3
  export declare const RUNE_DECIMAL = 8;
4
4
  export declare const DEFAULT_GAS_ADJUSTMENT = 2;
5
- export declare const DEFAULT_GAS_LIMIT_VALUE = "4000000";
5
+ export declare const DEFAULT_GAS_LIMIT_VALUE = "6000000";
6
6
  export declare const DEPOSIT_GAS_LIMIT_VALUE = "600000000";
7
7
  export declare const MAX_TX_COUNT_PER_PAGE = 100;
8
8
  export declare const MAX_TX_COUNT_PER_FUNCTION_CALL = 500;
@@ -49,3 +49,20 @@ export declare const AssetRuneERC20: Asset;
49
49
  * @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
50
50
  */
51
51
  export declare const AssetRuneERC20Testnet: Asset;
52
+ /**
53
+ * Fall back node's and rpc's
54
+ */
55
+ export declare const FallBackUrls: {
56
+ testnet: {
57
+ node: string[];
58
+ rpc: string[];
59
+ };
60
+ stagenet: {
61
+ node: string[];
62
+ rpc: string[];
63
+ };
64
+ mainnet: {
65
+ node: string[];
66
+ rpc: string[];
67
+ };
68
+ }[];
package/lib/index.esm.js CHANGED
@@ -4257,7 +4257,7 @@ const addressUrl = `${DEFAULT_EXPLORER_URL}/address`;
4257
4257
  const RUNE_TICKER = 'RUNE';
4258
4258
  const RUNE_DECIMAL = 8;
4259
4259
  const DEFAULT_GAS_ADJUSTMENT = 2;
4260
- const DEFAULT_GAS_LIMIT_VALUE = '4000000';
4260
+ const DEFAULT_GAS_LIMIT_VALUE = '6000000';
4261
4261
  const DEPOSIT_GAS_LIMIT_VALUE = '600000000';
4262
4262
  const MAX_TX_COUNT_PER_PAGE = 100;
4263
4263
  const MAX_TX_COUNT_PER_FUNCTION_CALL = 500;
@@ -4330,6 +4330,25 @@ const AssetRuneERC20Testnet = {
4330
4330
  ticker: RUNE_TICKER,
4331
4331
  synth: false,
4332
4332
  };
4333
+ /**
4334
+ * Fall back node's and rpc's
4335
+ */
4336
+ const FallBackUrls = [
4337
+ {
4338
+ [Network.Testnet]: {
4339
+ node: ['deprecated'],
4340
+ rpc: ['deprecated'],
4341
+ },
4342
+ [Network.Stagenet]: {
4343
+ node: ['https://stagenet-thornode.ninerealms.com'],
4344
+ rpc: ['https://stagenet-rpc.ninerealms.com'],
4345
+ },
4346
+ [Network.Mainnet]: {
4347
+ node: ['https://thornode-v1.ninerealms.com', 'https://thornode.thorswap.net/'],
4348
+ rpc: ['https://rpc-v1.ninerealms.com', 'https://rpc.thorswap.net'],
4349
+ },
4350
+ },
4351
+ ];
4333
4352
 
4334
4353
  var indexMinimal = {};
4335
4354
 
@@ -4972,21 +4991,29 @@ function requireFloat () {
4972
4991
  return float;
4973
4992
  }
4974
4993
 
4975
- var inquire_1 = inquire;
4994
+ var inquire_1;
4995
+ var hasRequiredInquire;
4996
+
4997
+ function requireInquire () {
4998
+ if (hasRequiredInquire) return inquire_1;
4999
+ hasRequiredInquire = 1;
5000
+ inquire_1 = inquire;
4976
5001
 
4977
- /**
4978
- * Requires a module only if available.
4979
- * @memberof util
4980
- * @param {string} moduleName Module to require
4981
- * @returns {?Object} Required module if available and not empty, otherwise `null`
4982
- */
4983
- function inquire(moduleName) {
4984
- try {
4985
- var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
4986
- if (mod && (mod.length || Object.keys(mod).length))
4987
- return mod;
4988
- } catch (e) {} // eslint-disable-line no-empty
4989
- return null;
5002
+ /**
5003
+ * Requires a module only if available.
5004
+ * @memberof util
5005
+ * @param {string} moduleName Module to require
5006
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
5007
+ */
5008
+ function inquire(moduleName) {
5009
+ try {
5010
+ var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
5011
+ if (mod && (mod.length || Object.keys(mod).length))
5012
+ return mod;
5013
+ } catch (e) {} // eslint-disable-line no-empty
5014
+ return null;
5015
+ }
5016
+ return inquire_1;
4990
5017
  }
4991
5018
 
4992
5019
  var utf8$2 = {};
@@ -5390,7 +5417,7 @@ function requireMinimal () {
5390
5417
  util.float = requireFloat();
5391
5418
 
5392
5419
  // requires modules optionally and hides the call from bundlers
5393
- util.inquire = inquire_1;
5420
+ util.inquire = requireInquire();
5394
5421
 
5395
5422
  // converts to / from utf8 encoded strings
5396
5423
  util.utf8 = requireUtf8();
@@ -10373,6 +10400,40 @@ class Client extends BaseXChainClient {
10373
10400
  };
10374
10401
  return assetInfo;
10375
10402
  }
10403
+ /**
10404
+ *
10405
+ * @param txId - tx hash
10406
+ * @returns txResponse
10407
+ */
10408
+ fetchTransaction(txId) {
10409
+ return __awaiter(this, void 0, void 0, function* () {
10410
+ try {
10411
+ const transaction = yield this.cosmosClient.txsHashGet(txId);
10412
+ return transaction;
10413
+ }
10414
+ catch (error) {
10415
+ for (const fallback of FallBackUrls) {
10416
+ for (const network of Object.keys(fallback)) {
10417
+ try {
10418
+ const networkObj = fallback[network];
10419
+ const clientUrl = networkObj.node;
10420
+ const cosmosClient = new CosmosSDKClient({
10421
+ server: Array.isArray(clientUrl) ? clientUrl[0] : clientUrl,
10422
+ chainId: this.getChainId(network),
10423
+ prefix: getPrefix(network),
10424
+ });
10425
+ const tx = yield cosmosClient.txsHashGet(txId);
10426
+ return tx;
10427
+ }
10428
+ catch (error) {
10429
+ // Handle specific error if needed
10430
+ }
10431
+ }
10432
+ }
10433
+ return null;
10434
+ }
10435
+ });
10436
+ }
10376
10437
  /**
10377
10438
  * Get the transaction details of a given transaction id.
10378
10439
  *
@@ -10382,8 +10443,9 @@ class Client extends BaseXChainClient {
10382
10443
  getTransactionData(txId, address) {
10383
10444
  var _a, _b, _c;
10384
10445
  return __awaiter(this, void 0, void 0, function* () {
10385
- try {
10386
- const txResult = yield this.cosmosClient.txsHashGet(txId);
10446
+ const response = yield this.fetchTransaction(txId);
10447
+ if (response) {
10448
+ const txResult = response;
10387
10449
  const bond = txResult.logs && txResult.logs[0].events.filter((i) => i.type === 'bond');
10388
10450
  const transfer = txResult.logs && txResult.logs[0].events.filter((i) => i.type === 'transfer');
10389
10451
  if (!transfer)
@@ -10403,10 +10465,10 @@ class Client extends BaseXChainClient {
10403
10465
  if (!bond)
10404
10466
  throw new Error(`Failed to get transaction logs (tx-hash: ${txId})`);
10405
10467
  // Rune only transactions
10406
- if (bond[0].type === 'bond' || action === 'send') {
10468
+ if (action === 'send' || bond[0].type === 'bond') {
10407
10469
  const assetTo = AssetRuneNative;
10408
10470
  const txData = txResult && txResult.logs
10409
- ? getDepositTxDataFromLogs(txResult.logs, senderAddress, senderAsset, assetTo)
10471
+ ? getDepositTxDataFromLogs(txResult.logs, `${senderAddress}`, senderAsset, assetTo)
10410
10472
  : null;
10411
10473
  //console.log(JSON.stringify(txData, null, 2))
10412
10474
  if (!txData)
@@ -10424,7 +10486,9 @@ class Client extends BaseXChainClient {
10424
10486
  // synths and other tx types
10425
10487
  const messageBody = JSON.stringify((_c = txResult.tx) === null || _c === void 0 ? void 0 : _c.body.messages).split(':');
10426
10488
  const assetTo = assetFromStringEx(messageBody[7]);
10427
- const txData = txResult && txResult.logs ? getDepositTxDataFromLogs(txResult.logs, senderAddress, senderAsset, assetTo) : null;
10489
+ const txData = txResult && txResult.logs
10490
+ ? getDepositTxDataFromLogs(txResult.logs, `${senderAddress}`, senderAsset, assetTo)
10491
+ : null;
10428
10492
  if (!txData)
10429
10493
  throw new Error(`Failed to get transaction data (tx-hash: ${txId})`);
10430
10494
  const { from, to, type } = txData;
@@ -10437,8 +10501,9 @@ class Client extends BaseXChainClient {
10437
10501
  type,
10438
10502
  };
10439
10503
  }
10440
- catch (error) { }
10441
- return yield this.getTransactionDataThornode(txId);
10504
+ else {
10505
+ return yield this.getTransactionDataThornode(txId);
10506
+ }
10442
10507
  });
10443
10508
  }
10444
10509
  /** This function is used when in bound or outbound tx is not of thorchain
@@ -10739,5 +10804,5 @@ const msgNativeTxFromJson = (value) => {
10739
10804
  return new MsgNativeTx(value.coins, value.memo, cosmosclient.AccAddress.fromString(value.signer));
10740
10805
  };
10741
10806
 
10742
- export { AssetRune67C, AssetRuneB1A, AssetRuneERC20, AssetRuneERC20Testnet, AssetRuneNative, Client, DEFAULT_GAS_ADJUSTMENT, DEFAULT_GAS_LIMIT_VALUE, DEPOSIT_GAS_LIMIT_VALUE, MAX_PAGES_PER_FUNCTION_CALL, MAX_TX_COUNT_PER_FUNCTION_CALL, MAX_TX_COUNT_PER_PAGE, MsgNativeTx, RUNE_DECIMAL, RUNE_SYMBOL, THORChain, assetFromDenom, buildDepositTx, buildTransferTx, buildUnsignedTx, defaultExplorerUrls, getAccount, getBalance, getChainId, getDefaultFees, getDenom, getDepositTxDataFromLogs, getEstimatedGas, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getSequence, getTxType, isAssetRuneNative, isBroadcastSuccess, msgNativeTxFromJson, registerDepositCodecs, registerSendCodecs };
10807
+ export { AssetRune67C, AssetRuneB1A, AssetRuneERC20, AssetRuneERC20Testnet, AssetRuneNative, Client, DEFAULT_GAS_ADJUSTMENT, DEFAULT_GAS_LIMIT_VALUE, DEPOSIT_GAS_LIMIT_VALUE, FallBackUrls, MAX_PAGES_PER_FUNCTION_CALL, MAX_TX_COUNT_PER_FUNCTION_CALL, MAX_TX_COUNT_PER_PAGE, MsgNativeTx, RUNE_DECIMAL, RUNE_SYMBOL, THORChain, assetFromDenom, buildDepositTx, buildTransferTx, buildUnsignedTx, defaultExplorerUrls, getAccount, getBalance, getChainId, getDefaultFees, getDenom, getDepositTxDataFromLogs, getEstimatedGas, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getSequence, getTxType, isAssetRuneNative, isBroadcastSuccess, msgNativeTxFromJson, registerDepositCodecs, registerSendCodecs };
10743
10808
  //# sourceMappingURL=index.esm.js.map