Skip to content

Commit

Permalink
chore(wasm-dpp): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic committed Dec 24, 2024
1 parent 9925a68 commit e8defe8
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 375 deletions.
107 changes: 2 additions & 105 deletions packages/rs-dpp/src/document/document_factory/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,9 @@ impl DocumentFactoryV0 {
nonce_counter,
platform_version,
),
DocumentTransitionActionType::Transfer => Self::document_transfer_transitions(
documents
.into_iter()
.map(|(document, document_type, _)| (document, document_type))
.collect(),
nonce_counter,
platform_version,
),
DocumentTransitionActionType::Purchase => {
Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for Transfer".to_string(),
))
}
DocumentTransitionActionType::UpdatePrice => Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for UpdatePrice".to_string(),
_ => Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for".to_string(),
)),
DocumentTransitionActionType::IgnoreWhileBumpingRevision => Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for IgnoreWhileBumpingRevision".to_string(),
))
})
.collect::<Result<Vec<_>, ProtocolError>>()?
.into_iter()
Expand Down Expand Up @@ -524,93 +508,6 @@ impl DocumentFactoryV0 {
// Ok(raw_transitions)
}

#[cfg(feature = "state-transitions")]
fn document_transfer_transitions(
documents: Vec<(Document, DocumentTypeRef)>,
nonce_counter: &mut BTreeMap<(Identifier, Identifier), u64>, //IdentityID/ContractID -> nonce
platform_version: &PlatformVersion,
) -> Result<Vec<DocumentTransition>, ProtocolError> {
documents
.into_iter()
.map(|(mut document, document_type)| {
if !document_type.documents_mutable() {
return Err(DocumentError::TryingToReplaceImmutableDocument {
document: Box::new(document),
}
.into());
}
if document.revision().is_none() {
return Err(DocumentError::RevisionAbsentError {
document: Box::new(document),
}
.into());
};

document.increment_revision()?;
document.set_updated_at(Some(Utc::now().timestamp_millis() as TimestampMillis));

let recipient_owner_id = document.owner_id();

let nonce = nonce_counter
.entry((document.owner_id(), document_type.data_contract_id()))
.or_default();

let transition = DocumentTransferTransition::from_document(
document,
document_type,
*nonce,
recipient_owner_id,
platform_version,
None,
None,
)?;

*nonce += 1;

Ok(transition.into())
})
.collect()
// let mut raw_transitions = vec![];
// for (document, document_type) in documents {
// if !document_type.documents_mutable() {
// return Err(DocumentError::TryingToReplaceImmutableDocument {
// document: Box::new(document),
// }
// .into());
// }
// let Some(document_revision) = document.revision() else {
// return Err(DocumentError::RevisionAbsentError {
// document: Box::new(document),
// }.into());
// };
// let mut map = document.to_map_value()?;
//
// map.retain(|key, _| {
// !key.starts_with('$') || DOCUMENT_REPLACE_KEYS_TO_STAY.contains(&key.as_str())
// });
// map.insert(
// PROPERTY_ACTION.to_string(),
// Value::U8(DocumentTransitionActionType::Replace as u8),
// );
// let new_revision = document_revision + 1;
// map.insert(PROPERTY_REVISION.to_string(), Value::U64(new_revision));
//
// // If document have an originally set `updatedAt`
// // we should update it then
// let contains_updated_at = document_type
// .required_fields()
// .contains(PROPERTY_UPDATED_AT);
//
// if contains_updated_at {
// let now = Utc::now().timestamp_millis() as TimestampMillis;
// map.insert(PROPERTY_UPDATED_AT.to_string(), Value::U64(now));
// }
//
// raw_transitions.push(map.into());
// }
// Ok(raw_transitions)
}

#[cfg(feature = "state-transitions")]
fn document_delete_transitions(
documents: Vec<(Document, DocumentTypeRef)>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,9 @@ impl SpecializedDocumentFactoryV0 {
nonce_counter,
platform_version,
),
DocumentTransitionActionType::Transfer => {
Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for Transfer".to_string(),
))
},
DocumentTransitionActionType::Purchase => {
Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for Purchase".to_string(),
))
}
DocumentTransitionActionType::UpdatePrice => Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for UpdatePrice".to_string(),
_ => Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for".to_string(),
)),
DocumentTransitionActionType::IgnoreWhileBumpingRevision => Err(ProtocolError::InvalidStateTransitionType(
"action type not accounted for IgnoreWhileBumpingRevision".to_string(),
))
})
.collect::<Result<Vec<_>, ProtocolError>>()?
.into_iter()
Expand Down
8 changes: 0 additions & 8 deletions packages/wasm-dpp/src/document/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub struct DocumentTransitions {
create: Vec<ExtendedDocumentWasm>,
replace: Vec<ExtendedDocumentWasm>,
delete: Vec<ExtendedDocumentWasm>,
transfer: Vec<ExtendedDocumentWasm>,
}

#[wasm_bindgen(js_class=DocumentTransitions)]
Expand All @@ -56,11 +55,6 @@ impl DocumentTransitions {
pub fn add_transition_delete(&mut self, transition: ExtendedDocumentWasm) {
self.delete.push(transition)
}

#[wasm_bindgen(js_name = "addTransitionTransfer")]
pub fn add_transition_transfer(&mut self, transition: ExtendedDocumentWasm) {
self.transfer.push(transition)
}
}

#[wasm_bindgen(js_name = DocumentFactory)]
Expand Down Expand Up @@ -284,12 +278,10 @@ fn extract_documents_by_action(
let documents_create = extract_documents_of_action(documents, "create").with_js_error()?;
let documents_replace = extract_documents_of_action(documents, "replace").with_js_error()?;
let documents_delete = extract_documents_of_action(documents, "delete").with_js_error()?;
let documents_transfer = extract_documents_of_action(documents, "transfer").with_js_error()?;

documents_by_action.insert(DocumentTransitionActionType::Create, documents_create);
documents_by_action.insert(DocumentTransitionActionType::Replace, documents_replace);
documents_by_action.insert(DocumentTransitionActionType::Delete, documents_delete);
documents_by_action.insert(DocumentTransitionActionType::Transfer, documents_transfer);

Ok(documents_by_action)
}
Expand Down
Loading

0 comments on commit e8defe8

Please sign in to comment.