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');
|
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 = [];
|
var buffer = [];
|
||||||
|
|
||||||
@ -143,14 +143,6 @@ Encoding.prototype.encodeAddressCacheValue = function(lastTx, balance, received,
|
|||||||
txApperancesBuffer.writeUInt32BE(txApperances || 0);
|
txApperancesBuffer.writeUInt32BE(txApperances || 0);
|
||||||
buffer.push(txApperancesBuffer);
|
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');
|
var txidBuffer = new Buffer(lastTx || Array(65).join('0'), 'hex');
|
||||||
buffer.push(txidBuffer);
|
buffer.push(txidBuffer);
|
||||||
|
|
||||||
@ -163,11 +155,9 @@ Encoding.prototype.decodeAddressCacheValue = function(buffer) {
|
|||||||
var received = buffer.readUInt32BE(4);
|
var received = buffer.readUInt32BE(4);
|
||||||
var sent = buffer.readUInt32BE(8);
|
var sent = buffer.readUInt32BE(8);
|
||||||
var txApperances = buffer.readUInt32BE(12);
|
var txApperances = buffer.readUInt32BE(12);
|
||||||
var unconfirmedBalance = buffer.readUInt32BE(16);
|
|
||||||
var unconfirmedTxApperances = buffer.readUInt32BE(20);
|
|
||||||
var lastTx = buffer.slice(24).toString('hex');
|
var lastTx = buffer.slice(24).toString('hex');
|
||||||
|
|
||||||
return { lastTx, balance, received, sent, txApperances, unconfirmedBalance, unconfirmedTxApperances };
|
return { lastTx, balance, received, sent, txApperances };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Encoding;
|
module.exports = Encoding;
|
||||||
|
|||||||
@ -357,7 +357,9 @@ AddressService.prototype.getAddressSummary = function(address, options, streamer
|
|||||||
if(tx) {
|
if(tx) {
|
||||||
count++;
|
count++;
|
||||||
self._aggregateAddressSummaryResult(tx, address, result, options);
|
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
|
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,
|
totalReceivedSat: result.totalReceivedSat,
|
||||||
totalSentSat: result.totalSentSat,
|
totalSentSat: result.totalSentSat,
|
||||||
txApperances: result.txApperances,
|
txApperances: result.txApperances,
|
||||||
unconfirmedBalanceSat: result.unconfirmedBalanceSat,
|
unconfirmedBalanceSat: 0, //unconfirmed (mempool) values should not be cached
|
||||||
unconfirmedTxApperances: result.unconfirmedTxApperances
|
unconfirmedTxApperances: 0
|
||||||
};
|
};
|
||||||
const options = { queryMempool: false, after: lastTx, noTxList: true };
|
const options = { queryMempool: false, after: lastTx, noTxList: true };
|
||||||
var lastItem;
|
var lastItem;
|
||||||
|
|
||||||
@ -428,7 +430,8 @@ AddressService.prototype._cacheSummaryInBackground = function(address, lastTx, r
|
|||||||
|
|
||||||
if(tx) {
|
if(tx) {
|
||||||
self._aggregateAddressSummaryResult(tx, address, cache, options);
|
self._aggregateAddressSummaryResult(tx, address, cache, options);
|
||||||
lastItem = tx.txid();
|
if(tx.confirmations)
|
||||||
|
lastItem = tx.txid();
|
||||||
}
|
}
|
||||||
|
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
@ -440,8 +443,6 @@ AddressService.prototype._cacheSummaryInBackground = function(address, lastTx, r
|
|||||||
cache.totalReceivedSat = parseInt(cache.totalReceivedSat.toFixed());
|
cache.totalReceivedSat = parseInt(cache.totalReceivedSat.toFixed());
|
||||||
cache.totalSentSat = parseInt(cache.totalSentSat.toFixed());
|
cache.totalSentSat = parseInt(cache.totalSentSat.toFixed());
|
||||||
cache.txApperances = parseInt(cache.txApperances.toFixed());
|
cache.txApperances = parseInt(cache.txApperances.toFixed());
|
||||||
cache.unconfirmedBalanceSat = parseInt(cache.unconfirmedBalanceSat.toFixed());
|
|
||||||
cache.unconfirmedTxApperances = parseInt(cache.unconfirmedTxApperances.toFixed());
|
|
||||||
|
|
||||||
if(_.isUndefined(lastItem))
|
if(_.isUndefined(lastItem))
|
||||||
self._storeCache(address, lastItem, cache);
|
self._storeCache(address, lastItem, cache);
|
||||||
@ -454,7 +455,7 @@ AddressService.prototype._cacheSummaryInBackground = function(address, lastTx, r
|
|||||||
|
|
||||||
AddressService.prototype._storeCache = function(address, lastCacheTx, result, callback) {
|
AddressService.prototype._storeCache = function(address, lastCacheTx, result, callback) {
|
||||||
var key = self._encoding.encodeAddressCacheKey(address);
|
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
|
if(!_.isFunction(callback)) //if callback is not passed, call a empty function
|
||||||
callback = () => null;
|
callback = () => null;
|
||||||
@ -482,8 +483,6 @@ AddressService.prototype._loadCache = function(address, result, useCache, next)
|
|||||||
result.totalReceivedSat = addressCache.received;
|
result.totalReceivedSat = addressCache.received;
|
||||||
result.totalSentSat = addressCache.sent;
|
result.totalSentSat = addressCache.sent;
|
||||||
result.txApperances = addressCache.txApperances;
|
result.txApperances = addressCache.txApperances;
|
||||||
result.unconfirmedBalanceSat = addressCache.unconfirmedBalance;
|
|
||||||
result.unconfirmedTxApperances = addressCache.unconfirmedTxApperances;
|
|
||||||
|
|
||||||
next(null, addressCache.lastTx);
|
next(null, addressCache.lastTx);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user