Skip to main content

parse_script

Function parse_script 

Source
pub fn parse_script(bytes: &[u8]) -> Result<Vec<Token>, ScriptError>
Expand description

Parses raw script bytes into a sequence of tokens.

Walks the byte slice left-to-right, dispatching on each byte:

  • 0x01-0x4b: direct push (byte value = data length)
  • 0x4c: OP_PUSHDATA1 (1-byte length prefix)
  • 0x4d: OP_PUSHDATA2 (2-byte little-endian length prefix)
  • 0x4e: OP_PUSHDATA4 (4-byte little-endian length prefix)
  • All other bytes: looked up via Opcode::from_byte

Returns ScriptError::UnexpectedEndOfScript if a push-data instruction extends beyond the end of the byte slice, or ScriptError::UnsupportedOpcode for unrecognized byte values.