Struct RuntimeContext

Source
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, Error = Error>,

Source

pub fn new( named_keys: &'a mut NamedKeys, runtime_footprint: Rc<RefCell<RuntimeFootprint>>, context_key: Key, authorization_keys: BTreeSet<AccountHash>, access_rights: ContextAccessRights, account_hash: AccountHash, address_generator: Rc<RefCell<AddressGenerator>>, tracking_copy: Rc<RefCell<TrackingCopy<R>>>, engine_config: EngineConfig, block_info: BlockInfo, transaction_hash: TransactionHash, phase: Phase, args: RuntimeArgs, gas_limit: Gas, gas_counter: Gas, transfers: Vec<Transfer>, remaining_spending_limit: U512, entry_point_type: EntryPointType, allow_install_upgrade: AllowInstallUpgrade, ) -> 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, context_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 maybe_payment_purse(&self) -> Option<URef>

Returns the payment purse, if set.

Source

pub fn set_payment_purse(&mut self, uref: URef)

Sets the payment purse to the imputed uref.

Source

pub fn engine_config(&self) -> &EngineConfig

Returns an instance of the engine config.

Source

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

Remove Key from the named_keys map of the current context. It removes both from the ephemeral map (RuntimeContext::named_keys) but also the to-be-persisted map (in the TrackingCopy/GlobalState).

Source

pub fn get_block_info(&self) -> BlockInfo

Returns block info.

Source

pub fn get_transaction_hash(&self) -> TransactionHash

Returns the transaction 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 runtime_footprint(&self) -> Rc<RefCell<RuntimeFootprint>>

Returns footprint 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 get_context_key(&self) -> Key

Returns the context key for this instance.

Source

pub fn get_initiator(&self) -> AccountHash

Returns the initiator of the call chain.

Source

pub fn protocol_version(&self) -> ProtocolVersion

Returns the protocol version.

Source

pub fn phase(&self) -> Phase

Returns the current phase.

Source

pub fn install_upgrade_allowed(&self) -> bool

Returns true if the execution is permitted to call casper_add_contract_version().

Source

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

Generates new deterministic hash for uses as an address.

Source

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

Returns 32 pseudo random bytes.

Source

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

Creates new URef instance.

Source

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

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

Source

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

Read a stored value under a Key.

Source

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

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

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

Returns all keys based on the tag prefix.

Source

pub fn get_keys_with_prefix( &mut self, prefix: &[u8], ) -> Result<Vec<Key>, ExecError>

Returns all key’s that start with prefix, if any.

Source

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

Write an era info instance to the global state.

Source

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

Write an account to the global state.

Source

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

Read an account from 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 effects(&self) -> Effects

Returns a copy of the current effects of a tracking copy.

Source

pub fn messages(&self) -> Messages

Returns a copy of the current messages of a tracking copy.

Source

pub fn cache(&self) -> TrackingCopyCache

Returns a copy of the current named keys of a tracking copy.

Source

pub fn emit_message_cost(&self) -> U512

Returns the cost charged for the last emitted message.

Source

pub fn set_emit_message_cost(&mut self, cost: U512)

Sets the cost charged for the last emitted message.

Source

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

Returns list of transfers.

Source

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

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

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<(), ExecError>

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

Source

pub fn system_entity_registry(&self) -> Result<SystemHashRegistry, ExecError>

Returns system entity registry by querying the global state.

Auto Trait Implementations§

§

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

§

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

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

Source§

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

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

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

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

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

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

Source§

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