pub struct Env { /* private fields */ }
Expand description

The Env type provides access to the environment the contract is executing within.

The Env provides access to information about the currently executing contract, who invoked it, contract data, functions for signing, hashing, etc.

Most types require access to an Env to be constructed or converted.

Implementations

Invokes a function of a contract that is registered in the Env.

Panics

Will panic if the contract_id does not match a registered contract, func does not match a function of the referenced contract, or the number of args do not match the argument count of the referenced contract function.

Will also panic if the value returned from the contract cannot be converted into the type T.

TODO

Return a Result instead of panic.

Get a ContractData for accessing and update contract data that has been stored by the currently executing contract.

Get a Ledger for accessing the current ledger.

Get Events for publishing events associated with the currently executing contract.

Get a deployer for deploying contracts.

Get the 32-byte hash identifier of the current executing contract.

Get the 32-byte hash identifier of the contract that invoked this contract.

Panics

Will panic the contract was not invoked by another contract.

Computes a SHA-256 hash.

Verifies an ed25519 signature.

The ed25519 siganture (sig) is verified as a valid signature of the message (msg) by the ed25519 public key (pk).

Panics

Will panic if the siganture verification fails.

TODO

Return a Result instead of panicking.

Available on crate feature testutils only.

Sets ledger information in the Env, which will be accessible via Env::ledger.

Available on crate feature testutils only.

Register a contract with the Env for testing.

Examples
use soroban_sdk::{contractimpl, BytesN, Env, Symbol};

pub struct HelloContract;

#[contractimpl]
impl HelloContract {
    pub fn hello(env: Env, recipient: soroban_sdk::Symbol) -> soroban_sdk::Symbol {
        todo!()
    }
}

let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, HelloContract);
Available on crate feature testutils only.

Register a contract in a WASM file with the Env for testing.

Examples
use soroban_sdk::{BytesN, Env};

const WASM: &[u8] = include_bytes!("../doctest_fixtures/contract.wasm");

let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract_wasm(&contract_id, WASM);
Available on crate feature testutils only.

Register the built-in token contract with the Env for testing.

Examples
use soroban_sdk::{BytesN, Env};

let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract_token(&contract_id);
Available on crate feature testutils only.
Available on crate feature testutils only.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.