diff --git a/lib/services/address/index.js b/lib/services/address/index.js index f9023c12..d4f49011 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -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 = []; diff --git a/lib/services/transaction/index.js b/lib/services/transaction/index.js index 97d9d1bf..177bf018 100644 --- a/lib/services/transaction/index.js +++ b/lib/services/transaction/index.js @@ -100,9 +100,6 @@ TransactionService.prototype._getSpentInformationForOutputs = function(tx, callb callback(); - - - }); };