Skip to content

Commit

Permalink
work done
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jul 22, 2024
1 parent 3a0a930 commit 5a859c1
Show file tree
Hide file tree
Showing 43 changed files with 2,184 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use std::convert::TryInto;

#[cfg(feature = "validation")]
use crate::consensus::basic::data_contract::ContestedUniqueIndexOnMutableDocumentTypeError;
#[cfg(feature = "validation")]
use crate::consensus::basic::data_contract::ContestedUniqueIndexWithUniqueIndexError;
#[cfg(any(test, feature = "validation"))]
use crate::consensus::basic::data_contract::InvalidDocumentTypeNameError;
#[cfg(feature = "validation")]
Expand Down Expand Up @@ -50,7 +52,6 @@ use crate::version::PlatformVersion;
use crate::ProtocolError;
use platform_value::btreemap_extensions::BTreeValueMapHelper;
use platform_value::{Identifier, Value};
use crate::consensus::basic::data_contract::ContestedUniqueIndexWithUniqueIndexError;

const NOT_ALLOWED_SYSTEM_PROPERTIES: [&str; 1] = ["$id"];

Expand Down Expand Up @@ -285,10 +286,10 @@ impl DocumentTypeV0 {
let mut unique_indices_count = 0;

#[cfg(feature = "validation")]
let mut last_non_contested_unique_index_name : Option<String> = None;
let mut last_non_contested_unique_index_name: Option<String> = None;

#[cfg(feature = "validation")]
let mut last_contested_unique_index_name : Option<String> = None;
let mut last_contested_unique_index_name: Option<String> = None;

#[cfg(feature = "validation")]
let mut contested_indices_count = 0;
Expand Down Expand Up @@ -339,17 +340,17 @@ impl DocumentTypeV0 {
)));
}

if let Some(last_contested_unique_index_name) = last_contested_unique_index_name.as_ref() {

if let Some(last_contested_unique_index_name) =
last_contested_unique_index_name.as_ref()
{
return Err(ProtocolError::ConsensusError(Box::new(
ContestedUniqueIndexWithUniqueIndexError::new(
name.to_string(),
last_contested_unique_index_name.clone(),
index.name,
)
.into(),
.into(),
)));

}

if index.contested_index.is_none() {
Expand Down Expand Up @@ -379,18 +380,18 @@ impl DocumentTypeV0 {
.into(),
)));
}
if let Some(last_unique_index_name) = last_non_contested_unique_index_name.as_ref() {

return Err(ProtocolError::ConsensusError(Box::new(
ContestedUniqueIndexWithUniqueIndexError::new(
name.to_string(),
index.name,
last_unique_index_name.clone()
)
.into(),
)));


if let Some(last_unique_index_name) =
last_non_contested_unique_index_name.as_ref()
{
return Err(ProtocolError::ConsensusError(Box::new(
ContestedUniqueIndexWithUniqueIndexError::new(
name.to_string(),
index.name,
last_unique_index_name.clone(),
)
.into(),
)));
}

if documents_mutable {
Expand Down
29 changes: 22 additions & 7 deletions packages/rs-dpp/src/data_contract/document_type/index_level/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ pub enum IndexType {
ContestedResourceIndex,
}

#[derive(Debug, PartialEq, Copy, Clone)]
pub struct IndexLevelTypeInfo {
/// should we insert if all fields up to here are null
pub should_insert_with_all_null: bool,
/// The index type
pub index_type: IndexType,
}

impl IndexType {
pub fn is_unique(&self) -> bool {
match self {
Expand All @@ -39,12 +47,14 @@ impl IndexType {
}
}

pub type ShouldInsertWithAllNull = bool;

#[derive(Debug, PartialEq, Clone)]
pub struct IndexLevel {
/// the lower index levels from this level
sub_index_levels: BTreeMap<String, IndexLevel>,
/// did an index terminate at this level
has_index_with_type: Option<IndexType>,
has_index_with_type: Option<IndexLevelTypeInfo>,
/// unique level identifier
level_identifier: u64,
}
Expand All @@ -58,7 +68,7 @@ impl IndexLevel {
&self.sub_index_levels
}

pub fn has_index_with_type(&self) -> Option<IndexType> {
pub fn has_index_with_type(&self) -> Option<IndexLevelTypeInfo> {
self.has_index_with_type
}

Expand Down Expand Up @@ -199,7 +209,12 @@ impl IndexLevel {
NonUniqueIndex
};

current_level.has_index_with_type = Some(index_type);
// if things are null searchable that means we should insert with all null

current_level.has_index_with_type = Some(IndexLevelTypeInfo {
should_insert_with_all_null: index.null_searchable,
index_type,
});
}
}
}
Expand Down Expand Up @@ -305,7 +320,7 @@ mod tests {
}],
unique: false,
null_searchable: true,
contested_index: None,
contested_index: None,
},
Index {
name: "test2".to_string(),
Expand All @@ -315,7 +330,7 @@ mod tests {
}],
unique: false,
null_searchable: true,
contested_index: None,
contested_index: None,
},
];

