Struct odra::ContractEnv
source · pub struct ContractEnv { /* private fields */ }
Expand description
Represents the environment accessible in the contract context.
The ContractEnv
struct provides methods for interacting with the contract environment,
such as accessing storage, calling other contracts, and handling various contract-related operations.
The ContractEnv
is available for the user to use in the module code.
Implementations§
source§impl ContractEnv
impl ContractEnv
sourcepub const fn new(
index: u32,
backend: Rc<RefCell<dyn ContractContext>>
) -> ContractEnv
pub const fn new( index: u32, backend: Rc<RefCell<dyn ContractContext>> ) -> ContractEnv
Creates a new ContractEnv instance.
sourcepub fn get_value<T>(&self, key: &[u8]) -> Option<T>where
T: FromBytes,
pub fn get_value<T>(&self, key: &[u8]) -> Option<T>where
T: FromBytes,
Retrieves the value associated with the given key from the contract storage.
§Returns
The value associated with the key, if it exists.
sourcepub fn set_value<T>(&self, key: &[u8], value: T)
pub fn set_value<T>(&self, key: &[u8], value: T)
Sets the value associated with the given key in the contract storage.
sourcepub fn call_contract<T>(&self, address: Address, call: CallDef) -> Twhere
T: FromBytes,
pub fn call_contract<T>(&self, address: Address, call: CallDef) -> Twhere
T: FromBytes,
Calls another contract with the specified address and call definition.
§Returns
The result of the contract call. If any error occurs during the call, the contract will revert.
sourcepub fn self_address(&self) -> Address
pub fn self_address(&self) -> Address
Returns the address of the current contract.
sourcepub fn transfer_tokens(&self, to: &Address, amount: &U512)
pub fn transfer_tokens(&self, to: &Address, amount: &U512)
Transfers tokens to the specified address.
sourcepub fn get_block_time(&self) -> u64
pub fn get_block_time(&self) -> u64
Returns the current block time as u64 value.
sourcepub fn attached_value(&self) -> U512
pub fn attached_value(&self) -> U512
Returns the value attached to the contract call.
sourcepub fn self_balance(&self) -> U512
pub fn self_balance(&self) -> U512
Returns the CSPR balance of the current contract.
sourcepub fn revert<E>(&self, error: E) -> !
pub fn revert<E>(&self, error: E) -> !
Reverts the contract execution with the specified error.
sourcepub fn emit_event<T>(&self, event: T)where
T: ToBytes,
pub fn emit_event<T>(&self, event: T)where
T: ToBytes,
Emits an event with the specified data.
Trait Implementations§
source§impl Clone for ContractEnv
impl Clone for ContractEnv
source§fn clone(&self) -> ContractEnv
fn clone(&self) -> ContractEnv
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for ContractEnv
impl !RefUnwindSafe for ContractEnv
impl !Send for ContractEnv
impl !Sync for ContractEnv
impl Unpin for ContractEnv
impl !UnwindSafe for ContractEnv
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
source§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
source§impl<T> PipeDeref for T
impl<T> PipeDeref for T
source§impl<T> PipeRef for T
impl<T> PipeRef for T
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_dbg<F, R>(self, func: F) -> Self
fn tap_dbg<F, R>(self, func: F) -> Self
tap
in debug builds, and does nothing in release builds.source§fn tap_mut_dbg<F, R>(self, func: F) -> Self
fn tap_mut_dbg<F, R>(self, func: F) -> Self
tap_mut
in debug builds, and does nothing in release builds.source§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
source§fn tap_ref<F, R>(self, func: F) -> Self
fn tap_ref<F, R>(self, func: F) -> Self
source§fn tap_ref_dbg<F, R>(self, func: F) -> Self
fn tap_ref_dbg<F, R>(self, func: F) -> Self
tap_ref
in debug builds, and does nothing in release builds.source§fn tap_ref_mut<F, R>(self, func: F) -> Self
fn tap_ref_mut<F, R>(self, func: F) -> Self
source§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
source§fn tap_borrow<F, R>(self, func: F) -> Self
fn tap_borrow<F, R>(self, func: F) -> Self
source§fn tap_borrow_dbg<F, R>(self, func: F) -> Self
fn tap_borrow_dbg<F, R>(self, func: F) -> Self
tap_borrow
in debug builds, and does nothing in release builds.source§fn tap_borrow_mut<F, R>(self, func: F) -> Self
fn tap_borrow_mut<F, R>(self, func: F) -> Self
source§impl<T> TapDeref for T
impl<T> TapDeref for T
source§fn tap_deref_dbg<F, R>(self, func: F) -> Self
fn tap_deref_dbg<F, R>(self, func: F) -> Self
tap_deref
in debug builds, and does nothing in release builds.source§fn tap_deref_mut<F, R>(self, func: F) -> Self
fn tap_deref_mut<F, R>(self, func: F) -> Self
self
for modification.