pub struct RuntimeContext<'a, R> { /* private fields */ }
Expand description

Holds information specific to the deployed contract.

Implementations§

source§

impl<'a, R> RuntimeContext<'a, R>

source

pub fn new( tracking_copy: Rc<RefCell<TrackingCopy<R>>>, entry_point_type: EntryPointType, named_keys: &'a mut NamedKeys, access_rights: ContextAccessRights, runtime_args: RuntimeArgs, authorization_keys: BTreeSet<AccountHash>, account: &'a Account, base_key: Key, blocktime: BlockTime, deploy_hash: DeployHash, gas_limit: Gas, gas_counter: Gas, address_generator: Rc<RefCell<AddressGenerator>>, protocol_version: ProtocolVersion, correlation_id: CorrelationId, phase: Phase, engine_config: EngineConfig, transfers: Vec<TransferAddr>, remaining_spending_limit: U512 ) -> Self

Creates new runtime context where we don’t already have one.

Where we already have a runtime context, consider using new_from_self().

source

pub fn new_from_self( &self, base_key: Key, entry_point_type: EntryPointType, named_keys: &'a mut NamedKeys, access_rights: ContextAccessRights, runtime_args: RuntimeArgs ) -> Self

Creates new runtime context cloning values from self.

source

pub fn authorization_keys(&self) -> &BTreeSet<AccountHash>

Returns all authorization keys for this deploy.

source

pub fn named_keys_get(&self, name: &str) -> Option<&Key>

Returns a named key by a name if it exists.

source

pub fn named_keys(&self) -> &NamedKeys

Returns named keys.

source

pub fn named_keys_mut(&mut self) -> &mut NamedKeys

Returns a mutable reference to named keys.

source

pub fn named_keys_contains_key(&self, name: &str) -> bool

Checks if named keys contains a key referenced by name.

source

pub fn remove_key(&mut self, name: &str) -> Result<(), Error>

Remove Key from the named_keys map of the current context. It removes both from the ephemeral map (RuntimeContext::named_keys) but also persistable map (one that is found in the TrackingCopy/GlobalState).

source

pub fn get_caller(&self) -> AccountHash

Returns the caller of the contract.

source

pub fn get_blocktime(&self) -> BlockTime

Returns the block time.

source

pub fn get_deploy_hash(&self) -> DeployHash

Returns the deploy hash.

source

pub fn access_rights_extend(&mut self, urefs: &[URef])

Extends access rights with a new map.

source

pub fn access_rights(&self) -> &ContextAccessRights

Returns a mapping of access rights for each URefs address.

source

pub fn account(&self) -> &'a Account

Returns account of the caller.

source

pub fn args(&self) -> &RuntimeArgs

Returns arguments.

source

pub fn address_generator(&self) -> Rc<RefCell<AddressGenerator>>

Returns new shared instance of an address generator.

source

pub fn gas_limit(&self) -> Gas

Returns the gas limit.

source

pub fn gas_counter(&self) -> Gas

Returns the current gas counter.

source

pub fn set_gas_counter(&mut self, new_gas_counter: Gas)

Sets the gas counter to a new value.

source

pub fn base_key(&self) -> Key

Returns the base key.

This could be either a Key::Account or a Key::Hash depending on the entry point type.

source

pub fn protocol_version(&self) -> ProtocolVersion

Returns the protocol version.

source

pub fn correlation_id(&self) -> CorrelationId

Returns the correlation id.

source

pub fn phase(&self) -> Phase

Returns the current phase.

source

pub fn new_hash_address(&mut self) -> Result<[u8; 32], Error>

Generates new deterministic hash for uses as an address.

source

pub fn random_bytes(&mut self) -> Result<[u8; 32], Error>

Returns 32 pseudo random bytes.

source

pub fn new_uref(&mut self, value: StoredValue) -> Result<URef, Error>

Creates new URef instance.

source

pub fn new_transfer_addr(&mut self) -> Result<TransferAddr, Error>

Creates a new transfer address using a transfer address generator.

source

pub fn put_key(&mut self, name: String, key: Key) -> Result<(), Error>

Puts key to the map of named keys of current context.

source

pub fn read_gs(&mut self, key: &Key) -> Result<Option<StoredValue>, Error>

Read a stored value under a Key.

source

pub fn read_gs_direct( &mut self, key: &Key ) -> Result<Option<StoredValue>, Error>

Reads a value from a global state directly.

Usage

DO NOT EXPOSE THIS VIA THE FFI - This function bypasses security checks and should be used with caution.

source

pub fn read_gs_typed<T>(&mut self, key: &Key) -> Result<T, Error>
where T: TryFrom<StoredValue>, T::Error: Debug,

This method is a wrapper over read_gs in the sense that it extracts the type held by a StoredValue stored in the global state in a type safe manner.

This is useful if you want to get the exact type from global state.

source

pub fn get_keys(&mut self, key_tag: &KeyTag) -> Result<BTreeSet<Key>, Error>

Returns all keys based on the tag prefix.

source

pub fn read_account(&mut self, key: &Key) -> Result<Option<StoredValue>, Error>

Read an account from the global state.

source

pub fn write_account(&mut self, key: Key, account: Account) -> Result<(), Error>

Write an account to the global state.

source

pub fn write_transfer(&mut self, key: Key, value: Transfer)

Write a transfer instance to the global state.

source

pub fn write_era_info(&mut self, key: Key, value: EraInfo)

Write an era info instance to the global state.

source

pub fn grant_access(&mut self, uref: URef) -> GrantedAccess

Grants access to a URef; unless access was pre-existing.

source

pub fn remove_access( &mut self, uref_addr: URefAddr, access_rights: AccessRights )

Removes an access right from the current runtime context.

source

pub fn effect(&self) -> ExecutionEffect

Returns current effects of a tracking copy.

source

pub fn execution_journal(&self) -> ExecutionJournal

Returns an ExecutionJournal.

source

pub fn transfers(&self) -> &Vec<TransferAddr>

Returns list of transfers.

source

pub fn transfers_mut(&mut self) -> &mut Vec<TransferAddr>

Returns mutable list of transfers.

source

pub fn is_readable(&self, key: &Key) -> bool

Tests whether reading from the key is valid.

source

pub fn is_addable(&self, key: &Key) -> bool

Tests whether addition to key is valid.

source

pub fn is_writeable(&self, key: &Key) -> bool

Tests whether writing to key is valid.

source

pub fn get_main_purse(&mut self) -> Result<URef, Error>

Gets main purse id

source

pub fn entry_point_type(&self) -> EntryPointType

Gets entry point type.

source

pub fn dictionary_put( &mut self, seed_uref: URef, dictionary_item_key: &str, cl_value: CLValue ) -> Result<(), Error>

Puts a dictionary item key from a dictionary referenced by a uref.

source

pub fn system_contract_registry(&self) -> Result<SystemContractRegistry, Error>

Returns system contract registry by querying the global state.

Auto Trait Implementations§

§

impl<'a, R> !RefUnwindSafe for RuntimeContext<'a, R>

§

impl<'a, R> !Send for RuntimeContext<'a, R>

§

impl<'a, R> !Sync for RuntimeContext<'a, R>

§

impl<'a, R> Unpin for RuntimeContext<'a, R>

§

impl<'a, R> !UnwindSafe for RuntimeContext<'a, R>

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
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into a target type. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

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

fn as_any(&self) -> &(dyn Any + 'static)

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

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

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

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
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.

§

impl<T> Pipe for T

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more
§

impl<T> PipeAsRef for T

§

fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: AsRef<T>, T: 'a, R: 'a,

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
§

fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R
where Self: AsMut<T>, T: 'a, R: 'a,

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
§

impl<T> PipeBorrow for T

§

fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Borrow<T>, T: 'a, R: 'a,

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
§

fn pipe_borrow_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> R
where Self: BorrowMut<T>, T: 'a, R: 'a,

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
§

impl<T> PipeDeref for T

§

fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R
where Self: Deref, R: 'a,

Pipes a dereference into a function that cannot normally be called in suffix position. Read more
§

fn pipe_deref_mut<'a, R>( &'a mut self, func: impl FnOnce(&'a mut Self::Target) -> R ) -> R
where Self: DerefMut, R: 'a,

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more
§

impl<T> PipeRef for T

§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more
§

fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap<F, R>(self, func: F) -> Self
where F: FnOnce(&Self) -> R,

Provides immutable access for inspection. Read more
§

fn tap_dbg<F, R>(self, func: F) -> Self
where F: FnOnce(&Self) -> R,

Calls tap in debug builds, and does nothing in release builds.
§

fn tap_mut<F, R>(self, func: F) -> Self
where F: FnOnce(&mut Self) -> R,

Provides mutable access for modification. Read more
§

fn tap_mut_dbg<F, R>(self, func: F) -> Self
where F: FnOnce(&mut Self) -> R,

Calls tap_mut in debug builds, and does nothing in release builds.
§

impl<T, U> TapAsRef<U> for T
where U: ?Sized,

§

fn tap_ref<F, R>(self, func: F) -> Self
where Self: AsRef<T>, F: FnOnce(&T) -> R,

Provides immutable access to the reference for inspection.
§

fn tap_ref_dbg<F, R>(self, func: F) -> Self
where Self: AsRef<T>, F: FnOnce(&T) -> R,

Calls tap_ref in debug builds, and does nothing in release builds.
§

fn tap_ref_mut<F, R>(self, func: F) -> Self
where Self: AsMut<T>, F: FnOnce(&mut T) -> R,

Provides mutable access to the reference for modification.
§

fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self
where Self: AsMut<T>, F: FnOnce(&mut T) -> R,

Calls tap_ref_mut in debug builds, and does nothing in release builds.
§

impl<T, U> TapBorrow<U> for T
where U: ?Sized,

§

fn tap_borrow<F, R>(self, func: F) -> Self
where Self: Borrow<T>, F: FnOnce(&T) -> R,

Provides immutable access to the borrow for inspection. Read more
§

fn tap_borrow_dbg<F, R>(self, func: F) -> Self
where Self: Borrow<T>, F: FnOnce(&T) -> R,

Calls tap_borrow in debug builds, and does nothing in release builds.
§

fn tap_borrow_mut<F, R>(self, func: F) -> Self
where Self: BorrowMut<T>, F: FnOnce(&mut T) -> R,

Provides mutable access to the borrow for modification.
§

fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self
where Self: BorrowMut<T>, F: FnOnce(&mut T) -> R,

Calls tap_borrow_mut in debug builds, and does nothing in release builds.
§

impl<T> TapDeref for T

§

fn tap_deref<F, R>(self, func: F) -> Self
where Self: Deref, F: FnOnce(&Self::Target) -> R,

Immutably dereferences self for inspection.
§

fn tap_deref_dbg<F, R>(self, func: F) -> Self
where Self: Deref, F: FnOnce(&Self::Target) -> R,

Calls tap_deref in debug builds, and does nothing in release builds.
§

fn tap_deref_mut<F, R>(self, func: F) -> Self
where Self: DerefMut, F: FnOnce(&mut Self::Target) -> R,

Mutably dereferences self for modification.
§

fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self
where Self: DerefMut, F: FnOnce(&mut Self::Target) -> R,

Calls tap_deref_mut in debug builds, and does nothing in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into a target type. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

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

§

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