Bugfix for getting wallet history when cache is empty, while still enforcing overlap in transactions when cache contains transactions, to ensure no transactions are missed.

This commit is contained in:
Brendon Duncan 2018-09-26 18:03:14 +12:00
commit d68870f743

View file

@ -6,7 +6,7 @@
.module('bitcoincom.services')
.factory('walletHistoryService', walletHistoryService);
function walletHistoryService(configService, storageService, lodash, $log, txFormatService) {
function walletHistoryService(storageService, lodash, $log, txFormatService) {
var PAGE_SIZE = 50;
//var PAGE_SIZE = 20; // For dev only
// How much to overlap on each end of the page, for mitigating inconsistent sort order.
@ -47,11 +47,17 @@
}
});
var overlappingTxFraction = overlappingTxsCount / Math.min(cachedTxs.length, PAGE_OVERLAP);
console.log('overlappingTxFraction:', overlappingTxFraction);
console.log('overlappingTxsCount:', overlappingTxsCount);
if (overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION || (someTransactionsWereNew && overlappingTxsCount === 0)) { // We are good
var txsAreContinuous = false;
if (cachedTxs.length > 0) {
var overlappingTxFraction = overlappingTxsCount / Math.min(cachedTxs.length, PAGE_OVERLAP);
console.log('overlappingTxsCount:', overlappingTxsCount);
console.log('overlappingTxFraction:', overlappingTxFraction);
txsAreContinuous = overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION;
} else {
txsAreContinuous = true;
}
if (txsAreContinuous) {
if (someTransactionsWereNew) {
saveTxHistory(walletId, cachedTxs);
} else if (confirmationsUpdated) {
@ -62,7 +68,7 @@
return cachedTxs;
} else {
// We might be missing some txs.
console.error('We might be missing some txs in the history.');
$log.error('We might be missing some txs in the history.');
// Our history is wrong, so remove it - we could instead, try to fetch data that was not so early.
storageService.removeTxHistory(walletId, function onRemoveTxHistory(){});
return [];
@ -92,9 +98,17 @@
}
});
var overlappingTxFraction = overlappingTxsCount / Math.min(cachedTxs.length, PAGE_OVERLAP);
var txsAreContinuous = false;
if (cachedTxs.length > 0) {
var overlappingTxFraction = overlappingTxsCount / Math.min(cachedTxs.length, PAGE_OVERLAP);
console.log('overlappingTxsCount:', overlappingTxsCount);
console.log('overlappingTxFraction:', overlappingTxFraction);
txsAreContinuous = overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION;
} else {
txsAreContinuous = true;
}
if (overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION || (someTransactionsWereNew && overlappingTxsCount === 0)) { // We are good
if (txsAreContinuous) {
if (someTransactionsWereNew) {
var allTxs = uniqueNewTxs.concat(cachedTxs);
saveTxHistory(walletId, allTxs);
@ -107,6 +121,7 @@
}
} else {
// We might be missing some txs.
$log.error('We might be missing some txs in the history.');
// Our history is wrong, so just include the latest ones
saveTxHistory(walletId, newTxs);
return newTxs;