Skip to main content

dash_platform_queries/transition/
validation.rs

1use crate::Error;
2use dpp::{
3    consensus::{basic::BasicError, ConsensusError},
4    state_transition::{StateTransition, StateTransitionStructureValidation},
5    version::PlatformVersion,
6};
7
8/// Checks if an error is an UnsupportedFeatureError
9fn is_unsupported_feature_error(error: &ConsensusError) -> bool {
10    matches!(
11        error,
12        ConsensusError::BasicError(BasicError::UnsupportedFeatureError(_))
13    )
14}
15
16/// Ensures a state transition passes structure validation before broadcasting.
17///
18/// Note: UnsupportedFeatureError is allowed to pass through, as it indicates
19/// that structure validation is not implemented for that state transition type
20/// (e.g., identity-based state transitions). The platform will still perform
21/// validation during execution.
22pub fn ensure_valid_state_transition_structure(
23    state_transition: &StateTransition,
24    platform_version: &PlatformVersion,
25) -> Result<(), Error> {
26    let validation_result = state_transition.validate_structure(platform_version);
27    if validation_result.is_valid() {
28        Ok(())
29    } else {
30        // Allow UnsupportedFeatureError to pass through - this means structure
31        // validation is not implemented for this state transition type
32        let all_unsupported_feature_errors = validation_result
33            .errors
34            .iter()
35            .all(is_unsupported_feature_error);
36        if all_unsupported_feature_errors {
37            Ok(())
38        } else {
39            Err(validation_result.into())
40        }
41    }
42}