pub struct RuntimeContext<'a, R> { /* private fields */ }
Expand description
Holds information specific to the deployed contract.
Implementations§
Source§impl<'a, R> RuntimeContext<'a, R>
impl<'a, R> RuntimeContext<'a, R>
Sourcepub 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
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()
.
Sourcepub fn new_from_self(
&self,
context_key: Key,
entry_point_type: EntryPointType,
named_keys: &'a mut NamedKeys,
access_rights: ContextAccessRights,
runtime_args: RuntimeArgs,
) -> Self
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.
Returns all authorization keys for this deploy.
Sourcepub fn named_keys_get(&self, name: &str) -> Option<&Key>
pub fn named_keys_get(&self, name: &str) -> Option<&Key>
Returns a named key by a name if it exists.
Sourcepub fn named_keys(&self) -> &NamedKeys
pub fn named_keys(&self) -> &NamedKeys
Returns named keys.
Sourcepub fn named_keys_mut(&mut self) -> &mut NamedKeys
pub fn named_keys_mut(&mut self) -> &mut NamedKeys
Returns a mutable reference to named keys.
Sourcepub fn named_keys_contains_key(&self, name: &str) -> bool
pub fn named_keys_contains_key(&self, name: &str) -> bool
Checks if named keys contains a key referenced by name.
Sourcepub fn maybe_payment_purse(&self) -> Option<URef>
pub fn maybe_payment_purse(&self) -> Option<URef>
Returns the payment purse, if set.
Sourcepub fn set_payment_purse(&mut self, uref: URef)
pub fn set_payment_purse(&mut self, uref: URef)
Sets the payment purse to the imputed uref.
Sourcepub fn engine_config(&self) -> &EngineConfig
pub fn engine_config(&self) -> &EngineConfig
Returns an instance of the engine config.
Sourcepub fn remove_key(&mut self, name: &str) -> Result<(), ExecError>
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).
Sourcepub fn get_block_info(&self) -> BlockInfo
pub fn get_block_info(&self) -> BlockInfo
Returns block info.
Sourcepub fn get_transaction_hash(&self) -> TransactionHash
pub fn get_transaction_hash(&self) -> TransactionHash
Returns the transaction hash.
Sourcepub fn access_rights_extend(&mut self, urefs: &[URef])
pub fn access_rights_extend(&mut self, urefs: &[URef])
Extends access rights with a new map.
Sourcepub fn access_rights(&self) -> &ContextAccessRights
pub fn access_rights(&self) -> &ContextAccessRights
Returns a mapping of access rights for each URef
s address.
Sourcepub fn runtime_footprint(&self) -> Rc<RefCell<RuntimeFootprint>>
pub fn runtime_footprint(&self) -> Rc<RefCell<RuntimeFootprint>>
Returns footprint of the caller.
Sourcepub fn args(&self) -> &RuntimeArgs
pub fn args(&self) -> &RuntimeArgs
Returns arguments.
Sourcepub fn address_generator(&self) -> Rc<RefCell<AddressGenerator>>
pub fn address_generator(&self) -> Rc<RefCell<AddressGenerator>>
Returns new shared instance of an address generator.
Sourcepub fn gas_counter(&self) -> Gas
pub fn gas_counter(&self) -> Gas
Returns the current gas counter.
Sourcepub fn set_gas_counter(&mut self, new_gas_counter: Gas)
pub fn set_gas_counter(&mut self, new_gas_counter: Gas)
Sets the gas counter to a new value.
Sourcepub fn get_context_key(&self) -> Key
pub fn get_context_key(&self) -> Key
Returns the context key for this instance.
Sourcepub fn get_initiator(&self) -> AccountHash
pub fn get_initiator(&self) -> AccountHash
Returns the initiator of the call chain.
Sourcepub fn protocol_version(&self) -> ProtocolVersion
pub fn protocol_version(&self) -> ProtocolVersion
Returns the protocol version.
Sourcepub fn install_upgrade_allowed(&self) -> bool
pub fn install_upgrade_allowed(&self) -> bool
Returns true
if the execution is permitted to call casper_add_contract_version()
.
Sourcepub fn new_hash_address(&mut self) -> Result<[u8; 32], ExecError>
pub fn new_hash_address(&mut self) -> Result<[u8; 32], ExecError>
Generates new deterministic hash for uses as an address.
Sourcepub fn new_uref(&mut self, value: StoredValue) -> Result<URef, ExecError>
pub fn new_uref(&mut self, value: StoredValue) -> Result<URef, ExecError>
Creates new URef
instance.
Sourcepub fn put_key(&mut self, name: String, key: Key) -> Result<(), ExecError>
pub fn put_key(&mut self, name: String, key: Key) -> Result<(), ExecError>
Puts key
to the map of named keys of current context.
Sourcepub fn read_gs(&mut self, key: &Key) -> Result<Option<StoredValue>, ExecError>
pub fn read_gs(&mut self, key: &Key) -> Result<Option<StoredValue>, ExecError>
Read a stored value under a Key
.
Sourcepub fn read_gs_unsafe(
&mut self,
key: &Key,
) -> Result<Option<StoredValue>, ExecError>
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.
Sourcepub fn read_gs_typed<T>(&mut self, key: &Key) -> Result<T, ExecError>
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.
Sourcepub fn get_keys(&mut self, key_tag: &KeyTag) -> Result<BTreeSet<Key>, ExecError>
pub fn get_keys(&mut self, key_tag: &KeyTag) -> Result<BTreeSet<Key>, ExecError>
Returns all keys based on the tag prefix.
Sourcepub fn get_keys_with_prefix(
&mut self,
prefix: &[u8],
) -> Result<Vec<Key>, ExecError>
pub fn get_keys_with_prefix( &mut self, prefix: &[u8], ) -> Result<Vec<Key>, ExecError>
Returns all key’s that start with prefix, if any.
Sourcepub fn write_era_info(&mut self, key: Key, value: EraInfo)
pub fn write_era_info(&mut self, key: Key, value: EraInfo)
Write an era info instance to the global state.
Sourcepub fn write_account(
&mut self,
key: Key,
account: Account,
) -> Result<(), ExecError>
pub fn write_account( &mut self, key: Key, account: Account, ) -> Result<(), ExecError>
Write an account to the global state.
Sourcepub fn read_account(
&mut self,
key: &Key,
) -> Result<Option<StoredValue>, ExecError>
pub fn read_account( &mut self, key: &Key, ) -> Result<Option<StoredValue>, ExecError>
Read an account from the global state.
Sourcepub fn grant_access(&mut self, uref: URef) -> GrantedAccess
pub fn grant_access(&mut self, uref: URef) -> GrantedAccess
Grants access to a URef
; unless access was pre-existing.
Sourcepub fn remove_access(
&mut self,
uref_addr: URefAddr,
access_rights: AccessRights,
)
pub fn remove_access( &mut self, uref_addr: URefAddr, access_rights: AccessRights, )
Removes an access right from the current runtime context.
Sourcepub fn cache(&self) -> TrackingCopyCache
pub fn cache(&self) -> TrackingCopyCache
Returns a copy of the current named keys of a tracking copy.
Sourcepub fn emit_message_cost(&self) -> U512
pub fn emit_message_cost(&self) -> U512
Returns the cost charged for the last emitted message.
Sourcepub fn set_emit_message_cost(&mut self, cost: U512)
pub fn set_emit_message_cost(&mut self, cost: U512)
Sets the cost charged for the last emitted message.
Sourcepub fn transfers_mut(&mut self) -> &mut Vec<Transfer>
pub fn transfers_mut(&mut self) -> &mut Vec<Transfer>
Returns mutable list of transfers.
Sourcepub fn is_readable(&self, key: &Key) -> bool
pub fn is_readable(&self, key: &Key) -> bool
Tests whether reading from the key
is valid.
Sourcepub fn is_addable(&self, key: &Key) -> bool
pub fn is_addable(&self, key: &Key) -> bool
Tests whether addition to key
is valid.
Sourcepub fn is_writeable(&self, key: &Key) -> bool
pub fn is_writeable(&self, key: &Key) -> bool
Tests whether writing to key
is valid.
Sourcepub fn get_main_purse(&mut self) -> Result<URef, ExecError>
pub fn get_main_purse(&mut self) -> Result<URef, ExecError>
Gets main purse id
Sourcepub fn entry_point_type(&self) -> EntryPointType
pub fn entry_point_type(&self) -> EntryPointType
Gets entry point type.
Sourcepub fn dictionary_put(
&mut self,
seed_uref: URef,
dictionary_item_key: &str,
cl_value: CLValue,
) -> Result<(), ExecError>
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
.
Sourcepub fn system_entity_registry(&self) -> Result<SystemHashRegistry, ExecError>
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> 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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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