Fixed issue with query mempool option.

This commit is contained in:
Chris Kleeschulte 2017-10-12 15:06:13 -04:00
parent 8b1099986b
commit 1af9c07bfa
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F
2 changed files with 62 additions and 47 deletions

View File

@ -52,7 +52,10 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
options = options || {};
options.from = options.from || 0;
options.to = options.to || 0xffffffff;
options.queryMempool = _.isUndefined(options.queryMempool) ? true : false;
if (_.isUndefined(options.queryMempool)) {
options.queryMempool = true;
}
if (_.isString(addresses)) {
addresses = [addresses];
@ -90,7 +93,10 @@ AddressService.prototype.getAddressSummary = function(address, options, callback
options = options || {};
options.from = options.from || 0;
options.to = options.to || 0xffffffff;
options.queryMempool = _.isUndefined(options.queryMempool) ? true : false;
if (_.isUndefined(options.queryMempool)) {
options.queryMempool = true;
}
var result = {
addrStr: address,
@ -114,47 +120,7 @@ AddressService.prototype.getAddressSummary = function(address, options, callback
}
var txs = results.items;
for(var i = 0; i < txs.length; i++) {
var tx = txs[i];
for(var j = 0; j < tx.outputs.length; j++) {
var output = tx.outputs[j];
if (utils.getAddress(output, self._network) !== address) {
continue;
}
result.txApperances++;
result.totalReceivedSat += output.value;
result.balanceSat += output.value;
if (tx.confirmations === 0) {
result.unconfirmedTxApperances++;
result.unconfirmedBalanceSat += output.value;
}
}
for(j = 0; j < tx.inputs.length; j++) {
var input = tx.inputs[j];
if (utils.getAddress(input, self._network) !== address) {
continue;
}
result.totalSentSat += tx.__inputValues[j];
result.balanceSat -= tx.__inputValues[j];
if (tx.confirmations === 0) {
result.unconfirmedBalanceSat -= tx.__inputValues[j];
}
}
result.transactions.push(tx.txid());
}
self._getAddressSummaryResult(txs, address, result);
result.balance = Unit.fromSatoshis(result.balanceSat).toBTC();
result.totalReceived = Unit.fromSatoshis(result.totalReceivedSat).toBTC();
@ -165,6 +131,55 @@ AddressService.prototype.getAddressSummary = function(address, options, callback
};
AddressService.prototype._getAddressSummaryResult = function(txs, address, result) {
var self = this;
for(var i = 0; i < txs.length; i++) {
var tx = txs[i];
for(var j = 0; j < tx.outputs.length; j++) {
var output = tx.outputs[j];
if (utils.getAddress(output, self._network) !== address) {
continue;
}
result.txApperances++;
result.totalReceivedSat += output.value;
result.balanceSat += output.value;
if (tx.confirmations === 0) {
result.unconfirmedTxApperances++;
result.unconfirmedBalanceSat += output.value;
}
}
for(j = 0; j < tx.inputs.length; j++) {
var input = tx.inputs[j];
if (utils.getAddress(input, self._network) !== address) {
continue;
}
result.totalSentSat += tx.__inputValues[j];
result.balanceSat -= tx.__inputValues[j];
if (tx.confirmations === 0) {
result.unconfirmedBalanceSat -= tx.__inputValues[j];
}
}
result.transactions.push(tx.txid());
}
return result;
};
AddressService.prototype.getAddressUnspentOutputs = function(address, options, callback) {
var self = this;
@ -172,7 +187,10 @@ AddressService.prototype.getAddressUnspentOutputs = function(address, options, c
options = options || {};
options.from = options.from || 0;
options.to = options.to || 0xffffffff;
options.queryMempool = _.isUndefined(options.queryMempool) ? true : false;
if (_.isUndefined(options.queryMempool)) {
options.queryMempool = true;
}
var results = [];

View File

@ -100,9 +100,6 @@ TransactionService.prototype._getSpentInformationForOutputs = function(tx, callb
callback();
});
};