Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(dpp): version InstantAssetLockProof.validate_structure #1549

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SimpleConsensusValidationResult, ProtocolError> {
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)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod validate_structure;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod v0;

pub use v0::validate_instant_asset_lock_proof_structure_v0;

Check failure on line 3 in packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs

View workflow job for this annotation

GitHub Actions / Rust / Linting

`validate_instant_asset_lock_proof_structure_v0` is private, and cannot be re-exported

error[E0364]: `validate_instant_asset_lock_proof_structure_v0` is private, and cannot be re-exported --> packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs:3:9 | 3 | pub use v0::validate_instant_asset_lock_proof_structure_v0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: consider marking `validate_instant_asset_lock_proof_structure_v0` as `pub` in the imported module --> packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs:3:9 | 3 | pub use v0::validate_instant_asset_lock_proof_structure_v0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check failure on line 3 in packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs

View workflow job for this annotation

GitHub Actions / Rust / Linting

`validate_instant_asset_lock_proof_structure_v0` is private, and cannot be re-exported

error[E0364]: `validate_instant_asset_lock_proof_structure_v0` is private, and cannot be re-exported --> packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs:3:9 | 3 | pub use v0::validate_instant_asset_lock_proof_structure_v0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: consider marking `validate_instant_asset_lock_proof_structure_v0` as `pub` in the imported module --> packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs:3:9 | 3 | pub use v0::validate_instant_asset_lock_proof_structure_v0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check failure on line 3 in packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs

View workflow job for this annotation

GitHub Actions / Rust / Linting

`validate_instant_asset_lock_proof_structure_v0` is private, and cannot be re-exported

error[E0364]: `validate_instant_asset_lock_proof_structure_v0` is private, and cannot be re-exported --> packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs:3:9 | 3 | pub use v0::validate_instant_asset_lock_proof_structure_v0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: consider marking `validate_instant_asset_lock_proof_structure_v0` as `pub` in the imported module --> packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/methods/validate_structure/mod.rs:3:9 | 3 | pub use v0::validate_instant_asset_lock_proof_structure_v0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -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(in crate::identity::state_transition::asset_lock_proof::instant) fn validate_instant_asset_lock_proof_structure_v0(
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
proof: &InstantAssetLockProof,
platform_version: &PlatformVersion,
) -> Result<SimpleConsensusValidationResult, ProtocolError> {
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)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use instant_asset_lock_proof::*;

mod instant_asset_lock_proof;
mod methods;
1 change: 1 addition & 0 deletions packages/rs-platform-version/src/version/dpp_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions packages/rs-platform-version/src/version/mocks/v2_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/rs-platform-version/src/version/mocks/v3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/rs-platform-version/src/version/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down
Loading