Module: BTC::ScriptInterpreterExtension

Includes:
Opcodes, ScriptErrors, ScriptFlags
Included in:
CLTVExtension, P2SHExtension
Defined in:
lib/btcruby/script/script_interpreter_extension.rb

Overview

ScriptInterpreterExtension allows adding extensions to the script machinery without requiring source code meddling. ScriptInterpreter provides several extension points:

  • extra flags (e.g. requirement for push-only opcodes in signature script)
  • pre-flight hook to completely take control over both scripts' execution
  • callback after signature script execution
  • interior hook to take control over output script execution after signature script is being executed
  • callback after output script execution
  • hook for handling the opcodes

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

BTC::ScriptErrors::SCRIPT_ERR_BAD_OPCODE, BTC::ScriptErrors::SCRIPT_ERR_CHECKMULTISIGVERIFY, BTC::ScriptErrors::SCRIPT_ERR_CHECKSIGVERIFY, BTC::ScriptErrors::SCRIPT_ERR_CLEANSTACK, BTC::ScriptErrors::SCRIPT_ERR_DISABLED_OPCODE, BTC::ScriptErrors::SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS, BTC::ScriptErrors::SCRIPT_ERR_EQUALVERIFY, BTC::ScriptErrors::SCRIPT_ERR_EVAL_FALSE, BTC::ScriptErrors::SCRIPT_ERR_INVALID_ALTSTACK_OPERATION, BTC::ScriptErrors::SCRIPT_ERR_INVALID_STACK_OPERATION, BTC::ScriptErrors::SCRIPT_ERR_MINIMALDATA, BTC::ScriptErrors::SCRIPT_ERR_NEGATIVE_LOCKTIME, BTC::ScriptErrors::SCRIPT_ERR_NUMEQUALVERIFY, BTC::ScriptErrors::SCRIPT_ERR_OK, BTC::ScriptErrors::SCRIPT_ERR_OP_COUNT, BTC::ScriptErrors::SCRIPT_ERR_OP_RETURN, BTC::ScriptErrors::SCRIPT_ERR_PUBKEYTYPE, BTC::ScriptErrors::SCRIPT_ERR_PUBKEY_COUNT, BTC::ScriptErrors::SCRIPT_ERR_PUSH_SIZE, BTC::ScriptErrors::SCRIPT_ERR_SCRIPT_SIZE, BTC::ScriptErrors::SCRIPT_ERR_SIG_COUNT, BTC::ScriptErrors::SCRIPT_ERR_SIG_DER, BTC::ScriptErrors::SCRIPT_ERR_SIG_HASHTYPE, BTC::ScriptErrors::SCRIPT_ERR_SIG_HIGH_S, BTC::ScriptErrors::SCRIPT_ERR_SIG_NULLDUMMY, BTC::ScriptErrors::SCRIPT_ERR_SIG_PUSHONLY, BTC::ScriptErrors::SCRIPT_ERR_STACK_SIZE, BTC::ScriptErrors::SCRIPT_ERR_UNBALANCED_CONDITIONAL, BTC::ScriptErrors::SCRIPT_ERR_UNKNOWN_ERROR, BTC::ScriptErrors::SCRIPT_ERR_UNSATISFIED_LOCKTIME, BTC::ScriptErrors::SCRIPT_ERR_VERIFY

Constants included from ScriptFlags

BTC::ScriptFlags::SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, BTC::ScriptFlags::SCRIPT_VERIFY_CLEANSTACK, BTC::ScriptFlags::SCRIPT_VERIFY_DERSIG, BTC::ScriptFlags::SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS, BTC::ScriptFlags::SCRIPT_VERIFY_LOW_S, BTC::ScriptFlags::SCRIPT_VERIFY_MINIMALDATA, BTC::ScriptFlags::SCRIPT_VERIFY_NONE, BTC::ScriptFlags::SCRIPT_VERIFY_NULLDUMMY, BTC::ScriptFlags::SCRIPT_VERIFY_P2SH, BTC::ScriptFlags::SCRIPT_VERIFY_SIGPUSHONLY, BTC::ScriptFlags::SCRIPT_VERIFY_STRICTENC

Instance Method Summary collapse

Instance Method Details

#did_execute_output_script(interpreter: nil, output_script: nil) ⇒ Object

Every extension gets this callback. If extension return false, execution is stopped and interpreter returns false. Default value is true.



53
54
55
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 53

def did_execute_output_script(interpreter: nil, output_script: nil)
  true
end

#did_execute_signature_script(interpreter: nil, signature_script: nil) ⇒ Object

Every extension gets this callback. If extension return false, execution is stopped and interpreter returns false. Default value is true.



35
36
37
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 35

def did_execute_signature_script(interpreter: nil, signature_script: nil)
  true
end

#extra_flagsObject

Returns additional flags to be available to #flag? checks during script execution. This way one extension can affect evaluation of another.



17
18
19
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 17

def extra_flags
  0
end

#handle_opcode(interpreter: nil, opcode: nil) ⇒ Object

Returns false if failed to execute the opcode.



64
65
66
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 64

def handle_opcode(interpreter: nil, opcode: nil)
  false
end

#handle_output_script(interpreter: nil, output_script: nil) ⇒ Object

Returns true/false depending on result of script's evaluation



47
48
49
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 47

def handle_output_script(interpreter: nil, output_script: nil)
  false
end

#handle_scripts(interpreter: nil, signature_script: nil, output_script: nil) ⇒ Object

Returns true/false depending on result of scripts' evaluation



29
30
31
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 29

def handle_scripts(interpreter: nil, signature_script: nil, output_script: nil)
  false
end

#should_handle_opcode(interpreter: nil, opcode: nil) ⇒ Object

The first extension that returns true takes control over that opcode. Default value is false.



59
60
61
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 59

def should_handle_opcode(interpreter: nil, opcode: nil)
  false
end

#should_handle_output_script(interpreter: nil, output_script: nil) ⇒ Object

The first extension that returns true takes control over output script via #handle_output_script. No other callbacks are called for this extension or any other. Default value is false.



42
43
44
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 42

def should_handle_output_script(interpreter: nil, output_script: nil)
  false
end

#should_handle_scripts(interpreter: nil, signature_script: nil, output_script: nil) ⇒ Object

The first extension that returns true takes control over both scripts via handle_scripts. No other callbacks are called for this extension or any other. Default value is false.



24
25
26
# File 'lib/btcruby/script/script_interpreter_extension.rb', line 24

def should_handle_scripts(interpreter: nil, signature_script: nil, output_script: nil)
  false
end