pub trait HostContext {
Show 27 methods
// Required methods
fn set_caller(&self, caller: Address);
fn set_gas(&self, gas: u64);
fn caller(&self) -> Address;
fn get_account(&self, index: usize) -> Address;
fn get_validator(&self, index: usize) -> PublicKey;
fn remove_validator(&self, index: usize);
fn balance_of(&self, address: &Address) -> U512;
fn advance_block_time(&self, time_diff: u64);
fn advance_with_auctions(&self, time_diff: u64);
fn auction_delay(&self) -> u64;
fn unbonding_delay(&self) -> u64;
fn delegated_amount(&self, delegator: Address, validator: PublicKey) -> U512;
fn block_time(&self) -> u64;
fn get_event(
&self,
contract_address: &Address,
index: u32,
) -> Result<Bytes, EventError>;
fn get_native_event(
&self,
contract_address: &Address,
index: u32,
) -> Result<Bytes, EventError>;
fn get_events_count(
&self,
contract_address: &Address,
) -> Result<u32, EventError>;
fn get_native_events_count(
&self,
contract_address: &Address,
) -> Result<u32, EventError>;
fn call_contract(
&self,
address: &Address,
call_def: CallDef,
use_proxy: bool,
) -> OdraResult<Bytes>;
fn new_contract(
&self,
name: &str,
init_args: RuntimeArgs,
entry_points_caller: EntryPointsCaller,
) -> OdraResult<Address>;
fn upgrade_contract(
&self,
name: &str,
contract_to_upgrade: Address,
upgrade_args: RuntimeArgs,
entry_points_caller: EntryPointsCaller,
) -> OdraResult<Address>;
fn register_contract(
&self,
address: Address,
contract_name: String,
entry_points_caller: EntryPointsCaller,
);
fn contract_env(&self) -> ContractEnv;
fn gas_report(&self) -> GasReport;
fn last_call_gas_cost(&self) -> u64;
fn sign_message(&self, message: &Bytes, address: &Address) -> Bytes;
fn public_key(&self, address: &Address) -> PublicKey;
fn transfer(&self, to: Address, amount: U512) -> OdraResult<()>;
}Expand description
The HostContext trait defines the interface for interacting with the host environment.
Required Methods§
Sourcefn set_caller(&self, caller: Address)
fn set_caller(&self, caller: Address)
Sets the caller address for the current contract execution.
Sourcefn get_account(&self, index: usize) -> Address
fn get_account(&self, index: usize) -> Address
Returns the account address at the specified index.
Sourcefn get_validator(&self, index: usize) -> PublicKey
fn get_validator(&self, index: usize) -> PublicKey
Returns the validator public key.
Sourcefn remove_validator(&self, index: usize)
fn remove_validator(&self, index: usize)
The validator at the given index will withdraw all funds and be removed from the validator set.
Sourcefn balance_of(&self, address: &Address) -> U512
fn balance_of(&self, address: &Address) -> U512
Returns the CSPR balance of the specified address.
Sourcefn advance_block_time(&self, time_diff: u64)
fn advance_block_time(&self, time_diff: u64)
Advances the block time by the specified time difference.
Sourcefn advance_with_auctions(&self, time_diff: u64)
fn advance_with_auctions(&self, time_diff: u64)
Advances the block time by the specified time difference and processes auctions.
Sourcefn auction_delay(&self) -> u64
fn auction_delay(&self) -> u64
Time between auctions in milliseconds.
Sourcefn unbonding_delay(&self) -> u64
fn unbonding_delay(&self) -> u64
Time for the funds to be transferred back to the delegator after undelegation in milliseconds.
Sourcefn delegated_amount(&self, delegator: Address, validator: PublicKey) -> U512
fn delegated_amount(&self, delegator: Address, validator: PublicKey) -> U512
Returns the delegated amount for the specified delegator and validator.
Sourcefn block_time(&self) -> u64
fn block_time(&self) -> u64
Returns the current block time.
Sourcefn get_event(
&self,
contract_address: &Address,
index: u32,
) -> Result<Bytes, EventError>
fn get_event( &self, contract_address: &Address, index: u32, ) -> Result<Bytes, EventError>
Returns the event bytes for the specified contract address and index.
Sourcefn get_native_event(
&self,
contract_address: &Address,
index: u32,
) -> Result<Bytes, EventError>
fn get_native_event( &self, contract_address: &Address, index: u32, ) -> Result<Bytes, EventError>
Returns the native event bytes for the specified contract address and index.
Sourcefn get_events_count(
&self,
contract_address: &Address,
) -> Result<u32, EventError>
fn get_events_count( &self, contract_address: &Address, ) -> Result<u32, EventError>
Returns the number of emitted events for the specified contract address.
Sourcefn get_native_events_count(
&self,
contract_address: &Address,
) -> Result<u32, EventError>
fn get_native_events_count( &self, contract_address: &Address, ) -> Result<u32, EventError>
Returns the number of emitted native events for the specified contract address.
Sourcefn call_contract(
&self,
address: &Address,
call_def: CallDef,
use_proxy: bool,
) -> OdraResult<Bytes>
fn 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.
Sourcefn new_contract(
&self,
name: &str,
init_args: RuntimeArgs,
entry_points_caller: EntryPointsCaller,
) -> OdraResult<Address>
fn new_contract( &self, name: &str, init_args: RuntimeArgs, entry_points_caller: EntryPointsCaller, ) -> OdraResult<Address>
Creates a new contract with the specified name, initialization arguments, and entry points caller.
Sourcefn upgrade_contract(
&self,
name: &str,
contract_to_upgrade: Address,
upgrade_args: RuntimeArgs,
entry_points_caller: EntryPointsCaller,
) -> OdraResult<Address>
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.
Sourcefn register_contract(
&self,
address: Address,
contract_name: String,
entry_points_caller: EntryPointsCaller,
)
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.
Sourcefn contract_env(&self) -> ContractEnv
fn contract_env(&self) -> ContractEnv
Returns the contract environment.
Sourcefn gas_report(&self) -> GasReport
fn gas_report(&self) -> GasReport
Returns the gas report for the current contract execution.
Sourcefn last_call_gas_cost(&self) -> u64
fn last_call_gas_cost(&self) -> u64
Returns the gas cost of the last contract call.
Sourcefn sign_message(&self, message: &Bytes, address: &Address) -> Bytes
fn sign_message(&self, message: &Bytes, address: &Address) -> Bytes
Signs the specified message with the given address and returns the signature.
Sourcefn public_key(&self, address: &Address) -> PublicKey
fn public_key(&self, address: &Address) -> PublicKey
Returns the public key associated with the specified address.