Struct TrackingCopy

Source
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> TrackingCopy<R>

Source

pub fn new( reader: R, max_query_depth: u64, enable_addressable_entity: bool, ) -> 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 shared_reader(&self) -> Arc<R>

Returns a shared reference to the reader used to access the state.

Source

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

Creates a new TrackingCopy using the reader as the interface to the state. Returns a new TrackingCopy instance that is a snapshot of the current state, allowing further changes to be made.

This method creates a new TrackingCopy using the current instance (including its mutations) as the base state to read against. Mutations made to the new TrackingCopy will not impact the original instance.

Note: Currently, there is no join or merge function to bring changes from a fork back to the main TrackingCopy. Therefore, forking should be done repeatedly, which is suboptimal and will be improved in the future.

Source

pub fn fork2(&self) -> Self

Returns a new TrackingCopy instance that is a snapshot of the current state, allowing further changes to be made.

This method creates a new TrackingCopy using the current instance (including its mutations) as the base state to read against. Mutations made to the new TrackingCopy will not impact the original instance.

Note: Currently, there is no join or merge function to bring changes from a fork back to the main TrackingCopy. This method is an alternative to the fork method and is provided for clarity and consistency in naming.

Source

pub fn apply_changes( &mut self, effects: Effects, cache: TrackingCopyCache, messages: Messages, )

Applies the changes to the state.

This is a low-level function that should be used only by the execution engine. The purpose of this function is to apply the changes to the state from a forked tracking copy. Once caller decides that the changes are valid, they can be applied to the state and the processing can resume.

Source

pub fn effects(&self) -> Effects

Returns a copy of the execution effects cached by this instance.

Source

pub fn cache(&self) -> TrackingCopyCache

Returns copy of cache.

Source

pub fn destructure(self) -> (Vec<(Key, StoredValue)>, BTreeSet<Key>, Effects)

Destructure cached entries.

Source

pub fn enable_addressable_entity(&self) -> bool

Enable the addressable entity and migrate accounts/contracts to entities.

Source

pub fn get( &mut self, key: &Key, ) -> Result<Option<StoredValue>, TrackingCopyError>

Get record by key.

Source

pub fn get_keys( &self, key_tag: &KeyTag, ) -> Result<BTreeSet<Key>, TrackingCopyError>

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

Source

pub fn get_keys_by_prefix( &self, key_prefix: &KeyPrefix, ) -> Result<BTreeSet<Key>, TrackingCopyError>

Get keys by prefix.

Source

pub fn read( &mut self, key: &Key, ) -> Result<Option<StoredValue>, TrackingCopyError>

Reads the value stored under key.

Source

pub fn read_first( &mut self, keys: &[&Key], ) -> Result<Option<StoredValue>, TrackingCopyError>

Reads the first value stored under the keys in keys.

Source

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

Writes value under key. Note that the written value is only cached.

Source

pub fn emit_message( &mut self, message_topic_key: Key, message_topic_summary: StoredValue, message_key: Key, message_value: StoredValue, block_message_count_value: StoredValue, message: Message, )

Caches the emitted message and writes the message topic summary under the specified key.

This function does not check the types for the key and the value so the caller should correctly set the type. The message_topic_key should be of the Key::MessageTopic variant and the message_topic_summary should be of the StoredValue::Message variant.

Source

pub fn prune(&mut self, key: Key)

Prunes a key.

Source

pub fn add( &mut self, key: Key, value: StoredValue, ) -> Result<AddResult, TrackingCopyError>

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 messages(&self) -> Messages

Returns a copy of the messages cached by this instance.

Source

pub fn query( &self, base_key: Key, path: &[String], ) -> Result<TrackingCopyQueryResult, TrackingCopyError>

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: Clone> Clone for TrackingCopy<R>

Source§

fn clone(&self) -> TrackingCopy<R>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: StateReader<Key, StoredValue>> StateReader 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.

Source§

type Error = <R as StateReader>::Error

An error which occurs when reading state
Source§

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

Returns the state value from the corresponding key
Source§

fn read_with_proof( &self, 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, byte_prefix: &[u8]) -> Result<Vec<Key>, Self::Error>

Returns the keys in the trie matching prefix.
Source§

impl<R> TrackingCopyEntityExt<R> for TrackingCopy<R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

type Error = Error

The type for the returned errors.
Source§

fn runtime_footprint_by_entity_addr( &self, entity_addr: EntityAddr, ) -> Result<RuntimeFootprint, Self::Error>

Gets a runtime information by entity_addr.
Source§

fn runtime_footprint_by_hash_addr( &mut self, hash_addr: HashAddr, ) -> Result<RuntimeFootprint, Self::Error>

Gets a runtime information by hash_addr.
Source§

fn runtime_footprint_by_account_hash( &mut self, protocol_version: ProtocolVersion, account_hash: AccountHash, ) -> Result<(EntityAddr, RuntimeFootprint), Self::Error>

Gets a runtime information by account hash.
Source§

fn authorized_runtime_footprint_by_account( &mut self, protocol_version: ProtocolVersion, account_hash: AccountHash, authorization_keys: &BTreeSet<AccountHash>, administrative_accounts: &BTreeSet<AccountHash>, ) -> Result<(RuntimeFootprint, EntityAddr), Self::Error>

Get runtime information for an account if authorized, else error.
Source§

fn authorized_runtime_footprint_with_access_rights( &mut self, protocol_version: ProtocolVersion, initiating_address: AccountHash, authorization_keys: &BTreeSet<AccountHash>, administrative_accounts: &BTreeSet<AccountHash>, ) -> Result<(EntityAddr, RuntimeFootprint, ContextAccessRights), TrackingCopyError>

