Skip to content

Built-in Objects Documentation

This document provides detailed introduction to the built-in objects defined by the system, including Self object and BVM object. The document covers object names, functions, attributes, methods, and usage examples, aiming to provide clear and accurate function usage guides for developers.

1. Self Object

  • Object Name: Self
  • Short Description: Represents the "self" concept built-in object, used for handling member access related to the current context.
  • Example:
    python
    # Initialize Self object and set attributes
    def __init__(pubKeyH: hex):
        self.pubKeyHash = pubKeyH  # Add pubKeyHash attribute to self object and assign value
    
    # Use Self object attributes
    def verify_key(signature: string):
        result = CheckSig(self.pubKeyHash, signature)

2. BVM Object

  • Object Name: BVM (Bytecode Virtual Machine)
  • Short Description: Represents the bytecode virtual machine built-in object, provides access to virtual machine metadata (such as version, input/output counts).
  • Predefined Member Mapping Table:
    Member NameCorresponding ValuePurpose
    "version"1Virtual machine version number
    "locktime"2Lock time
    "inputCount"3Input data count
    "outputCount"4Output data count
    "inputsHash"5Hash value of input data
    "unlockingInput"6Unlocking input data
    "outputsHash"7Hash value of output data
  • Example:
    python
    # Process transaction data and verify
    tx_data = Cat(pretx.VLIO, tx_data)  # Concatenate transaction data
    txid = Hash256(tx_data)  # Calculate transaction ID
    
    # Access BVM object metadata
    meta_data = BVM.unlockingInput  # Get unlocking input metadata
    {meta_data_txid, meta_data_remain} = Split(meta_data, 32)  # Extract transaction ID from metadata
    
    EqualVerify(txid, meta_data_txid)  # Verify transaction ID consistency

Released under the MIT License.