ContractContext

Trait ContractContext 

Source
pub trait ContractContext {
Show 28 methods // Required methods fn get_value(&self, key: &[u8]) -> Option<Bytes>; fn set_value(&self, key: &[u8], value: Bytes); fn get_named_value(&self, name: &str) -> Option<Bytes>; fn set_named_value(&self, name: &str, value: CLValue); fn get_dictionary_value( &self, dictionary_name: &str, key: &[u8], ) -> Option<Bytes>; fn set_dictionary_value( &self, dictionary_name: &str, key: &[u8], value: CLValue, ); fn remove_dictionary(&self, dictionary_name: &str); fn init_dictionary(&self, dictionary_name: &str); 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 emit_native_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) -> OdraResult<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]; fn delegate(&self, validator: PublicKey, amount: U512); fn undelegate(&self, validator: PublicKey, amount: U512); fn delegated_amount(&self, validator: PublicKey) -> U512; fn get_validator_info(&self, validator: PublicKey) -> Option<ValidatorInfo>; fn pseudorandom_bytes(&self) -> [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 get_named_value(&self, name: &str) -> Option<Bytes>

Retrieves the value behind a named key.

§Arguments
  • name - The name of the key.
Source

fn set_named_value(&self, name: &str, value: CLValue)

Sets the value behind a named key.

§Arguments
  • name - The name of the key.
  • value - The value to set.
Source

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

Retrieves the key value behind a named dictionary.

§Arguments
  • dictionary_name - The name of the dictionary.
  • key - The key to retrieve the value for.
Source

fn set_dictionary_value( &self, dictionary_name: &str, key: &[u8], value: CLValue, )

Sets the key value behind a named dictionary.

§Arguments
  • dictionary_name - The name of the dictionary.
  • key - The key to set the value for.
  • value - The value to set.
Source

fn remove_dictionary(&self, dictionary_name: &str)

Removes the named key from the storage.

§Arguments
  • dictionary_name - The name of the dictionary.
Source

fn init_dictionary(&self, dictionary_name: &str)

Initializes the empty dictionary with the given name.

§Arguments
  • dictionary_name - The name of the dictionary to initialize.
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 in milliseconds.

§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 emit_native_event(&self, event: &Bytes)

Emits an event with the specified event data using native mechanism.

§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) -> OdraResult<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.

Source

fn delegate(&self, validator: PublicKey, amount: U512)

Delegate the amount of tokens to the validator

§Arguments
  • validator - The validator to delegate the tokens to.
  • amount - The amount of tokens to delegate.
Source

fn undelegate(&self, validator: PublicKey, amount: U512)

Undelegate the amount of tokens from the validator

§Arguments
  • validator - The validator to undelegate the tokens from.
  • amount - The amount of tokens to undelegate.
Source

fn delegated_amount(&self, validator: PublicKey) -> U512

Gets the amount of tokens delegated to the validator

§Arguments
  • validator - The validator to get the delegated amount from.
§Returns

The amount of tokens delegated to the validator as a U512 value.

Source

fn get_validator_info(&self, validator: PublicKey) -> Option<ValidatorInfo>

Returns information about the validator

§Arguments
  • validator - The validator to query
§Returns

Option

Source

fn pseudorandom_bytes(&self) -> [u8; 32]

Returns a vector of pseudorandom bytes of the specified size. There is no guarantee that the returned bytes are in any way cryptographically secure.

Implementors§