Struct soroban_sdk::Env
source · [−]pub struct Env { /* private fields */ }
Expand description
Implementations
sourceimpl Env
impl Env
sourcepub fn invoke_contract<T: TryFromVal<Env, RawVal>>(
&self,
contract_id: &FixedBinary<32>,
func: &Symbol,
args: Vec<EnvVal>
) -> T
pub fn invoke_contract<T: TryFromVal<Env, RawVal>>(
&self,
contract_id: &FixedBinary<32>,
func: &Symbol,
args: Vec<EnvVal>
) -> T
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.
sourcepub fn contract_data(&self) -> ContractData
pub fn contract_data(&self) -> ContractData
Get a ContractData for accessing and update contract data that has been stored by the currently executing contract.
sourcepub fn get_current_contract(&self) -> FixedBinary<32>
pub fn get_current_contract(&self) -> FixedBinary<32>
Get the 32-byte hash identifier of the current executing contract.
sourcepub fn get_invoking_contract(&self) -> FixedBinary<32>
pub fn get_invoking_contract(&self) -> FixedBinary<32>
Get the 32-byte hash identifier of the contract that invoked this contract.
Panics
Will panic the contract was not invoked by another contract.
sourcepub fn compute_hash_sha256(&self, msg: Binary) -> FixedBinary<32>
pub fn compute_hash_sha256(&self, msg: Binary) -> FixedBinary<32>
Computes a SHA-256 hash.
sourcepub fn verify_sig_ed25519(
&self,
pk: FixedBinary<32>,
msg: Binary,
sig: FixedBinary<64>
)
pub fn verify_sig_ed25519(
&self,
pk: FixedBinary<32>,
msg: Binary,
sig: FixedBinary<64>
)
sourceimpl Env
impl Env
sourcepub fn register_contract<T: ContractFunctionSet + 'static>(
&self,
contract_id: &FixedBinary<32>,
contract: T
)
Available on crate feature testutils
only.
pub fn register_contract<T: ContractFunctionSet + 'static>(
&self,
contract_id: &FixedBinary<32>,
contract: T
)
testutils
only.Register a contract with the Env for testing.
Examples
use soroban_sdk::{contractimpl, FixedBinary, 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 = FixedBinary::from_array(&env, [0; 32]);
env.register_contract(&contract_id, HelloContract);
pub fn assert_panic_with_string<F, T: Debug>(&self, s: &str, f: F) where
F: FnOnce(Env) -> T,
testutils
only.pub fn assert_panic_with_status<F, T: Debug>(&self, status: Status, f: F) where
F: FnOnce(Env) -> T,
testutils
only.Trait Implementations
sourceimpl<const N: usize> IntoVal<Env, FixedBinary<N>> for [u8; N]
impl<const N: usize> IntoVal<Env, FixedBinary<N>> for [u8; N]
fn into_val(self, env: &Env) -> FixedBinary<N>
fn into_env_val(self, env: &E) -> EnvVal<E, V>
sourceimpl TryIntoVal<Env, BigInt> for RawVal
impl TryIntoVal<Env, BigInt> for RawVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<BigInt, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl TryIntoVal<Env, BigInt> for ScVal
impl TryIntoVal<Env, BigInt> for ScVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<BigInt, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl TryIntoVal<Env, Binary> for RawVal
impl TryIntoVal<Env, Binary> for RawVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Binary, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl TryIntoVal<Env, Binary> for ScVal
impl TryIntoVal<Env, Binary> for ScVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Binary, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<const N: usize> TryIntoVal<Env, FixedBinary<N>> for RawVal
impl<const N: usize> TryIntoVal<Env, FixedBinary<N>> for RawVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<FixedBinary<N>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<const N: usize> TryIntoVal<Env, FixedBinary<N>> for ScVal
impl<const N: usize> TryIntoVal<Env, FixedBinary<N>> for ScVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<FixedBinary<N>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<K, V> TryIntoVal<Env, Map<K, V>> for RawVal where
K: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
V: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<K, V> TryIntoVal<Env, Map<K, V>> for RawVal where
K: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
V: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Map<K, V>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<K, V> TryIntoVal<Env, Map<K, V>> for ScVal where
K: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
V: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<K, V> TryIntoVal<Env, Map<K, V>> for ScVal where
K: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
V: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Map<K, V>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<T> TryIntoVal<Env, Vec<T>> for RawVal where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> TryIntoVal<Env, Vec<T>> for RawVal where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Vec<T>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<T> TryIntoVal<Env, Vec<T>> for ScVal where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> TryIntoVal<Env, Vec<T>> for ScVal where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Vec<T>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
Auto Trait Implementations
impl !RefUnwindSafe for Env
impl !Send for Env
impl !Sync for Env
impl Unpin for Env
impl !UnwindSafe for Env
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more