|
@ -66,6 +66,12 @@ function Transaction(serialized) { |
|
|
// max amount of satoshis in circulation
|
|
|
// max amount of satoshis in circulation
|
|
|
Transaction.MAX_MONEY = 21000000 * 1e8; |
|
|
Transaction.MAX_MONEY = 21000000 * 1e8; |
|
|
|
|
|
|
|
|
|
|
|
// nlocktime limit to be considered block height rather than a timestamp
|
|
|
|
|
|
Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT = 5e8; |
|
|
|
|
|
|
|
|
|
|
|
// Max value for an unsigned 32 bit value
|
|
|
|
|
|
Transaction.NLOCKTIME_MAX_VALUE = 4294967295; |
|
|
|
|
|
|
|
|
/* Constructors and Serialization */ |
|
|
/* Constructors and Serialization */ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -280,13 +286,41 @@ Transaction.prototype.fromObject = function(transaction) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* sets nLockTime so that transaction is not valid until |
|
|
* Sets nLockTime so that transaction is not valid until the desired date(a |
|
|
* the desired date or block height |
|
|
* timestamp in seconds since UNIX epoch is also accepted) |
|
|
|
|
|
* |
|
|
* @param {Date | Number} time |
|
|
* @param {Date | Number} time |
|
|
|
|
|
* @return {Transaction} this |
|
|
*/ |
|
|
*/ |
|
|
Transaction.prototype.lockUntil = function(time) { |
|
|
Transaction.prototype.lockUntilDate = function(time) { |
|
|
$.checkArgument(time); |
|
|
$.checkArgument(time); |
|
|
this.nLockTime = DEFAULT_NLOCKTIME; |
|
|
if (_.isNumber(time) && time < Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) { |
|
|
|
|
|
throw new errors.Transaction.LockTimeTooEarly(); |
|
|
|
|
|
} |
|
|
|
|
|
if (_.isDate(time)) { |
|
|
|
|
|
time = time.getTime() / 1000; |
|
|
|
|
|
} |
|
|
|
|
|
this.nLockTime = time; |
|
|
|
|
|
return this; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Sets nLockTime so that transaction is not valid until the desired block |
|
|
|
|
|
* height. |
|
|
|
|
|
* |
|
|
|
|
|
* @param {Number} time |
|
|
|
|
|
* @return {Transaction} this |
|
|
|
|
|
*/ |
|
|
|
|
|
Transaction.prototype.lockUntilBlockHeight = function(time) { |
|
|
|
|
|
$.checkArgument(_.isNumber(time)); |
|
|
|
|
|
if (time >= Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) { |
|
|
|
|
|
throw new errors.Transaction.BlockHeightTooHigh(); |
|
|
|
|
|
} |
|
|
|
|
|
if (time < 0) { |
|
|
|
|
|
throw new errors.Transaction.NLockTimeOutOfRange(); |
|
|
|
|
|
} |
|
|
|
|
|
this.nLockTime = time; |
|
|
|
|
|
return this; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Transaction.prototype.toJSON = function toJSON() { |
|
|
Transaction.prototype.toJSON = function toJSON() { |
|
|