|
| 1 | +pub mod v0; |
| 2 | + |
| 3 | +use std::collections::{BTreeMap, BTreeSet}; |
| 4 | + |
| 5 | +use dpp::platform_value::Value; |
| 6 | +use dpp::validation::SimpleConsensusValidationResult; |
| 7 | +use dpp::version::PlatformVersion; |
| 8 | +use drive::query::TransactionArg; |
| 9 | +use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionAction; |
| 10 | + |
| 11 | +use crate::error::execution::ExecutionError; |
| 12 | +use crate::error::Error; |
| 13 | +use crate::execution::types::state_transition_execution_context::StateTransitionExecutionContext; |
| 14 | +use crate::execution::validation::state_transition::batch::action_validation::document::document_reference_validation::v0::DocumentReferenceValidationV0; |
| 15 | +use crate::platform_types::platform::PlatformStateRef; |
| 16 | + |
| 17 | +pub(crate) trait DocumentReferenceValidation { |
| 18 | + fn validate_document_references( |
| 19 | + &self, |
| 20 | + document_data: &BTreeMap<String, Value>, |
| 21 | + changed_fields: Option<&BTreeSet<String>>, |
| 22 | + platform: &PlatformStateRef, |
| 23 | + transaction: TransactionArg, |
| 24 | + execution_context: &mut StateTransitionExecutionContext, |
| 25 | + platform_version: &PlatformVersion, |
| 26 | + ) -> Result<SimpleConsensusValidationResult, Error>; |
| 27 | +} |
| 28 | + |
| 29 | +impl DocumentReferenceValidation for DocumentBaseTransitionAction { |
| 30 | + fn validate_document_references( |
| 31 | + &self, |
| 32 | + document_data: &BTreeMap<String, Value>, |
| 33 | + changed_fields: Option<&BTreeSet<String>>, |
| 34 | + platform: &PlatformStateRef, |
| 35 | + transaction: TransactionArg, |
| 36 | + execution_context: &mut StateTransitionExecutionContext, |
| 37 | + platform_version: &PlatformVersion, |
| 38 | + ) -> Result<SimpleConsensusValidationResult, Error> { |
| 39 | + match platform_version |
| 40 | + .drive_abci |
| 41 | + .validation_and_processing |
| 42 | + .state_transitions |
| 43 | + .batch_state_transition |
| 44 | + .document_reference_validation |
| 45 | + { |
| 46 | + 0 => self.validate_document_references_v0( |
| 47 | + document_data, |
| 48 | + changed_fields, |
| 49 | + platform, |
| 50 | + transaction, |
| 51 | + execution_context, |
| 52 | + platform_version, |
| 53 | + ), |
| 54 | + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { |
| 55 | + method: "DocumentBaseTransitionAction::validate_document_references".to_string(), |
| 56 | + known_versions: vec![0], |
| 57 | + received: version, |
| 58 | + })), |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments