Docs
chromia.com

op_context

On this page

The op_context namespace provides information about the current operation context, including block information, transaction details, and signer verification. For complete API documentation, see the op_context reference in the Standard Library.

Overview

The op_context namespace includes:

  • Block information – block_height, last_block_time for accessing blockchain state
  • Transaction details – transaction, op_index for information about the current transaction and operation
  • Signer verification – get_signers, is_signer for checking transaction signatures
  • Operation access – get_all_operations, get_current_operation for inspecting transaction operations
  • Event emission – emit_event for communication with Postchain components

Key functions and fields

Example: Verify transaction signer

Rell
operation transfer(to: text, amount: integer) {
    val sender_pubkey = x'036d6caac248af96f6afa7f904f550253a0f3ef3f5aa2fe6838a95b216691468e2';

    // Check if the expected public key signed this transaction
    require(op_context.is_signer(sender_pubkey), "Unauthorized: sender must sign the transaction");

    // Perform transfer logic
    // ...
}

Example: Access block and operation information

Rell
operation log_operation() {
    print("Block height: %d".format(op_context.block_height));
    print("Operation index: %d".format(op_context.op_index));
    print("Number of signers: %d".format(op_context.get_signers().size()));
    print("Last block time: %d".format(op_context.last_block_time));
}

Example: Get all operations in a transaction

Rell
operation process_batch() {
    val all_ops = op_context.get_all_operations();

    for (op in all_ops) {
        print("Operation: %s".format(op.name));
    }
}