Skip to content
Merged
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.

Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function prepareProposalHandlerFactory(
invalidTxCount,
mempoolTxCount,
},
`Prepared block proposal for height #${height} with appHash ${appHash.toString('hex').toUpperCase()}`
`Prepared proposal #${height} with appHash ${appHash.toString('hex').toUpperCase()}`
+ ` in ${roundExecutionTime} seconds (valid txs = ${validTxCount}, invalid txs = ${invalidTxCount}, mempool txs = ${mempoolTxCount})`,
);

Expand Down
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,6 @@ 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)]
pub data_contract: DataContract,
pub signature_public_key_id: KeyID,
pub signature: BinaryData,
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
26 changes: 16 additions & 10 deletions packages/rs-dpp/src/data_trigger/get_data_triggers_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ use crate::{

use super::{DataTrigger, DataTriggerKind};

// TODO: Move to system contract crates
pub const REWARD_SHARE_DOCUMENT_TYPE: &str = "rewardShare";
pub const CONTACT_REQUEST_DOCUMENT_TYPE: &str = "contactRequest";
pub const DOMAIN_DOCUMENT_TYPE: &str = "domain";
pub const PREORDER_DOCUMENT_TYPE: &str = "preorder";

/// returns Date Triggers filtered out by dataContractId, documentType, transactionAction
pub fn get_data_triggers<'a>(
data_contract_id: &'a Identifier,
Expand Down Expand Up @@ -58,56 +64,56 @@ pub fn data_triggers() -> Result<Vec<DataTrigger>, ProtocolError> {
let data_triggers = vec![
DataTrigger {
data_contract_id: dpns_data_contract_id,
document_type: "domain".to_string(),
document_type: DOMAIN_DOCUMENT_TYPE.to_string(),
transition_action: Action::Create,
data_trigger_kind: DataTriggerKind::DataTriggerCreateDomain,
top_level_identity: Some(dpns_owner_id),
},
DataTrigger {
data_contract_id: dpns_data_contract_id,
document_type: "domain".to_string(),
document_type: DOMAIN_DOCUMENT_TYPE.to_string(),
transition_action: Action::Replace,
data_trigger_kind: DataTriggerKind::DataTriggerReject,
top_level_identity: None,
},
DataTrigger {
data_contract_id: dpns_data_contract_id,
document_type: "domain".to_string(),
document_type: DOMAIN_DOCUMENT_TYPE.to_string(),
transition_action: Action::Delete,
data_trigger_kind: DataTriggerKind::DataTriggerReject,
top_level_identity: None,
},
DataTrigger {
data_contract_id: dpns_data_contract_id,
document_type: "preorder".to_string(),
document_type: PREORDER_DOCUMENT_TYPE.to_string(),
transition_action: Action::Delete,
data_trigger_kind: DataTriggerKind::DataTriggerReject,
top_level_identity: None,
},
DataTrigger {
data_contract_id: dpns_data_contract_id,
document_type: "preorder".to_string(),
document_type: PREORDER_DOCUMENT_TYPE.to_string(),
transition_action: Action::Delete,
data_trigger_kind: DataTriggerKind::DataTriggerReject,
top_level_identity: None,
},
DataTrigger {
data_contract_id: dashpay_data_contract_id,
document_type: "contactRequest".to_string(),
document_type: CONTACT_REQUEST_DOCUMENT_TYPE.to_string(),
transition_action: Action::Create,
data_trigger_kind: DataTriggerKind::CreateDataContractRequest,
top_level_identity: None,
},
DataTrigger {
data_contract_id: dashpay_data_contract_id,
document_type: "contactRequest".to_string(),
document_type: CONTACT_REQUEST_DOCUMENT_TYPE.to_string(),
transition_action: Action::Replace,
data_trigger_kind: DataTriggerKind::DataTriggerReject,
top_level_identity: None,
},
DataTrigger {
data_contract_id: dashpay_data_contract_id,
document_type: "contactRequest".to_string(),
document_type: CONTACT_REQUEST_DOCUMENT_TYPE.to_string(),
transition_action: Action::Delete,
data_trigger_kind: DataTriggerKind::DataTriggerReject,
top_level_identity: None,
Expand Down Expand Up @@ -135,14 +141,14 @@ 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: REWARD_SHARE_DOCUMENT_TYPE.to_string(),
transition_action: Action::Create,
data_trigger_kind: DataTriggerKind::DataTriggerRewardShare,
top_level_identity: None,
},
DataTrigger {
data_contract_id: master_node_reward_shares_contract_id,
document_type: "rewardShare".to_string(),
document_type: REWARD_SHARE_DOCUMENT_TYPE.to_string(),
transition_action: Action::Replace,
data_trigger_kind: DataTriggerKind::DataTriggerRewardShare,
top_level_identity: None,
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-dpp/src/data_trigger/mod.rs
Original file line number Diff line number Diff line change
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