Expand Down Expand Up @@ -351,7 +366,7 @@ mod tests {
}],
unique: false,
null_searchable: true,
contested_index: None,
contested_index: None,
},
Index {
name: "test2".to_string(),
Expand All @@ -361,7 +376,7 @@ mod tests {
}],
unique: false,
null_searchable: true,
contested_index: None,
contested_index: None,
},
];

Expand Down
1 change: 1 addition & 0 deletions packages/rs-dpp/src/data_contract/document_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod methods;
pub use index::*;
mod index_level;
pub use index_level::IndexLevel;
pub use index_level::IndexLevelTypeInfo;
pub use index_level::IndexType;

#[cfg(feature = "random-documents")]
Expand Down
7 changes: 7 additions & 0 deletions packages/rs-dpp/src/document/accessors/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ pub trait DocumentV0Setters: DocumentV0Getters {
}
}

/// Removes the value under the given path.
/// The path supports syntax from the `lodash` JS library. Example: "root.people[0].name".
/// If parents are not present, they will be automatically created.
fn remove(&mut self, path: &str) -> Option<Value> {
self.properties_mut().remove(path)
}

/// Sets a `u8` value for the specified property name.
fn set_u8(&mut self, property_name: &str, value: u8) {
self.properties_mut()
Expand Down
14 changes: 13 additions & 1 deletion packages/rs-dpp/src/errors/consensus/basic/basic_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ use thiserror::Error;
use crate::consensus::basic::data_contract::data_contract_max_depth_exceed_error::DataContractMaxDepthExceedError;
#[cfg(feature = "json-schema-validation")]
use crate::consensus::basic::data_contract::InvalidJsonSchemaRefError;
use crate::consensus::basic::data_contract::{ContestedUniqueIndexOnMutableDocumentTypeError, DataContractHaveNewUniqueIndexError, DataContractImmutablePropertiesUpdateError, DataContractInvalidIndexDefinitionUpdateError, DataContractUniqueIndicesChangedError, DuplicateIndexError, DuplicateIndexNameError, IncompatibleDataContractSchemaError, IncompatibleDocumentTypeSchemaError, IncompatibleRe2PatternError, InvalidCompoundIndexError, InvalidDataContractIdError, InvalidDataContractVersionError, InvalidDocumentTypeNameError, InvalidDocumentTypeRequiredSecurityLevelError, InvalidIndexPropertyTypeError, InvalidIndexedPropertyConstraintError, SystemPropertyIndexAlreadyPresentError, UndefinedIndexPropertyError, UniqueIndicesLimitReachedError, UnknownDocumentCreationRestrictionModeError, UnknownSecurityLevelError, UnknownStorageKeyRequirementsError, UnknownTradeModeError, UnknownTransferableTypeError, ContestedUniqueIndexWithUniqueIndexError};
use crate::consensus::basic::data_contract::{
ContestedUniqueIndexOnMutableDocumentTypeError, ContestedUniqueIndexWithUniqueIndexError,
DataContractHaveNewUniqueIndexError, DataContractImmutablePropertiesUpdateError,
DataContractInvalidIndexDefinitionUpdateError, DataContractUniqueIndicesChangedError,
DuplicateIndexError, DuplicateIndexNameError, IncompatibleDataContractSchemaError,
IncompatibleDocumentTypeSchemaError, IncompatibleRe2PatternError, InvalidCompoundIndexError,
InvalidDataContractIdError, InvalidDataContractVersionError, InvalidDocumentTypeNameError,
InvalidDocumentTypeRequiredSecurityLevelError, InvalidIndexPropertyTypeError,
InvalidIndexedPropertyConstraintError, SystemPropertyIndexAlreadyPresentError,
UndefinedIndexPropertyError, UniqueIndicesLimitReachedError,
UnknownDocumentCreationRestrictionModeError, UnknownSecurityLevelError,
UnknownStorageKeyRequirementsError, UnknownTradeModeError, UnknownTransferableTypeError,
};
use crate::consensus::basic::decode::{
ProtocolVersionParsingError, SerializedObjectParsingError, VersionError,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ pub struct ContestedUniqueIndexWithUniqueIndexError {
}

impl ContestedUniqueIndexWithUniqueIndexError {
pub fn new(document_type: String, contested_unique_index_name: String, unique_index_name: String) -> Self {
pub fn new(
document_type: String,
contested_unique_index_name: String,
unique_index_name: String,
) -> Self {
Self {
document_type,
contested_unique_index_name,
Expand All @@ -47,8 +51,6 @@ impl ContestedUniqueIndexWithUniqueIndexError {

impl From<ContestedUniqueIndexWithUniqueIndexError> for ConsensusError {
fn from(err: ContestedUniqueIndexWithUniqueIndexError) -> Self {
Self::BasicError(BasicError::ContestedUniqueIndexWithUniqueIndexError(
err,
))
Self::BasicError(BasicError::ContestedUniqueIndexWithUniqueIndexError(err))
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod contested_unique_index_on_mutable_document_type_error;
mod contested_unique_index_with_unique_index_error;
mod data_contract_have_new_unique_index_error;
mod data_contract_immutable_properties_update_error;
mod data_contract_invalid_index_definition_update_error;
Expand Down Expand Up @@ -27,7 +28,6 @@ mod unknown_security_level_error;
mod unknown_storage_key_requirements_error;
mod unknown_trade_mode_error;
mod unknown_transferable_type_error;
mod contested_unique_index_with_unique_index_error;

pub use data_contract_have_new_unique_index_error::*;
pub use data_contract_immutable_properties_update_error::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::identity::Identity;

#[cfg(feature = "state-transition-signing")]
use crate::identity::core_script::CoreScript;
#[cfg(feature = "state-transition-signing")]
use crate::identity::IdentityPublicKey;
#[cfg(feature = "state-transition-signing")]
use crate::prelude::{IdentityNonce, UserFeeIncrease};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::identity::core_script::CoreScript;
use crate::identity::signer::Signer;
#[cfg(feature = "state-transition-signing")]
use crate::identity::Identity;
#[cfg(feature = "state-transition-signing")]
use crate::identity::IdentityPublicKey;
#[cfg(feature = "state-transition-signing")]
use crate::prelude::{IdentityNonce, UserFeeIncrease};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::identity::accessors::IdentityGettersV0;
use crate::identity::core_script::CoreScript;
#[cfg(feature = "state-transition-signing")]
use crate::identity::signer::Signer;
#[cfg(feature = "state-transition-signing")]
use crate::identity::IdentityPublicKey;
#[cfg(feature = "state-transition-signing")]
use crate::identity::{Identity, KeyType, Purpose, SecurityLevel};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ mod tests {
assert_eq!(
root_hash,
[
37, 162, 178, 238, 218, 180, 162, 24, 34, 199, 191, 38, 43, 39, 197, 101, 133,
229, 130, 128, 20, 135, 168, 126, 219, 15, 235, 112, 139, 89, 187, 115
248, 90, 202, 206, 96, 59, 148, 53, 168, 193, 17, 125, 14, 157, 48, 42, 236,
180, 135, 136, 12, 89, 15, 254, 72, 134, 239, 246, 242, 126, 239, 52
]
)
}
Expand Down
Loading

0 comments on commit 5a859c1

Please sign in to comment.