Fixes: cache storing unconfirmed values
- removed unconfirmed values from cache store and get - do not update lastItem value for unconfirmed tx
This commit is contained in:
parent
adb81616aa
commit
6b794aa9a3
@ -123,7 +123,7 @@ Encoding.prototype.decodeAddressCacheKey = function(buffer) {
|
||||
return buffer.slice(3).toString('utf8');
|
||||
}
|
||||
|
||||
Encoding.prototype.encodeAddressCacheValue = function(lastTx, balance, received, sent, txApperances, unconfirmedBalance, unconfirmedTxApperances) {
|
||||
Encoding.prototype.encodeAddressCacheValue = function(lastTx, balance, received, sent, txApperances) {
|
||||
|
||||
var buffer = [];
|
||||
|
||||
@ -143,14 +143,6 @@ Encoding.prototype.encodeAddressCacheValue = function(lastTx, balance, received,
|
||||
txApperancesBuffer.writeUInt32BE(txApperances || 0);
|
||||
buffer.push(txApperancesBuffer);
|
||||
|
||||
var unconfirmedBalanceBuffer = new Buffer(4);
|
||||
unconfirmedBalanceBuffer.writeUInt32BE(unconfirmedBalance || 0);
|
||||
buffer.push(unconfirmedBalanceBuffer);
|
||||
|
||||
var unconfirmedTxApperancesBuffer = new Buffer(4);
|
||||
unconfirmedTxApperancesBuffer.writeUInt32BE(unconfirmedTxApperances || 0);
|
||||
buffer.push(unconfirmedTxApperancesBuffer);
|
||||
|
||||
var txidBuffer = new Buffer(lastTx || Array(65).join('0'), 'hex');
|
||||
buffer.push(txidBuffer);
|
||||
|
||||
@ -163,11 +155,9 @@ Encoding.prototype.decodeAddressCacheValue = function(buffer) {
|
||||
var received = buffer.readUInt32BE(4);
|
||||
var sent = buffer.readUInt32BE(8);
|
||||
var txApperances = buffer.readUInt32BE(12);
|
||||
var unconfirmedBalance = buffer.readUInt32BE(16);
|
||||
var unconfirmedTxApperances = buffer.readUInt32BE(20);
|
||||
var lastTx = buffer.slice(24).toString('hex');
|
||||
|
||||
return { lastTx, balance, received, sent, txApperances, unconfirmedBalance, unconfirmedTxApperances };
|
||||
return { lastTx, balance, received, sent, txApperances };
|
||||
}
|
||||
|
||||
module.exports = Encoding;
|
||||
|
||||
@ -357,7 +357,9 @@ AddressService.prototype.getAddressSummary = function(address, options, streamer
|
||||
if(tx) {
|
||||
count++;
|
||||
self._aggregateAddressSummaryResult(tx, address, result, options);
|
||||
result.lastItem = tx.txid();
|
||||
|
||||
if(tx.confirmations)
|
||||
result.lastItem = tx.txid();
|
||||
}
|
||||
|
||||
if(count >= MAX_TX_QUERY_LIMIT) {//stop quering db when limit reached
|
||||
@ -415,9 +417,9 @@ AddressService.prototype._cacheSummaryInBackground = function(address, lastTx, r
|
||||
totalReceivedSat: result.totalReceivedSat,
|
||||
totalSentSat: result.totalSentSat,
|
||||
txApperances: result.txApperances,
|
||||
unconfirmedBalanceSat: result.unconfirmedBalanceSat,
|
||||
unconfirmedTxApperances: result.unconfirmedTxApperances
|
||||
};
|
||||
unconfirmedBalanceSat: 0, //unconfirmed (mempool) values should not be cached
|
||||
unconfirmedTxApperances: 0
|
||||
};
|
||||
const options = { queryMempool: false, after: lastTx, noTxList: true };
|
||||
var lastItem;
|
||||
|
||||
@ -428,7 +430,8 @@ AddressService.prototype._cacheSummaryInBackground = function(address, lastTx, r
|
||||
|
||||
if(tx) {
|
||||
self._aggregateAddressSummaryResult(tx, address, cache, options);
|
||||
lastItem = tx.txid();
|
||||
if(tx.confirmations)
|
||||
lastItem = tx.txid();
|
||||
}
|
||||
|
||||
}, function(err) {
|
||||
@ -440,8 +443,6 @@ AddressService.prototype._cacheSummaryInBackground = function(address, lastTx, r
|
||||
cache.totalReceivedSat = parseInt(cache.totalReceivedSat.toFixed());
|
||||
cache.totalSentSat = parseInt(cache.totalSentSat.toFixed());
|
||||
cache.txApperances = parseInt(cache.txApperances.toFixed());
|
||||
cache.unconfirmedBalanceSat = parseInt(cache.unconfirmedBalanceSat.toFixed());
|
||||
cache.unconfirmedTxApperances = parseInt(cache.unconfirmedTxApperances.toFixed());
|
||||
|
||||
if(_.isUndefined(lastItem))
|
||||
self._storeCache(address, lastItem, cache);
|
||||
@ -454,7 +455,7 @@ AddressService.prototype._cacheSummaryInBackground = function(address, lastTx, r
|
||||
|
||||
AddressService.prototype._storeCache = function(address, lastCacheTx, result, callback) {
|
||||
var key = self._encoding.encodeAddressCacheKey(address);
|
||||
var value = self._encoding.encodeAddressCacheValue(lastCacheTx, result.balanceSat, result.totalReceivedSat, result.totalSentSat, result.txApperances, result.unconfirmedBalanceSat, result.unconfirmedTxApperances)
|
||||
var value = self._encoding.encodeAddressCacheValue(lastCacheTx, result.balanceSat, result.totalReceivedSat, result.totalSentSat, result.txApperances)
|
||||
|
||||
if(!_.isFunction(callback)) //if callback is not passed, call a empty function
|
||||
callback = () => null;
|
||||
@ -482,8 +483,6 @@ AddressService.prototype._loadCache = function(address, result, useCache, next)
|
||||
result.totalReceivedSat = addressCache.received;
|
||||
result.totalSentSat = addressCache.sent;
|
||||
result.txApperances = addressCache.txApperances;
|
||||
result.unconfirmedBalanceSat = addressCache.unconfirmedBalance;
|
||||
result.unconfirmedTxApperances = addressCache.unconfirmedTxApperances;
|
||||
|
||||
next(null, addressCache.lastTx);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user