@ -191,58 +191,54 @@ Transaction.prototype.invalidSatoshis = function() {
Transaction . prototype . getSerializationError = function ( opts ) {
opts = opts || { } ;
var unspent = this . _ getUnspentValue ( ) ;
return this . _ isInvalidSatoshis ( ) ||
this . _ hasMoreOutputThanInput ( opts , unspent ) ||
this . _ hasFeeError ( opts , unspent ) ||
this . _ hasDustOutputs ( opts ) ||
this . _ isMissingSignatures ( opts ) ;
} ;
Transaction . prototype . _ isInvalidSatoshis = function ( ) {
if ( this . invalidSatoshis ( ) ) {
return new errors . Transaction . InvalidSatoshis ( ) ;
}
} ;
Transaction . prototype . _ hasFeeError = function ( opts , unspent ) {
var unspent = this . _ getUnspentValue ( ) ;
var unspentError ;
if ( unspent < 0 ) {
// The concept of a fee is meaningless when the unspent output value is negative.
return ;
if ( ! opts . disableMoreOutputThanInput ) {
unspentError = new errors . Transaction . InvalidOutputAmountSum ( ) ;
}
} else {
unspentError = this . _ hasFeeError ( opts , unspent ) ;
}
return this . _ isFeeDifferent ( unspent ) ||
this . _ isFeeTooLarge ( opts , unspent ) ||
this . _ isFeeTooSmall ( opts , unspent ) ;
return unspentError ||
this . _ hasDustOutputs ( opts ) ||
this . _ isMissingSignatures ( opts ) ;
} ;
Transaction . prototype . _ isFeeDifferent = function ( unspent ) {
Transaction . prototype . _ hasFeeError = function ( opts , unspent ) {
if ( ! _ . isUndefined ( this . _ fee ) && this . _ fee !== unspent ) {
return new errors . Transaction . FeeError . Different (
'Unspent value is ' + unspent + ' but specified fee is ' + this . _ fee
) ;
}
} ;
Transaction . prototype . _ isFeeTooLarge = function ( opts , fee ) {
if ( opts . disableLargeFees ) {
return ;
}
var maximumFee = Math . floor ( Transaction . FEE_SECURITY_MARGIN * this . _ estimateFee ( ) ) ;
if ( fee > maximumFee ) {
if ( this . _ missingChange ( ) ) {
return new errors . Transaction . ChangeAddressMissing ( 'Fee is too large and no change address was provided' ) ;
if ( ! opts . disableLargeFees ) {
var maximumFee = Math . floor ( Transaction . FEE_SECURITY_MARGIN * this . _ estimateFee ( ) ) ;
if ( unspent > maximumFee ) {
if ( this . _ missingChange ( ) ) {
return new errors . Transaction . ChangeAddressMissing (
'Fee is too large and no change address was provided'
) ;
}
return new errors . Transaction . FeeError . TooLarge (
'expected less than ' + maximumFee + ' but got ' + unspent
) ;
}
return new errors . Transaction . FeeError . TooLarge ( 'expected less than ' + maximumFee + ' but got ' + fee ) ;
}
} ;
Transaction . prototype . _ isFeeTooSmall = function ( opts , fee ) {
if ( opts . disableSmallFees ) {
return ;
}
var minimumFee = Math . ceil ( this . _ estimateFee ( ) / Transaction . FEE_SECURITY_MARGIN ) ;
if ( fee < minimumFee ) {
return new errors . Transaction . FeeError . TooSmall ( 'expected more than ' + minimumFee + ' but got ' + fee ) ;
if ( ! opts . disableSmallFees ) {
var minimumFee = Math . ceil ( this . _ estimateFee ( ) / Transaction . FEE_SECURITY_MARGIN ) ;
if ( unspent < minimumFee ) {
return new errors . Transaction . FeeError . TooSmall (
'expected more than ' + minimumFee + ' but got ' + unspent
) ;
}
}
} ;
@ -272,15 +268,6 @@ Transaction.prototype._isMissingSignatures = function(opts) {
}
} ;
Transaction . prototype . _ hasMoreOutputThanInput = function ( opts , unspent ) {
if ( opts . disableMoreOutputThanInput ) {
return ;
}
if ( unspent < 0 ) {
return new errors . Transaction . InvalidOutputAmountSum ( ) ;
}
} ;
Transaction . prototype . inspect = function ( ) {
return '<Transaction: ' + this . uncheckedSerialize ( ) + '>' ;
} ;