Fixed addressTransactions with pagination in electrum API.

This commit is contained in:
softsimon 2020-12-30 02:27:34 +07:00
parent 5390629e41
commit 89b4de2484
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -110,14 +110,25 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
if (!addressInfo || !addressInfo.isvalid) {
return [];
}
const history = await this.$getScriptHashHistory(addressInfo.scriptPubKey);
const transactions: IEsploraApi.Transaction[] = [];
for (const h of history) {
const tx = await this.$getRawTransaction(h.tx_hash, false, true);
const history = await this.$getScriptHashHistory(addressInfo.scriptPubKey);
history.reverse();
let startingIndex = 0;
if (lastSeenTxId) {
const pos = history.findIndex((historicalTx) => historicalTx.tx_hash === lastSeenTxId);
if (pos) {
startingIndex = pos + 1;
}
}
for (let i = startingIndex; i < Math.min(startingIndex + 10, history.length); i++) {
const tx = await this.$getRawTransaction(history[i].tx_hash, false, true);
if (tx) {
transactions.push(tx);
}
}
return transactions;
}