Update confirmations on cached transactions
This commit is contained in:
parent
78e4942fd6
commit
3cad7d7ad8
1 changed files with 14 additions and 10 deletions
|
|
@ -66,16 +66,21 @@
|
|||
|
||||
function addLatestTransactions(walletId, cachedTxs, newTxs) {
|
||||
var cachedTxIds = {};
|
||||
cachedTxs.forEach(function forCachedTx(tx){
|
||||
cachedTxIds[tx.txid] = true;
|
||||
cachedTxs.forEach(function forCachedTx(tx, txIndex){
|
||||
cachedTxIds[tx.txid] = txIndex;
|
||||
});
|
||||
|
||||
var someTransactionsWereNew = false;
|
||||
var confirmationsUpdated = false;
|
||||
var overlappingTxsCount = 0;
|
||||
var uniqueNewTxs = [];
|
||||
|
||||
newTxs.forEach(function forNewTx(tx){
|
||||
if (cachedTxIds[tx.txid]) {
|
||||
if (typeof cachedTxIds[tx.txid] !== "undefined") {
|
||||
if (cachedTxs[cachedTxIds[tx.txid]].confirmations < SAFE_CONFIRMATIONS && tx.confirmations >= SAFE_CONFIRMATIONS) {
|
||||
cachedTxs[cachedTxIds[tx.txid]].confirmations = tx.confirmations;
|
||||
confirmationsUpdated = true;
|
||||
}
|
||||
overlappingTxsCount++;
|
||||
} else {
|
||||
someTransactionsWereNew = true;
|
||||
|
|
@ -91,6 +96,9 @@
|
|||
saveTxHistory(walletId, allTxs);
|
||||
return allTxs;
|
||||
} else {
|
||||
if (confirmationsUpdated) {
|
||||
saveTxHistory(walletId, cachedTxs);
|
||||
}
|
||||
return cachedTxs;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -104,6 +112,8 @@
|
|||
|
||||
// Only clear the cache once we have received new transactions from the server.
|
||||
/**
|
||||
* @param wallet
|
||||
* @param start
|
||||
* @param {function(err, txs)} cb - transactions is always an array, may be empty
|
||||
*/
|
||||
function fetchTxHistoryByPage(wallet, start, cb) {
|
||||
|
|
@ -187,7 +197,7 @@
|
|||
});
|
||||
|
||||
return processedTxs;
|
||||
};
|
||||
}
|
||||
|
||||
function saveTxHistory(walletId, processedTxs) {
|
||||
storageService.setTxHistory(processedTxs, walletId, function onSetTxHistory(error){
|
||||
|
|
@ -197,7 +207,6 @@
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
function updateLocalTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) {
|
||||
|
||||
if (flushCacheOnNew) {
|
||||
|
|
@ -240,10 +249,5 @@
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue