tx: refactor locktimes.

This commit is contained in:
Christopher Jeffrey 2017-01-06 11:09:52 -08:00
parent 122b4a9fb3
commit 3236c367b1
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1154,10 +1154,8 @@ TX.prototype.verifyLocktime = function verifyLocktime(index, locktime) {
var threshold = consensus.LOCKTIME_THRESHOLD;
var input = this.inputs[index];
if (!(
(this.locktime < threshold && locktime < threshold)
|| (this.locktime >= threshold && locktime >= threshold)
)) {
if (!((this.locktime < threshold && locktime < threshold)
|| (this.locktime >= threshold && locktime >= threshold))) {
return false;
}
@ -1173,37 +1171,36 @@ TX.prototype.verifyLocktime = function verifyLocktime(index, locktime) {
/**
* Verify the nSequence locktime of a transaction.
* @param {Number} index - Index of input being verified.
* @param {Number} sequence - Locktime to verify against.
* @param {Number} locktime - Sequence locktime to verify against.
* @returns {Boolean}
*/
TX.prototype.verifySequence = function verifySequence(index, sequence) {
TX.prototype.verifySequence = function verifySequence(index, locktime) {
var DISABLE_FLAG = consensus.SEQUENCE_DISABLE_FLAG;
var TYPE_FLAG = consensus.SEQUENCE_TYPE_FLAG;
var SEQUENCE_MASK = consensus.SEQUENCE_MASK;
var input = this.inputs[index];
var mask, seq1, seq2;
var mask, sequence, predicate;
if ((sequence & consensus.SEQUENCE_DISABLE_FLAG) !== 0)
if ((locktime & DISABLE_FLAG) !== 0)
return true;
if (this.version < 2)
return false;
if (input.sequence & consensus.SEQUENCE_DISABLE_FLAG)
if ((input.sequence & DISABLE_FLAG) !== 0)
return false;
mask = consensus.SEQUENCE_TYPE_FLAG | consensus.SEQUENCE_MASK;
seq1 = input.sequence & mask;
seq2 = sequence & mask;
mask = TYPE_FLAG | SEQUENCE_MASK;
sequence = input.sequence & mask;
predicate = locktime & mask;
if (!(
(seq1 < consensus.SEQUENCE_TYPE_FLAG
&& seq2 < consensus.SEQUENCE_TYPE_FLAG)
|| (seq1 >= consensus.SEQUENCE_TYPE_FLAG
&& seq2 >= consensus.SEQUENCE_TYPE_FLAG)
)) {
if (!((sequence < TYPE_FLAG && predicate < TYPE_FLAG)
|| (sequence >= TYPE_FLAG && predicate >= TYPE_FLAG))) {
return false;
}
if (seq2 > seq1)
if (predicate > sequence)
return false;
return true;