|
@ -602,7 +602,9 @@ WalletService.prototype._getUtxos = function(cb) { |
|
|
return cb(new ClientError('BLOCKCHAINERROR', 'Could not fetch unspent outputs')); |
|
|
return cb(new ClientError('BLOCKCHAINERROR', 'Could not fetch unspent outputs')); |
|
|
} |
|
|
} |
|
|
var utxos = _.map(inutxos, function(utxo) { |
|
|
var utxos = _.map(inutxos, function(utxo) { |
|
|
return _.pick(utxo, ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis']); |
|
|
var u = _.pick(utxo, ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis']); |
|
|
|
|
|
u.locked = false; |
|
|
|
|
|
return u; |
|
|
}); |
|
|
}); |
|
|
self.getPendingTxs({}, function(err, txps) { |
|
|
self.getPendingTxs({}, function(err, txps) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
@ -686,7 +688,33 @@ WalletService.prototype.getBalance = function(opts, cb) { |
|
|
|
|
|
|
|
|
balance.byAddress = _.values(byAddress); |
|
|
balance.byAddress = _.values(byAddress); |
|
|
|
|
|
|
|
|
return cb(null, balance); |
|
|
// Compute KB of a tx to send all non-locked funds
|
|
|
|
|
|
balance.totalKbToSendMax = 0; |
|
|
|
|
|
self.getWallet({}, function(err, wallet) { |
|
|
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
|
|
|
var unlockedUtxos = _.filter(utxos, { |
|
|
|
|
|
locked: false |
|
|
|
|
|
}); |
|
|
|
|
|
if (unlockedUtxos.length > 0) { |
|
|
|
|
|
var t = WalletUtils.newBitcoreTransaction(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
_.each(unlockedUtxos, function(i) { |
|
|
|
|
|
t.from(i, i.publicKeys, wallet.m); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var address = utxos[0].address; |
|
|
|
|
|
t.to(address, balance.totalAmount - balance.lockedAmount); |
|
|
|
|
|
|
|
|
|
|
|
balance.totalKbToSendMax = Math.ceil(t._estimateSize() / 1000); |
|
|
|
|
|
} catch (ex) { |
|
|
|
|
|
log.error('Could not compute fees needed to transfer max amount', ex); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return cb(null, balance); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -720,13 +748,12 @@ WalletService.prototype._selectTxInputs = function(txp, cb) { |
|
|
|
|
|
|
|
|
if (total >= txp.amount) { |
|
|
if (total >= txp.amount) { |
|
|
try { |
|
|
try { |
|
|
txp.inputs = selected; |
|
|
txp.setInputs(selected); |
|
|
bitcoreTx = txp.getBitcoreTx(); |
|
|
bitcoreTx = txp.getBitcoreTx(); |
|
|
bitcoreError = bitcoreTx.getSerializationError({ |
|
|
bitcoreError = bitcoreTx.getSerializationError({ |
|
|
disableIsFullySigned: true, |
|
|
disableIsFullySigned: true, |
|
|
}); |
|
|
}); |
|
|
if (!bitcoreError) { |
|
|
if (!bitcoreError) { |
|
|
txp.inputPaths = _.pluck(txp.inputs, 'path'); |
|
|
|
|
|
txp.fee = bitcoreTx.getFee(); |
|
|
txp.fee = bitcoreTx.getFee(); |
|
|
return cb(); |
|
|
return cb(); |
|
|
} |
|
|
} |
|
|