Returns runtime information and access rights if authorized, else error.
Source§

fn system_entity_runtime_footprint( &mut self, protocol_version: ProtocolVersion, ) -> Result<(EntityAddr, RuntimeFootprint, ContextAccessRights), TrackingCopyError>

Returns runtime information for systemic functionality.
Source§

fn migrate_named_keys( &mut self, entity_addr: EntityAddr, named_keys: NamedKeys, ) -> Result<(), Self::Error>

Migrate the NamedKeys for a entity.
Source§

fn migrate_entry_points( &mut self, entity_addr: EntityAddr, entry_points: EntryPoints, ) -> Result<(), Self::Error>

Migrate entry points from and older structure to top level entries.
Source§

fn upsert_uref_to_named_keys( &mut self, entity_addr: EntityAddr, name: &str, named_keys: &NamedKeys, uref: URef, stored_value: StoredValue, ) -> Result<(), Self::Error>

Upsert uref value to global state and imputed entity’s named keys.
Source§

fn migrate_account( &mut self, account_hash: AccountHash, protocol_version: ProtocolVersion, ) -> Result<(), Self::Error>

Migrate Account to AddressableEntity.
Source§

fn create_new_addressable_entity_on_transfer( &mut self, account_hash: AccountHash, main_purse: URef, protocol_version: ProtocolVersion, ) -> Result<(), Self::Error>

Create an addressable entity to receive transfer.
Source§

fn create_addressable_entity_from_account( &mut self, account: Account, protocol_version: ProtocolVersion, ) -> Result<(), Self::Error>

Create an addressable entity instance using the field data of an account instance.
Source§

fn migrate_package( &mut self, legacy_package_key: Key, protocol_version: ProtocolVersion, ) -> Result<(), Self::Error>

Migrate ContractPackage to Package.
Source§

fn fees_purse( &mut self, protocol_version: ProtocolVersion, fees_purse_handling: FeesPurseHandling, ) -> Result<URef, TrackingCopyError>

Returns fee purse.
Source§

fn system_contract_named_key( &mut self, system_contract_name: &str, name: &str, ) -> Result<Option<Key>, Self::Error>

Returns named key from selected system contract.
Source§

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

Source§

type Error = Error

The type for the returned errors.
Source§

fn read_account_key( &mut self, account_hash: AccountHash, ) -> Result<Key, Self::Error>

Reads the entity key for a given account hash.
Source§

fn get_block_time(&self) -> Result<Option<BlockTime>, Self::Error>

Returns block time associated with checked out root hash.
Source§

fn get_balance_hold_config( &self, hold_kind: BalanceHoldAddrTag, ) -> Result<Option<(BlockTime, HoldBalanceHandling, u64)>, Self::Error>

Returns balance hold configuration settings for imputed kind of balance hold.
Source§

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

Gets the purse balance key for a given purse.
Source§

fn get_balance_hold_addresses( &self, purse_addr: URefAddr, ) -> Result<Vec<BalanceHoldAddr>, Self::Error>

Gets the balance hold keys for the imputed purse (if any).
Source§

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

Returns total balance.
Source§

fn get_available_balance(&mut self, key: Key) -> Result<Motes, Self::Error>

Returns the available balance, considering any holds from holds_epoch to now.
Source§

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

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

fn get_total_balance_with_proof( &self, key: Key, ) -> Result<(U512, TrieMerkleProof<Key, StoredValue>), Self::Error>

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

fn clear_expired_balance_holds( &mut self, purse_addr: URefAddr, filter: Vec<(BalanceHoldAddrTag, HoldsEpoch)>, ) -> Result<(), Self::Error>

Clear expired balance holds.
Source§

fn get_balance_holds( &mut self, purse_addr: URefAddr, block_time: BlockTime, interval: u64, ) -> Result<BTreeMap<BlockTime, BalanceHolds>, Self::Error>

Gets the balance holds for a given balance, without Merkle proofs.
Source§

fn get_balance_holds_with_proof( &self, purse_addr: URefAddr, ) -> Result<BTreeMap<BlockTime, BalanceHoldsWithProof>, Self::Error>

Gets the balance holds for a given balance, with Merkle proofs.
Source§

fn get_message_topics( &self, hash_addr: EntityAddr, ) -> Result<MessageTopics, Self::Error>

Returns the collection of message topics (if any) for a given HashAddr.
Source§

fn get_named_keys( &self, entity_addr: EntityAddr, ) -> Result<NamedKeys, Self::Error>

Returns the collection of named keys for a given AddressableEntity.
Source§

fn get_v1_entry_points( &self, entity_addr: EntityAddr, ) -> Result<EntryPoints, Self::Error>

Returns the collection of entry points for a given AddresableEntity.
Source§

fn get_package(&mut self, hash_addr: HashAddr) -> Result<Package, Self::Error>

Gets a package by hash.
Source§

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

Get a Contract record.
Source§

fn get_system_entity_registry(&self) -> Result<SystemHashRegistry, Self::Error>

Gets the system entity registry.
Source§

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

Gets the system checksum registry.
Source§

fn get_byte_code( &mut self, byte_code_hash: ByteCodeHash, ) -> Result<ByteCode, Self::Error>

Gets byte code by hash.

Auto Trait Implementations§

§

impl<R> Freeze for TrackingCopy<R>

§

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

§

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

§

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

§

impl<R> Unpin for TrackingCopy<R>

§

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

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

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