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
6#[allow(clippy::ptr_arg)]
7pub trait SystemActorKeyValueEntryApi<E> {
8    /// Returns a handle for a specified key value entry in a collection. If an invalid collection
9    /// index or key is passed an error is returned.
10    fn actor_open_key_value_entry(
11        &mut self,
12        object_handle: ActorStateHandle,
13        collection_index: CollectionIndex,
14        key: &Vec<u8>,
15        flags: LockFlags,
16    ) -> Result<KeyValueEntryHandle, E>;
17
18    /// Removes an entry from a collection. If an invalid collection index or key is passed an
19    /// error is returned, otherwise the encoding of a value of the entry is returned.
20    fn actor_remove_key_value_entry(
21        &mut self,
22        object_handle: ActorStateHandle,
23        collection_index: CollectionIndex,
24        key: &Vec<u8>,
25    ) -> Result<Vec<u8>, E>;
26
27    /// Removes an entry from a collection. If an invalid collection index or key is passed an
28    /// error is returned, otherwise the value of the entry is returned.
29    fn actor_remove_key_value_entry_typed<V: ScryptoDecode>(
30        &mut self,
31        object_handle: ActorStateHandle,
32        collection_index: CollectionIndex,
33        key: &Vec<u8>,
34    ) -> Result<Option<V>, E> {
35        let removed = self.actor_remove_key_value_entry(object_handle, collection_index, key)?;
36        let rtn = scrypto_decode(&removed).unwrap();
37        Ok(rtn)
38    }
39}