Struct odra::host::HostEnv

source ·
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

source

pub fn new(backend: Rc<RefCell<dyn HostContext>>) -> HostEnv

Creates a new HostEnv instance with the specified backend.

source

pub fn get_account(&self, index: usize) -> Address

Returns the account address at the specified index.

source

pub fn set_caller(&self, address: Address)

Sets the caller address for the current contract execution.

source

pub fn advance_block_time(&self, time_diff: u64)

Advances the block time by the specified time difference.

source

pub fn block_time(&self) -> u64

Returns the current block time.

source

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.

source

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.

source

pub fn call_contract<T>( &self, address: Address, call_def: CallDef ) -> Result<T, OdraError>
where T: FromBytes + CLTyped,

Calls a contract at the specified address with the given call definition.

source

pub fn contract_env(&self) -> ContractEnv

Returns the gas cost of the last contract call.

source

pub fn gas_report(&self) -> Vec<DeployReport>

Prints the gas report for the current contract execution.

source

pub fn balance_of(&self, address: &Address) -> U512

Returns the CSPR balance of the specified address.

source

pub fn get_event<T>( &self, contract_address: &Address, 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.

source

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.

source

pub fn event_names(&self, contract_address: &Address) -> Vec<String>

Returns the names of all events emitted by the specified contract.

source

pub fn events(&self, contract_address: &Address) -> Vec<Bytes>

Returns all events emitted by the specified contract.

source

pub fn events_count(&self, contract_address: &Address) -> u32

Returns the number of events emitted by the specified contract.

source

pub fn emitted_event<T>(&self, contract_address: &Address, event: &T) -> bool

Returns true if the specified event was emitted by the specified contract.

source

pub fn emitted<T>(&self, contract_address: &Address, event_name: T) -> bool
where T: AsRef<str>,

Returns true if an event with the specified name was emitted by the specified contract.

source

pub fn last_call_result(&self, contract_address: Address) -> ContractCallResult

Returns the last call result for the specified contract.

source

pub fn sign_message(&self, message: &Bytes, address: &Address) -> Bytes

Signs the specified message with the private key of the specified address.

source

pub fn public_key(&self, address: &Address) -> PublicKey

Returns the public key associated with the specified address.

source

pub fn caller(&self) -> Address

Returns the caller address for the current contract execution.

source

pub fn set_gas(&self, gas: u64)

Sets the gas limit for the current contract execution.

Trait Implementations§

source§

impl Clone for HostEnv

source§

fn clone(&self) -> HostEnv

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.