pub trait Context {
    type Runtime: Runtime;

Show 28 methods // Required methods fn get_logger(&self, module: &'static str) -> Logger; fn mode(&self) -> Mode; fn host_info(&self) -> &HostInfo; fn key_manager(&self) -> Option<&dyn KeyManager>; fn runtime_header(&self) -> &Header; fn runtime_round_results(&self) -> &RoundResults; fn consensus_state(&self) -> &ConsensusState; fn history(&self) -> &dyn HistoryHost; fn epoch(&self) -> EpochTime; fn emit_event<E: Event>(&mut self, event: E); fn emit_etag(&mut self, etag: EventTag); fn emit_etags(&mut self, etags: EventTags); fn commit(self) -> State; fn rollback(self) -> EventTags; fn value<V: Any>(&mut self, key: &'static str) -> ContextValue<'_, V>; fn remaining_messages(&self) -> u32; fn limit_max_messages(&mut self, max_messages: u32) -> Result<(), Error>; fn with_child<F, Rs>(&mut self, mode: Mode, f: F) -> Rs where F: FnOnce(RuntimeBatchContext<'_, Self::Runtime>) -> Rs; fn rng(&mut self, pers: &[u8]) -> Result<LeafRng, Error>; // Provided methods fn is_check_only(&self) -> bool { ... } fn is_pre_schedule(&self) -> bool { ... } fn is_simulation(&self) -> bool { ... } fn should_execute_contracts(&self) -> bool { ... } fn is_allowed_query<R: Runtime>(&self, method: &str) -> bool { ... } fn local_config<T>(&self, key: &str) -> Option<T> where T: Decode { ... } fn runtime_id(&self) -> &Namespace { ... } fn is_confidential(&self) -> bool { ... } fn with_simulation<F, Rs>(&mut self, f: F) -> Rs where F: FnOnce(RuntimeBatchContext<'_, Self::Runtime>) -> Rs { ... }
}
Expand description

Runtime SDK context.

Required Associated Types§

source

type Runtime: Runtime

Runtime that the context is being invoked in.

Required Methods§

source

fn get_logger(&self, module: &'static str) -> Logger

Returns a logger.

source

fn mode(&self) -> Mode

Context mode.

source

fn host_info(&self) -> &HostInfo

Information about the host environment.

source

fn key_manager(&self) -> Option<&dyn KeyManager>

The key manager, if the runtime is confidential.

source

fn runtime_header(&self) -> &Header

Last runtime block header.

source

fn runtime_round_results(&self) -> &RoundResults

Results of executing the last successful runtime round.

source

fn consensus_state(&self) -> &ConsensusState

Consensus state.

source

fn history(&self) -> &dyn HistoryHost

Historical state.

source

fn epoch(&self) -> EpochTime

Current epoch.

source

fn emit_event<E: Event>(&mut self, event: E)

Emits an event by transforming it into a tag and emitting a tag.

source

fn emit_etag(&mut self, etag: EventTag)

Emits a tag.

source

fn emit_etags(&mut self, etags: EventTags)

Emits event tags.

source

fn commit(self) -> State

Return any emitted tags and runtime messages. It consumes the transaction context.

Storage

This does not commit any storage transaction.

source

fn rollback(self) -> EventTags

Rollback any changes made by this context. This method only needs to be called explicitly in case you want to retrieve possibly emitted unconditional events. Simply dropping the context without calling commit will also result in a rollback.

Storage

This does not rollback any storage transaction.

source

fn value<V: Any>(&mut self, key: &'static str) -> ContextValue<'_, V>

Fetches a value entry associated with the context.

source

fn remaining_messages(&self) -> u32

Number of consensus messages that can still be emitted.

source

fn limit_max_messages(&mut self, max_messages: u32) -> Result<(), Error>

Set an upper limit on the number of consensus messages that can be emitted in this context. Note that the limit can only be decreased and calling this function will return an error in case the passed max_messages is higher than the current limit.

source

fn with_child<F, Rs>(&mut self, mode: Mode, f: F) -> Rswhere F: FnOnce(RuntimeBatchContext<'_, Self::Runtime>) -> Rs,

Executes a function in a child context with the given mode.

The context collects its own messages and starts with an empty set of context values.

Storage

This does not start a new storage transaction. Start a transaction and explicitly commit or rollback if you want to discard storage side effects.

source

fn rng(&mut self, pers: &[u8]) -> Result<LeafRng, Error>

Returns a random number generator, if it is available, with optional personalization.

Provided Methods§

source

fn is_check_only(&self) -> bool

Whether the transaction is just being checked for validity.

source

fn is_pre_schedule(&self) -> bool

Whether the transaction is just being checked for validity before being scheduled.

source

fn is_simulation(&self) -> bool

Whether the transaction is just being simulated.

source

fn should_execute_contracts(&self) -> bool

Whether smart contracts should be executed in this context.

source

fn is_allowed_query<R: Runtime>(&self, method: &str) -> bool

Whether method is an allowed query per policy in the local config.

source

fn local_config<T>(&self, key: &str) -> Option<T>where T: Decode,

Returns node operator-provided local configuration.

This method will always return None in Mode::ExecuteTx contexts.

source

fn runtime_id(&self) -> &Namespace

Runtime ID.

source

fn is_confidential(&self) -> bool

Whether the context has a key manager available (e.g. the runtime is confidential).

source

fn with_simulation<F, Rs>(&mut self, f: F) -> Rswhere F: FnOnce(RuntimeBatchContext<'_, Self::Runtime>) -> Rs,

Executes a function in a simulation context.

The simulation context collects its own messages and starts with an empty set of context values.

Storage

This does not start a new storage transaction. Start a transaction and explicitly commit or rollback if you want to discard storage side effects.

Implementations on Foreign Types§

source§

impl<'a, 'b, C: Context> Context for RefMut<'a, &'b mut C>

§

type Runtime = <C as Context>::Runtime

source§

fn get_logger(&self, module: &'static str) -> Logger

source§

fn mode(&self) -> Mode

source§

fn host_info(&self) -> &HostInfo

source§

fn key_manager(&self) -> Option<&dyn KeyManager>

source§

fn runtime_header(&self) -> &Header

source§

fn runtime_round_results(&self) -> &RoundResults

source§

fn consensus_state(&self) -> &ConsensusState

source§

fn history(&self) -> &dyn HistoryHost

source§

fn epoch(&self) -> EpochTime

source§

fn emit_event<E: Event>(&mut self, event: E)

source§

fn emit_etag(&mut self, etag: EventTag)

source§

fn emit_etags(&mut self, etags: EventTags)

source§

fn commit(self) -> State

source§

fn rollback(self) -> EventTags

source§

fn value<V: Any>(&mut self, key: &'static str) -> ContextValue<'_, V>

source§

fn remaining_messages(&self) -> u32

source§

fn limit_max_messages(&mut self, max_messages: u32) -> Result<(), Error>

source§

fn with_child<F, Rs>(&mut self, mode: Mode, f: F) -> Rswhere F: FnOnce(RuntimeBatchContext<'_, Self::Runtime>) -> Rs,

source§

fn rng(&mut self, pers: &[u8]) -> Result<LeafRng, Error>

Implementors§

source§

impl<'a, R: Runtime> Context for RuntimeBatchContext<'a, R>

§

type Runtime = R

source§

impl<'round, 'store, R: Runtime> Context for RuntimeTxContext<'round, 'store, R>

§

type Runtime = R