@ -1347,6 +1347,7 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
selected . push ( input ) ;
selected . push ( input ) ;
total += inputAmount ;
var txpSize = baseTxpSize + selected . length * sizePerInput ;
var txpSize = baseTxpSize + selected . length * sizePerInput ;
var txpFee = baseTxpFee + selected . length * feePerInput ;
var txpFee = baseTxpFee + selected . length * feePerInput ;
@ -1379,10 +1380,19 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
}
}
}
}
total += inputAmount ;
log . debug ( 'Cumuled total so far: ' + Utils . formatAmountInBtc ( total ) ) ;
log . debug ( 'Cumuled total so far: ' + Utils . formatAmountInBtc ( total ) ) ;
if ( total >= txpAmount ) return false ;
if ( total >= txpAmount ) {
var changeAmount = total - txpAmount - txpFee ;
log . debug ( 'Tx change: ' , Utils . formatAmountInBtc ( changeAmount ) ) ;
if ( changeAmount <= Bitcore . Transaction . DUST_AMOUNT ) {
log . debug ( 'Change (' + Utils . formatAmountInBtc ( changeAmount ) + ') below dust amount (' + Utils . formatAmountInBtc ( Bitcore . Transaction . DUST_AMOUNT ) + ')' ) ;
return ;
}
return false ;
}
} ) ;
} ) ;
if ( total < txpAmount ) {
if ( total < txpAmount ) {
@ -1479,7 +1489,7 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
var err = self . _ checkTxAndEstimateFee ( txp ) ;
var err = self . _ checkTxAndEstimateFee ( txp ) ;
if ( ! err ) {
if ( ! err ) {
log . debug ( 'Successfully built transaction. Total fees: ' , Utils . formatAmountInBtc ( txp . fee ) ) ;
log . debug ( 'Successfully built transaction. Total fees: ' + Utils . formatAmountInBtc ( txp . fee ) + ' , total change: ' + Utils . formatAmountInBtc ( _ . sum ( txp . inputs , 'satoshis' ) - txp . fee ) ) ;
} else {
} else {
log . warn ( 'Error building transaction' , err ) ;
log . warn ( 'Error building transaction' , err ) ;
}
}