This commit is contained in:
Brendon Duncan 2018-08-22 19:32:53 +12:00
commit 95de043d3d
2 changed files with 51 additions and 43 deletions

View file

@ -18,12 +18,46 @@
var SAFE_CONFIRMATIONS = 6;
var allTransactionsFetched = false;
var service = {
getCachedTxHistory: getCachedTxHistory,
updateLocalTxHistoryByPage: updateLocalTxHistoryByPage,
};
return service;
/*
function hasAllTransactionsFetched(walletId, cachedTxs, newTxs) {
var cachedTxIds = {};
cachedTxs.forEach(function forCachedTx(tx){
cachedTxIds[tx.txid] = true;
});
var someTransactionWereNew = false;
var overlappingTxsCount = 0;
newTxs.forEach(function forNewTx(tx){
if (cachedTxIds[tx.txid]) {
overlappingTxsCount++;
} else {
someTransactionWereNew = true;
}
});
console.log('pagination Overlapping transactions:', overlappingTxsCount);
if (overlappingTxsCount >= MIN_KNOWN_TX_OVERLAP) { // We are good
if (!someTransactionWereNew && overlappingTxsCount === newTxs.length) {
console.log("We probably have all of the transactions fetched!!")
return true;
}
} else {
console.log("Something went wrong")
return true; // Something went wrong, so stop fetching..
}
return false;
}
*/
function addEarlyTransactions(walletId, cachedTxs, newTxs) {
var cachedTxIds = {};
@ -48,6 +82,9 @@
if (someTransactionsWereNew) {
console.log('pagination someTransactionsWereNew');
saveTxHistory(walletId, cachedTxs);
} else if (overlappingTxsCount === newTxs.length) {
console.log('We probably have all transactions now');
allTransactionsFetched = true;
}
return cachedTxs;
} else {
@ -225,7 +262,7 @@
}
if (fetchedTxs.length === 0) {
return cb(null, cachedTxs);
return cb(null, cachedTxs, true /*fetchedAllTransactions*/);
}
var txs = [];
@ -233,11 +270,12 @@
txs = addLatestTransactions(wallet.id, cachedTxs, fetchedTxs);
} else {
txs = addEarlyTransactions(wallet.id, cachedTxs, fetchedTxs);
return cb(null, txs, allTransactionsFetched/*, hasAllTransactionsFetched(wallet.id, cachedTxs, fetchedTxs)*/);
}
return cb(null, txs);
});
});
}
}