Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/rs-dpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ json-patch = "0.2.6"
jsonptr = "0.1.5"
jsonschema = { git="https://github.com/fominok/jsonschema-rs", branch="feat-unevaluated-properties", default-features=false, features=["draft202012"] }
lazy_static = { version ="1.4"}
log = { version="0.4"}
log = { version = "0.4.6" }
num_enum = "0.5.7"
bincode = "1.3.3"
rand = { version = "0.8.4", features = ["small_rng"] }
Expand Down
32 changes: 29 additions & 3 deletions packages/rs-dpp/src/data_contract/data_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,36 @@ impl DataContract {
self.document_types.get(document_type_name).is_some()
}

pub fn set_document_schema(&mut self, doc_type: String, schema: JsonSchema) {
pub fn set_document_schema(
&mut self,
doc_type: String,
schema: JsonSchema,
) -> Result<(), ProtocolError> {
let binary_properties = get_binary_properties(&schema);
self.documents.insert(doc_type.clone(), schema);
self.binary_properties.insert(doc_type, binary_properties);
self.documents.insert(doc_type.clone(), schema.clone());
self.binary_properties
.insert(doc_type.clone(), binary_properties);

let document_type_value = platform_value::Value::from(schema);

// Make sure the document_type_value is a map
let Some(document_type_value_map) = document_type_value.as_map() else {
return Err(ProtocolError::DataContractError(DataContractError::InvalidContractStructure(
"document type data is not a map as expected",
)));
};

let document_type = DocumentType::from_platform_value(
&doc_type,
document_type_value_map,
&BTreeMap::new(),
self.config.documents_keep_history_contract_default,
self.config.documents_mutable_contract_default,
)?;

self.document_types.insert(doc_type, document_type);

Ok(())
}

pub fn get_document_schema(&self, doc_type: &str) -> Result<&JsonSchema, ProtocolError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
state_transition: &DataContractUpdateTransition,
) -> Result<()> {
self.state_repository
.store_data_contract(
.update_data_contract(
state_transition.data_contract.clone(),
Some(state_transition.get_execution_context()),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub struct DataContractUpdateTransition {
pub protocol_version: u32,
#[serde(rename = "type")]
pub transition_type: StateTransitionType,
// we want to skip serialization of transitions, as we does it manually in `to_object()` and `to_json()`
#[serde(skip_serializing)]
// we want to skip serialization of transitions, as we do it manually in `to_object()` and `to_json()`
// #[serde(skip_serializing)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to do about this one - this one was done for a reason, but it broke stuff. So while we're not 100% sure (it seems like it doesn't) it doesn't break anything I would keep it here

@shumkov shumkov Apr 11, 2023

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bring it back then? My point was that we shouldn't commit commented code.

pub data_contract: DataContract,
pub signature_public_key_id: KeyID,
pub signature: BinaryData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ pub fn pattern_is_valid_regex_validator(
}
}

fn unwrap_error_to_result<'a, 'b>(
fn unwrap_error_to_result<'a>(
v: Result<Option<&'a Value>, ConsensusError>,
result: &'b mut SimpleValidationResult,
result: &mut SimpleValidationResult,
) -> Option<&'a Value> {
match v {
Ok(v) => v,
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-dpp/src/data_trigger/dashpay_data_triggers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{anyhow, bail};
use platform_value::btreemap_extensions::BTreeValueMapHelper;

use crate::consensus::state::data_trigger::data_trigger_condition_error::DataTriggerConditionError;
use crate::consensus::state::data_trigger::data_trigger_error::DataTriggerError;

use crate::data_trigger::dashpay_data_triggers::property_names::CORE_HEIGHT_CREATED_AT;
use crate::{
document::document_transition::DocumentTransition, get_from_transition, prelude::Identifier,
Expand Down Expand Up @@ -121,7 +121,7 @@ where

#[cfg(test)]
mod test {
use super::*;
use super::super::DataTriggerError;

use platform_value::btreemap_extensions::BTreeValueMapHelper;
use platform_value::platform_value;
Expand Down
22 changes: 12 additions & 10 deletions packages/rs-dpp/src/data_trigger/dpns_triggers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ where
.map_err(ProtocolError::ValueError)?;

let mut result = DataTriggerExecutionResult::default();
let full_domain_name = normalized_label;
let mut full_domain_name = normalized_label.to_string();

if !is_dry_run {
if full_domain_name.len() > MAX_PRINTABLE_DOMAIN_NAME_LENGTH {
let err = create_error(
context,
dt_create,
dt_create.base.id,
format!(
"Full domain name length can not be more than {} characters long but got {}",
MAX_PRINTABLE_DOMAIN_NAME_LENGTH,
Expand All @@ -96,7 +96,7 @@ where
if normalized_label != label.to_lowercase() {
let err = create_error(
context,
dt_create,
dt_create.base.id,
"Normalized label doesn't match label".to_string(),
);
result.add_error(err.into());
Expand All @@ -109,7 +109,7 @@ where
if id != owner_id {
let err = create_error(
context,
dt_create,
dt_create.base.id,
format!(
"ownerId {} doesn't match {} {}",
owner_id, PROPERTY_DASH_UNIQUE_IDENTITY_ID, id
Expand All @@ -126,7 +126,7 @@ where
if id != owner_id {
let err = create_error(
context,
dt_create,
dt_create.base.id,
format!(
"ownerId {} doesn't match {} {}",
owner_id, PROPERTY_DASH_ALIAS_IDENTITY_ID, id
Expand All @@ -139,14 +139,16 @@ where
if normalized_parent_domain_name.is_empty() && context.owner_id != top_level_identity {
let err = create_error(
context,
dt_create,
dt_create.base.id,
"Can't create top level domain for this identity".to_string(),
);
result.add_error(err.into())
}
}

if !normalized_parent_domain_name.is_empty() {
full_domain_name = format!("{full_domain_name}.{normalized_parent_domain_name}");

//? What is the `normalized_parent_name`. Are we sure the content is a valid dot-separated data
let mut parent_domain_segments = normalized_parent_domain_name.split('.');
let parent_domain_label = parent_domain_segments.next().unwrap().to_string();
Expand Down Expand Up @@ -175,7 +177,7 @@ where
if documents.is_empty() {
let err = create_error(
context,
dt_create,
dt_create.base.id,
"Parent domain is not present".to_string(),
);
result.add_error(err.into());
Expand All @@ -186,7 +188,7 @@ where
if rule_allow_subdomains {
let err = create_error(
context,
dt_create,
dt_create.base.id,
"Allowing subdomains registration is forbidden for non top level domains"
.to_string(),
);
Expand All @@ -200,7 +202,7 @@ where
{
let err = create_error(
context,
dt_create,
dt_create.base.id,
"The subdomain can be created only by the parent domain owner".to_string(),
);
result.add_error(err.into());
Expand Down Expand Up @@ -238,7 +240,7 @@ where
if preorder_documents.is_empty() {
let err = create_error(
context,
dt_create,
dt_create.base.id,
"preorderDocument was not found".to_string(),
);
result.add_error(err.into())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
if enable_at_height < block_height {
let err = create_error(
context,
dt_create,
dt_create.base.id,
"This identity can't activate selected feature flag".to_string(),
);
result.add_error(err.into());
Expand All @@ -65,7 +65,7 @@ where
if context.owner_id != top_level_identity {
let err = create_error(
context,
dt_create,
dt_create.base.id,
"This Identity can't activate selected feature flag".to_string(),
);
result.add_error(err.into());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn data_triggers() -> Result<Vec<DataTrigger>, ProtocolError> {
},
DataTrigger {
data_contract_id: master_node_reward_shares_contract_id,
document_type: feature_flags_contract::types::UPDATE_CONSENSUS_PARAMS.to_string(),
document_type: "rewardShare".to_string(),
transition_action: Action::Create,
data_trigger_kind: DataTriggerKind::DataTriggerRewardShare,
top_level_identity: None,
Expand Down
8 changes: 4 additions & 4 deletions packages/rs-dpp/src/data_trigger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use reject_data_trigger::*;
use crate::consensus::state::data_trigger::data_trigger_condition_error::DataTriggerConditionError;
use crate::consensus::state::data_trigger::data_trigger_error::DataTriggerError;
use crate::consensus::state::data_trigger::data_trigger_execution_error::DataTriggerExecutionError;
use crate::document::document_transition::{Action, DocumentCreateTransition, DocumentTransition};
use crate::document::document_transition::{Action, DocumentTransition};
use crate::{get_from_transition, prelude::Identifier, state_repository::StateRepositoryLike};

use self::dashpay_data_triggers::create_contact_request_data_trigger;
Expand Down Expand Up @@ -71,7 +71,7 @@ impl DataTrigger {
document_type: &str,
transition_action: Action,
) -> bool {
&self.data_contract_id == data_contract_id
self.data_contract_id == data_contract_id
&& self.document_type == document_type
&& self.transition_action == transition_action
}
Expand Down Expand Up @@ -147,11 +147,11 @@ where

fn create_error<SR>(
context: &DataTriggerExecutionContext<SR>,
dt_create: &DocumentCreateTransition,
transition_id: Identifier,
msg: String,
) -> DataTriggerError
where
SR: StateRepositoryLike,
{
DataTriggerConditionError::new(context.data_contract.id, dt_create.base.id, msg).into()
DataTriggerConditionError::new(context.data_contract.id, transition_id, msg).into()
}
Loading