HostEnv

Struct 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 set_captures_events(&self, captures: bool)

Sets the captures_events flag, which determines whether events should be captured.

Source

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

Returns the account address at the specified index.

Source

pub fn get_validator(&self, index: usize) -> PublicKey

Returns the validator public key.

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 in milliseconds.

Source

pub fn advance_with_auctions(&self, time_diff: u64)

Advances the block time by the specified time difference in milliseconds and processes auctions.

Source

pub fn auction_delay(&self) -> u64

Returns the era length in milliseconds.

Source

pub fn unbonding_delay(&self) -> u64

Returns the delay between unstaking and the transfer of funds back to the delegator in milliseconds.

Source

pub fn delegated_amount(&self, delegator: Address, validator: PublicKey) -> U512

Returns the amount of CSPR delegated to the specified validator by the specified delegator.

Source

pub fn remove_validator(&self, index: usize)

Evicts the validator at the specified index from the validator set.

Source

pub fn block_time(&self) -> u64

Returns the current block time in milliseconds.

Source

pub fn block_time_millis(&self) -> u64

Returns the current block time in milliseconds.

Source

pub fn block_time_secs(&self) -> u64

Returns the current block time in seconds.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn contract_env(&self) -> ContractEnv

Returns the gas cost of the last contract call.

Source

pub fn gas_report(&self) -> GasReport

Prints the gas report for the current contract execution.

Source

pub fn balance_of<T: Addressable>(&self, addr: &T) -> U512

Returns the CSPR balance of the specified address.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn event_names<T: Addressable>(&self, addr: &T) -> Vec<String>

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

Source

pub fn events<T: Addressable>(&self, addr: &T) -> Vec<Bytes>

Returns all events emitted by the specified contract.

Source

pub fn events_count<T: Addressable>(&self, addr: &T) -> u32

Returns the number of events emitted by the specified contract.

Source

pub fn native_events_count<T: Addressable>(&self, addr: &T) -> u32

Returns the number of native events emitted by the specified contract.

Source

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.

Source

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.

Source

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.

Source

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.

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.

Source

pub fn transfer(&self, to: Address, amount: U512) -> OdraResult<()>

Transfers the specified amount of CSPR from the current caller to the specified address.

Trait Implementations§

Source§

impl Clone for HostEnv

Source§

fn clone(&self) -> HostEnv

Returns a duplicate 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more