|
|
@ -23,8 +23,6 @@ var Script = require('../script'); |
|
|
|
var PrivateKey = require('../privatekey'); |
|
|
|
var BN = require('../crypto/bn'); |
|
|
|
|
|
|
|
var MAX_BLOCK_SIZE = 1000000; |
|
|
|
|
|
|
|
/** |
|
|
|
* Represents a transaction, a set of inputs and outputs to change ownership of tokens |
|
|
|
* |
|
|
@ -61,7 +59,7 @@ function Transaction(serialized) { |
|
|
|
|
|
|
|
var CURRENT_VERSION = 1; |
|
|
|
var DEFAULT_NLOCKTIME = 0; |
|
|
|
var MAX_SAFE_INTEGER = 0x1fffffffffffff; |
|
|
|
var MAX_BLOCK_SIZE = 1000000; |
|
|
|
|
|
|
|
// Minimum amount for an output for it not to be considered a dust output
|
|
|
|
Transaction.DUST_AMOUNT = 546; |
|
|
@ -169,12 +167,22 @@ Transaction.prototype.checkedSerialize = function(opts) { |
|
|
|
var serializationError = this.getSerializationError(opts); |
|
|
|
if (serializationError) { |
|
|
|
serializationError.message += ' Use Transaction#uncheckedSerialize if you want to skip security checks. ' + |
|
|
|
'See http://bitcore.io/guide/transaction.html#Serialization for more info.' |
|
|
|
'See http://bitcore.io/guide/transaction.html#Serialization for more info.'; |
|
|
|
throw serializationError; |
|
|
|
} |
|
|
|
return this.uncheckedSerialize(); |
|
|
|
}; |
|
|
|
|
|
|
|
Transaction.prototype.invalidSatoshis = function() { |
|
|
|
var invalid = false; |
|
|
|
for (var i = 0; i < this.outputs.length; i++) { |
|
|
|
if (this.outputs[i].invalidSatoshis()) { |
|
|
|
invalid = true; |
|
|
|
} |
|
|
|
} |
|
|
|
return invalid; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Retrieve a possible error that could appear when trying to serialize and broadcast this transaction |
|
|
|
* |
|
|
@ -183,6 +191,11 @@ Transaction.prototype.checkedSerialize = function(opts) { |
|
|
|
*/ |
|
|
|
Transaction.prototype.getSerializationError = function(opts) { |
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
if (this.invalidSatoshis()) { |
|
|
|
return new errors.Transaction.InvalidSatoshis(); |
|
|
|
} |
|
|
|
|
|
|
|
var missingChange = this._missingChange(); |
|
|
|
var feeIsTooLarge = this._isFeeTooLarge(); |
|
|
|
var feeIsTooSmall = this._isFeeTooSmall(); |
|
|
@ -986,14 +999,9 @@ Transaction.prototype.verify = function() { |
|
|
|
var valueoutbn = new BN(0); |
|
|
|
for (var i = 0; i < this.outputs.length; i++) { |
|
|
|
var txout = this.outputs[i]; |
|
|
|
if (txout._satoshis > MAX_SAFE_INTEGER) { |
|
|
|
return 'transaction txout ' + i + ' satoshis greater than max safe integer'; |
|
|
|
} |
|
|
|
if (txout._satoshis !== txout._satoshisBN.toNumber()) { |
|
|
|
return 'transaction txout ' + i + ' satoshis has corrupted value'; |
|
|
|
} |
|
|
|
if (txout._satoshis < 0) { |
|
|
|
return 'transaction txout ' + i + ' negative'; |
|
|
|
|
|
|
|
if (txout.invalidSatoshis()) { |
|
|
|
return 'transaction txout ' + i + ' satoshis is invalid'; |
|
|
|
} |
|
|
|
if (txout._satoshisBN.gt(new BN(Transaction.MAX_MONEY, 10))) { |
|
|
|
return 'transaction txout ' + i + ' greater than MAX_MONEY'; |
|
|
|