Trait odra::ContractContext

source ·
pub trait ContractContext {
Show 16 methods // Required methods fn get_value(&self, key: &[u8]) -> Option<Bytes>; fn set_value(&self, key: &[u8], value: Bytes); fn caller(&self) -> Address; fn self_address(&self) -> Address; fn call_contract(&self, address: Address, call_def: CallDef) -> Bytes; fn get_block_time(&self) -> u64; fn attached_value(&self) -> U512; fn self_balance(&self) -> U512; fn emit_event(&self, event: &Bytes); fn transfer_tokens(&self, to: &Address, amount: &U512); fn revert(&self, error: OdraError) -> !; fn get_named_arg_bytes(&self, name: &str) -> Bytes; fn get_opt_named_arg_bytes(&self, name: &str) -> Option<Bytes>; fn handle_attached_value(&self); fn clear_attached_value(&self); fn hash(&self, bytes: &[u8]) -> [u8; 32];
}
Expand description

Trait representing the context of a smart contract.

Required Methods§

source

fn get_value(&self, key: &[u8]) -> Option<Bytes>

Retrieves from the storage the value associated with the given key.

§Arguments
  • key - The key to retrieve the value for.
§Returns

An Option containing the value associated with the key, or None if the key is not found.

source

fn set_value(&self, key: &[u8], value: Bytes)

Writes to the storage the value associated with the given key.

§Arguments
  • key - The key to set the value for.
  • value - The value to be set.
source

fn caller(&self) -> Address

Retrieves the address of the caller.

source

fn self_address(&self) -> Address

Retrieves the address of the current contract.

source

fn call_contract(&self, address: Address, call_def: CallDef) -> Bytes

Calls another contract at the specified address with the given call definition.

§Arguments
  • address - The address of the contract to call.
  • call_def - The call definition specifying the method and arguments to call.
§Returns

The result of the contract call as a byte array.

source

fn get_block_time(&self) -> u64

Retrieves the current block time.

§Returns

The current block time as a u64 value.

source

fn attached_value(&self) -> U512

Retrieves the value attached to the call.

§Returns

The attached value as a U512 value.

source

fn self_balance(&self) -> U512

Retrieves the balance of the current contract.

§Returns

The balance of the current contract in U512

source

fn emit_event(&self, event: &Bytes)

Emits an event with the specified event data.

§Arguments
  • event - The event data to emit.
source

fn transfer_tokens(&self, to: &Address, amount: &U512)

Transfers tokens to the specified address.

§Arguments
  • to - The address to transfer the tokens to.
  • amount - The amount of tokens to transfer.
source

fn revert(&self, error: OdraError) -> !

Reverts the contract execution with the specified error.

§Arguments
  • error - The error to revert with.
§Panics

This function will panic and abort the contract execution.

source

fn get_named_arg_bytes(&self, name: &str) -> Bytes

Retrieves the value of the named argument as a byte array.

§Arguments
  • name - The name of the argument.
§Returns

The value of the named argument as a byte array.

source

fn get_opt_named_arg_bytes(&self, name: &str) -> Option<Bytes>

Similar to get_named_arg_bytes, but returns None if the named argument is not present.

source

fn handle_attached_value(&self)

Handles the value attached to the call. Sets the value in the contract context.

source

fn clear_attached_value(&self)

Clears the value attached to the call.

source

fn hash(&self, bytes: &[u8]) -> [u8; 32]

Computes the hash of the given byte array.

§Arguments
  • bytes - The byte array to compute the hash for.
§Returns

The computed hash as a fixed-size byte array of length 32.

Implementors§