From 8ec166f905621ddc3d04f34153f5db3fed51aacf Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 1 Nov 2023 22:08:16 +0700 Subject: [PATCH 1/3] chore: version validate_instant_asset_lock_proof_structure --- .../instant/instant_asset_lock_proof.rs | 42 ++++++++----------- .../asset_lock_proof/instant/methods/mod.rs | 1 + .../instant/methods/validate_structure/mod.rs | 3 ++ .../methods/validate_structure/v0/mod.rs | 35 ++++++++++++++++ .../asset_lock_proof/instant/mod.rs | 1 + .../src/version/dpp_versions.rs | 1 + .../src/version/mocks/v2_test.rs | 1 + .../src/version/mocks/v3_test.rs | 1 + .../rs-platform-version/src/version/v1.rs | 1 + 9 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/mod.rs create mode 100644 packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs create mode 100644 packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs diff --git a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs index ac5a96d481c..5d11032960d 100644 --- a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +++ b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs @@ -10,7 +10,8 @@ use crate::consensus::basic::identity::IdentityAssetLockProofLockedTransactionMi use serde::de::Error as DeError; use serde::ser::Error as SerError; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use platform_version::version::PlatformVersion; +use platform_version::version::{FeatureVersion, PlatformVersion}; +use crate::identity::state_transition::asset_lock_proof::instant::methods; use crate::identity::state_transition::asset_lock_proof::validate_asset_lock_transaction_structure::validate_asset_lock_transaction_structure; use crate::prelude::Identifier; @@ -159,36 +160,29 @@ impl InstantAssetLockProof { .map_err(|e| ProtocolError::EncodingError(e.to_string())) } - // TODO: Versioning /// Validate Instant Asset Lock Proof structure #[cfg(feature = "validation")] pub fn validate_structure( &self, platform_version: &PlatformVersion, ) -> Result { - let mut result = SimpleConsensusValidationResult::default(); - - let transaction_id = self.transaction().txid(); - if self.instant_lock().txid != transaction_id { - result.add_error(IdentityAssetLockProofLockedTransactionMismatchError::new( - self.instant_lock().txid, - transaction_id, - )); - - return Ok(result); - } - - let validate_transaction_result = validate_asset_lock_transaction_structure( - self.transaction(), - self.output_index(), - platform_version, - )?; - - if !validate_transaction_result.is_valid() { - result.merge(validate_transaction_result); + match platform_version + .dpp + .state_transitions + .identities + .asset_locks + .validate_instant_asset_lock_proof_structure + { + 0 => methods::validate_structure::validate_instant_asset_lock_proof_structure_v0( + self, + platform_version, + ), + version => Err(ProtocolError::UnknownVersionMismatch { + method: "validate_instant_asset_lock_proof_structure".to_string(), + known_versions: vec![0], + received: version, + }), } - - Ok(result) } } diff --git a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/mod.rs b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/mod.rs new file mode 100644 index 00000000000..7b1bcf11037 --- /dev/null +++ b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/mod.rs @@ -0,0 +1 @@ +pub mod validate_structure; diff --git a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs new file mode 100644 index 00000000000..c4d78cf1d08 --- /dev/null +++ b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs @@ -0,0 +1,3 @@ +mod v0; + +pub use v0::validate_instant_asset_lock_proof_structure_v0; diff --git a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs new file mode 100644 index 00000000000..1ebf37418bd --- /dev/null +++ b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs @@ -0,0 +1,35 @@ +use platform_version::version::PlatformVersion; +use crate::consensus::basic::identity::IdentityAssetLockProofLockedTransactionMismatchError; +use crate::identity::state_transition::asset_lock_proof::InstantAssetLockProof; +use crate::identity::state_transition::asset_lock_proof::validate_asset_lock_transaction_structure::validate_asset_lock_transaction_structure; +use crate::ProtocolError; +use crate::validation::SimpleConsensusValidationResult; + +pub fn validate_instant_asset_lock_proof_structure_v0( + proof: &InstantAssetLockProof, + platform_version: &PlatformVersion, +) -> Result { + let mut result = SimpleConsensusValidationResult::default(); + + let transaction_id = proof.transaction().txid(); + if proof.instant_lock().txid != transaction_id { + result.add_error(IdentityAssetLockProofLockedTransactionMismatchError::new( + proof.instant_lock().txid, + transaction_id, + )); + + return Ok(result); + } + + let validate_transaction_result = validate_asset_lock_transaction_structure( + proof.transaction(), + proof.output_index(), + platform_version, + )?; + + if !validate_transaction_result.is_valid() { + result.merge(validate_transaction_result); + } + + Ok(result) +} diff --git a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/mod.rs b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/mod.rs index 017076fe68c..d259f39556c 100644 --- a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/mod.rs +++ b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/mod.rs @@ -1,3 +1,4 @@ pub use instant_asset_lock_proof::*; mod instant_asset_lock_proof; +mod methods; diff --git a/packages/rs-platform-version/src/version/dpp_versions.rs b/packages/rs-platform-version/src/version/dpp_versions.rs index 7fba8e1516b..6c271f17f2e 100644 --- a/packages/rs-platform-version/src/version/dpp_versions.rs +++ b/packages/rs-platform-version/src/version/dpp_versions.rs @@ -28,6 +28,7 @@ pub struct IdentityTransitionVersions { #[derive(Clone, Debug, Default)] pub struct IdentityTransitionAssetLockVersions { pub validate_asset_lock_transaction_structure: FeatureVersion, + pub validate_instant_asset_lock_proof_structure: FeatureVersion, } #[derive(Clone, Debug, Default)] diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index e3d56d0e396..481b2b0a6a3 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -825,6 +825,7 @@ pub(crate) const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { identities: IdentityTransitionVersions { asset_locks: IdentityTransitionAssetLockVersions { validate_asset_lock_transaction_structure: 0, + validate_instant_asset_lock_proof_structure: 0, }, }, }, diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index 79de6ae7c57..846fbf9b013 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -825,6 +825,7 @@ pub(crate) const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { identities: IdentityTransitionVersions { asset_locks: IdentityTransitionAssetLockVersions { validate_asset_lock_transaction_structure: 0, + validate_instant_asset_lock_proof_structure: 0, }, }, }, diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index 2bb81da1fc5..f53927ca66f 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -822,6 +822,7 @@ pub(super) const PLATFORM_V1: PlatformVersion = PlatformVersion { identities: IdentityTransitionVersions { asset_locks: IdentityTransitionAssetLockVersions { validate_asset_lock_transaction_structure: 0, + validate_instant_asset_lock_proof_structure: 0, }, }, }, From 59e2bb31a998b42257f611468aa3cd40a30db34a Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 2 Nov 2023 07:57:57 +0700 Subject: [PATCH 2/3] chore: add visibility setting --- .../instant/methods/validate_structure/v0/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs index 1ebf37418bd..c2f923478f6 100644 --- a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs +++ b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs @@ -5,7 +5,7 @@ use crate::identity::state_transition::asset_lock_proof::validate_asset_lock_tra use crate::ProtocolError; use crate::validation::SimpleConsensusValidationResult; -pub fn validate_instant_asset_lock_proof_structure_v0( +pub(in crate::identity::state_transition::asset_lock_proof::instant) fn validate_instant_asset_lock_proof_structure_v0( proof: &InstantAssetLockProof, platform_version: &PlatformVersion, ) -> Result { From 286493b97681c09d0c1a8f3d932ff30954569299 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 2 Nov 2023 08:14:03 +0700 Subject: [PATCH 3/3] fix: invalid re-export --- .../asset_lock_proof/instant/methods/validate_structure/mod.rs | 2 +- .../instant/methods/validate_structure/v0/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs index c4d78cf1d08..9743445699b 100644 --- a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs +++ b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs @@ -1,3 +1,3 @@ mod v0; -pub use v0::validate_instant_asset_lock_proof_structure_v0; +pub(in crate::identity::state_transition::asset_lock_proof::instant) use v0::validate_instant_asset_lock_proof_structure_v0; diff --git a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs index c2f923478f6..1ebf37418bd 100644 --- a/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs +++ b/packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/v0/mod.rs @@ -5,7 +5,7 @@ use crate::identity::state_transition::asset_lock_proof::validate_asset_lock_tra use crate::ProtocolError; use crate::validation::SimpleConsensusValidationResult; -pub(in crate::identity::state_transition::asset_lock_proof::instant) fn validate_instant_asset_lock_proof_structure_v0( +pub fn validate_instant_asset_lock_proof_structure_v0( proof: &InstantAssetLockProof, platform_version: &PlatformVersion, ) -> Result {