|
@ -363,7 +363,7 @@ WalletService.prototype._getUtxos = function(cb) { |
|
|
bc.getUnspentUtxos(addressStrs, function(err, inutxos) { |
|
|
bc.getUnspentUtxos(addressStrs, function(err, inutxos) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
var utxos = _.map(inutxos, function(i) { |
|
|
var utxos = _.map(inutxos, function(i) { |
|
|
return _.pick(i, ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis']); |
|
|
return _.pick(i.toObject(), ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis']); |
|
|
}); |
|
|
}); |
|
|
self.getPendingTxs({}, function(err, txps) { |
|
|
self.getPendingTxs({}, function(err, txps) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
@ -432,22 +432,28 @@ WalletService.prototype.getBalance = function(opts, cb) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WalletService.prototype._selectUtxos = function(txp, utxos) { |
|
|
WalletService.prototype._selectUtxos = function(txp, utxos) { |
|
|
|
|
|
console.log('[server.js.434:utxos:]',utxos); //TODO
|
|
|
var i = 0; |
|
|
var i = 0; |
|
|
var total = 0; |
|
|
var total = 0; |
|
|
var selected = []; |
|
|
var selected = []; |
|
|
var inputs = _.sortBy(utxos, 'amount'); |
|
|
var inputs = _.sortBy(utxos, 'amount'); |
|
|
|
|
|
console.log('[server.js.438:inputs:]',inputs); //TODO
|
|
|
|
|
|
|
|
|
while (i < inputs.length) { |
|
|
while (i < inputs.length) { |
|
|
selected.push(inputs[i]); |
|
|
selected.push(inputs[i]); |
|
|
total += inputs[i].satoshis; |
|
|
total += inputs[i].satoshis; |
|
|
|
|
|
|
|
|
|
|
|
console.log('[server.js.443]'); //TODO
|
|
|
if (total >= txp.amount + Bitcore.Transaction.FEE_PER_KB) { |
|
|
if (total >= txp.amount + Bitcore.Transaction.FEE_PER_KB) { |
|
|
try { |
|
|
try { |
|
|
// Check if there are enough fees
|
|
|
// Check if there are enough fees
|
|
|
txp.inputs = selected; |
|
|
txp.inputs = selected; |
|
|
|
|
|
|
|
|
|
|
|
console.log('[server.js.449]'); //TODO
|
|
|
var raw = txp.getRawTx(); |
|
|
var raw = txp.getRawTx(); |
|
|
return; |
|
|
return; |
|
|
} catch (ex) { |
|
|
} catch (ex) { |
|
|
|
|
|
console.log('[server.js.453:ex:]',ex); //TODO
|
|
|
if (ex.name != 'bitcore.ErrorTransactionFeeError') { |
|
|
if (ex.name != 'bitcore.ErrorTransactionFeeError') { |
|
|
throw ex.message; |
|
|
throw ex.message; |
|
|
} |
|
|
} |
|
@ -498,6 +504,7 @@ WalletService.prototype.createTx = function(opts, cb) { |
|
|
return cb(new ClientError('DUSTAMOUNT', 'Amount below dust threshold')); |
|
|
return cb(new ClientError('DUSTAMOUNT', 'Amount below dust threshold')); |
|
|
|
|
|
|
|
|
self._getUtxos(function(err, utxos) { |
|
|
self._getUtxos(function(err, utxos) { |
|
|
|
|
|
console.log('[server.js.506:utxos:]',utxos); //TODO
|
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
var changeAddress = wallet.createAddress(true); |
|
|
var changeAddress = wallet.createAddress(true); |
|
@ -520,6 +527,7 @@ WalletService.prototype.createTx = function(opts, cb) { |
|
|
try { |
|
|
try { |
|
|
self._selectUtxos(txp, utxos); |
|
|
self._selectUtxos(txp, utxos); |
|
|
} catch (ex) { |
|
|
} catch (ex) { |
|
|
|
|
|
console.log('[server.js.523:ex:]',ex); //TODO
|
|
|
return cb(new ClientError(ex)); |
|
|
return cb(new ClientError(ex)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -528,6 +536,7 @@ WalletService.prototype.createTx = function(opts, cb) { |
|
|
|
|
|
|
|
|
txp.inputPaths = _.pluck(txp.inputs, 'path'); |
|
|
txp.inputPaths = _.pluck(txp.inputs, 'path'); |
|
|
|
|
|
|
|
|
|
|
|
console.log('[server.js.530]'); //TODO
|
|
|
self.storage.storeAddressAndWallet(wallet, changeAddress, function(err) { |
|
|
self.storage.storeAddressAndWallet(wallet, changeAddress, function(err) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|