Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jul 23, 2024
1 parent 6a42ee2 commit ea80b2b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
31 changes: 12 additions & 19 deletions packages/rs-dpp/src/document/v0/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl DocumentPlatformSerializationMethodsV0 for DocumentV0 {
.try_for_each(|(field_name, property)| {
if let Some(value) = self.properties.get(field_name) {
if value.is_null() {
if property.required {
if property.required && !property.transient {
Err(ProtocolError::DataContractError(
DataContractError::MissingRequiredKey(
"a required field is not present".to_string(),
Expand All @@ -225,7 +225,7 @@ impl DocumentPlatformSerializationMethodsV0 for DocumentV0 {
Ok(())
}
} else {
if !property.required {
if !property.required || property.transient {
// dbg!("we added 1", field_name);
buffer.push(1);
}
Expand All @@ -236,19 +236,12 @@ impl DocumentPlatformSerializationMethodsV0 for DocumentV0 {
buffer.extend(value.as_slice());
Ok(())
}
} else if property.required {
//TODO: LEFT OFF HERE: this is probably wrong
if property.transient {
// We don't have something that was required but is transient, we push 0
buffer.push(0);
Ok(())
} else {
Err(ProtocolError::DataContractError(
DataContractError::MissingRequiredKey(format!(
"a required field {field_name} is not present"
)),
))
}
} else if property.required && !property.transient {
Err(ProtocolError::DataContractError(
DataContractError::MissingRequiredKey(format!(
"a required field {field_name} is not present"
)),
))
} else {
// dbg!("we pushed {} with 0", field_name);
// We don't have something that wasn't required
Expand Down Expand Up @@ -448,7 +441,7 @@ impl DocumentPlatformSerializationMethodsV0 for DocumentV0 {
Ok(())
}
} else {
if !property.required {
if !property.required || property.transient {
// dbg!("we added 1", field_name);
buffer.push(1);
}
Expand All @@ -459,7 +452,7 @@ impl DocumentPlatformSerializationMethodsV0 for DocumentV0 {
buffer.extend(value.as_slice());
Ok(())
}
} else if property.required {
} else if property.required && !property.transient {
Err(ProtocolError::DataContractError(
DataContractError::MissingRequiredKey(format!(
"a required field {field_name} is not present"
Expand Down Expand Up @@ -651,7 +644,7 @@ impl DocumentPlatformDeserializationMethodsV0 for DocumentV0 {
.iter()
.filter_map(|(key, property)| {
if finished_buffer {
return if property.required {
return if property.required && !property.transient {
Some(Err(DataContractError::CorruptedSerialization(
"required field after finished buffer".to_string(),
)))
Expand All @@ -661,7 +654,7 @@ impl DocumentPlatformDeserializationMethodsV0 for DocumentV0 {
}
let read_value = property
.property_type
.read_optionally_from(&mut buf, property.required);
.read_optionally_from(&mut buf, property.required & !property.transient);

match read_value {
Ok(read_value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ mod tests {

assert_eq!(
hex::encode(root_hash),
"edc1f51a2725e13e02f0a5dd9aad1b3de07872c9cd03e83388a10b0016a27f86"
"6cf0ca2eea48431b1df389a2d360fa1e9889c34f05248a7159b4e45c818fb80d"
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/rs-drive-abci/tests/strategy_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ mod tests {
.unwrap()
.unwrap()
),
"5d71ec297867cf1e9b6655451385b0c72b56d582abc1576885a78e5754ac5f14".to_string()
"2f5fd65cc5392f9be3a8ceab38f2e284a0c1ccd87b744d3d392ac83a97d0f4b9".to_string()
)
}

Expand Down Expand Up @@ -1915,7 +1915,7 @@ mod tests {
.unwrap()
.unwrap()
),
"36116eb13b2dfada15853aa54f9c81ebb2590aa99d512c12604c4bd5d622c49a".to_string()
"85114fce944f2583751d38cb427571e00fc957f2fd6f37a355298e697370c143".to_string()
)
}

Expand Down Expand Up @@ -2050,7 +2050,7 @@ mod tests {
.unwrap()
.unwrap()
),
"ee6682a2acd816d3277c55b5886199029ed33c13dc902ea8efab3ba7f20271e2".to_string()
"b563c5583d8aae38d0cd841c956c44b029705b915af89416d20a3a20f54bfc39".to_string()
)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ mod tests {

assert_eq!(
first_contender.document.as_ref().map(hex::encode),
Some("00177f2479090a0286a67d6a1f67b563b51518edd6eea0461829f7d630fd65708d29124be7e86f97e959894a67a9cc078c3e0106d4bfcfbf34bc403a4f099925b401000700000187690895980000018769089598000001876908959800077175616e74756d077175616e74756d00046461736861e49b7e1e1286c69aefdb8b33243524d4c6b48b2e5782b834ae77b0c033eff5210129124be7e86f97e959894a67a9cc078c3e0106d4bfcfbf34bc403a4f099925b40101".to_string())
Some("00177f2479090a0286a67d6a1f67b563b51518edd6eea0461829f7d630fd65708d29124be7e86f97e959894a67a9cc078c3e0106d4bfcfbf34bc403a4f099925b401000700000187690895980000018769089598000001876908959800077175616e74756d077175616e74756d00046461736800210129124be7e86f97e959894a67a9cc078c3e0106d4bfcfbf34bc403a4f099925b40101".to_string())
);

assert_eq!(
second_contender.document.as_ref().map(hex::encode),
Some("00490e212593a1d3cc6ae17bf107ab9cb465175e7877fcf7d085ed2fce27be11d68b8948a6801501bbe0431e3d994dcf71cf5a2a0939fe51b0e600076199aba4fb01000700000187690895980000018769089598000001876908959800077175616e74756d077175616e74756d00046461736894be348633f0cdceeb5548e4816963ad9e2ff06432d56d7f521ad902b8e5ac8121018b8948a6801501bbe0431e3d994dcf71cf5a2a0939fe51b0e600076199aba4fb0100".to_string())
Some("00490e212593a1d3cc6ae17bf107ab9cb465175e7877fcf7d085ed2fce27be11d68b8948a6801501bbe0431e3d994dcf71cf5a2a0939fe51b0e600076199aba4fb01000700000187690895980000018769089598000001876908959800077175616e74756d077175616e74756d0004646173680021018b8948a6801501bbe0431e3d994dcf71cf5a2a0939fe51b0e600076199aba4fb0100".to_string())
);

assert_eq!(first_contender.identifier, identity2_id.to_vec());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ impl DocumentFromCreateTransitionActionV0 for Document {
..
} = v0;

let mut data = data.clone();

match base {
DocumentBaseTransitionAction::V0(base_v0) => {
let DocumentBaseTransitionActionV0 {
Expand All @@ -148,6 +150,12 @@ impl DocumentFromCreateTransitionActionV0 for Document {

let required_fields = document_type.required_fields();

let transient_fields = document_type.transient_fields();

if !transient_fields.is_empty() {
data.retain(|key, _| !transient_fields.contains(key));
}

let is_created_at_required = required_fields.contains(CREATED_AT);
let is_updated_at_required = required_fields.contains(UPDATED_AT);
let is_transferred_at_required = required_fields.contains(TRANSFERRED_AT);
Expand All @@ -174,7 +182,7 @@ impl DocumentFromCreateTransitionActionV0 for Document {
0 => Ok(DocumentV0 {
id: *id,
owner_id,
properties: data.clone(),
properties: data,
revision: document_type.initial_revision(),
created_at: if is_created_at_required {
Some(block_info.time_ms)
Expand Down Expand Up @@ -260,9 +268,9 @@ impl DocumentFromCreateTransitionActionV0 for Document {
.document_type_for_name(document_type_name.as_str())?;

let required_fields = document_type.required_fields();

let transient_fields = document_type.transient_fields();

if !transient_fields.is_empty() {
data.retain(|key, _| !transient_fields.contains(key));
}
Expand Down

0 comments on commit ea80b2b

Please sign in to comment.