Type alias InstructionSet<ResolvedTransaction, AuthenticationProgram, ProgramState>

InstructionSet<ResolvedTransaction, AuthenticationProgram, ProgramState>: {
    clone: Operation<ProgramState>;
    continue: ((state) => boolean);
    evaluate: ((program, stateEvaluate) => ProgramState);
    every?: Operation<ProgramState>;
    operations: InstructionSetOperationMapping<ProgramState>;
    success: ((state) => string | true);
    undefined: Operation<ProgramState>;
    verify: ((resolvedTransaction, evaluate, success) => string | true);
}

An InstructionSet is a mapping of methods that define the operation of an AuthenticationVirtualMachine.

An instruction set is composed of Operations that take a ProgramState and return a ProgramState, as well as several instruction set "lifecycle" methods.

Each operation is assigned to its opcode number (between 0 and 255). When evaluating instructions, the virtual machine will select an Operation based on its opcode. Any opcodes that are unassigned by the instruction set will use the undefined operation.

Type Parameters

  • ResolvedTransaction

  • AuthenticationProgram

  • ProgramState

Type declaration

  • clone: Operation<ProgramState>

    Take a ProgramState and return a new copy of that ProgramState.

    Remarks

    This method is used internally by stateEvaluate, stateStep, and stateDebug to prevent the AuthenticationVirtualMachine from mutating an input when mutation is not desirable.

    Deprecated

    use structuredClone instead

  • continue: ((state) => boolean)

    Test the ProgramState to determine if execution should continue.

    Remarks

    This method is used internally by the AuthenticationVirtualMachine's stateEvaluate and stateDebug methods after each operation, and should usually test for errors or program completion. This method is exposed via the AuthenticationVirtualMachine's stateContinue method.

      • (state): boolean
      • Test the ProgramState to determine if execution should continue.

        Parameters

        Returns boolean

        Remarks

        This method is used internally by the AuthenticationVirtualMachine's stateEvaluate and stateDebug methods after each operation, and should usually test for errors or program completion. This method is exposed via the AuthenticationVirtualMachine's stateContinue method.

  • evaluate: ((program, stateEvaluate) => ProgramState)

    Evaluate a program to completion given the AuthenticationVirtualMachine's stateEvaluate method.

    Remarks

    Each AuthenticationVirtualMachine can have precise operation requirements modifying the ways in which AuthenticationPrograms and ProgramStates are interpreted. (In the C++ implementations, these requirements are encoded in VerifyScript, and can significantly modify the behavior of the basic EvalScript system.) For example, the secondary evaluation step required for P2SH can be performed in this method.

    This method is used internally by the AuthenticationVirtualMachine's evaluate and debug methods. It should perform any necessary operations and validations before returning a fully-evaluated ProgramState.

      • (program, stateEvaluate): ProgramState
      • Evaluate a program to completion given the AuthenticationVirtualMachine's stateEvaluate method.

        Parameters

        Returns ProgramState

        Remarks

        Each AuthenticationVirtualMachine can have precise operation requirements modifying the ways in which AuthenticationPrograms and ProgramStates are interpreted. (In the C++ implementations, these requirements are encoded in VerifyScript, and can significantly modify the behavior of the basic EvalScript system.) For example, the secondary evaluation step required for P2SH can be performed in this method.

        This method is used internally by the AuthenticationVirtualMachine's evaluate and debug methods. It should perform any necessary operations and validations before returning a fully-evaluated ProgramState.

  • Optional every?: Operation<ProgramState>

    An optional operation to be performed after every executed virtual machine operation. This is useful for implementing logic that is common to all operations, e.g. stack depth or memory usage, operation count, etc.

  • operations: InstructionSetOperationMapping<ProgramState>

    A mapping of opcode numbers (between 0 and 255) to Operations. When the AuthenticationVirtualMachine encounters an instruction for the specified opcode, the program state will be passed to the specified operation.

  • success: ((state) => string | true)

    Verify that a program state has completed evaluation successfully.

    Remarks

    This method should return true if the evaluation was successful, or an error message on failure.

      • (state): string | true
      • Verify that a program state has completed evaluation successfully.

        Parameters

        Returns string | true

        Remarks

        This method should return true if the evaluation was successful, or an error message on failure.

  • undefined: Operation<ProgramState>

    This operation is called when an undefined opcode is encountered.

    Remarks

    This method should usually mark the ProgramState with an error.

  • verify: ((resolvedTransaction, evaluate, success) => string | true)

    Verify a transaction given the InstructionSet's evaluate and success methods and a fully-resolved transaction (e.g. the decoded transaction and an array of the outputs spent by its inputs).

    This method should perform all possible stateless transaction validation but should not attempt to perform any kinds of network state-sensitive validation (ensuring source outputs remain unspent, validating claimed absolute or relative locktime values against current network conditions, etc.), as such results could not be safely cached.

    Remarks

    This method should return true if the transaction is valid, or an array of error messages on failure.

      • (resolvedTransaction, evaluate, success): string | true
      • Verify a transaction given the InstructionSet's evaluate and success methods and a fully-resolved transaction (e.g. the decoded transaction and an array of the outputs spent by its inputs).

        This method should perform all possible stateless transaction validation but should not attempt to perform any kinds of network state-sensitive validation (ensuring source outputs remain unspent, validating claimed absolute or relative locktime values against current network conditions, etc.), as such results could not be safely cached.

        Parameters

        Returns string | true

        Remarks

        This method should return true if the transaction is valid, or an array of error messages on failure.

Generated using TypeDoc