drive_abci/execution/validation/state_transition/processor/
mod.rs

1/// Processor traits.
2pub mod traits;
3pub(crate) mod v0;
4
5use crate::error::execution::ExecutionError;
6use crate::error::Error;
7use crate::execution::types::execution_event::ExecutionEvent;
8use crate::platform_types::platform::PlatformRef;
9use crate::rpc::core::CoreRPCLike;
10use dpp::block::block_info::BlockInfo;
11use dpp::prelude::ConsensusValidationResult;
12use dpp::state_transition::StateTransition;
13
14use crate::platform_types::platform_state::PlatformStateV0Methods;
15use drive::grovedb::TransactionArg;
16pub(crate) use traits::*;
17
18/// There are multiple stages in a state transition processing:
19///     Basic Structure
20///     Signature
21///     Balance
22///     Advanced Structure
23///     State
24///
25/// The structure validation verifies that the form of the state transition is good, for example
26/// that a contract is well formed, or that a document is valid against the contract.
27///
28/// Signature validation verifies signatures of a state transition, it will also verify
29/// signatures of keys for identity create and identity update. At this stage we will get back
30/// a partial identity.
31///
32/// Validate state verifies that there are no state based conflicts, for example that a document
33/// with a unique index isn't already taken.
34///
35pub(in crate::execution) fn process_state_transition<'a, C: CoreRPCLike>(
36    platform: &'a PlatformRef<C>,
37    block_info: &BlockInfo,
38    state_transition: StateTransition,
39    transaction: TransactionArg,
40) -> Result<ConsensusValidationResult<ExecutionEvent<'a>>, Error> {
41    let platform_version = platform.state.current_platform_version()?;
42    match platform_version
43        .drive_abci
44        .validation_and_processing
45        .process_state_transition
46    {
47        0 => v0::process_state_transition_v0(
48            platform,
49            block_info,
50            state_transition,
51            transaction,
52            platform_version,
53        ),
54        version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
55            method: "process_state_transition".to_string(),
56            known_versions: vec![0],
57            received: version,
58        })),
59    }
60}