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 new_contract(
&self,
name: &str,
init_args: RuntimeArgs,
entry_points_caller: EntryPointsCaller
) -> Address
pub fn new_contract( &self, name: &str, init_args: RuntimeArgs, entry_points_caller: EntryPointsCaller ) -> Address
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 print_gas_report(&self)
pub fn print_gas_report(&self)
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.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for HostEnv
impl !Send for HostEnv
impl !Sync for HostEnv
impl Unpin for HostEnv
impl !UnwindSafe for HostEnv
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§impl<T> Pipe for T
impl<T> Pipe for T
§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
§impl<T> PipeDeref for T
impl<T> PipeDeref for T
§impl<T> PipeRef for T
impl<T> PipeRef for T
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
§fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_dbg<F, R>(self, func: F) -> Self
fn tap_dbg<F, R>(self, func: F) -> Self
tap
in debug builds, and does nothing in release builds.§fn tap_mut_dbg<F, R>(self, func: F) -> Self
fn tap_mut_dbg<F, R>(self, func: F) -> Self
tap_mut
in debug builds, and does nothing in release builds.§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
§fn tap_ref_dbg<F, R>(self, func: F) -> Self
fn tap_ref_dbg<F, R>(self, func: F) -> Self
tap_ref
in debug builds, and does nothing in release builds.§fn tap_ref_mut<F, R>(self, func: F) -> Self
fn tap_ref_mut<F, R>(self, func: F) -> Self
§fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self
tap_ref_mut
in debug builds, and does nothing in release builds.§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
§fn tap_borrow<F, R>(self, func: F) -> Self
fn tap_borrow<F, R>(self, func: F) -> Self
§fn tap_borrow_dbg<F, R>(self, func: F) -> Self
fn tap_borrow_dbg<F, R>(self, func: F) -> Self
tap_borrow
in debug builds, and does nothing in release builds.§fn tap_borrow_mut<F, R>(self, func: F) -> Self
fn tap_borrow_mut<F, R>(self, func: F) -> Self
§fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self
tap_borrow_mut
in debug builds, and does nothing in release
builds.§impl<T> TapDeref for T
impl<T> TapDeref for T
§fn tap_deref_dbg<F, R>(self, func: F) -> Self
fn tap_deref_dbg<F, R>(self, func: F) -> Self
tap_deref
in debug builds, and does nothing in release builds.§fn tap_deref_mut<F, R>(self, func: F) -> Self
fn tap_deref_mut<F, R>(self, func: F) -> Self
self
for modification.§fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self
tap_deref_mut
in debug builds, and does nothing in release
builds.