pub struct HostEnv { /* private fields */ }
Expand description
Represents the host environment for executing smart contracts.
It provides methods for interacting with the underlying host context and managing the execution of contracts.
Implementations§
source§impl HostEnv
impl HostEnv
sourcepub fn new(backend: Rc<RefCell<dyn HostContext>>) -> HostEnv
pub fn new(backend: Rc<RefCell<dyn HostContext>>) -> HostEnv
Creates a new HostEnv
instance with the specified backend.
sourcepub fn get_account(&self, index: usize) -> Address
pub fn get_account(&self, index: usize) -> Address
Returns the account address at the specified index.
sourcepub fn set_caller(&self, address: Address)
pub fn set_caller(&self, address: Address)
Sets the caller address for the current contract execution.
sourcepub fn advance_block_time(&self, time_diff: u64)
pub fn advance_block_time(&self, time_diff: u64)
Advances the block time by the specified time difference.
sourcepub fn block_time(&self) -> u64
pub fn block_time(&self) -> u64
Returns the current block time.
sourcepub fn new_contract(
&self,
name: &str,
init_args: RuntimeArgs,
entry_points_caller: EntryPointsCaller
) -> Result<Address, OdraError>
pub fn new_contract( &self, name: &str, init_args: RuntimeArgs, entry_points_caller: EntryPointsCaller ) -> Result<Address, OdraError>
Registers a new contract with the specified name, initialization arguments, and entry points caller.
sourcepub fn register_contract(
&self,
address: Address,
entry_points_caller: EntryPointsCaller
)
pub fn register_contract( &self, address: Address, entry_points_caller: EntryPointsCaller )
Registers an existing contract with the specified address and entry points caller.
Similar to new_contract
, but skips the deployment phase.
sourcepub fn call_contract<T>(
&self,
address: Address,
call_def: CallDef
) -> Result<T, OdraError>
pub fn call_contract<T>( &self, address: Address, call_def: CallDef ) -> Result<T, OdraError>
Calls a contract at the specified address with the given call definition.
sourcepub fn contract_env(&self) -> ContractEnv
pub fn contract_env(&self) -> ContractEnv
Returns the gas cost of the last contract call.
sourcepub fn gas_report(&self) -> Vec<DeployReport>
pub fn gas_report(&self) -> Vec<DeployReport>
Prints the gas report for the current contract execution.
sourcepub fn balance_of(&self, address: &Address) -> U512
pub fn balance_of(&self, address: &Address) -> U512
Returns the CSPR balance of the specified address.
sourcepub fn get_event<T>(
&self,
contract_address: &Address,
index: i32
) -> Result<T, EventError>where
T: FromBytes + EventInstance,
pub fn get_event<T>(
&self,
contract_address: &Address,
index: i32
) -> Result<T, EventError>where
T: FromBytes + EventInstance,
Retrieves an event with the specified index from the specified contract.
§Returns
Returns the event as an instance of the specified type, or an error if the event couldn’t be retrieved or parsed.
sourcepub fn get_event_bytes(
&self,
contract_address: &Address,
index: u32
) -> Result<Bytes, EventError>
pub fn get_event_bytes( &self, contract_address: &Address, index: u32 ) -> Result<Bytes, EventError>
Retrieves a raw event (serialized) with the specified index from the specified contract.
sourcepub fn event_names(&self, contract_address: &Address) -> Vec<String>
pub fn event_names(&self, contract_address: &Address) -> Vec<String>
Returns the names of all events emitted by the specified contract.
sourcepub fn events(&self, contract_address: &Address) -> Vec<Bytes>
pub fn events(&self, contract_address: &Address) -> Vec<Bytes>
Returns all events emitted by the specified contract.
sourcepub fn events_count(&self, contract_address: &Address) -> u32
pub fn events_count(&self, contract_address: &Address) -> u32
Returns the number of events emitted by the specified contract.
sourcepub fn emitted_event<T>(&self, contract_address: &Address, event: &T) -> boolwhere
T: ToBytes + EventInstance,
pub fn emitted_event<T>(&self, contract_address: &Address, event: &T) -> boolwhere
T: ToBytes + EventInstance,
Returns true if the specified event was emitted by the specified contract.
sourcepub fn emitted<T>(&self, contract_address: &Address, event_name: T) -> bool
pub fn emitted<T>(&self, contract_address: &Address, event_name: T) -> bool
Returns true if an event with the specified name was emitted by the specified contract.
sourcepub fn last_call_result(&self, contract_address: Address) -> ContractCallResult
pub fn last_call_result(&self, contract_address: Address) -> ContractCallResult
Returns the last call result for the specified contract.
sourcepub fn sign_message(&self, message: &Bytes, address: &Address) -> Bytes
pub fn sign_message(&self, message: &Bytes, address: &Address) -> Bytes
Signs the specified message with the private key of the specified address.
sourcepub fn public_key(&self, address: &Address) -> PublicKey
pub fn public_key(&self, address: &Address) -> PublicKey
Returns the public key associated with the specified address.