[−][src]Trait transact::state::Write
state::Write
provides a way to write to a particular state storage system.
It provides the ability for the caller to either compute the next StateId
-
useful for validating expected results - or committing the results to an
underlying store.
A StateId
, in the context of Write, is used to indicate the
starting state on which the changes will be applied. It can be thought of
as the identifier of a checkpoint or snapshot.
All operations are made using StateChange
instances. These are the
ordered set of changes to be applied onto the given StateId
.
Implementations are expected to be thread-safe.
Associated Types
type StateId
A reference to a checkpoint in state. It could be a merkle hash for a merkle database.
type Key
The Key that is being stored in state.
type Value
The Value that is being stored in state.
Required methods
fn commit(
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
Given a StateId
and a slice of StateChange
values, persist the
state changes and return the resulting next StateId
value.
This function will persist the state values to the underlying storage mechanism.
Errors
Any issues with committing the processing results will return a
StateWriteError
.
fn compute_state_id(
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
Given a StateId
and a slice of StateChange
values, compute the
next StateId
value.
This function will compute the value of the next StateId
without
actually persisting the state changes. Effectively, it is a dry-run.
Returns the next StateId
value;
Errors
StateWriteError
is returned if any issues occur while trying to
generate this next id.
Implementors
impl Write for HashMapState
[src]
type StateId = String
type Key = String
type Value = Vec<u8>
fn commit(
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
[src]
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
fn compute_state_id(
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
[src]
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
impl Write for MerkleState
[src]
type StateId = String
type Key = String
type Value = Vec<u8>
fn commit(
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
[src]
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
fn compute_state_id(
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>
[src]
&self,
state_id: &Self::StateId,
state_changes: &[StateChange]
) -> Result<Self::StateId, StateWriteError>