pub trait FinalizeStorage<N: Network>:
'static
+ Clone
+ Send
+ Sync {
type CommitteeStorage: CommitteeStorage<N>;
type ProgramIDMap: for<'a> Map<'a, ProgramID<N>, IndexSet<Identifier<N>>>;
type KeyValueMap: for<'a> NestedMap<'a, (ProgramID<N>, Identifier<N>), Plaintext<N>, Value<N>>;
Show 32 methods
// Required methods
fn open<S: Clone + Into<StorageMode>>(storage: S) -> Result<Self>;
fn committee_store(&self) -> &CommitteeStore<N, Self::CommitteeStorage>;
fn program_id_map(&self) -> &Self::ProgramIDMap;
fn key_value_map(&self) -> &Self::KeyValueMap;
fn storage_mode(&self) -> &StorageMode;
// Provided methods
fn start_atomic(&self) { ... }
fn is_atomic_in_progress(&self) -> bool { ... }
fn atomic_checkpoint(&self) { ... }
fn clear_latest_checkpoint(&self) { ... }
fn atomic_rewind(&self) { ... }
fn abort_atomic(&self) { ... }
fn finish_atomic(&self) -> Result<()> { ... }
fn initialize_mapping(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
) -> Result<FinalizeOperation<N>> { ... }
fn insert_key_value(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: Plaintext<N>,
value: Value<N>,
) -> Result<FinalizeOperation<N>> { ... }
fn update_key_value(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: Plaintext<N>,
value: Value<N>,
) -> Result<FinalizeOperation<N>> { ... }
fn remove_key_value(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<Option<FinalizeOperation<N>>> { ... }
fn replace_mapping(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
entries: Vec<(Plaintext<N>, Value<N>)>,
) -> Result<FinalizeOperation<N>> { ... }
fn remove_mapping(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
) -> Result<FinalizeOperation<N>> { ... }
fn remove_program(&self, program_id: &ProgramID<N>) -> Result<()> { ... }
fn contains_program_confirmed(
&self,
program_id: &ProgramID<N>,
) -> Result<bool> { ... }
fn contains_mapping_confirmed(
&self,
program_id: &ProgramID<N>,
mapping_name: &Identifier<N>,
) -> Result<bool> { ... }
fn contains_mapping_speculative(
&self,
program_id: &ProgramID<N>,
mapping_name: &Identifier<N>,
) -> Result<bool> { ... }
fn contains_key_confirmed(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<bool> { ... }
fn contains_key_speculative(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<bool> { ... }
fn get_mapping_names_confirmed(
&self,
program_id: &ProgramID<N>,
) -> Result<Option<IndexSet<Identifier<N>>>> { ... }
fn get_mapping_names_speculative(
&self,
program_id: &ProgramID<N>,
) -> Result<Option<IndexSet<Identifier<N>>>> { ... }
fn get_mapping_confirmed(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
) -> Result<Vec<(Plaintext<N>, Value<N>)>> { ... }
fn get_mapping_speculative(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
) -> Result<Vec<(Plaintext<N>, Value<N>)>> { ... }
fn get_value_confirmed(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<Option<Value<N>>> { ... }
fn get_value_speculative(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<Option<Value<N>>> { ... }
fn get_checksum_confirmed(&self) -> Result<Field<N>> { ... }
fn get_checksum_pending(&self) -> Result<Field<N>> { ... }
}
Expand description
A trait for program state storage. Note: For the program logic, see DeploymentStorage
.
We define the key ID := Hash ( program ID || mapping name || Hash(key) )
and the value ID := Hash ( key ID || Hash(value) )
.
FinalizeStorage
emulates the following data structure:
// (program_id => (mapping_name => (key => value)))
BTreeMap<ProgramID<N>, BTreeMap<Identifier<N>, BTreeMap<Key, Value>>>
Required Associated Types§
Sourcetype CommitteeStorage: CommitteeStorage<N>
type CommitteeStorage: CommitteeStorage<N>
The committee storage.
Sourcetype ProgramIDMap: for<'a> Map<'a, ProgramID<N>, IndexSet<Identifier<N>>>
type ProgramIDMap: for<'a> Map<'a, ProgramID<N>, IndexSet<Identifier<N>>>
The mapping of program ID
to [mapping name]
.
Sourcetype KeyValueMap: for<'a> NestedMap<'a, (ProgramID<N>, Identifier<N>), Plaintext<N>, Value<N>>
type KeyValueMap: for<'a> NestedMap<'a, (ProgramID<N>, Identifier<N>), Plaintext<N>, Value<N>>
The mapping of (program ID, mapping name)
to [(key, value)]
.
Required Methods§
Sourcefn open<S: Clone + Into<StorageMode>>(storage: S) -> Result<Self>
fn open<S: Clone + Into<StorageMode>>(storage: S) -> Result<Self>
Initializes the program state storage.
Sourcefn committee_store(&self) -> &CommitteeStore<N, Self::CommitteeStorage>
fn committee_store(&self) -> &CommitteeStore<N, Self::CommitteeStorage>
Returns the committee storage.
Sourcefn program_id_map(&self) -> &Self::ProgramIDMap
fn program_id_map(&self) -> &Self::ProgramIDMap
Returns the program ID map.
Sourcefn key_value_map(&self) -> &Self::KeyValueMap
fn key_value_map(&self) -> &Self::KeyValueMap
Returns the key-value map.
Sourcefn storage_mode(&self) -> &StorageMode
fn storage_mode(&self) -> &StorageMode
Returns the storage mode.
Provided Methods§
Sourcefn start_atomic(&self)
fn start_atomic(&self)
Starts an atomic batch write operation.
Sourcefn is_atomic_in_progress(&self) -> bool
fn is_atomic_in_progress(&self) -> bool
Checks if an atomic batch is in progress.
Sourcefn atomic_checkpoint(&self)
fn atomic_checkpoint(&self)
Checkpoints the atomic batch.
Sourcefn clear_latest_checkpoint(&self)
fn clear_latest_checkpoint(&self)
Clears the latest atomic batch checkpoint.
Sourcefn atomic_rewind(&self)
fn atomic_rewind(&self)
Rewinds the atomic batch to the previous checkpoint.
Sourcefn abort_atomic(&self)
fn abort_atomic(&self)
Aborts an atomic batch write operation.
Sourcefn finish_atomic(&self) -> Result<()>
fn finish_atomic(&self) -> Result<()>
Finishes an atomic batch write operation.
Sourcefn initialize_mapping(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
) -> Result<FinalizeOperation<N>>
fn initialize_mapping( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, ) -> Result<FinalizeOperation<N>>
Initializes the given program ID
and mapping name
in storage.
If the mapping name
is already initialized, an error is returned.
Sourcefn insert_key_value(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: Plaintext<N>,
value: Value<N>,
) -> Result<FinalizeOperation<N>>
fn insert_key_value( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, key: Plaintext<N>, value: Value<N>, ) -> Result<FinalizeOperation<N>>
Stores the given (key, value)
pair at the given program ID
and mapping name
in storage.
If the mapping name
is not initialized, an error is returned.
If the key
already exists, the method returns an error.
Sourcefn update_key_value(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: Plaintext<N>,
value: Value<N>,
) -> Result<FinalizeOperation<N>>
fn update_key_value( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, key: Plaintext<N>, value: Value<N>, ) -> Result<FinalizeOperation<N>>
Stores the given (key, value)
pair at the given program ID
and mapping name
in storage.
If the mapping name
is not initialized, an error is returned.
If the key
does not exist, the (key, value)
pair is initialized.
If the key
already exists, the value
is overwritten.
Sourcefn remove_key_value(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<Option<FinalizeOperation<N>>>
fn remove_key_value( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, key: &Plaintext<N>, ) -> Result<Option<FinalizeOperation<N>>>
Removes the key-value pair for the given program ID
, mapping name
, and key
from storage.
If the key
does not exist, None
is returned.
Sourcefn replace_mapping(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
entries: Vec<(Plaintext<N>, Value<N>)>,
) -> Result<FinalizeOperation<N>>
fn replace_mapping( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, entries: Vec<(Plaintext<N>, Value<N>)>, ) -> Result<FinalizeOperation<N>>
Replaces the mapping for the given program ID
and mapping name
from storage,
with the given key-value
pairs.
Sourcefn remove_mapping(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
) -> Result<FinalizeOperation<N>>
fn remove_mapping( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, ) -> Result<FinalizeOperation<N>>
Removes the mapping for the given program ID
and mapping name
from storage,
along with all associated key-value pairs in storage.
Sourcefn remove_program(&self, program_id: &ProgramID<N>) -> Result<()>
fn remove_program(&self, program_id: &ProgramID<N>) -> Result<()>
Removes the program for the given program ID
from storage,
along with all associated mappings and key-value pairs in storage.
Sourcefn contains_program_confirmed(&self, program_id: &ProgramID<N>) -> Result<bool>
fn contains_program_confirmed(&self, program_id: &ProgramID<N>) -> Result<bool>
Returns true
if the given program ID
exist.
Sourcefn contains_mapping_confirmed(
&self,
program_id: &ProgramID<N>,
mapping_name: &Identifier<N>,
) -> Result<bool>
fn contains_mapping_confirmed( &self, program_id: &ProgramID<N>, mapping_name: &Identifier<N>, ) -> Result<bool>
Returns true
if the given program ID
and mapping name
exist.
Sourcefn contains_mapping_speculative(
&self,
program_id: &ProgramID<N>,
mapping_name: &Identifier<N>,
) -> Result<bool>
fn contains_mapping_speculative( &self, program_id: &ProgramID<N>, mapping_name: &Identifier<N>, ) -> Result<bool>
Returns true
if the given program ID
and mapping name
exist.
Sourcefn contains_key_confirmed(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<bool>
fn contains_key_confirmed( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, key: &Plaintext<N>, ) -> Result<bool>
Returns true
if the given program ID
, mapping name
, and key
exist.
Sourcefn contains_key_speculative(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<bool>
fn contains_key_speculative( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, key: &Plaintext<N>, ) -> Result<bool>
Returns true
if the given program ID
, mapping name
, and key
exist.
Sourcefn get_mapping_names_confirmed(
&self,
program_id: &ProgramID<N>,
) -> Result<Option<IndexSet<Identifier<N>>>>
fn get_mapping_names_confirmed( &self, program_id: &ProgramID<N>, ) -> Result<Option<IndexSet<Identifier<N>>>>
Returns the confirmed mapping names for the given program ID
.
Sourcefn get_mapping_names_speculative(
&self,
program_id: &ProgramID<N>,
) -> Result<Option<IndexSet<Identifier<N>>>>
fn get_mapping_names_speculative( &self, program_id: &ProgramID<N>, ) -> Result<Option<IndexSet<Identifier<N>>>>
Returns the speculative mapping names for the given program ID
.
Sourcefn get_mapping_confirmed(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
) -> Result<Vec<(Plaintext<N>, Value<N>)>>
fn get_mapping_confirmed( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, ) -> Result<Vec<(Plaintext<N>, Value<N>)>>
Returns the confirmed mapping entries for the given program ID
and mapping name
.
Sourcefn get_mapping_speculative(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
) -> Result<Vec<(Plaintext<N>, Value<N>)>>
fn get_mapping_speculative( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, ) -> Result<Vec<(Plaintext<N>, Value<N>)>>
Returns the speculative mapping entries for the given program ID
and mapping name
.
Sourcefn get_value_confirmed(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<Option<Value<N>>>
fn get_value_confirmed( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, key: &Plaintext<N>, ) -> Result<Option<Value<N>>>
Returns the confirmed value for the given program ID
, mapping name
, and key
.
Sourcefn get_value_speculative(
&self,
program_id: ProgramID<N>,
mapping_name: Identifier<N>,
key: &Plaintext<N>,
) -> Result<Option<Value<N>>>
fn get_value_speculative( &self, program_id: ProgramID<N>, mapping_name: Identifier<N>, key: &Plaintext<N>, ) -> Result<Option<Value<N>>>
Returns the speculative value for the given program ID
, mapping name
, and key
.
Sourcefn get_checksum_confirmed(&self) -> Result<Field<N>>
fn get_checksum_confirmed(&self) -> Result<Field<N>>
Returns the confirmed checksum of the finalize storage.
Sourcefn get_checksum_pending(&self) -> Result<Field<N>>
fn get_checksum_pending(&self) -> Result<Field<N>>
Returns the pending checksum of the finalize storage.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.