|
@ -626,6 +626,9 @@ WalletService.prototype._getBlockchainExplorer = function(network) { |
|
|
WalletService.prototype.getUtxos = function(cb) { |
|
|
WalletService.prototype.getUtxos = function(cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
|
|
function utxoKey(utxo) { |
|
|
|
|
|
return utxo.txid + '|' + utxo.vout |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
// Get addresses for this wallet
|
|
|
// Get addresses for this wallet
|
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
@ -651,24 +654,13 @@ WalletService.prototype.getUtxos = function(cb) { |
|
|
self.getPendingTxs({}, function(err, txps) { |
|
|
self.getPendingTxs({}, function(err, txps) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
var utxoKey = function(utxo) { |
|
|
var lockedInputs = _.map(_.flatten(_.pluck(txps, 'inputs')), utxoKey); |
|
|
return utxo.txid + '|' + utxo.vout |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var inputs = _.chain(txps) |
|
|
|
|
|
.pluck('inputs') |
|
|
|
|
|
.flatten() |
|
|
|
|
|
.map(utxoKey) |
|
|
|
|
|
.value(); |
|
|
|
|
|
|
|
|
|
|
|
var dictionary = _.reduce(utxos, function(memo, utxo) { |
|
|
var utxoIndex = _.indexBy(utxos, utxoKey); |
|
|
memo[utxoKey(utxo)] = utxo; |
|
|
|
|
|
return memo; |
|
|
|
|
|
}, {}); |
|
|
|
|
|
|
|
|
|
|
|
_.each(inputs, function(input) { |
|
|
_.each(lockedInputs, function(input) { |
|
|
if (dictionary[input]) { |
|
|
if (utxoIndex[input]) { |
|
|
dictionary[input].locked = true; |
|
|
utxoIndex[input].locked = true; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -703,9 +695,7 @@ WalletService.prototype._totalizeUtxos = function(utxos) { |
|
|
WalletService.prototype._computeKbToSendMax = function(utxos, amount, cb) { |
|
|
WalletService.prototype._computeKbToSendMax = function(utxos, amount, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
var unlockedUtxos = _.filter(utxos, { |
|
|
var unlockedUtxos = _.reject(utxos, 'locked'); |
|
|
locked: false |
|
|
|
|
|
}); |
|
|
|
|
|
if (_.isEmpty(unlockedUtxos)) return cb(null, 0); |
|
|
if (_.isEmpty(unlockedUtxos)) return cb(null, 0); |
|
|
|
|
|
|
|
|
self.getWallet({}, function(err, wallet) { |
|
|
self.getWallet({}, function(err, wallet) { |
|
@ -1500,10 +1490,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { |
|
|
var filter = {}; |
|
|
var filter = {}; |
|
|
if (_.isBoolean(isMine)) filter.isMine = isMine; |
|
|
if (_.isBoolean(isMine)) filter.isMine = isMine; |
|
|
if (_.isBoolean(isChange)) filter.isChange = isChange; |
|
|
if (_.isBoolean(isChange)) filter.isChange = isChange; |
|
|
return _.reduce(_.where(items, filter), |
|
|
return _.sum(_.filter(items, filter), 'amount'); |
|
|
function(memo, item) { |
|
|
|
|
|
return memo + item.amount; |
|
|
|
|
|
}, 0); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
function classify(items) { |
|
|
function classify(items) { |
|
|