Class: BTC::CLTVExtension
- Inherits:
-
Object
- Object
- BTC::CLTVExtension
- Includes:
- ScriptInterpreterExtension
- Defined in:
- lib/btcruby/script/cltv_extension.rb
Overview
Performs CHECKLOCKTIMEVERIFY (BIP65) evaluation
Constant Summary
Constants included from Opcodes
Opcodes::OPCODE_NAME_TO_VALUE, Opcodes::OPCODE_VALUE_TO_NAME, Opcodes::OP_0, Opcodes::OP_0NOTEQUAL, Opcodes::OP_1, Opcodes::OP_10, Opcodes::OP_11, Opcodes::OP_12, Opcodes::OP_13, Opcodes::OP_14, Opcodes::OP_15, Opcodes::OP_16, Opcodes::OP_1ADD, Opcodes::OP_1NEGATE, Opcodes::OP_1SUB, Opcodes::OP_2, Opcodes::OP_2DIV, Opcodes::OP_2DROP, Opcodes::OP_2DUP, Opcodes::OP_2MUL, Opcodes::OP_2OVER, Opcodes::OP_2ROT, Opcodes::OP_2SWAP, Opcodes::OP_3, Opcodes::OP_3DUP, Opcodes::OP_4, Opcodes::OP_5, Opcodes::OP_6, Opcodes::OP_7, Opcodes::OP_8, Opcodes::OP_9, Opcodes::OP_ABS, Opcodes::OP_ADD, Opcodes::OP_AND, Opcodes::OP_BOOLAND, Opcodes::OP_BOOLOR, Opcodes::OP_CAT, Opcodes::OP_CHECKLOCKTIMEVERIFY, Opcodes::OP_CHECKMULTISIG, Opcodes::OP_CHECKMULTISIGVERIFY, Opcodes::OP_CHECKSIG, Opcodes::OP_CHECKSIGVERIFY, Opcodes::OP_CODESEPARATOR, Opcodes::OP_DEPTH, Opcodes::OP_DIV, Opcodes::OP_DROP, Opcodes::OP_DUP, Opcodes::OP_ELSE, Opcodes::OP_ENDIF, Opcodes::OP_EQUAL, Opcodes::OP_EQUALVERIFY, Opcodes::OP_FALSE, Opcodes::OP_FROMALTSTACK, Opcodes::OP_GREATERTHAN, Opcodes::OP_GREATERTHANOREQUAL, Opcodes::OP_HASH160, Opcodes::OP_HASH256, Opcodes::OP_IF, Opcodes::OP_IFDUP, Opcodes::OP_INVALIDOPCODE, Opcodes::OP_INVERT, Opcodes::OP_LEFT, Opcodes::OP_LESSTHAN, Opcodes::OP_LESSTHANOREQUAL, Opcodes::OP_LSHIFT, Opcodes::OP_MAX, Opcodes::OP_MIN, Opcodes::OP_MOD, Opcodes::OP_MUL, Opcodes::OP_NEGATE, Opcodes::OP_NIP, Opcodes::OP_NOP, Opcodes::OP_NOP1, Opcodes::OP_NOP10, Opcodes::OP_NOP2, Opcodes::OP_NOP3, Opcodes::OP_NOP4, Opcodes::OP_NOP5, Opcodes::OP_NOP6, Opcodes::OP_NOP7, Opcodes::OP_NOP8, Opcodes::OP_NOP9, Opcodes::OP_NOT, Opcodes::OP_NOTIF, Opcodes::OP_NUMEQUAL, Opcodes::OP_NUMEQUALVERIFY, Opcodes::OP_NUMNOTEQUAL, Opcodes::OP_OR, Opcodes::OP_OVER, Opcodes::OP_PICK, Opcodes::OP_PUSHDATA1, Opcodes::OP_PUSHDATA2, Opcodes::OP_PUSHDATA4, Opcodes::OP_RESERVED, Opcodes::OP_RESERVED1, Opcodes::OP_RESERVED2, Opcodes::OP_RETURN, Opcodes::OP_RIGHT, Opcodes::OP_RIPEMD160, Opcodes::OP_ROLL, Opcodes::OP_ROT, Opcodes::OP_RSHIFT, Opcodes::OP_SHA1, Opcodes::OP_SHA256, Opcodes::OP_SIZE, Opcodes::OP_SUB, Opcodes::OP_SUBSTR, Opcodes::OP_SWAP, Opcodes::OP_TOALTSTACK, Opcodes::OP_TRUE, Opcodes::OP_TUCK, Opcodes::OP_VER, Opcodes::OP_VERIF, Opcodes::OP_VERIFY, Opcodes::OP_VERNOTIF, Opcodes::OP_WITHIN, Opcodes::OP_XOR
Constants included from ScriptErrors
ScriptErrors::SCRIPT_ERR_BAD_OPCODE, ScriptErrors::SCRIPT_ERR_CHECKMULTISIGVERIFY, ScriptErrors::SCRIPT_ERR_CHECKSIGVERIFY, ScriptErrors::SCRIPT_ERR_CLEANSTACK, ScriptErrors::SCRIPT_ERR_DISABLED_OPCODE, ScriptErrors::SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS, ScriptErrors::SCRIPT_ERR_EQUALVERIFY, ScriptErrors::SCRIPT_ERR_EVAL_FALSE, ScriptErrors::SCRIPT_ERR_INVALID_ALTSTACK_OPERATION, ScriptErrors::SCRIPT_ERR_INVALID_STACK_OPERATION, ScriptErrors::SCRIPT_ERR_MINIMALDATA, ScriptErrors::SCRIPT_ERR_NEGATIVE_LOCKTIME, ScriptErrors::SCRIPT_ERR_NUMEQUALVERIFY, ScriptErrors::SCRIPT_ERR_OK, ScriptErrors::SCRIPT_ERR_OP_COUNT, ScriptErrors::SCRIPT_ERR_OP_RETURN, ScriptErrors::SCRIPT_ERR_PUBKEYTYPE, ScriptErrors::SCRIPT_ERR_PUBKEY_COUNT, ScriptErrors::SCRIPT_ERR_PUSH_SIZE, ScriptErrors::SCRIPT_ERR_SCRIPT_SIZE, ScriptErrors::SCRIPT_ERR_SIG_COUNT, ScriptErrors::SCRIPT_ERR_SIG_DER, ScriptErrors::SCRIPT_ERR_SIG_HASHTYPE, ScriptErrors::SCRIPT_ERR_SIG_HIGH_S, ScriptErrors::SCRIPT_ERR_SIG_NULLDUMMY, ScriptErrors::SCRIPT_ERR_SIG_PUSHONLY, ScriptErrors::SCRIPT_ERR_STACK_SIZE, ScriptErrors::SCRIPT_ERR_UNBALANCED_CONDITIONAL, ScriptErrors::SCRIPT_ERR_UNKNOWN_ERROR, ScriptErrors::SCRIPT_ERR_UNSATISFIED_LOCKTIME, ScriptErrors::SCRIPT_ERR_VERIFY
Constants included from ScriptFlags
ScriptFlags::SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, ScriptFlags::SCRIPT_VERIFY_CLEANSTACK, ScriptFlags::SCRIPT_VERIFY_DERSIG, ScriptFlags::SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS, ScriptFlags::SCRIPT_VERIFY_LOW_S, ScriptFlags::SCRIPT_VERIFY_MINIMALDATA, ScriptFlags::SCRIPT_VERIFY_NONE, ScriptFlags::SCRIPT_VERIFY_NULLDUMMY, ScriptFlags::SCRIPT_VERIFY_P2SH, ScriptFlags::SCRIPT_VERIFY_SIGPUSHONLY, ScriptFlags::SCRIPT_VERIFY_STRICTENC
Instance Method Summary collapse
- #extra_flags ⇒ Object
-
#handle_opcode(interpreter: nil, opcode: nil) ⇒ Object
Returns
falseif failed to execute the opcode. -
#initialize(locktime_max_size: nil, lock_time_checker: nil) ⇒ CLTVExtension
constructor
Default
locktime_max_sizeis 5. - #should_handle_opcode(interpreter: nil, opcode: nil) ⇒ Object
Methods included from ScriptInterpreterExtension
#did_execute_output_script, #did_execute_signature_script, #handle_output_script, #handle_scripts, #should_handle_output_script, #should_handle_scripts
Constructor Details
#initialize(locktime_max_size: nil, lock_time_checker: nil) ⇒ CLTVExtension
Default locktime_max_size is 5.
Default lock_time_checker equals current interpreter's signature checker.
8 9 10 11 |
# File 'lib/btcruby/script/cltv_extension.rb', line 8 def initialize(locktime_max_size: nil, lock_time_checker: nil) @locktime_max_size = locktime_max_size || 5 @lock_time_checker = lock_time_checker end |
Instance Method Details
#extra_flags ⇒ Object
13 14 15 |
# File 'lib/btcruby/script/cltv_extension.rb', line 13 def extra_flags SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY end |
#handle_opcode(interpreter: nil, opcode: nil) ⇒ Object
Returns false if failed to execute the opcode.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/btcruby/script/cltv_extension.rb', line 22 def handle_opcode(interpreter: nil, opcode: nil) # We are not supposed to handle any other opcodes here. return false if opcode != OP_CHECKLOCKTIMEVERIFY if interpreter.stack.size < 1 return interpreter.set_error(SCRIPT_ERR_INVALID_STACK_OPERATION) end # Note that elsewhere numeric opcodes are limited to # operands in the range -2**31+1 to 2**31-1, however it is # legal for opcodes to produce results exceeding that # range. This limitation is implemented by CScriptNum's # default 4-byte limit. # # If we kept to that limit we'd have a year 2038 problem, # even though the nLockTime field in transactions # themselves is uint32 which only becomes meaningless # after the year 2106. # # Thus as a special case we tell CScriptNum to accept up # to 5-byte bignums, which are good until 2**39-1, well # beyond the 2**32-1 limit of the nLockTime field itself. locktime = interpreter.cast_to_number(interpreter.stack.last, max_size: @locktime_max_size) # In the rare event that the argument may be < 0 due to # some arithmetic being done first, you can always use # 0 MAX CHECKLOCKTIMEVERIFY. if locktime < 0 return interpreter.set_error(SCRIPT_ERR_NEGATIVE_LOCKTIME) end # Actually compare the specified lock time with the transaction. checker = @lock_time_checker || interpreter.signature_checker if !checker.check_lock_time(locktime) return interpreter.set_error(SCRIPT_ERR_UNSATISFIED_LOCKTIME) end return true end |
#should_handle_opcode(interpreter: nil, opcode: nil) ⇒ Object
17 18 19 |
# File 'lib/btcruby/script/cltv_extension.rb', line 17 def should_handle_opcode(interpreter: nil, opcode: nil) opcode == OP_CHECKLOCKTIMEVERIFY end |