pub struct TrackingCopy<R> { /* private fields */ }
Expand description

An interface for the global state that caches all operations (reads and writes) instead of applying them directly to the state. This way the state remains unmodified, while the user can interact with it as if it was being modified in real time.

Implementations§

source§

impl<R: StateReader<Key, StoredValue>> TrackingCopy<R>

source

pub fn new(reader: R) -> TrackingCopy<R>

Creates a new TrackingCopy using the reader as the interface to the state.

source

pub fn reader(&self) -> &R

Returns the reader used to access the state.

source

pub fn fork(&self) -> TrackingCopy<&TrackingCopy<R>>

Creates a new TrackingCopy, using this one (including its mutations) as the base state to read against. The intended use case for this function is to “snapshot” the current TrackingCopy and produce a new TrackingCopy where further changes can be made. This allows isolating a specific set of changes (those in the new TrackingCopy) from existing changes. Note that mutations to state caused by new changes (i.e. writes and adds) only impact the new TrackingCopy, not this one. Note that currently there is no join / merge function to bring changes from a fork back to the main TrackingCopy. this means the current usage requires repeated forking, however we recognize this is sub-optimal and will revisit in the future.

source

pub fn get_keys( &mut self, correlation_id: CorrelationId, key_tag: &KeyTag ) -> Result<BTreeSet<Key>, R::Error>

Gets the set of keys in the state whose tag is key_tag.

source

pub fn read( &mut self, correlation_id: CorrelationId, key: &Key ) -> Result<Option<StoredValue>, R::Error>

Reads the value stored under key.

source

pub fn write(&mut self, key: Key, value: StoredValue)

Writes value under key. Note that the write is only cached, and the global state itself remains unmodified.

source

pub fn add( &mut self, correlation_id: CorrelationId, key: Key, value: StoredValue ) -> Result<AddResult, R::Error>

Ok(None) represents missing key to which we want to “add” some value. Ok(Some(unit)) represents successful operation. Err(error) is reserved for unexpected errors when accessing global state.

source

pub fn effect(&self) -> ExecutionEffect

Returns the execution effects cached by this instance.

source

pub fn execution_journal(&self) -> ExecutionJournal

Returns the journal of operations executed on this instance.

source

pub fn query( &self, correlation_id: CorrelationId, config: &EngineConfig, base_key: Key, path: &[String] ) -> Result<TrackingCopyQueryResult, R::Error>

Calling query() avoids calling into self.cache, so this will not return any values written or mutated in this TrackingCopy via previous calls to write() or add(), since these updates are only held in self.cache.

The intent is that query() is only used to satisfy QueryRequests made to the server. Other EE internal use cases should call read() or get() in order to retrieve cached values.

Trait Implementations§

source§

impl<R: StateReader<Key, StoredValue>> StateReader<Key, StoredValue> for &TrackingCopy<R>

The purpose of this implementation is to allow a “snapshot” mechanism for TrackingCopy. The state of a TrackingCopy (including the effects of any transforms it has accumulated) can be read using an immutable reference to that TrackingCopy via this trait implementation. See TrackingCopy::fork for more information.

§

type Error = <R as StateReader<Key, StoredValue>>::Error

An error which occurs when reading state
source§

fn read( &self, correlation_id: CorrelationId, key: &Key ) -> Result<Option<StoredValue>, Self::Error>

Returns the state value from the corresponding key
source§

fn read_with_proof( &self, correlation_id: CorrelationId, key: &Key ) -> Result<Option<TrieMerkleProof<Key, StoredValue>>, Self::Error>

Returns the merkle proof of the state value from the corresponding key
source§

fn keys_with_prefix( &self, correlation_id: CorrelationId, prefix: &[u8] ) -> Result<Vec<Key>, Self::Error>

Returns the keys in the trie matching prefix.
source§

impl<R> TrackingCopyExt<R> for TrackingCopy<R>where R: StateReader<Key, StoredValue>, R::Error: Into<Error>,

source§

fn get_contract_wasm( &mut self, correlation_id: CorrelationId, contract_wasm_hash: ContractWasmHash ) -> Result<ContractWasm, Self::Error>

Gets a contract wasm by Key

source§

fn get_contract( &mut self, correlation_id: CorrelationId, contract_hash: ContractHash ) -> Result<Contract, Self::Error>

Gets a contract header by Key

§

type Error = Error

The type for the returned errors.
source§

fn get_account( &mut self, correlation_id: CorrelationId, account_hash: AccountHash ) -> Result<Account, Self::Error>

Gets the account at a given account address.
source§

fn read_account( &mut self, correlation_id: CorrelationId, account_hash: AccountHash ) -> Result<Account, Self::Error>

Reads the account at a given account address.
source§

fn get_purse_balance_key( &self, _correlation_id: CorrelationId, purse_key: Key ) -> Result<Key, Self::Error>

Gets the purse balance key for a given purse id
source§

fn get_purse_balance( &self, correlation_id: CorrelationId, key: Key ) -> Result<Motes, Self::Error>

Gets the balance at a given balance key.
source§

fn get_purse_balance_key_with_proof( &self, correlation_id: CorrelationId, purse_key: Key ) -> Result<(Key, TrieMerkleProof<Key, StoredValue>), Self::Error>

Gets the purse balance key for a given purse id and provides a Merkle proof.
source§

fn get_purse_balance_with_proof( &self, correlation_id: CorrelationId, key: Key ) -> Result<(Motes, TrieMerkleProof<Key, StoredValue>), Self::Error>

Gets the balance at a given balance key and provides a Merkle proof.
source§

fn get_contract_package( &mut self, correlation_id: CorrelationId, contract_package_hash: ContractPackageHash ) -> Result<ContractPackage, Self::Error>

Gets a contract package by Key.
source§

fn get_system_contracts( &mut self, correlation_id: CorrelationId ) -> Result<SystemContractRegistry, Self::Error>

Gets the system contract registry.
source§

fn get_checksum_registry( &mut self, correlation_id: CorrelationId ) -> Result<Option<ChecksumRegistry>, Self::Error>

Gets the system checksum registry.

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for TrackingCopy<R>where R: RefUnwindSafe,

§

impl<R> Send for TrackingCopy<R>where R: Send,

§

impl<R> Sync for TrackingCopy<R>where R: Sync,

§

impl<R> Unpin for TrackingCopy<R>where R: Unpin,

§

impl<R> UnwindSafe for TrackingCopy<R>where R: UnwindSafe,

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

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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