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§
sourcefn set_value(&self, key: &[u8], value: Bytes)
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.
sourcefn self_address(&self) -> Address
fn self_address(&self) -> Address
Retrieves the address of the current contract.
sourcefn call_contract(&self, address: Address, call_def: CallDef) -> Bytes
fn call_contract(&self, address: Address, call_def: CallDef) -> Bytes
sourcefn get_block_time(&self) -> u64
fn get_block_time(&self) -> u64
sourcefn attached_value(&self) -> U512
fn attached_value(&self) -> U512
sourcefn self_balance(&self) -> U512
fn self_balance(&self) -> U512
sourcefn emit_event(&self, event: &Bytes)
fn emit_event(&self, event: &Bytes)
sourcefn transfer_tokens(&self, to: &Address, amount: &U512)
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.
sourcefn get_named_arg_bytes(&self, name: &str) -> Bytes
fn get_named_arg_bytes(&self, name: &str) -> Bytes
sourcefn get_opt_named_arg_bytes(&self, name: &str) -> Option<Bytes>
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.
sourcefn handle_attached_value(&self)
fn handle_attached_value(&self)
Handles the value attached to the call. Sets the value in the contract context.
sourcefn clear_attached_value(&self)
fn clear_attached_value(&self)
Clears the value attached to the call.