This commit is contained in:
Ivan Socolsky 2016-03-04 17:53:16 -03:00
parent 2581f488fa
commit 60f6300fbc
2 changed files with 5 additions and 7 deletions

View File

@ -1398,7 +1398,6 @@ WalletService.prototype._selectTxInputs2 = function(txp, utxosToExclude, cb) {
};
function select(utxos) {
// TODO: fix for when fee is specified instead of feePerKb
var txpAmount = txp.getTotalAmount();
var baseTxpSize = txp.getEstimatedSize();
var baseTxpFee = baseTxpSize * txp.feePerKb / 1000.;
@ -1408,11 +1407,11 @@ WalletService.prototype._selectTxInputs2 = function(txp, utxosToExclude, cb) {
var totalValueInUtxos = _.sum(utxos, 'satoshis');
var netValueInUtxos = totalValueInUtxos - baseTxpFee - (utxos.length * feePerInput);
if (totalValueInUtxos < txpAmount) {
log.debug('Total value in all utxos (' + formatAmount(totalValueInUtxos) + ') is insufficient to cover for txp amount (' + formatAmount(txpAmount) + ')'); // TODO
log.debug('Total value in all utxos (' + formatAmount(totalValueInUtxos) + ') is insufficient to cover for txp amount (' + formatAmount(txpAmount) + ')');
return Errors.INSUFFICIENT_FUNDS;
}
if (netValueInUtxos < txpAmount) {
log.debug('Value after fees in all utxos (' + formatAmount(netValueInUtxos) + ') is insufficient to cover for txp amount (' + formatAmount(txpAmount) + ')'); // TODO
log.debug('Value after fees in all utxos (' + formatAmount(netValueInUtxos) + ') is insufficient to cover for txp amount (' + formatAmount(txpAmount) + ')');
return Errors.INSUFFICIENT_FUNDS_FOR_FEE;
}
@ -1462,7 +1461,7 @@ WalletService.prototype._selectTxInputs2 = function(txp, utxosToExclude, cb) {
log.debug('Tx amount/input amount:' + formatRatio(amountVsUtxoRatio) + ' (min: ' + formatRatio(Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) + ')');
if (txpSize / 1000. > Defaults.MAX_TX_SIZE_IN_KB) {
log.debug('Breaking because tx size (' + formatSize(txpSize) + ') is too big (max: ' + formatSize(Defaults.MAX_TX_SIZE_IN_KB * 1000.) + ')'); // TODO
log.debug('Breaking because tx size (' + formatSize(txpSize) + ') is too big (max: ' + formatSize(Defaults.MAX_TX_SIZE_IN_KB * 1000.) + ')');
error = Errors.TX_MAX_SIZE_EXCEEDED;
return false;
}

View File

@ -2355,7 +2355,7 @@ describe('Wallet service', function() {
});
it('should fail to create a tx exceeding max size in kb', function(done) {
log.level = 'debug';
// log.level = 'debug';
var _oldDefault = Defaults.MAX_TX_SIZE_IN_KB;
Defaults.MAX_TX_SIZE_IN_KB = 1;
helpers.stubUtxos(server, wallet, _.range(1, 10, 0), function() {
@ -3186,8 +3186,7 @@ describe('Wallet service', function() {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
amount: 0.8 * 1e8,
}],
message: 'some message',
customData: 'some custom data',
feePerKb: 100e2,
};
server.createTx(txOpts, function(err, tx) {
should.not.exist(err);