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 set_captures_events(&self, captures: bool)
pub fn set_captures_events(&self, captures: bool)
Sets the captures_events flag, which determines whether events should be captured.
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 get_validator(&self, index: usize) -> PublicKey
pub fn get_validator(&self, index: usize) -> PublicKey
Returns the validator public key.
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 in milliseconds.
Sourcepub fn advance_with_auctions(&self, time_diff: u64)
pub fn advance_with_auctions(&self, time_diff: u64)
Advances the block time by the specified time difference in milliseconds and processes auctions.
Sourcepub fn auction_delay(&self) -> u64
pub fn auction_delay(&self) -> u64
Returns the era length in milliseconds.
Sourcepub fn unbonding_delay(&self) -> u64
pub fn unbonding_delay(&self) -> u64
Returns the delay between unstaking and the transfer of funds back to the delegator in milliseconds.
Sourcepub fn delegated_amount(&self, delegator: Address, validator: PublicKey) -> U512
pub fn delegated_amount(&self, delegator: Address, validator: PublicKey) -> U512
Returns the amount of CSPR delegated to the specified validator by the specified delegator.
Sourcepub fn remove_validator(&self, index: usize)
pub fn remove_validator(&self, index: usize)
Evicts the validator at the specified index from the validator set.
Sourcepub fn block_time(&self) -> u64
pub fn block_time(&self) -> u64
Returns the current block time in milliseconds.
Sourcepub fn block_time_millis(&self) -> u64
pub fn block_time_millis(&self) -> u64
Returns the current block time in milliseconds.
Sourcepub fn block_time_secs(&self) -> u64
pub fn block_time_secs(&self) -> u64
Returns the current block time in seconds.
Sourcepub fn new_contract(
&self,
name: &str,
init_args: RuntimeArgs,
entry_points_caller: EntryPointsCaller,
) -> OdraResult<Address>
pub fn new_contract( &self, name: &str, init_args: RuntimeArgs, entry_points_caller: EntryPointsCaller, ) -> OdraResult<Address>
Registers a new contract with the specified name, initialization arguments, and entry points caller.
Sourcepub fn upgrade_contract(
&self,
name: &str,
contract_to_upgrade: Address,
upgrade_args: RuntimeArgs,
entry_points_caller: EntryPointsCaller,
) -> OdraResult<Address>
pub fn upgrade_contract( &self, name: &str, contract_to_upgrade: Address, upgrade_args: RuntimeArgs, entry_points_caller: EntryPointsCaller, ) -> OdraResult<Address>
Upgrades an existing contract with a new one with given upgrade arguments and new entry points caller.
Sourcepub fn register_contract(
&self,
address: Address,
contract_name: String,
entry_points_caller: EntryPointsCaller,
)
pub fn register_contract( &self, address: Address, contract_name: String, entry_points_caller: EntryPointsCaller, )
Registers an existing contract with the specified address, name and entry points caller.
Similar to new_contract, but skips the deployment phase.
Sourcepub fn call_contract<T: FromBytes + CLTyped>(
&self,
address: Address,
call_def: CallDef,
) -> OdraResult<T>
pub fn call_contract<T: FromBytes + CLTyped>( &self, address: Address, call_def: CallDef, ) -> OdraResult<T>
Calls a contract at the specified address with the given call definition.
Sourcepub fn raw_call_contract(
&self,
address: Address,
call_def: CallDef,
use_proxy: bool,
) -> OdraResult<Bytes>
pub fn raw_call_contract( &self, address: Address, call_def: CallDef, use_proxy: bool, ) -> OdraResult<Bytes>
Calls a contract at the specified address with the given call definition. Returns raw, not serialized bytes.
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) -> GasReport
pub fn gas_report(&self) -> GasReport
Prints the gas report for the current contract execution.
Sourcepub fn balance_of<T: Addressable>(&self, addr: &T) -> U512
pub fn balance_of<T: Addressable>(&self, addr: &T) -> U512
Returns the CSPR balance of the specified address.
Sourcepub fn get_event<T: FromBytes + EventInstance, R: Addressable>(
&self,
addr: &R,
index: i32,
) -> Result<T, EventError>
pub fn get_event<T: FromBytes + EventInstance, R: Addressable>( &self, addr: &R, index: i32, ) -> Result<T, EventError>
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_native_event<T: FromBytes + EventInstance, R: Addressable>(
&self,
addr: &R,
index: i32,
) -> Result<T, EventError>
pub fn get_native_event<T: FromBytes + EventInstance, R: Addressable>( &self, addr: &R, index: i32, ) -> Result<T, EventError>
Retrieves a native 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<T: Addressable>(
&self,
addr: &T,
index: u32,
) -> Result<Bytes, EventError>
pub fn get_event_bytes<T: Addressable>( &self, addr: &T, index: u32, ) -> Result<Bytes, EventError>
Retrieves a raw event (serialized) with the specified index from the specified contract.
Sourcepub fn get_native_event_bytes<T: Addressable>(
&self,
addr: &T,
index: u32,
) -> Result<Bytes, EventError>
pub fn get_native_event_bytes<T: Addressable>( &self, addr: &T, index: u32, ) -> Result<Bytes, EventError>
Retrieves a raw native event (serialized) with the specified index from the specified contract.
Sourcepub fn event_names<T: Addressable>(&self, addr: &T) -> Vec<String>
pub fn event_names<T: Addressable>(&self, addr: &T) -> Vec<String>
Returns the names of all events emitted by the specified contract.
Sourcepub fn events<T: Addressable>(&self, addr: &T) -> Vec<Bytes>
pub fn events<T: Addressable>(&self, addr: &T) -> Vec<Bytes>
Returns all events emitted by the specified contract.
Sourcepub fn events_count<T: Addressable>(&self, addr: &T) -> u32
pub fn events_count<T: Addressable>(&self, addr: &T) -> u32
Returns the number of events emitted by the specified contract.
Sourcepub fn native_events_count<T: Addressable>(&self, addr: &T) -> u32
pub fn native_events_count<T: Addressable>(&self, addr: &T) -> u32
Returns the number of native events emitted by the specified contract.
Sourcepub fn emitted_event<T: ToBytes + EventInstance, R: Addressable>(
&self,
addr: &R,
event: T,
) -> bool
pub fn emitted_event<T: ToBytes + EventInstance, R: Addressable>( &self, addr: &R, event: T, ) -> bool
Returns true if the specified event was emitted by the specified contract.
Sourcepub fn emitted_native_event<T: ToBytes + EventInstance, R: Addressable>(
&self,
addr: &R,
event: T,
) -> bool
pub fn emitted_native_event<T: ToBytes + EventInstance, R: Addressable>( &self, addr: &R, event: T, ) -> bool
Returns true if the specified event was emitted by the specified contract.
Sourcepub fn emitted<T: AsRef<str>, R: Addressable>(
&self,
addr: &R,
event_name: T,
) -> bool
pub fn emitted<T: AsRef<str>, R: Addressable>( &self, addr: &R, event_name: T, ) -> bool
Returns true if an event with the specified name was emitted by the specified contract.
Sourcepub fn emitted_native<T: AsRef<str>, R: Addressable>(
&self,
addr: &R,
event_name: T,
) -> bool
pub fn emitted_native<T: AsRef<str>, R: Addressable>( &self, addr: &R, event_name: T, ) -> bool
Returns true if a native 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 Freeze for HostEnv
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more