script: implement minimalif.
This commit is contained in:
parent
144beb343a
commit
63dd30393c
@ -775,8 +775,9 @@ exports.flags = {
|
||||
VERIFY_CHECKSEQUENCEVERIFY: (1 << 10),
|
||||
VERIFY_WITNESS: (1 << 11),
|
||||
VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM: (1 << 12),
|
||||
VERIFY_MAST: (1 << 13),
|
||||
VERIFY_MINIMALIF: (1 << 13),
|
||||
VERIFY_NULLFAIL: (1 << 14),
|
||||
VERIFY_MAST: (1 << 15), // should be 1 << 13
|
||||
VERIFY_SEQUENCE: (1 << 0),
|
||||
MEDIAN_TIME_PAST: (1 << 1)
|
||||
};
|
||||
|
||||
@ -362,33 +362,52 @@ Script.prototype.execute = function execute(stack, flags, tx, index, version) {
|
||||
case opcodes.OP_IF:
|
||||
case opcodes.OP_NOTIF: {
|
||||
val = false;
|
||||
|
||||
if (negate === 0) {
|
||||
if (stack.length < 1)
|
||||
throw new ScriptError('UNBALANCED_CONDITIONAL', op, ip);
|
||||
|
||||
val = Script.bool(stack.pop());
|
||||
|
||||
if (version == 1 && (flags & constants.flags.VERIFY_MINIMALIF)) {
|
||||
if (val.length > 1)
|
||||
throw new ScriptError('MINIMALIF');
|
||||
|
||||
if (val.length === 1 && val[0] !== 1)
|
||||
throw new ScriptError('MINIMALIF');
|
||||
}
|
||||
|
||||
if (op === opcodes.OP_NOTIF)
|
||||
val = !val;
|
||||
}
|
||||
|
||||
state.push(val);
|
||||
|
||||
if (!val)
|
||||
negate++;
|
||||
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_ELSE: {
|
||||
if (state.length === 0)
|
||||
throw new ScriptError('UNBALANCED_CONDITIONAL', op, ip);
|
||||
|
||||
state[state.length - 1] = !state[state.length - 1];
|
||||
|
||||
if (!state[state.length - 1])
|
||||
negate++;
|
||||
else
|
||||
negate--;
|
||||
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_ENDIF: {
|
||||
if (state.length === 0)
|
||||
throw new ScriptError('UNBALANCED_CONDITIONAL', op, ip);
|
||||
|
||||
if (!state.pop())
|
||||
negate--;
|
||||
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_VERIF:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user