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

Holds information specific to the deployed contract.

Implementations§

source§

impl<'a, R> RuntimeContext<'a, R>where R: StateReader<Key, StoredValue>, R::Error: Into<Error>,

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for Twhere 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.
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 Twhere 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.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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 Twhere 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