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

fix(platform)!: data contract validation improvements #1768

Merged
merged 22 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d57186a
a lot of work around errors
QuantumExplorer Mar 12, 2024
c788c33
more work and fmt
QuantumExplorer Mar 12, 2024
2beae74
better contract validation
QuantumExplorer Mar 12, 2024
6784699
clippy fixes
QuantumExplorer Mar 13, 2024
3244906
Merge branch 'v1.0-dev' into feat/betterDataContractUpdateProcessing
QuantumExplorer Mar 13, 2024
0354626
Merge branch 'v1.0-dev' into feat/betterDataContractUpdateProcessing
QuantumExplorer Mar 13, 2024
7ce3efb
Merge branch 'feat/betterDataContractUpdateProcessing' of github.com:…
QuantumExplorer Mar 13, 2024
69c1547
fixes for each feature
QuantumExplorer Mar 13, 2024
81f96fb
small fix
QuantumExplorer Mar 13, 2024
1113f3f
more fixes
QuantumExplorer Mar 13, 2024
cbf2994
more fixes
QuantumExplorer Mar 13, 2024
fee2b2b
fix(sdk): public key security level
markin-io Mar 13, 2024
e846508
more fixes for data contract update
QuantumExplorer Mar 13, 2024
bc03faa
Merge branch 'feat/betterDataContractUpdateProcessing' of github.com:…
QuantumExplorer Mar 13, 2024
5bfae10
adding a identity data contract nonce set to 0 for data contract create
QuantumExplorer Mar 13, 2024
4feb611
fixes
QuantumExplorer Mar 13, 2024
4d385df
security level can not be updated
QuantumExplorer Mar 13, 2024
b73529a
security level can not be updated
QuantumExplorer Mar 13, 2024
0f4a5a5
fixes from review
QuantumExplorer Mar 14, 2024
26dadc4
Merge branch 'v1.0-dev' into feat/betterDataContractUpdateProcessing
QuantumExplorer Mar 14, 2024
43976cb
fixes from review
QuantumExplorer Mar 14, 2024
430746b
Merge branch 'feat/betterDataContractUpdateProcessing' of github.com:…
QuantumExplorer Mar 14, 2024
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 @@ -40,6 +40,7 @@ export async function createIdentityCreateTransition(

const keyOne = new IdentityPublicKey(1);
keyOne.setData(identityMasterPublicKey.toBuffer());
keyOne.setSecurityLevel(IdentityPublicKey.SECURITY_LEVELS.MASTER);

const keyTwo = new IdentityPublicKey(1);
keyTwo.setId(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function createIdentityFixtureInAccount(account) {

const publicKeyOne = new IdentityPublicKey(1);
publicKeyOne.setData(identityMasterPrivateKey.toPublicKey().toBuffer());
publicKeyOne.setSecurityLevel(IdentityPublicKey.SECURITY_LEVELS.MASTER);

const publicKeyTwo = new IdentityPublicKey(1);
publicKeyTwo.setId(1);
Expand Down
7 changes: 4 additions & 3 deletions packages/rs-dpp/src/data_contract/accessors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use crate::data_contract::document_type::{DocumentType, DocumentTypeRef};
use crate::data_contract::DocumentName;
use crate::metadata::Metadata;
use crate::prelude::DataContract;
use crate::ProtocolError;

use platform_value::Identifier;

use crate::data_contract::errors::DataContractError;
use std::collections::BTreeMap;

pub mod v0;
Expand Down Expand Up @@ -36,13 +37,13 @@ impl DataContractV0Getters for DataContract {
}
}

fn document_type_cloned_for_name(&self, name: &str) -> Result<DocumentType, ProtocolError> {
fn document_type_cloned_for_name(&self, name: &str) -> Result<DocumentType, DataContractError> {
match self {
DataContract::V0(v0) => v0.document_type_cloned_for_name(name),
}
}

fn document_type_for_name(&self, name: &str) -> Result<DocumentTypeRef, ProtocolError> {
fn document_type_for_name(&self, name: &str) -> Result<DocumentTypeRef, DataContractError> {
match self {
DataContract::V0(v0) => v0.document_type_for_name(name),
}
Expand Down
7 changes: 4 additions & 3 deletions packages/rs-dpp/src/data_contract/accessors/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::data_contract::config::DataContractConfig;
use crate::data_contract::document_type::{DocumentType, DocumentTypeRef};
use crate::data_contract::errors::DataContractError;
use crate::data_contract::DocumentName;
use crate::metadata::Metadata;
use crate::ProtocolError;

use platform_value::Identifier;
use std::collections::BTreeMap;

Expand All @@ -17,10 +18,10 @@ pub trait DataContractV0Getters {

/// Returns the identifier of the contract owner.
fn owner_id(&self) -> Identifier;
fn document_type_cloned_for_name(&self, name: &str) -> Result<DocumentType, ProtocolError>;
fn document_type_cloned_for_name(&self, name: &str) -> Result<DocumentType, DataContractError>;

/// Returns the document type for the given document name.
fn document_type_for_name(&self, name: &str) -> Result<DocumentTypeRef, ProtocolError>;
fn document_type_for_name(&self, name: &str) -> Result<DocumentTypeRef, DataContractError>;

fn document_type_optional_for_name(&self, name: &str) -> Option<DocumentTypeRef>;
fn document_type_cloned_optional_for_name(&self, name: &str) -> Option<DocumentType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl DataContractConfig {
{
0 => Ok(self.validate_config_update_v0(new_config, contract_id)),
version => Err(ProtocolError::UnknownVersionMismatch {
method: "DataContractConfig::from_value".to_string(),
method: "validate_config_update".to_string(),
known_versions: vec![0],
received: version,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ impl DataContractConfig {
new_config: &DataContractConfig,
contract_id: Identifier,
) -> SimpleConsensusValidationResult {
// Validate: Old contract is not read_only

if self.readonly() {
return SimpleConsensusValidationResult::new_with_error(
DataContractIsReadonlyError::new(contract_id).into(),
);
}

// Validate: New contract is not read_only

if new_config.readonly() {
return SimpleConsensusValidationResult::new_with_error(
DataContractConfigUpdateError::new(
Expand All @@ -27,6 +31,8 @@ impl DataContractConfig {
);
}

// Validate: Keeps history did not change

if new_config.keeps_history() != self.keeps_history() {
return SimpleConsensusValidationResult::new_with_error(
DataContractConfigUpdateError::new(
Expand All @@ -41,6 +47,8 @@ impl DataContractConfig {
);
}

// Validate: Can be deleted did not change

if new_config.can_be_deleted() != self.can_be_deleted() {
return SimpleConsensusValidationResult::new_with_error(
DataContractConfigUpdateError::new(
Expand All @@ -55,6 +63,8 @@ impl DataContractConfig {
);
}

// Validate: Documents keep history did not change

if new_config.documents_keep_history_contract_default()
!= self.documents_keep_history_contract_default()
{
Expand All @@ -67,6 +77,8 @@ impl DataContractConfig {
);
}

// Validate: Documents mutable contract default did not change

if new_config.documents_mutable_contract_default()
!= self.documents_mutable_contract_default()
{
Expand All @@ -79,6 +91,8 @@ impl DataContractConfig {
);
}

// Validate: Requires identity encryption bounded key did not change

if new_config.requires_identity_encryption_bounded_key()
!= self.requires_identity_encryption_bounded_key()
{
Expand All @@ -91,6 +105,8 @@ impl DataContractConfig {
);
}

// Validate: Requires identity decryption bounded key did not change

if new_config.requires_identity_decryption_bounded_key()
!= self.requires_identity_decryption_bounded_key()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod test {
false,
false,
false,
&crate::version::PlatformVersion::latest(),
crate::version::PlatformVersion::latest(),
);

match result {
Expand Down
Loading
Loading