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>

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

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into a target type. Read more
§

impl<T> Downcast for T
where 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 T
where 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.
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
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.

§

impl<T> Pipe for T

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more
§

impl<T> PipeAsRef for T

§

fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: AsRef<T>, T: 'a, R: 'a,

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
§

fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R
where Self: AsMut<T>, T: 'a, R: 'a,

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
§

impl<T> PipeBorrow for T

§

fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Borrow<T>, T: 'a, R: 'a,

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
§

fn pipe_borrow_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> R
where Self: BorrowMut<T>, T: 'a, R: 'a,

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
§

impl<T> PipeDeref for T

§

fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R
where Self: Deref, R: 'a,

Pipes a dereference into a function that cannot normally be called in suffix position. Read more
§

fn pipe_deref_mut<'a, R>( &'a mut self, func: impl FnOnce(&'a mut Self::Target) -> R ) -> R
where Self: DerefMut, R: 'a,

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more
§

impl<T> PipeRef for T

§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more
§

fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap<F, R>(self, func: F) -> Self
where F: FnOnce(&Self) -> R,

Provides immutable access for inspection. Read more
§

fn tap_dbg<F, R>(self, func: F) -> Self
where F: FnOnce(&Self) -> R,

Calls tap in debug builds, and does nothing in release builds.
§

fn tap_mut<F, R>(self, func: F) -> Self
where F: FnOnce(&mut Self) -> R,

Provides mutable access for modification. Read more
§

fn tap_mut_dbg<F, R>(self, func: F) -> Self
where F: FnOnce(&mut Self) -> R,

Calls tap_mut in debug builds, and does nothing in release builds.
§

impl<T, U> TapAsRef<U> for T
where U: ?Sized,

§

fn tap_ref<F, R>(self, func: F) -> Self
where Self: AsRef<T>, F: FnOnce(&T) -> R,

Provides immutable access to the reference for inspection.
§

fn tap_ref_dbg<F, R>(self, func: F) -> Self
where Self: AsRef<T>, F: FnOnce(&T) -> R,

Calls tap_ref in debug builds, and does nothing in release builds.
§

fn tap_ref_mut<F, R>(self, func: F) -> Self
where Self: AsMut<T>, F: FnOnce(&mut T) -> R,

Provides mutable access to the reference for modification.
§

fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self
where Self: AsMut<T>, F: FnOnce(&mut T) -> R,

Calls tap_ref_mut in debug builds, and does nothing in release builds.
§

impl<T, U> TapBorrow<U> for T
where U: ?Sized,

§

fn tap_borrow<F, R>(self, func: F) -> Self
where Self: Borrow<T>, F: FnOnce(&T) -> R,

Provides immutable access to the borrow for inspection. Read more
§

fn tap_borrow_dbg<F, R>(self, func: F) -> Self
where Self: Borrow<T>, F: FnOnce(&T) -> R,

Calls tap_borrow in debug builds, and does nothing in release builds.
§

fn tap_borrow_mut<F, R>(self, func: F) -> Self
where Self: BorrowMut<T>, F: FnOnce(&mut T) -> R,

Provides mutable access to the borrow for modification.
§

fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self
where Self: BorrowMut<T>, F: FnOnce(&mut T) -> R,

Calls tap_borrow_mut in debug builds, and does nothing in release builds.
§

impl<T> TapDeref for T

§

fn tap_deref<F, R>(self, func: F) -> Self
where Self: Deref, F: FnOnce(&Self::Target) -> R,

Immutably dereferences self for inspection.
§

fn tap_deref_dbg<F, R>(self, func: F) -> Self
where Self: Deref, F: FnOnce(&Self::Target) -> R,

Calls tap_deref in debug builds, and does nothing in release builds.
§

fn tap_deref_mut<F, R>(self, func: F) -> Self
where Self: DerefMut, F: FnOnce(&mut Self::Target) -> R,

Mutably dereferences self for modification.
§

fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self
where Self: DerefMut, F: FnOnce(&mut Self::Target) -> R,

Calls tap_deref_mut in debug builds, and does nothing in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into a target type. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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 T
where 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