From 5b6bb13790dd1b8d5066cb1273b3a4eda6dfa654 Mon Sep 17 00:00:00 2001 From: Jonathan Erlich <35579235+joerlop@users.noreply.github.com> Date: Sat, 16 Nov 2019 15:16:05 -0500 Subject: [PATCH] Update evaluate method in script.py to be able to handle opcodes 177 and 178. OP_CHECKLOCKTIMEVERIFY needs locktime and sequence to be passed as arguments. OP_CHECKSEQUENCEVERIFY needs version and sequence to be passed as parameters. These parameters would need to be passed to the evaluate method if any of these opcodes were part of the script. --- code-ch13/script.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/code-ch13/script.py b/code-ch13/script.py index 3a9f0583..1238f2a0 100644 --- a/code-ch13/script.py +++ b/code-ch13/script.py @@ -153,7 +153,7 @@ def serialize(self): # encode_varint the total length of the result and prepend return encode_varint(total) + result - def evaluate(self, z, witness): + def evaluate(self, z, witness, version=None, locktime=None, sequence=None): # create a copy as we may need to add to this list if we have a # RedeemScript cmds = self.cmds[:] @@ -180,6 +180,16 @@ def evaluate(self, z, witness): if not operation(stack, z): LOGGER.info('bad op: {}'.format(OP_CODE_NAMES[cmd])) return False + elif cmd == 177: + # 177 is OP_CHECKLOCKTIMEVERIFY. Operation requires locktime and sequence. + if not operation(stack, locktime, sequence): + LOGGER.info(f"bad op: {OP_CODE_NAMES[cmd]}") + return False + elif cmd == 178: + # 178 is OP_CHECKSEQUENCEVERIFY. Operation requires sequence and version. + if not operation(stack, version, sequence): + LOGGER.info(f"bad op: {OP_CODE_NAMES[cmd]}") + return False else: if not operation(stack): LOGGER.info('bad op: {}'.format(OP_CODE_NAMES[cmd]))