FIX: some transactions displayed with 0 value - improved work with gap limit (closes #1835)

This commit is contained in:
Overtorment 2020-09-20 21:22:22 +01:00
parent 592ca890f1
commit 3e0a01254d

View file

@ -553,27 +553,33 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
async _fetchBalance() { async _fetchBalance() {
// probing future addressess in hierarchy whether they have any transactions, in case // probing future addressess in hierarchy whether they have any transactions, in case
// our 'next free addr' pointers are lagging behind // our 'next free addr' pointers are lagging behind
let tryAgain = false; // for that we are gona batch fetch history for all addresses between last used and last used + gap_limit
let txs = await BlueElectrum.getTransactionsByAddress(
this._getExternalAddressByIndex(this.next_free_address_index + this.gap_limit - 1), const lagAddressesToFetch = [];
); for (let c = this.next_free_address_index; c < this.next_free_address_index + this.gap_limit; c++) {
if (txs.length > 0) { lagAddressesToFetch.push(this._getExternalAddressByIndex(c));
// whoa, someone uses our wallet outside! better catch up }
this.next_free_address_index += this.gap_limit; for (let c = this.next_free_change_address_index; c < this.next_free_change_address_index + this.gap_limit; c++) {
tryAgain = true; lagAddressesToFetch.push(this._getInternalAddressByIndex(c));
} }
txs = await BlueElectrum.getTransactionsByAddress( const txs = await BlueElectrum.multiGetHistoryByAddress(lagAddressesToFetch); // <------ electrum call
this._getInternalAddressByIndex(this.next_free_change_address_index + this.gap_limit - 1),
); for (let c = this.next_free_address_index; c < this.next_free_address_index + this.gap_limit; c++) {
if (txs.length > 0) { const address = this._getExternalAddressByIndex(c);
this.next_free_change_address_index += this.gap_limit; if (txs[address] && Array.isArray(txs[address]) && txs[address].length > 0) {
tryAgain = true; // whoa, someone uses our wallet outside! better catch up
this.next_free_address_index = c + 1;
}
} }
// FIXME: refactor me ^^^ can be batched in single call. plus not just couple of addresses, but all between [ next_free .. (next_free + gap_limit) ] for (let c = this.next_free_change_address_index; c < this.next_free_change_address_index + this.gap_limit; c++) {
const address = this._getInternalAddressByIndex(c);
if (tryAgain) return this._fetchBalance(); if (txs[address] && Array.isArray(txs[address]) && txs[address].length > 0) {
// whoa, someone uses our wallet outside! better catch up
this.next_free_change_address_index = c + 1;
}
}
// next, business as usuall. fetch balances // next, business as usuall. fetch balances