Trait concordium_std::HasStateApi
source · [−]pub trait HasStateApi: Clone {
type EntryType: HasStateEntry;
type IterType: Iterator<Item = Self::EntryType>;
fn create_entry(&mut self, key: &[u8]) -> Result<Self::EntryType, StateError>;
fn lookup_entry(&self, key: &[u8]) -> Option<Self::EntryType>;
fn delete_entry(&mut self, key: Self::EntryType) -> Result<(), StateError>;
fn delete_prefix(&mut self, prefix: &[u8]) -> Result<bool, StateError>;
fn iterator(&self, prefix: &[u8]) -> Result<Self::IterType, StateError>;
fn delete_iterator(&mut self, iter: Self::IterType);
fn entry<K: AsRef<[u8]> + Into<Key>>(&mut self, key: K) -> EntryRaw<Self> { ... }
}
Expand description
Types which can serve as the contract state.
Required Associated Types
Required Methods
fn create_entry(&mut self, key: &[u8]) -> Result<Self::EntryType, StateError>
fn create_entry(&mut self, key: &[u8]) -> Result<Self::EntryType, StateError>
Create a new entry in the state. If an entry with the given key already exists then it is reset to an empty entry. If the part of the tree where the key points to is locked due to an acquired iterator then no entry is created, and an error will be returned.
fn lookup_entry(&self, key: &[u8]) -> Option<Self::EntryType>
fn lookup_entry(&self, key: &[u8]) -> Option<Self::EntryType>
Lookup an entry in the state.
fn delete_entry(&mut self, key: Self::EntryType) -> Result<(), StateError>
fn delete_entry(&mut self, key: Self::EntryType) -> Result<(), StateError>
Delete an entry. Returns an error if the entry did not exist, or if it is part of a locked subtree.
fn delete_prefix(&mut self, prefix: &[u8]) -> Result<bool, StateError>
fn delete_prefix(&mut self, prefix: &[u8]) -> Result<bool, StateError>
Delete the entire subtree. Returns whether any values were deleted, or an error if the given prefix is part of a locked subtree.
Get an iterator over a map in the state.
An iterator locks the subtree with the given prefix. Locking means that the structure of the tree cannot be altered, i.e., that entries cannot be created or deleted. Altering the data inside an entry of a locked subtree is, however, allowed.
Deleting iterators with
delete_iterator
is necessary to
unlock the subtree. To unlock a subtree with prefix
p1
, all iterators with prefixes p2
, where p2
is a prefix of p1
,
must be deleted.
Returns an error if the number of active iterators for the same prefix exceeds u32::MAX.
fn delete_iterator(&mut self, iter: Self::IterType)
fn delete_iterator(&mut self, iter: Self::IterType)
Delete an iterator.
See the iterator
method for why this is
necessary.
Provided Methods
Like lookup_entry
except that it consumes the
key and returns an EntryRaw
instead of an optional entry.
For maximal flexibility the function is parametrized by the type of key
with the intention that needless allocations are avoided for short
keys and existing entries. The most common examples of keys will be Vec<u8>
or fixed sized arrays [u8; N]
.