@xchainjs/xchain-thorchain-query 0.6.3 → 0.6.5

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/index.esm.js CHANGED
@@ -890,13 +890,8 @@ class Thornode {
890
890
  try {
891
891
  const resp = (yield api.thorname(thorname, height)).data;
892
892
  return resp;
893
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
894
- }
895
- catch (e) {
896
- if (e.response.status == 404) {
897
- return undefined;
898
- }
899
893
  }
894
+ catch (e) { }
900
895
  }
901
896
  throw new Error(`THORNode is not responding`);
902
897
  });
@@ -1799,7 +1794,8 @@ class ThorchainQuery {
1799
1794
  const errors = [];
1800
1795
  const inboundDetails = yield this.thorchainCache.getInboundDetails();
1801
1796
  const blockData = (yield this.thorchainCache.thornode.getLastBlock()).find((item) => item.chain === params.asset.chain);
1802
- const savers = (yield this.thorchainCache.thornode.getSavers(`${params.asset.chain}.${params.asset.symbol}`)).find((item) => item.asset_address === params.address);
1797
+ // address comparison is done after conversion to lower case
1798
+ const savers = (yield this.thorchainCache.thornode.getSavers(`${params.asset.chain}.${params.asset.symbol}`)).find((item) => item.asset_address.toLowerCase() === params.address.toLowerCase());
1803
1799
  const pool = (yield this.thorchainCache.getPoolForAsset(params.asset)).thornodeDetails;
1804
1800
  if (!savers)
1805
1801
  errors.push(`Could not find position for ${params.address}`);
@@ -2002,12 +1998,38 @@ class ThorchainQuery {
2002
1998
  getThornameDetails(thorname, height) {
2003
1999
  return __awaiter(this, void 0, void 0, function* () {
2004
2000
  const errors = [];
2005
- const thornameResp = yield this.thorchainCache.thornode.getThornameDetails(thorname, height);
2006
- const thornameRawData = thornameResp; // TODO: Until integrate THORNode PR
2007
- const response = JSON.parse(JSON.stringify(thorname));
2008
- if (response.error)
2009
- errors.push(`Thornode request quote failed: ${response.error}`);
2010
- if (errors.length > 0) {
2001
+ try {
2002
+ const thornameResp = yield this.thorchainCache.thornode.getThornameDetails(thorname, height);
2003
+ const response = JSON.parse(JSON.stringify(thornameResp));
2004
+ if (response.error)
2005
+ errors.push(`Thornode request quote failed: ${response.error}`);
2006
+ if (errors.length > 0) {
2007
+ const errorResp = {
2008
+ name: '',
2009
+ expireBlockHeight: 0,
2010
+ owner: '',
2011
+ preferredAsset: '',
2012
+ affiliateCollectorRune: '',
2013
+ aliases: [],
2014
+ error: errors,
2015
+ };
2016
+ return errorResp;
2017
+ }
2018
+ const thornameAliases = thornameResp.aliases.map((alias) => ({
2019
+ chain: alias.chain,
2020
+ address: alias.address,
2021
+ }));
2022
+ const thornameDetails = {
2023
+ name: thornameResp.name || '',
2024
+ expireBlockHeight: thornameResp.expire_block_height || 0,
2025
+ owner: thornameResp.owner || '',
2026
+ preferredAsset: thornameResp.preferred_asset || '',
2027
+ affiliateCollectorRune: thornameResp.affiliate_collector_rune || '',
2028
+ aliases: thornameAliases || [],
2029
+ };
2030
+ return thornameDetails;
2031
+ }
2032
+ catch (e) {
2011
2033
  const errorResp = {
2012
2034
  name: '',
2013
2035
  expireBlockHeight: 0,
@@ -2019,19 +2041,6 @@ class ThorchainQuery {
2019
2041
  };
2020
2042
  return errorResp;
2021
2043
  }
2022
- const thornameAliases = thornameRawData.aliases.map((alias) => ({
2023
- chain: alias.chain,
2024
- address: alias.address,
2025
- }));
2026
- const thornameDetails = {
2027
- name: thornameRawData.name || '',
2028
- expireBlockHeight: thornameRawData.expire_block_height || 0,
2029
- owner: thornameRawData.owner || '',
2030
- preferredAsset: thornameRawData.preferred_asset,
2031
- affiliateCollectorRune: thornameRawData.affiliate_collector_rune || '',
2032
- aliases: thornameAliases,
2033
- };
2034
- return thornameDetails; // Return the array
2035
2044
  });
2036
2045
  }
2037
2046
  /**
@@ -2048,14 +2057,14 @@ class ThorchainQuery {
2048
2057
  estimateThorname(params) {
2049
2058
  return __awaiter(this, void 0, void 0, function* () {
2050
2059
  // CHECK IF ALREADY EXISTS
2051
- const thornameDetails = (yield this.thorchainCache.thornode.getThornameDetails(params.thorname)); // TODO: Until integrate THORNode PR
2052
- if (thornameDetails && !params.isUpdate) {
2053
- throw Error('Thorname already reistered');
2060
+ const thornameDetails = yield this.getThornameDetails(params.thorname);
2061
+ if (thornameDetails.owner !== '' && !params.isUpdate) {
2062
+ throw Error('Thorname already registered');
2054
2063
  }
2055
2064
  const blockData = yield this.thorchainCache.thornode.getLastBlock();
2056
2065
  const currentThorchainHeight = blockData[0].thorchain;
2057
2066
  const currentHeightForExpirity = params.isUpdate
2058
- ? thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expire_block_height
2067
+ ? thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expireBlockHeight
2059
2068
  : currentThorchainHeight;
2060
2069
  // DEFAULT EXPIRITY
2061
2070
  let numberOfBlocksToAddToExpirity = params.isUpdate ? 0 : 5259600; // One year by default
@@ -2066,8 +2075,8 @@ class ThorchainQuery {
2066
2075
  const numberOfSecondsToExpire = expirityTimestamp - currentTimestamp;
2067
2076
  const numberOfBlocks = Math.round(numberOfSecondsToExpire / 6);
2068
2077
  const newHeightExpirity = currentThorchainHeight + numberOfBlocks;
2069
- numberOfBlocksToAddToExpirity = (thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expire_block_height)
2070
- ? newHeightExpirity - (thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expire_block_height)
2078
+ numberOfBlocksToAddToExpirity = (thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expireBlockHeight)
2079
+ ? newHeightExpirity - (thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expireBlockHeight)
2071
2080
  : numberOfBlocks;
2072
2081
  }
2073
2082
  // COMPUTE VALUE
@@ -2247,8 +2256,8 @@ class TransactionStage {
2247
2256
  const assetIn = assetFromStringEx((_b = txData.tx.tx.coins) === null || _b === void 0 ? void 0 : _b[0].asset);
2248
2257
  const inboundAmount = (_c = txData.tx.tx.coins) === null || _c === void 0 ? void 0 : _c[0].amount;
2249
2258
  const fromAddress = (_d = txData.tx.tx.from_address) !== null && _d !== void 0 ? _d : 'unknkown';
2250
- const block = txData.tx.tx.chain == THORChain ? Number(txData.finalised_height) : Number(txData.tx.block_height);
2251
- const finalizeBlock = txData.tx.tx.chain == THORChain ? Number(txData.finalised_height) : Number(txData.tx.finalise_height);
2259
+ const block = txData.tx.tx.chain == THORChain ? Number(txData.finalised_height) : Number(txData.consensus_height);
2260
+ const finalizeBlock = txData.tx.tx.chain == THORChain ? Number(txData.finalised_height) : Number(txData.finalised_height);
2252
2261
  const status = txData.tx.status === 'done' ? InboundStatus.Observed_Consensus : InboundStatus.Observed_Incomplete;
2253
2262
  if (operation.match(/swap|s|=/gi))
2254
2263
  progress.txType = TxType.Swap;
@@ -2464,7 +2473,7 @@ class TransactionStage {
2464
2473
  let blockDifference;
2465
2474
  const currentHeight = lastBlockObj.find((obj) => obj.chain == chain);
2466
2475
  const chainHeight = Number(`${currentHeight === null || currentHeight === void 0 ? void 0 : currentHeight.last_observed_in}`);
2467
- const recordedChainHeight = Number(`${txData.tx.block_height}`);
2476
+ const recordedChainHeight = Number(`${txData.consensus_height}`);
2468
2477
  // If outbound time is required
2469
2478
  if (outboundBlock) {
2470
2479
  const currentHeight = lastBlockObj.find((obj) => obj);