Struct odra::ContractEnv
source · pub struct ContractEnv { /* private fields */ }
Expand description
Represents the environment accessible in the contract context.
The ContractEnv
struct provides methods for interacting with the contract environment,
such as accessing storage, calling other contracts, and handling various contract-related operations.
The ContractEnv
is available for the user to use in the module code.
Implementations§
source§impl ContractEnv
impl ContractEnv
sourcepub const fn new(
index: u32,
backend: Rc<RefCell<dyn ContractContext>>,
) -> ContractEnv
pub const fn new( index: u32, backend: Rc<RefCell<dyn ContractContext>>, ) -> ContractEnv
Creates a new ContractEnv instance.
sourcepub fn get_value<T>(&self, key: &[u8]) -> Option<T>where
T: FromBytes,
pub fn get_value<T>(&self, key: &[u8]) -> Option<T>where
T: FromBytes,
Retrieves the value associated with the given key from the contract storage.
§Returns
The value associated with the key, if it exists.
sourcepub fn set_value<T>(&self, key: &[u8], value: T)
pub fn set_value<T>(&self, key: &[u8], value: T)
Sets the value associated with the given key in the contract storage.
sourcepub fn get_named_value<T, U>(&self, name: U) -> Option<T>
pub fn get_named_value<T, U>(&self, name: U) -> Option<T>
Retrieves the value associated with the given named key from the contract storage.
sourcepub fn set_named_value<T, U>(&self, name: U, value: T)
pub fn set_named_value<T, U>(&self, name: U, value: T)
Sets the value associated with the given named key in the contract storage.
sourcepub fn get_dictionary_value<T, U>(
&self,
dictionary_name: U,
key: &[u8],
) -> Option<T>
pub fn get_dictionary_value<T, U>( &self, dictionary_name: U, key: &[u8], ) -> Option<T>
Retrieves the value associated with the given named key from the named dictionary in the contract storage.
sourcepub fn set_dictionary_value<T, U>(
&self,
dictionary_name: U,
key: &[u8],
value: T,
)
pub fn set_dictionary_value<T, U>( &self, dictionary_name: U, key: &[u8], value: T, )
Sets the value associated with the given named key in the named dictionary in the contract storage.
sourcepub fn remove_dictionary<U>(&self, dictionary_name: U)
pub fn remove_dictionary<U>(&self, dictionary_name: U)
Removes the dictionary from the contract storage.
sourcepub fn call_contract<T>(&self, address: Address, call: CallDef) -> Twhere
T: FromBytes,
pub fn call_contract<T>(&self, address: Address, call: CallDef) -> Twhere
T: FromBytes,
Calls another contract with the specified address and call definition.
§Returns
The result of the contract call. If any error occurs during the call, the contract will revert.
sourcepub fn self_address(&self) -> Address
pub fn self_address(&self) -> Address
Returns the address of the current contract.
sourcepub fn transfer_tokens(&self, to: &Address, amount: &U512)
pub fn transfer_tokens(&self, to: &Address, amount: &U512)
Transfers tokens to the specified address.
sourcepub fn get_block_time(&self) -> u64
pub fn get_block_time(&self) -> u64
Returns the current block time as u64 value.
sourcepub fn attached_value(&self) -> U512
pub fn attached_value(&self) -> U512
Returns the value attached to the contract call.
sourcepub fn self_balance(&self) -> U512
pub fn self_balance(&self) -> U512
Returns the CSPR balance of the current contract.
sourcepub fn revert<E>(&self, error: E) -> !
pub fn revert<E>(&self, error: E) -> !
Reverts the contract execution with the specified error.
sourcepub fn emit_event<T>(&self, event: T)where
T: ToBytes,
pub fn emit_event<T>(&self, event: T)where
T: ToBytes,
Emits an event with the specified data.
Trait Implementations§
source§impl Clone for ContractEnv
impl Clone for ContractEnv
source§fn clone(&self) -> ContractEnv
fn clone(&self) -> ContractEnv
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more