radix_engine_interface/api/
actor_key_value_entry_api.rs

1use radix_common::data::scrypto::{scrypto_decode, ScryptoDecode};
2use radix_engine_interface::api::key_value_entry_api::KeyValueEntryHandle;
3use radix_engine_interface::api::{ActorStateHandle, CollectionIndex, LockFlags};
4use sbor::rust::vec::Vec;
5
6pub trait SystemActorKeyValueEntryApi<E> {
7    /// Returns a handle for a specified key value entry in a collection. If an invalid collection
8    /// index or key is passed an error is returned.
9    fn actor_open_key_value_entry(
10        &mut self,
11        object_handle: ActorStateHandle,
12        collection_index: CollectionIndex,
13        key: &Vec<u8>,
14        flags: LockFlags,
15    ) -> Result<KeyValueEntryHandle, E>;
16
17    /// Removes an entry from a collection. If an invalid collection index or key is passed an
18    /// error is returned, otherwise the encoding of a value of the entry is returned.
19    fn actor_remove_key_value_entry(
20        &mut self,
21        object_handle: ActorStateHandle,
22        collection_index: CollectionIndex,
23        key: &Vec<u8>,
24    ) -> Result<Vec<u8>, E>;
25
26    /// Removes an entry from a collection. If an invalid collection index or key is passed an
27    /// error is returned, otherwise the value of the entry is returned.
28    fn actor_remove_key_value_entry_typed<V: ScryptoDecode>(
29        &mut self,
30        object_handle: ActorStateHandle,
31        collection_index: CollectionIndex,
32        key: &Vec<u8>,
33    ) -> Result<Option<V>, E> {
34        let removed = self.actor_remove_key_value_entry(object_handle, collection_index, key)?;
35        let rtn = scrypto_decode(&removed).unwrap();
36        Ok(rtn)
37    }
38}