pub trait ProgramStorage<N: Network>: Clone + Sync {
    type ProgramIDMap: for<'a> Map<'a, ProgramID<N>, IndexSet<Identifier<N>>>;
    type MappingIDMap: for<'a> Map<'a, (ProgramID<N>, Identifier<N>), Field<N>>;
    type KeyValueIDMap: for<'a> Map<'a, Field<N>, IndexMap<Field<N>, Field<N>>>;
    type KeyMap: for<'a> Map<'a, Field<N>, Plaintext<N>>;
    type ValueMap: for<'a> Map<'a, Field<N>, Value<N>>;

Show 26 methods fn open() -> Result<Self>; fn program_id_map(&self) -> &Self::ProgramIDMap; fn mapping_id_map(&self) -> &Self::MappingIDMap; fn key_value_id_map(&self) -> &Self::KeyValueIDMap; fn key_map(&self) -> &Self::KeyMap; fn value_map(&self) -> &Self::ValueMap; fn start_atomic(&self) { ... } fn is_atomic_in_progress(&self) -> bool { ... } fn abort_atomic(&self) { ... } fn finish_atomic(&self) -> Result<()> { ... } fn initialize_mapping(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>
    ) -> Result<()> { ... } fn insert_key_value(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>,
        key: Plaintext<N>,
        value: Value<N>
    ) -> Result<()> { ... } fn update_key_value(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>,
        key: Plaintext<N>,
        value: Value<N>
    ) -> Result<()> { ... } fn remove_key_value(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>,
        key: &Plaintext<N>
    ) -> Result<()> { ... } fn remove_mapping(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>
    ) -> Result<()> { ... } fn remove_program(&self, program_id: &ProgramID<N>) -> Result<()> { ... } fn contains_program(&self, program_id: &ProgramID<N>) -> Result<bool> { ... } fn contains_mapping(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>
    ) -> Result<bool> { ... } fn contains_key(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>,
        key: &Plaintext<N>
    ) -> Result<bool> { ... } fn get_mapping_names(
        &self,
        program_id: &ProgramID<N>
    ) -> Result<Option<IndexSet<Identifier<N>>>> { ... } fn get_mapping_id(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>
    ) -> Result<Option<Field<N>>> { ... } fn get_key_id(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>,
        key: &Plaintext<N>
    ) -> Result<Option<Field<N>>> { ... } fn get_key(&self, key_id: &Field<N>) -> Result<Option<Plaintext<N>>> { ... } fn get_value(
        &self,
        program_id: &ProgramID<N>,
        mapping_name: &Identifier<N>,
        key: &Plaintext<N>
    ) -> Result<Option<Value<N>>> { ... } fn get_value_from_key_id(
        &self,
        key_id: &Field<N>
    ) -> Result<Option<Value<N>>> { ... } fn get_checksum(&self) -> Result<Field<N>> { ... }
}
Expand description

A trait for program state storage. Note: For the program logic, see DeploymentStorage.

We define the mapping ID := Hash( program ID || mapping name ), and the key ID := Hash ( mapping ID || Hash(key) ), and the value ID := Hash ( key ID || Hash(value) ).

ProgramStorage emulates the following data structure:

// (program_id => (mapping_name => (key => value)))
IndexMap<ProgramID<N>, IndexMap<Identifier<N>, IndexMap<Key, Value>>>

Required Associated Types

The mapping of program ID to [mapping name].

The mapping of (program ID, mapping name) to mapping ID.

The mapping of mapping ID to [(key ID, value ID)].

The mapping of key ID to key.

The mapping of key ID to value.

Required Methods

Initializes the program state storage.

Returns the program ID map.

Returns the mapping ID map.

Returns the key-value ID map.

Returns the key map.

Returns the value map.

Provided Methods

Starts an atomic batch write operation.

Checks if an atomic batch is in progress.

Aborts an atomic batch write operation.

Finishes an atomic batch write operation.

Initializes the given program ID and mapping name in storage.

Stores the given (key, value) pair at the given program ID and mapping name in storage. If the key already exists, the method returns an error.

Stores the given (key, value) pair at the given program ID and mapping name in storage. If the key does not exist, the (key, value) pair is initialized. If the key already exists, the value is overwritten.

Removes the key-value pair for the given program ID, mapping name, and key from storage.

Removes the mapping for the given program ID and mapping name from storage, along with all associated key-value pairs in storage.

Removes the program for the given program ID from storage, along with all associated mappings and key-value pairs in storage.

Returns true if the given program ID exist.

Returns true if the given program ID and mapping name exist.

Returns true if the given program ID, mapping name, and key exist.

Returns the mapping names for the given program ID.

Returns the mapping ID for the given program ID and mapping name.

Returns the key ID for the given program ID, mapping name, and key.

Returns the key for the given key ID.

Returns the value for the given program ID, mapping name, and key.

Returns the value for the given key ID.

Returns the checksum.

Implementors