@xchainjs/xchain-thorchain 0.28.3 → 0.28.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/client.d.ts +1 -1
- package/lib/index.esm.js +89 -56
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +89 -56
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
package/lib/client.d.ts
CHANGED
|
@@ -177,7 +177,7 @@ declare class Client extends BaseXChainClient implements ThorchainClient, XChain
|
|
|
177
177
|
* @param {string} txId The transaction id.
|
|
178
178
|
* @returns {Tx} The transaction details of the given transaction id.
|
|
179
179
|
*/
|
|
180
|
-
getTransactionData(txId: string, address?:
|
|
180
|
+
getTransactionData(txId: string, address?: string): Promise<Tx>;
|
|
181
181
|
/** This function is used when in bound or outbound tx is not of thorchain
|
|
182
182
|
*
|
|
183
183
|
* @param txId - transaction hash
|
package/lib/index.esm.js
CHANGED
|
@@ -9870,8 +9870,12 @@ const getDepositTxDataFromLogs = (logs, address, senderAsset, receiverAsset) =>
|
|
|
9870
9870
|
newData.sender = value;
|
|
9871
9871
|
if (key === 'recipient')
|
|
9872
9872
|
newData.recipient = value;
|
|
9873
|
-
if (key === 'amount')
|
|
9874
|
-
|
|
9873
|
+
if (key === 'amount') {
|
|
9874
|
+
const amountAsset = value.match(/(\d+)(\D+)/);
|
|
9875
|
+
if (amountAsset) {
|
|
9876
|
+
newData.amount = baseAmount(parseInt(amountAsset[1]));
|
|
9877
|
+
}
|
|
9878
|
+
}
|
|
9875
9879
|
return acc2;
|
|
9876
9880
|
}, acc);
|
|
9877
9881
|
}
|
|
@@ -10208,7 +10212,10 @@ class Client extends BaseXChainClient {
|
|
|
10208
10212
|
const txs = [];
|
|
10209
10213
|
for (let i = 0; i < history.length; i += 10) {
|
|
10210
10214
|
const batch = history.slice(i, i + 10);
|
|
10211
|
-
const result = yield Promise.all(batch.map(({ hash }) => this
|
|
10215
|
+
const result = yield Promise.all(batch.map(({ hash }) => __awaiter(this, void 0, void 0, function* () {
|
|
10216
|
+
const data = yield this.getTransactionData(hash, address);
|
|
10217
|
+
return data;
|
|
10218
|
+
})));
|
|
10212
10219
|
txs.push(...result);
|
|
10213
10220
|
delay(2000); // Delay to avoid 503 from ninerealms server
|
|
10214
10221
|
}
|
|
@@ -10441,65 +10448,91 @@ class Client extends BaseXChainClient {
|
|
|
10441
10448
|
* @returns {Tx} The transaction details of the given transaction id.
|
|
10442
10449
|
*/
|
|
10443
10450
|
getTransactionData(txId, address) {
|
|
10444
|
-
var _a, _b, _c;
|
|
10451
|
+
var _a, _b, _c, _d, _e, _f;
|
|
10445
10452
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10446
|
-
const
|
|
10447
|
-
if (
|
|
10448
|
-
|
|
10449
|
-
const
|
|
10450
|
-
const
|
|
10451
|
-
if (!
|
|
10452
|
-
throw new Error(
|
|
10453
|
-
|
|
10454
|
-
const
|
|
10455
|
-
const
|
|
10456
|
-
|
|
10457
|
-
|
|
10458
|
-
|
|
10459
|
-
|
|
10460
|
-
|
|
10461
|
-
const
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
const
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10453
|
+
const txResult = yield this.fetchTransaction(txId);
|
|
10454
|
+
if (txResult && txResult.logs) {
|
|
10455
|
+
// extract values from the response
|
|
10456
|
+
const transferEvent = (_a = txResult.logs[0].events) === null || _a === void 0 ? void 0 : _a.find((event) => event.type === 'transfer');
|
|
10457
|
+
const messageEvent = (_b = txResult.logs[0].events) === null || _b === void 0 ? void 0 : _b.find((event) => event.type === 'message');
|
|
10458
|
+
if (!transferEvent || !messageEvent) {
|
|
10459
|
+
throw new Error('Invalid transaction data');
|
|
10460
|
+
}
|
|
10461
|
+
const attributeGroups = {};
|
|
10462
|
+
for (const attr of transferEvent.attributes) {
|
|
10463
|
+
if (!attributeGroups[attr.key]) {
|
|
10464
|
+
attributeGroups[attr.key] = [];
|
|
10465
|
+
}
|
|
10466
|
+
attributeGroups[attr.key].push(attr.value);
|
|
10467
|
+
}
|
|
10468
|
+
const assetAmount = attributeGroups['amount'][1]
|
|
10469
|
+
? attributeGroups['amount'][1].split(/(?<=\d)(?=\D)/).filter(Boolean)[0]
|
|
10470
|
+
: attributeGroups['amount'][0].split(/(?<=\d)(?=\D)/).filter(Boolean)[0];
|
|
10471
|
+
const assetString = attributeGroups['amount'][1]
|
|
10472
|
+
? attributeGroups['amount'][1]
|
|
10473
|
+
.split(/(?<=\d)(?=\D)/)
|
|
10474
|
+
.filter(Boolean)[1]
|
|
10475
|
+
.replace(/[a-z]/g, (letter) => letter.toUpperCase())
|
|
10476
|
+
: attributeGroups['amount'][0]
|
|
10477
|
+
.split(/(?<=\d)(?=\D)/)
|
|
10478
|
+
.filter(Boolean)[1]
|
|
10479
|
+
.replace(/[a-z]/g, (letter) => letter.toUpperCase());
|
|
10480
|
+
const fromAddress = ((_c = transferEvent.attributes.find((attr) => attr.key === 'sender')) === null || _c === void 0 ? void 0 : _c.value)
|
|
10481
|
+
? (_d = transferEvent.attributes.find((attr) => attr.key === 'sender')) === null || _d === void 0 ? void 0 : _d.value
|
|
10482
|
+
: address;
|
|
10483
|
+
const memo = ((_e = txResult.tx) === null || _e === void 0 ? void 0 : _e.body) ? txResult.tx.body.memo.split(':') : '';
|
|
10484
|
+
const toAddress = memo[2] ? memo[2] : '';
|
|
10485
|
+
const toAsset = memo[1] ? assetFromStringEx(memo[1]) : AssetRuneNative;
|
|
10486
|
+
const date = new Date(txResult.timestamp);
|
|
10487
|
+
const typeString = (_f = messageEvent.attributes.find((attr) => attr.key === 'action')) === null || _f === void 0 ? void 0 : _f.value;
|
|
10488
|
+
const hash = txResult.txhash;
|
|
10489
|
+
if (assetString && hash && fromAddress && typeString) {
|
|
10490
|
+
const fromAsset = assetString === 'RUNE' ? AssetRuneNative : assetFromStringEx(assetString);
|
|
10491
|
+
const txData = txResult && txResult.raw_log
|
|
10492
|
+
? getDepositTxDataFromLogs(txResult.logs, `${fromAddress}`, fromAsset, toAsset)
|
|
10472
10493
|
: null;
|
|
10473
|
-
//console.log(JSON.stringify(txData, null, 2))
|
|
10474
10494
|
if (!txData)
|
|
10475
10495
|
throw new Error(`Failed to get transaction data (tx-hash: ${txId})`);
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10496
|
+
if (isAssetRuneNative(toAsset) || toAsset.synth) {
|
|
10497
|
+
const { from, to, type } = txData;
|
|
10498
|
+
const tx = {
|
|
10499
|
+
asset: fromAsset,
|
|
10500
|
+
from: from,
|
|
10501
|
+
to: to,
|
|
10502
|
+
date: date,
|
|
10503
|
+
type: type,
|
|
10504
|
+
hash: hash,
|
|
10505
|
+
};
|
|
10506
|
+
return tx;
|
|
10507
|
+
}
|
|
10508
|
+
else {
|
|
10509
|
+
const tx = {
|
|
10510
|
+
asset: fromAsset,
|
|
10511
|
+
from: [{ from: fromAddress, amount: baseAmount(assetAmount), asset: fromAsset }],
|
|
10512
|
+
to: [{ to: toAddress, amount: baseAmount(memo[3]), asset: toAsset }],
|
|
10513
|
+
date: date,
|
|
10514
|
+
type: TxType.Transfer,
|
|
10515
|
+
hash: hash,
|
|
10516
|
+
};
|
|
10517
|
+
return tx;
|
|
10518
|
+
}
|
|
10519
|
+
}
|
|
10520
|
+
else {
|
|
10521
|
+
const tx = {
|
|
10522
|
+
asset: {
|
|
10523
|
+
chain: '',
|
|
10524
|
+
symbol: '',
|
|
10525
|
+
ticker: '',
|
|
10526
|
+
synth: false,
|
|
10527
|
+
},
|
|
10528
|
+
from: [],
|
|
10529
|
+
to: [],
|
|
10530
|
+
date: new Date(),
|
|
10531
|
+
type: TxType.Transfer,
|
|
10532
|
+
hash: '',
|
|
10484
10533
|
};
|
|
10534
|
+
return tx;
|
|
10485
10535
|
}
|
|
10486
|
-
// synths and other tx types
|
|
10487
|
-
const messageBody = JSON.stringify((_c = txResult.tx) === null || _c === void 0 ? void 0 : _c.body.messages).split(':');
|
|
10488
|
-
const assetTo = assetFromStringEx(messageBody[7]);
|
|
10489
|
-
const txData = txResult && txResult.logs
|
|
10490
|
-
? getDepositTxDataFromLogs(txResult.logs, `${senderAddress}`, senderAsset, assetTo)
|
|
10491
|
-
: null;
|
|
10492
|
-
if (!txData)
|
|
10493
|
-
throw new Error(`Failed to get transaction data (tx-hash: ${txId})`);
|
|
10494
|
-
const { from, to, type } = txData;
|
|
10495
|
-
return {
|
|
10496
|
-
hash: txId,
|
|
10497
|
-
asset: senderAsset,
|
|
10498
|
-
from,
|
|
10499
|
-
to,
|
|
10500
|
-
date: new Date(txResult.timestamp),
|
|
10501
|
-
type,
|
|
10502
|
-
};
|
|
10503
10536
|
}
|
|
10504
10537
|
else {
|
|
10505
10538
|
return yield this.getTransactionDataThornode(txId);
|