|
|
@ -378,6 +378,8 @@ CopayServer.prototype._getUtxos = function(cb) { |
|
|
|
|
|
|
|
// Needed for the clients to sign UTXOs
|
|
|
|
_.each(utxos, function(utxo) { |
|
|
|
utxo.satoshis = utxo.satoshis ? +utxo.satoshis : Utils.strip(utxo.amount * 1e8); |
|
|
|
delete utxo.amount; |
|
|
|
utxo.path = addressToPath[utxo.address].path; |
|
|
|
utxo.publicKeys = addressToPath[utxo.address].publicKeys; |
|
|
|
}); |
|
|
@ -402,13 +404,13 @@ CopayServer.prototype.getBalance = function(opts, cb) { |
|
|
|
|
|
|
|
var balance = {}; |
|
|
|
balance.totalAmount = Utils.strip(_.reduce(utxos, function(sum, utxo) { |
|
|
|
return sum + self._inputSatoshis(utxo); |
|
|
|
return sum + utxo.satoshis; |
|
|
|
}, 0)); |
|
|
|
|
|
|
|
balance.lockedAmount = Utils.strip(_.reduce(_.filter(utxos, { |
|
|
|
locked: true |
|
|
|
}), function(sum, utxo) { |
|
|
|
return sum + self._inputSatoshis(utxo); |
|
|
|
return sum + utxo.satoshis; |
|
|
|
}, 0)); |
|
|
|
|
|
|
|
return cb(null, balance); |
|
|
@ -416,11 +418,6 @@ CopayServer.prototype.getBalance = function(opts, cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: should be in Utils
|
|
|
|
CopayServer.prototype._inputSatoshis = function(i) { |
|
|
|
return i.amount ? Utils.strip(i.amount * 1e8) : i.satoshis; |
|
|
|
}; |
|
|
|
|
|
|
|
CopayServer.prototype._selectUtxos = function(txp, utxos) { |
|
|
|
var i = 0; |
|
|
|
var total = 0; |
|
|
@ -429,7 +426,7 @@ CopayServer.prototype._selectUtxos = function(txp, utxos) { |
|
|
|
|
|
|
|
while (i < inputs.length) { |
|
|
|
selected.push(inputs[i]); |
|
|
|
total += this._inputSatoshis(inputs[i]); |
|
|
|
total += inputs[i].satoshis; |
|
|
|
|
|
|
|
if (total >= txp.amount + Bitcore.Transaction.FEE_PER_KB) { |
|
|
|
try { |
|
|
|