Struct oasis_runtime_sdk::state::State
source · pub struct State { /* private fields */ }
Expand description
Mutable block state of a runtime.
The state includes storage, emitted events, messages to consensus layer, etc. States can be
nested via open
, commit
and rollback
methods which behave like transactions.
Implementations§
source§impl State
impl State
sourcepub fn commit(&mut self)
pub fn commit(&mut self)
Commit the current state and return to its parent state.
§Panics
This method will panic when attempting to commit the root state.
sourcepub fn rollback(&mut self)
pub fn rollback(&mut self)
Rollback the current state and return to its parent state.
§Panics
This method will panic when attempting to rollback the root state.
sourcepub fn block_value<V: Any>(&mut self, key: &'static str) -> StateValue<'_, V>
pub fn block_value<V: Any>(&mut self, key: &'static str) -> StateValue<'_, V>
Fetches a block state value entry.
Block values live as long as the root State
and are propagated to child states. They are
not affected by state rollbacks. If you need state-scoped values, use local values.
sourcepub fn local_value<V: Any>(&mut self, key: &'static str) -> StateValue<'_, V>
pub fn local_value<V: Any>(&mut self, key: &'static str) -> StateValue<'_, V>
Fetches a local state value entry.
Local values only live as long as the current State
, are dropped upon exiting to parent
state and child states start with an empty set. If you need longer-lived values, use block
values.
sourcepub fn hide_block_values(&mut self)
pub fn hide_block_values(&mut self)
Hides block values from the current state which will have an empty set of values after this method returns. Hidden values will be restored upon exit to parent state.
sourcepub fn emitted_messages_count(&self) -> usize
pub fn emitted_messages_count(&self) -> usize
Emitted messages count returns the number of messages emitted so far across this and all parent states.
sourcepub fn emitted_messages_local_count(&self) -> usize
pub fn emitted_messages_local_count(&self) -> usize
Emitted messages count returns the number of messages emitted so far in this state, not counting any parent states.
sourcepub fn emitted_messages_max<C: Context>(&self, ctx: &C) -> u32
pub fn emitted_messages_max<C: Context>(&self, ctx: &C) -> u32
Maximum number of messages that can be emitted.
sourcepub fn emit_message<C: Context>(
&mut self,
ctx: &C,
msg: Message,
hook: MessageEventHookInvocation,
) -> Result<(), Error>
pub fn emit_message<C: Context>( &mut self, ctx: &C, msg: Message, hook: MessageEventHookInvocation, ) -> Result<(), Error>
Queue a message to be emitted by the runtime for consensus layer to process.
sourcepub fn take_messages(&mut self) -> Vec<(Message, MessageEventHookInvocation)>
pub fn take_messages(&mut self) -> Vec<(Message, MessageEventHookInvocation)>
Take all messages accumulated in the current state.
sourcepub fn emit_event<E: Event>(&mut self, event: E)
pub fn emit_event<E: Event>(&mut self, event: E)
Emit an event.
sourcepub fn emit_event_raw(&mut self, etag: EventTag)
pub fn emit_event_raw(&mut self, etag: EventTag)
Emit a raw event.
sourcepub fn emit_unconditional_event<E: Event>(&mut self, event: E)
pub fn emit_unconditional_event<E: Event>(&mut self, event: E)
Emit an unconditional event.
The only difference to regular events is that these are handled as a separate set.
sourcepub fn take_events(&mut self) -> EventTags
pub fn take_events(&mut self) -> EventTags
Take all regular events accumulated in the current state.
sourcepub fn take_unconditional_events(&mut self) -> EventTags
pub fn take_unconditional_events(&mut self) -> EventTags
Take all unconditional events accumulated in the current state.
sourcepub fn take_all_events(&mut self) -> EventTags
pub fn take_all_events(&mut self) -> EventTags
Take all events accumulated in the current state and return the merged set.
sourcepub fn has_pending_store_updates(&self) -> bool
pub fn has_pending_store_updates(&self) -> bool
Whether the store associated with the state has any pending updates.
sourcepub fn pending_store_update_byte_size(&self) -> usize
pub fn pending_store_update_byte_size(&self) -> usize
Size (in bytes) of any pending updates in the associated store.
sourcepub fn env(&self) -> &Environment
pub fn env(&self) -> &Environment
Environment information.
sourcepub fn env_origin(&self) -> &Environment
pub fn env_origin(&self) -> &Environment
Origin environment information.
The origin environment is the first non-internal environment in the hierarchy.