tx: refactor.
This commit is contained in:
parent
74c177d623
commit
122b4a9fb3
@ -1143,6 +1143,72 @@ TX.prototype.isFinal = function isFinal(height, ts) {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Verify the nLockTime of a transaction.
|
||||
* @param {Number} index - Index of input being verified.
|
||||
* @param {Number} locktime - Locktime to verify against.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
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)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (locktime > this.locktime)
|
||||
return false;
|
||||
|
||||
if (input.sequence === 0xffffffff)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Verify the nSequence locktime of a transaction.
|
||||
* @param {Number} index - Index of input being verified.
|
||||
* @param {Number} sequence - Locktime to verify against.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
TX.prototype.verifySequence = function verifySequence(index, sequence) {
|
||||
var input = this.inputs[index];
|
||||
var mask, seq1, seq2;
|
||||
|
||||
if ((sequence & consensus.SEQUENCE_DISABLE_FLAG) !== 0)
|
||||
return true;
|
||||
|
||||
if (this.version < 2)
|
||||
return false;
|
||||
|
||||
if (input.sequence & consensus.SEQUENCE_DISABLE_FLAG)
|
||||
return false;
|
||||
|
||||
mask = consensus.SEQUENCE_TYPE_FLAG | consensus.SEQUENCE_MASK;
|
||||
seq1 = input.sequence & mask;
|
||||
seq2 = sequence & mask;
|
||||
|
||||
if (!(
|
||||
(seq1 < consensus.SEQUENCE_TYPE_FLAG
|
||||
&& seq2 < consensus.SEQUENCE_TYPE_FLAG)
|
||||
|| (seq1 >= consensus.SEQUENCE_TYPE_FLAG
|
||||
&& seq2 >= consensus.SEQUENCE_TYPE_FLAG)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (seq2 > seq1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate legacy (inaccurate) sigop count.
|
||||
* @returns {Number} sigop count
|
||||
@ -2552,72 +2618,6 @@ TX.isTX = function isTX(obj) {
|
||||
&& typeof obj.witnessHash === 'function';
|
||||
};
|
||||
|
||||
/**
|
||||
* Verify the nLockTime of a transaction.
|
||||
* @param {Number} index - Index of input being verified.
|
||||
* @param {Number} locktime - Locktime to verify against (max=u32).
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
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)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (locktime > this.locktime)
|
||||
return false;
|
||||
|
||||
if (input.sequence === 0xffffffff)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Verify the nSequence locktime of a transaction.
|
||||
* @param {Number} index - Index of input being verified.
|
||||
* @param {Number} sequence - Locktime to verify against (max=u32).
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
TX.prototype.verifySequence = function verifySequence(index, sequence) {
|
||||
var input = this.inputs[index];
|
||||
var mask, seq1, seq2;
|
||||
|
||||
if ((sequence & consensus.SEQUENCE_DISABLE_FLAG) !== 0)
|
||||
return true;
|
||||
|
||||
if (this.version < 2)
|
||||
return false;
|
||||
|
||||
if (input.sequence & consensus.SEQUENCE_DISABLE_FLAG)
|
||||
return false;
|
||||
|
||||
mask = consensus.SEQUENCE_TYPE_FLAG | consensus.SEQUENCE_MASK;
|
||||
seq1 = input.sequence & mask;
|
||||
seq2 = sequence & mask;
|
||||
|
||||
if (!(
|
||||
(seq1 < consensus.SEQUENCE_TYPE_FLAG
|
||||
&& seq2 < consensus.SEQUENCE_TYPE_FLAG)
|
||||
|| (seq1 >= consensus.SEQUENCE_TYPE_FLAG
|
||||
&& seq2 >= consensus.SEQUENCE_TYPE_FLAG)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (seq2 > seq1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/*
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user