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>
impl<R> TrackingCopy<R>
Sourcepub fn new(
reader: R,
max_query_depth: u64,
enable_addressable_entity: bool,
) -> TrackingCopy<R>
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.
Returns a shared reference to the reader used to access the state.
Sourcepub fn fork(&self) -> TrackingCopy<&TrackingCopy<R>>
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.
Sourcepub fn fork2(&self) -> Self
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.
Sourcepub fn apply_changes(
&mut self,
effects: Effects,
cache: TrackingCopyCache,
messages: Messages,
)
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.
Sourcepub fn effects(&self) -> Effects
pub fn effects(&self) -> Effects
Returns a copy of the execution effects cached by this instance.
Sourcepub fn cache(&self) -> TrackingCopyCache
pub fn cache(&self) -> TrackingCopyCache
Returns copy of cache.
Sourcepub fn destructure(self) -> (Vec<(Key, StoredValue)>, BTreeSet<Key>, Effects)
pub fn destructure(self) -> (Vec<(Key, StoredValue)>, BTreeSet<Key>, Effects)
Destructure cached entries.
Sourcepub fn enable_addressable_entity(&self) -> bool
pub fn enable_addressable_entity(&self) -> bool
Enable the addressable entity and migrate accounts/contracts to entities.
Sourcepub fn get(
&mut self,
key: &Key,
) -> Result<Option<StoredValue>, TrackingCopyError>
pub fn get( &mut self, key: &Key, ) -> Result<Option<StoredValue>, TrackingCopyError>
Get record by key.
Sourcepub fn get_keys(
&self,
key_tag: &KeyTag,
) -> Result<BTreeSet<Key>, TrackingCopyError>
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.
Sourcepub fn get_keys_by_prefix(
&self,
key_prefix: &KeyPrefix,
) -> Result<BTreeSet<Key>, TrackingCopyError>
pub fn get_keys_by_prefix( &self, key_prefix: &KeyPrefix, ) -> Result<BTreeSet<Key>, TrackingCopyError>
Get keys by prefix.
Sourcepub fn read(
&mut self,
key: &Key,
) -> Result<Option<StoredValue>, TrackingCopyError>
pub fn read( &mut self, key: &Key, ) -> Result<Option<StoredValue>, TrackingCopyError>
Reads the value stored under key.
Sourcepub fn read_first(
&mut self,
keys: &[&Key],
) -> Result<Option<StoredValue>, TrackingCopyError>
pub fn read_first( &mut self, keys: &[&Key], ) -> Result<Option<StoredValue>, TrackingCopyError>
Reads the first value stored under the keys in keys.
Sourcepub fn write(&mut self, key: Key, value: StoredValue)
pub fn write(&mut self, key: Key, value: StoredValue)
Writes value under key. Note that the written value is only cached.
Sourcepub 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,
)
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.
Sourcepub fn add(
&mut self,
key: Key,
value: StoredValue,
) -> Result<AddResult, TrackingCopyError>
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.
Sourcepub fn query(
&self,
base_key: Key,
path: &[String],
) -> Result<TrackingCopyQueryResult, TrackingCopyError>
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>
impl<R: Clone> Clone for TrackingCopy<R>
Source§fn clone(&self) -> TrackingCopy<R>
fn clone(&self) -> TrackingCopy<R>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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.
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
type Error = <R as StateReader>::Error
Source§fn read(&self, key: &Key) -> Result<Option<StoredValue>, Self::Error>
fn read(&self, key: &Key) -> Result<Option<StoredValue>, Self::Error>
Source§fn read_with_proof(
&self,
key: &Key,
) -> Result<Option<TrieMerkleProof<Key, StoredValue>>, Self::Error>
fn read_with_proof( &self, key: &Key, ) -> Result<Option<TrieMerkleProof<Key, StoredValue>>, Self::Error>
Source§impl<R> TrackingCopyEntityExt<R> for TrackingCopy<R>
impl<R> TrackingCopyEntityExt<R> for TrackingCopy<R>
Source§fn runtime_footprint_by_entity_addr(
&self,
entity_addr: EntityAddr,
) -> Result<RuntimeFootprint, Self::Error>
fn runtime_footprint_by_entity_addr( &self, entity_addr: EntityAddr, ) -> Result<RuntimeFootprint, Self::Error>
Source§fn runtime_footprint_by_hash_addr(
&mut self,
hash_addr: HashAddr,
) -> Result<RuntimeFootprint, Self::Error>
fn runtime_footprint_by_hash_addr( &mut self, hash_addr: HashAddr, ) -> Result<RuntimeFootprint, Self::Error>
Source§fn runtime_footprint_by_account_hash(
&mut self,
protocol_version: ProtocolVersion,
account_hash: AccountHash,
) -> Result<(EntityAddr, RuntimeFootprint), Self::Error>
fn runtime_footprint_by_account_hash( &mut self, protocol_version: ProtocolVersion, account_hash: AccountHash, ) -> Result<(EntityAddr, RuntimeFootprint), Self::Error>
Source§fn system_entity_runtime_footprint(
&mut self,
protocol_version: ProtocolVersion,
) -> Result<(EntityAddr, RuntimeFootprint, ContextAccessRights), TrackingCopyError>
fn system_entity_runtime_footprint( &mut self, protocol_version: ProtocolVersion, ) -> Result<(EntityAddr, RuntimeFootprint, ContextAccessRights), TrackingCopyError>
Source§fn migrate_named_keys(
&mut self,
entity_addr: EntityAddr,
named_keys: NamedKeys,
) -> Result<(), Self::Error>
fn migrate_named_keys( &mut self, entity_addr: EntityAddr, named_keys: NamedKeys, ) -> Result<(), Self::Error>
Source§fn migrate_entry_points(
&mut self,
entity_addr: EntityAddr,
entry_points: EntryPoints,
) -> Result<(), Self::Error>
fn migrate_entry_points( &mut self, entity_addr: EntityAddr, entry_points: EntryPoints, ) -> Result<(), Self::Error>
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>
fn upsert_uref_to_named_keys( &mut self, entity_addr: EntityAddr, name: &str, named_keys: &NamedKeys, uref: URef, stored_value: StoredValue, ) -> Result<(), Self::Error>
Source§fn migrate_account(
&mut self,
account_hash: AccountHash,
protocol_version: ProtocolVersion,
) -> Result<(), Self::Error>
fn migrate_account( &mut self, account_hash: AccountHash, protocol_version: ProtocolVersion, ) -> Result<(), Self::Error>
Source§fn create_new_addressable_entity_on_transfer(
&mut self,
account_hash: AccountHash,
main_purse: URef,
protocol_version: ProtocolVersion,
) -> Result<(), Self::Error>
fn create_new_addressable_entity_on_transfer( &mut self, account_hash: AccountHash, main_purse: URef, protocol_version: ProtocolVersion, ) -> Result<(), Self::Error>
Source§fn create_addressable_entity_from_account(
&mut self,
account: Account,
protocol_version: ProtocolVersion,
) -> Result<(), Self::Error>
fn create_addressable_entity_from_account( &mut self, account: Account, protocol_version: ProtocolVersion, ) -> Result<(), Self::Error>
Source§fn migrate_package(
&mut self,
legacy_package_key: Key,
protocol_version: ProtocolVersion,
) -> Result<(), Self::Error>
fn migrate_package( &mut self, legacy_package_key: Key, protocol_version: ProtocolVersion, ) -> Result<(), Self::Error>
Source§fn fees_purse(
&mut self,
protocol_version: ProtocolVersion,
fees_purse_handling: FeesPurseHandling,
) -> Result<URef, TrackingCopyError>
fn fees_purse( &mut self, protocol_version: ProtocolVersion, fees_purse_handling: FeesPurseHandling, ) -> Result<URef, TrackingCopyError>
Source§impl<R> TrackingCopyExt<R> for TrackingCopy<R>
impl<R> TrackingCopyExt<R> for TrackingCopy<R>
Source§fn read_account_key(
&mut self,
account_hash: AccountHash,
) -> Result<Key, Self::Error>
fn read_account_key( &mut self, account_hash: AccountHash, ) -> Result<Key, Self::Error>
Source§fn get_block_time(&self) -> Result<Option<BlockTime>, Self::Error>
fn get_block_time(&self) -> Result<Option<BlockTime>, Self::Error>
Source§fn get_balance_hold_config(
&self,
hold_kind: BalanceHoldAddrTag,
) -> Result<Option<(BlockTime, HoldBalanceHandling, u64)>, Self::Error>
fn get_balance_hold_config( &self, hold_kind: BalanceHoldAddrTag, ) -> Result<Option<(BlockTime, HoldBalanceHandling, u64)>, Self::Error>
Source§fn get_purse_balance_key(&self, purse_key: Key) -> Result<Key, Self::Error>
fn get_purse_balance_key(&self, purse_key: Key) -> Result<Key, Self::Error>
Source§fn get_balance_hold_addresses(
&self,
purse_addr: URefAddr,
) -> Result<Vec<BalanceHoldAddr>, Self::Error>
fn get_balance_hold_addresses( &self, purse_addr: URefAddr, ) -> Result<Vec<BalanceHoldAddr>, Self::Error>
Source§fn get_available_balance(&mut self, key: Key) -> Result<Motes, Self::Error>
fn get_available_balance(&mut self, key: Key) -> Result<Motes, Self::Error>
Source§fn get_purse_balance_key_with_proof(
&self,
purse_key: Key,
) -> Result<(Key, TrieMerkleProof<Key, StoredValue>), Self::Error>
fn get_purse_balance_key_with_proof( &self, purse_key: Key, ) -> Result<(Key, TrieMerkleProof<Key, StoredValue>), Self::Error>
Source§fn get_total_balance_with_proof(
&self,
key: Key,
) -> Result<(U512, TrieMerkleProof<Key, StoredValue>), Self::Error>
fn get_total_balance_with_proof( &self, key: Key, ) -> Result<(U512, TrieMerkleProof<Key, StoredValue>), Self::Error>
Source§fn clear_expired_balance_holds(
&mut self,
purse_addr: URefAddr,
filter: Vec<(BalanceHoldAddrTag, HoldsEpoch)>,
) -> Result<(), Self::Error>
fn clear_expired_balance_holds( &mut self, purse_addr: URefAddr, filter: Vec<(BalanceHoldAddrTag, HoldsEpoch)>, ) -> Result<(), Self::Error>
Source§fn get_balance_holds(
&mut self,
purse_addr: URefAddr,
block_time: BlockTime,
interval: u64,
) -> Result<BTreeMap<BlockTime, BalanceHolds>, Self::Error>
fn get_balance_holds( &mut self, purse_addr: URefAddr, block_time: BlockTime, interval: u64, ) -> Result<BTreeMap<BlockTime, BalanceHolds>, Self::Error>
Source§fn get_balance_holds_with_proof(
&self,
purse_addr: URefAddr,
) -> Result<BTreeMap<BlockTime, BalanceHoldsWithProof>, Self::Error>
fn get_balance_holds_with_proof( &self, purse_addr: URefAddr, ) -> Result<BTreeMap<BlockTime, BalanceHoldsWithProof>, Self::Error>
Source§fn get_message_topics(
&self,
hash_addr: EntityAddr,
) -> Result<MessageTopics, Self::Error>
fn get_message_topics( &self, hash_addr: EntityAddr, ) -> Result<MessageTopics, Self::Error>
Source§fn get_named_keys(
&self,
entity_addr: EntityAddr,
) -> Result<NamedKeys, Self::Error>
fn get_named_keys( &self, entity_addr: EntityAddr, ) -> Result<NamedKeys, Self::Error>
Source§fn get_v1_entry_points(
&self,
entity_addr: EntityAddr,
) -> Result<EntryPoints, Self::Error>
fn get_v1_entry_points( &self, entity_addr: EntityAddr, ) -> Result<EntryPoints, Self::Error>
Source§fn get_package(&mut self, hash_addr: HashAddr) -> Result<Package, Self::Error>
fn get_package(&mut self, hash_addr: HashAddr) -> Result<Package, Self::Error>
Source§fn get_contract(
&mut self,
contract_hash: ContractHash,
) -> Result<Contract, Self::Error>
fn get_contract( &mut self, contract_hash: ContractHash, ) -> Result<Contract, Self::Error>
Source§fn get_system_entity_registry(&self) -> Result<SystemHashRegistry, Self::Error>
fn get_system_entity_registry(&self) -> Result<SystemHashRegistry, Self::Error>
Source§fn get_checksum_registry(
&mut self,
) -> Result<Option<ChecksumRegistry>, Self::Error>
fn get_checksum_registry( &mut self, ) -> Result<Option<ChecksumRegistry>, Self::Error>
Source§fn get_byte_code(
&mut self,
byte_code_hash: ByteCodeHash,
) -> Result<ByteCode, Self::Error>
fn get_byte_code( &mut self, byte_code_hash: ByteCodeHash, ) -> Result<ByteCode, Self::Error>
Auto Trait Implementations§
impl<R> Freeze for TrackingCopy<R>
impl<R> RefUnwindSafe for TrackingCopy<R>where
R: RefUnwindSafe,
impl<R> Send for TrackingCopy<R>
impl<R> Sync for TrackingCopy<R>
impl<R> Unpin for TrackingCopy<R>
impl<R> UnwindSafe for TrackingCopy<R>where
R: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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