refactor. strict isscripthash.
This commit is contained in:
parent
7b1af73c46
commit
2b5c1369da
@ -865,7 +865,7 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
|
||||
n2 = Script.num(stack.pop(), flags);
|
||||
n1 = Script.num(stack.pop(), flags);
|
||||
val = n2.cmp(n1) <= 0 && n1.cmp(n3) < 0;
|
||||
stack.push(val.cmpn(0) !== 0 ? STACK_TRUE : STACK_FALSE);
|
||||
stack.push(val ? STACK_TRUE : STACK_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1124,7 +1124,7 @@ Script.checkSequence = function checkSequence(sequence, tx, i) {
|
||||
var txSequence = tx.inputs[i].sequence;
|
||||
var locktimeMask, txSequenceMasked, sequenceMasked;
|
||||
|
||||
if ((tx.version >>> 0) < 2)
|
||||
if (tx.version < 2)
|
||||
return false;
|
||||
|
||||
if (txSequence & constants.sequenceLocktimeDisableFlag)
|
||||
@ -1370,6 +1370,13 @@ Script.createWitnessProgram = function createWitnessProgram(version, data) {
|
||||
return new Script([version === 0 ? 0 : version + 0x50, data]);
|
||||
};
|
||||
|
||||
Script.prototype.createCommitment = function createCommitment(hash) {
|
||||
return new Script([
|
||||
opcodes.OP_RETURN,
|
||||
Buffer.concat([new Buffer([0xaa, 0x21, 0xa9, 0xed]), hash])
|
||||
]);
|
||||
};
|
||||
|
||||
Script.prototype.getRedeem = function getRedeem() {
|
||||
if (!this.redeem)
|
||||
this.redeem = Script.getRedeem(this.code);
|
||||
@ -1660,6 +1667,21 @@ Script.prototype.isMultisig = function isMultisig(keys) {
|
||||
Script.prototype.isScripthash = function isScripthash(hash) {
|
||||
var res;
|
||||
|
||||
// Bitcoind requires strict
|
||||
// minimaldata encoding for scripthash.
|
||||
if (this.raw) {
|
||||
if (hash) {
|
||||
if (!Script.isHash(this.code[1]))
|
||||
return false;
|
||||
if (!utils.isEqual(this.code[1], hash))
|
||||
return false;
|
||||
}
|
||||
return this.raw.length === 23
|
||||
&& this.raw[0] === opcodes.OP_HASH160
|
||||
&& this.raw[1] === 0x14
|
||||
&& this.raw[22] === opcodes.OP_EQUAL;
|
||||
}
|
||||
|
||||
if (this.code.length !== 3)
|
||||
return false;
|
||||
|
||||
@ -1700,13 +1722,6 @@ Script.prototype.isCommitment = function isCommitment() {
|
||||
&& utils.readU32BE(this.code[1], 0) === 0xaa21a9ed;
|
||||
};
|
||||
|
||||
Script.prototype.createCommitment = function createCommitment(hash) {
|
||||
return new Script([
|
||||
opcodes.OP_RETURN,
|
||||
Buffer.concat([new Buffer([0xaa, 0x21, 0xa9, 0xed]), hash])
|
||||
]);
|
||||
};
|
||||
|
||||
Script.prototype.getCommitmentHash = function getCommitmentHash() {
|
||||
if (!this.isCommitment())
|
||||
return;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user