From 61965552bb37071068accc44e139f4d15c8eb3bc Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 22 Nov 2024 03:16:54 +0700 Subject: [PATCH 01/20] feat(wasm-dpp): add resource vote choice --- .../masternode_vote_transition/mod.rs | 152 ++++++++++-------- 1 file changed, 82 insertions(+), 70 deletions(-) diff --git a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs index 4ee92d0023d..6ade2fc9cd2 100644 --- a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs +++ b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs @@ -23,7 +23,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] -#[wasm_bindgen(js_name=MasternodeVoteTransition)] +#[wasm_bindgen(js_name = MasternodeVoteTransition)] pub struct MasternodeVoteTransitionWasm(MasternodeVoteTransition); impl From for MasternodeVoteTransitionWasm { @@ -38,7 +38,7 @@ impl From for MasternodeVoteTransition { } } -#[wasm_bindgen(js_class=MasternodeVoteTransition)] +#[wasm_bindgen(js_class = MasternodeVoteTransition)] impl MasternodeVoteTransitionWasm { #[wasm_bindgen(constructor)] pub fn new(platform_version: u32) -> Result { @@ -50,27 +50,27 @@ impl MasternodeVoteTransitionWasm { .map_err(from_dpp_err) } - #[wasm_bindgen(js_name=getOwnerId)] + #[wasm_bindgen(js_name = getOwnerId)] pub fn get_owner_id(&self) -> IdentifierWrapper { self.0.owner_id().to_owned().into() } - #[wasm_bindgen(js_name=getType)] + #[wasm_bindgen(js_name = getType)] pub fn get_type(&self) -> u8 { self.0.state_transition_type() as u8 } - #[wasm_bindgen(js_name=getProTxHash)] + #[wasm_bindgen(js_name = getProTxHash)] pub fn get_pro_tx_hash(&self) -> IdentifierWrapper { self.0.pro_tx_hash().into() } - #[wasm_bindgen(js_name=setProTxHash)] + #[wasm_bindgen(js_name = setProTxHash)] pub fn set_pro_tx_hash(&mut self, pro_tx_hash: &IdentifierWrapper) { self.0.set_pro_tx_hash(pro_tx_hash.into()); } - #[wasm_bindgen(js_name=toObject)] + #[wasm_bindgen(js_name = toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: self::to_object::ToObjectOptions = if options.is_object() { with_js_error!(serde_wasm_bindgen::from_value(options))? @@ -128,16 +128,16 @@ impl MasternodeVoteTransitionWasm { Ok(js_object.into()) } - #[wasm_bindgen(js_name=toBuffer)] + #[wasm_bindgen(js_name = toBuffer)] pub fn to_buffer(&self) -> Result { let bytes = PlatformSerializable::serialize_to_bytes(&StateTransition::MasternodeVote( self.0.clone(), )) - .with_js_error()?; + .with_js_error()?; Ok(Buffer::from_bytes(&bytes)) } - #[wasm_bindgen(js_name=toJSON)] + #[wasm_bindgen(js_name = toJSON)] pub fn to_json(&self) -> Result { let object = self::to_object::to_object_struct(&self.0, Default::default()); let js_object = js_sys::Object::new(); @@ -191,7 +191,7 @@ impl MasternodeVoteTransitionWasm { Ok(js_object.into()) } - #[wasm_bindgen(js_name=getModifiedDataIds)] + #[wasm_bindgen(js_name = getModifiedDataIds)] pub fn modified_data_ids(&self) -> Vec { let ids = self.0.modified_data_ids(); @@ -200,84 +200,96 @@ impl MasternodeVoteTransitionWasm { .collect() } - #[wasm_bindgen(js_name=isDataContractStateTransition)] + #[wasm_bindgen(js_name = isDataContractStateTransition)] pub fn is_data_contract_state_transition(&self) -> bool { self.0.is_data_contract_state_transition() } - #[wasm_bindgen(js_name=isDocumentStateTransition)] + #[wasm_bindgen(js_name = isDocumentStateTransition)] pub fn is_document_state_transition(&self) -> bool { self.0.is_document_state_transition() } - #[wasm_bindgen(js_name=isIdentityStateTransition)] + #[wasm_bindgen(js_name = isIdentityStateTransition)] pub fn is_identity_state_transition(&self) -> bool { self.0.is_identity_state_transition() } - #[wasm_bindgen(js_name=isVotingStateTransition)] + #[wasm_bindgen(js_name = isVotingStateTransition)] pub fn is_voting_state_transition(&self) -> bool { self.0.is_voting_state_transition() } - #[wasm_bindgen(js_name=getContestedDocumentResourceVotePoll)] + #[wasm_bindgen(js_name = getContestedDocumentResourceVotePoll)] pub fn contested_document_resource_vote_poll(&self) -> Option { match self.0.vote() { - Vote::ResourceVote(vote) => match vote.vote_poll() { - VotePoll::ContestedDocumentResourceVotePoll( - contested_document_resource_vote_poll, - ) => { - let js_object = Object::new(); - - let contract_id = IdentifierWrapper::from( - contested_document_resource_vote_poll.contract_id.clone(), - ); - - Reflect::set(&js_object, &"contractId".into(), &contract_id.into()).unwrap(); - Reflect::set( - &js_object, - &"documentTypeName".into(), - &contested_document_resource_vote_poll - .document_type_name - .clone() - .into(), - ) - .unwrap(); - Reflect::set( - &js_object, - &"indexName".into(), - &contested_document_resource_vote_poll - .index_name - .clone() - .into(), - ) - .unwrap(); - - let config = bincode::config::standard() - .with_big_endian() - .with_no_limit(); - - let serialized_index_values = contested_document_resource_vote_poll - .index_values - .iter() - .map(|value| { - JsValue::from(Buffer::from_bytes_owned( - bincode::encode_to_vec(value, config) - .expect("expected to encode value in path"), - )) - }); - - let js_array = Array::from_iter(serialized_index_values); - - Reflect::set(&js_object, &"indexValues".into(), &js_array.into()).unwrap(); - - Some(js_object) + Vote::ResourceVote(vote) => { + let js_object = Object::new(); + + Reflect::set( + &js_object, + &"choice".into(), + &vote + .resource_vote_choice() + .clone() + .to_string() + .into(), + ).unwrap(); + + match vote.vote_poll() { + VotePoll::ContestedDocumentResourceVotePoll( + contested_document_resource_vote_poll, + ) => { + let contract_id = IdentifierWrapper::from( + contested_document_resource_vote_poll.contract_id.clone(), + ); + + Reflect::set(&js_object, &"contractId".into(), &contract_id.into()).unwrap(); + Reflect::set( + &js_object, + &"documentTypeName".into(), + &contested_document_resource_vote_poll + .document_type_name + .clone() + .into(), + ) + .unwrap(); + Reflect::set( + &js_object, + &"indexName".into(), + &contested_document_resource_vote_poll + .index_name + .clone() + .into(), + ) + .unwrap(); + + let config = bincode::config::standard() + .with_big_endian() + .with_no_limit(); + + let serialized_index_values = contested_document_resource_vote_poll + .index_values + .iter() + .map(|value| { + JsValue::from(Buffer::from_bytes_owned( + bincode::encode_to_vec(value, config) + .expect("expected to encode value in path"), + )) + }); + + let js_array = Array::from_iter(serialized_index_values); + + Reflect::set(&js_object, &"indexValues".into(), &js_array.into()).unwrap(); + + Some(js_object) + } } - }, + } } } - #[wasm_bindgen(js_name=signByPrivateKey)] + #[wasm_bindgen(js_name = signByPrivateKey)] pub fn sign_by_private_key( &mut self, private_key: Vec, @@ -292,7 +304,7 @@ impl MasternodeVoteTransitionWasm { return Err(JsError::new( format!("BLS adapter is required for BLS key type '{}'", key_type).as_str(), ) - .into()); + .into()); } let bls_adapter = if let Some(adapter) = bls { @@ -313,12 +325,12 @@ impl MasternodeVoteTransitionWasm { Ok(()) } - #[wasm_bindgen(js_name=getSignature)] + #[wasm_bindgen(js_name = getSignature)] pub fn get_signature(&self) -> Buffer { Buffer::from_bytes(self.0.signature().as_slice()) } - #[wasm_bindgen(js_name=setSignature)] + #[wasm_bindgen(js_name = setSignature)] pub fn set_signature(&mut self, signature: Option>) { self.0 .set_signature(BinaryData::new(signature.unwrap_or_default())) From b69bcc602f81cde178e6c28a1d3136f2175b3eb5 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Mon, 25 Nov 2024 13:39:49 +0700 Subject: [PATCH 02/20] feat(wasm-dpp): implement userFeeIncrease --- .../data_contract_create_transition/mod.rs | 11 +++++++++++ .../data_contract_update_transition/mod.rs | 9 +++++++++ .../state_transition/document_batch_transition/mod.rs | 10 ++++++++++ .../identity_create_transition.rs | 10 ++++++++++ .../identity_credit_transfer_transition/transition.rs | 10 ++++++++++ .../transition.rs | 10 ++++++++++ .../identity_topup_transition.rs | 10 ++++++++++ .../identity_update_transition.rs | 10 ++++++++++ 8 files changed, 80 insertions(+) diff --git a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_create_transition/mod.rs b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_create_transition/mod.rs index 536995f2b1a..dfb6de5a27f 100644 --- a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_create_transition/mod.rs +++ b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_create_transition/mod.rs @@ -81,6 +81,17 @@ impl DataContractCreateTransitionWasm { pub fn get_type(&self) -> u32 { self.0.state_transition_type() as u32 } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + // // #[wasm_bindgen(js_name=toJSON)] // pub fn to_json(&self, skip_signature: Option) -> Result { diff --git a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs index 02fa59c0b1c..f59e76a5fef 100644 --- a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs +++ b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs @@ -78,6 +78,15 @@ impl DataContractUpdateTransitionWasm { self.0.state_transition_type() as u32 } + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } // #[wasm_bindgen(js_name=toJSON)] // pub fn to_json(&self, skip_signature: Option) -> Result { // let serializer = serde_wasm_bindgen::Serializer::json_compatible(); diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs index d0ebb9ae56d..41634b985aa 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs @@ -98,6 +98,16 @@ impl DocumentsBatchTransitionWasm { self.0.owner_id().to_owned().into() } + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + #[wasm_bindgen(js_name=getTransitions)] pub fn get_transitions(&self) -> js_sys::Array { let array = js_sys::Array::new(); diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs index 86681592df3..b4c4e880532 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs @@ -170,6 +170,16 @@ impl IdentityCreateTransitionWasm { (IdentityCreateTransitionAccessorsV0::owner_id(&self.0)).into() } + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs index 40fcf84fb96..a9b609f4390 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs @@ -99,6 +99,16 @@ impl IdentityCreditTransferTransitionWasm { self.0.set_amount(amount as u64); } + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs index 3de33cb834d..33aec4a8326 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs @@ -136,6 +136,16 @@ impl IdentityCreditWithdrawalTransitionWasm { self.0.set_nonce(revision); } + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs index 5455e12edca..ff79eb2479c 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs @@ -115,6 +115,16 @@ impl IdentityTopUpTransitionWasm { self.0.owner_id().to_owned().into() } + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs index 1d8988ba6f9..5d4b08cc2a5 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs @@ -169,6 +169,16 @@ impl IdentityUpdateTransitionWasm { StateTransitionLike::owner_id(&self.0).to_owned().into() } + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { From 6744f4e7cc6e5661f4a3278dd68a2be4871d23e0 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Mon, 25 Nov 2024 22:57:05 +0700 Subject: [PATCH 03/20] feat(wasm-dpp): add identity and identity contract nonces --- .../data_contract_update_transition/mod.rs | 5 +++++ .../document_create_transition.rs | 16 ++++++++++++++++ .../document_delete_transition.rs | 14 ++++++++++++++ .../document_replace_transition.rs | 14 ++++++++++++++ .../transition.rs | 10 ++++++++++ .../transition.rs | 10 ++++++++++ .../identity_update_transition.rs | 10 ++++++++++ .../masternode_vote_transition/mod.rs | 15 +++++++++++++++ 8 files changed, 94 insertions(+) diff --git a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs index f59e76a5fef..4e61aa60a8b 100644 --- a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs +++ b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs @@ -73,6 +73,11 @@ impl DataContractUpdateTransitionWasm { self.0.owner_id().into() } + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_contract_nonce(&self) -> u64 { + self.0.identity_contract_nonce() as u64 + } + #[wasm_bindgen(js_name=getType)] pub fn get_type(&self) -> u32 { self.0.state_transition_type() as u32 diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs index 8cf7b5d0b97..9062574e5ab 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs @@ -5,6 +5,8 @@ use dpp::state_transition::documents_batch_transition::document_create_transitio use dpp::document::INITIAL_REVISION; use wasm_bindgen::prelude::*; +use dpp::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods; +use dpp::state_transition::documents_batch_transition::document_create_transition::v0::v0_methods::DocumentCreateTransitionV0Methods; #[wasm_bindgen(js_name=DocumentCreateTransition)] #[derive(Debug, Clone)] @@ -81,6 +83,20 @@ impl DocumentCreateTransitionWasm { INITIAL_REVISION as u32 } + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_contract_nonce(&self) -> u64 { + self.inner.base().identity_contract_nonce() as u64 + } + + #[wasm_bindgen(js_name=setIdentityContractNonce)] + pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: u64) -> () { + let mut base = self.inner.base().clone(); + + base.set_identity_contract_nonce(identity_contract_nonce); + + self.inner.set_base(base) + } + // // AbstractDocumentTransitionMethods // #[wasm_bindgen(js_name=getId)] // pub fn id(&self) -> IdentifierWrapper { diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs index df92c0605df..762e1fdb9a5 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs @@ -73,6 +73,20 @@ impl DocumentDeleteTransitionWasm { self.inner.base().data_contract_id().into() } + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_contract_nonce(&self) -> u64 { + self.inner.base().identity_contract_nonce() as u64 + } + + #[wasm_bindgen(js_name=setIdentityContractNonce)] + pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: u64) -> () { + let mut base = self.inner.base().clone(); + + base.set_identity_contract_nonce(identity_contract_nonce); + + self.inner.set_base(base) + } + #[wasm_bindgen(js_name=get)] pub fn get(&self, path: String) -> Result { let _ = path; diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs index e0fcdbaeb3f..af5711e9cd0 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs @@ -189,6 +189,20 @@ impl DocumentReplaceTransitionWasm { self.inner.base().data_contract_id().into() } + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_contract_nonce(&self) -> u64 { + self.inner.base().identity_contract_nonce() as u64 + } + + #[wasm_bindgen(js_name=setIdentityContractNonce)] + pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: u64) -> () { + let mut base = self.inner.base().clone(); + + base.set_identity_contract_nonce(identity_contract_nonce); + + self.inner.set_base(base) + } + #[wasm_bindgen(js_name=get)] pub fn get(&self, path: String) -> Result { let document_data = if let Some(ref data) = self.inner.data() { diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs index a9b609f4390..ba23c1915ab 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs @@ -109,6 +109,16 @@ impl IdentityCreditTransferTransitionWasm { self.0.set_user_fee_increase(user_fee_increase); } + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_nonce(&self) -> u64 { + self.0.nonce() + } + + #[wasm_bindgen(js_name=setIdentityContractNonce)] + pub fn set_identity_contract_nonce(&mut self, identity_nonce: u64) -> () { + self.0.set_nonce(identity_nonce) + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs index 33aec4a8326..f7239f9c5fe 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs @@ -146,6 +146,16 @@ impl IdentityCreditWithdrawalTransitionWasm { self.0.set_user_fee_increase(user_fee_increase); } + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_nonce(&self) -> u64 { + self.0.nonce() + } + + #[wasm_bindgen(js_name=setIdentityContractNonce)] + pub fn set_identity_contract_nonce(&mut self, identity_nonce: u64) -> () { + self.0.set_nonce(identity_nonce) + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs index 5d4b08cc2a5..026a9ee29c6 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs @@ -179,6 +179,16 @@ impl IdentityUpdateTransitionWasm { self.0.set_user_fee_increase(user_fee_increase); } + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_nonce(&self) -> u64 { + self.0.nonce() + } + + #[wasm_bindgen(js_name=setIdentityContractNonce)] + pub fn set_identity_contract_nonce(&mut self, identity_nonce: u64) -> () { + self.0.set_nonce(identity_nonce) + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { diff --git a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs index 6ade2fc9cd2..6dff23383ff 100644 --- a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs +++ b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs @@ -70,6 +70,21 @@ impl MasternodeVoteTransitionWasm { self.0.set_pro_tx_hash(pro_tx_hash.into()); } + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_nonce(&self) -> u64 { + self.0.nonce() + } + #[wasm_bindgen(js_name = toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: self::to_object::ToObjectOptions = if options.is_object() { From 699c6339a31aaf7e8c025b27cc1a1a82f61f23da Mon Sep 17 00:00:00 2001 From: pshenmic Date: Mon, 25 Nov 2024 23:47:00 +0700 Subject: [PATCH 04/20] feat(wasm-dpp): ensure signature and signature public key id in each transition --- .../data_contract_create_transition/mod.rs | 10 ++++++++++ .../data_contract_update_transition/mod.rs | 11 +++++++++++ .../state_transition/document_batch_transition/mod.rs | 10 ++++++++++ .../identity_create_transition.rs | 6 ++++++ .../identity_credit_transfer_transition/transition.rs | 5 +++++ .../transition.rs | 5 +++++ .../identity_topup_transition.rs | 5 +++++ .../identity_update_transition.rs | 5 +++++ .../masternode_vote_transition/mod.rs | 5 +++++ 9 files changed, 62 insertions(+) diff --git a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_create_transition/mod.rs b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_create_transition/mod.rs index dfb6de5a27f..23a3b157fb0 100644 --- a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_create_transition/mod.rs +++ b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_create_transition/mod.rs @@ -92,6 +92,16 @@ impl DataContractCreateTransitionWasm { self.0.user_fee_increase() as u16 } + #[wasm_bindgen(js_name=getSignature)] + pub fn get_signature(&self) -> Buffer { + Buffer::from_bytes(self.0.signature().as_slice()) + } + + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + // // #[wasm_bindgen(js_name=toJSON)] // pub fn to_json(&self, skip_signature: Option) -> Result { diff --git a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs index 4e61aa60a8b..994835a5b6d 100644 --- a/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs +++ b/packages/wasm-dpp/src/data_contract/state_transition/data_contract_update_transition/mod.rs @@ -92,6 +92,17 @@ impl DataContractUpdateTransitionWasm { pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { self.0.set_user_fee_increase(user_fee_increase); } + + #[wasm_bindgen(js_name=getSignature)] + pub fn get_signature(&self) -> Buffer { + Buffer::from_bytes(self.0.signature().as_slice()) + } + + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + // #[wasm_bindgen(js_name=toJSON)] // pub fn to_json(&self, skip_signature: Option) -> Result { // let serializer = serde_wasm_bindgen::Serializer::json_compatible(); diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs index 41634b985aa..4cce57f30ea 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs @@ -142,6 +142,16 @@ impl DocumentsBatchTransitionWasm { self.0.set_identity_contract_nonce(nonce as u64); } + #[wasm_bindgen(js_name=getSignature)] + pub fn get_signature(&self) -> Buffer { + Buffer::from_bytes(self.0.signature().as_slice()) + } + + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + // #[wasm_bindgen(js_name=toJSON)] // pub fn to_json(&self) -> Result { // let value = self.0.to_json(false).with_js_error()?; diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs index b4c4e880532..fef9cd5ecc2 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs @@ -376,4 +376,10 @@ impl IdentityCreateTransitionWasm { self.0 .set_signature(BinaryData::new(signature.unwrap_or_default())) } + + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + } diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs index ba23c1915ab..4f5139c1f1a 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs @@ -338,6 +338,11 @@ impl IdentityCreditTransferTransitionWasm { .set_signature(BinaryData::new(signature.unwrap_or_default())) } + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + #[wasm_bindgen] pub fn sign( &mut self, diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs index f7239f9c5fe..eaebf1b6d4a 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs @@ -420,6 +420,11 @@ impl IdentityCreditWithdrawalTransitionWasm { .set_signature(BinaryData::new(signature.unwrap_or_default())) } + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + #[wasm_bindgen] pub fn sign( &mut self, diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs index ff79eb2479c..38fab7cdbc7 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs @@ -125,6 +125,11 @@ impl IdentityTopUpTransitionWasm { self.0.set_user_fee_increase(user_fee_increase); } + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs index 026a9ee29c6..52e7e9e9d3e 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_update_transition/identity_update_transition.rs @@ -432,6 +432,11 @@ impl IdentityUpdateTransitionWasm { Buffer::from_bytes_owned(self.0.signature().to_vec()) } + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + #[wasm_bindgen(js_name=setSignature)] pub fn set_signature(&mut self, signature: Option>) { self.0 diff --git a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs index 6dff23383ff..62c7f32ec76 100644 --- a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs +++ b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs @@ -351,6 +351,11 @@ impl MasternodeVoteTransitionWasm { .set_signature(BinaryData::new(signature.unwrap_or_default())) } + #[wasm_bindgen(js_name=getSignaturePublicKeyId)] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + #[wasm_bindgen] pub fn sign( &mut self, From dc5aedb0cf28f7330a953e7eb58b194a2834ec9f Mon Sep 17 00:00:00 2001 From: pshenmic Date: Tue, 26 Nov 2024 01:55:05 +0700 Subject: [PATCH 05/20] fix(wasm-dpp): remove duplicated --- .../identity_create_transition.rs | 6 ------ .../identity_topup_transition/identity_topup_transition.rs | 5 ----- 2 files changed, 11 deletions(-) diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs index fef9cd5ecc2..b4c4e880532 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_create_transition/identity_create_transition.rs @@ -376,10 +376,4 @@ impl IdentityCreateTransitionWasm { self.0 .set_signature(BinaryData::new(signature.unwrap_or_default())) } - - #[wasm_bindgen(js_name=getSignaturePublicKeyId)] - pub fn get_signature_public_key_id(&self) -> u32 { - self.0.signature_public_key_id() - } - } diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs index 38fab7cdbc7..ff79eb2479c 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs @@ -125,11 +125,6 @@ impl IdentityTopUpTransitionWasm { self.0.set_user_fee_increase(user_fee_increase); } - #[wasm_bindgen(js_name=getSignaturePublicKeyId)] - pub fn get_signature_public_key_id(&self) -> u32 { - self.0.signature_public_key_id() - } - #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { From 797e75b1858eb01bdf4006920579cb538ab82d1d Mon Sep 17 00:00:00 2001 From: pshenmic Date: Tue, 26 Nov 2024 01:55:14 +0700 Subject: [PATCH 06/20] fix(wasm-dpp): remove duplicated --- .../state_transition/document_batch_transition/mod.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs index 4cce57f30ea..41634b985aa 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs @@ -142,16 +142,6 @@ impl DocumentsBatchTransitionWasm { self.0.set_identity_contract_nonce(nonce as u64); } - #[wasm_bindgen(js_name=getSignature)] - pub fn get_signature(&self) -> Buffer { - Buffer::from_bytes(self.0.signature().as_slice()) - } - - #[wasm_bindgen(js_name=getSignaturePublicKeyId)] - pub fn get_signature_public_key_id(&self) -> u32 { - self.0.signature_public_key_id() - } - // #[wasm_bindgen(js_name=toJSON)] // pub fn to_json(&self) -> Result { // let value = self.0.to_json(false).with_js_error()?; From cacc5e71b2df98ab8bcceab6358feb813ff07ee9 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Tue, 26 Nov 2024 01:55:49 +0700 Subject: [PATCH 07/20] fix(wasm-dpp): add prefundedVotingBalance in create document transition --- .../document_create_transition.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs index 9062574e5ab..a0cd41118db 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs @@ -97,6 +97,28 @@ impl DocumentCreateTransitionWasm { self.inner.set_base(base) } + #[wasm_bindgen(js_name = getPrefundedVotingBalance)] + pub fn get_prefunded_voting_balance(&self) -> Result { + let prefunded_voting_balance = self.inner.prefunded_voting_balance().clone(); + + match prefunded_voting_balance { + None => { + Ok(JsValue::null()) + }, + Some((index_name, credits)) => { + let js_object = js_sys::Object::new(); + + js_sys::Reflect::set( + &js_object, + &JsValue::from_str(&index_name), + &JsValue::from(credits), + )?; + + Ok(JsValue::from(js_object)) + } + } + } + // // AbstractDocumentTransitionMethods // #[wasm_bindgen(js_name=getId)] // pub fn id(&self) -> IdentifierWrapper { From 23c0672b26e3f3782a8b86ddbf06fac55cf50f35 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Tue, 26 Nov 2024 03:42:28 +0700 Subject: [PATCH 08/20] feat(wasm-dpp): add prefundedVotingBalance in document transition --- .../document_transition/mod.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs index a26d579d7de..8dd48046ff9 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs @@ -82,6 +82,32 @@ impl DocumentTransitionWasm { _ => false, } } + + #[wasm_bindgen(js_name=hasPrefundedBalance)] + pub fn get_prefunded_voting_balance(&self) -> Result { + match &self.0 { + DocumentTransition::Create(create_transition) => { + let prefunded_voting_balance = create_transition.prefunded_voting_balance().clone(); + + if prefunded_voting_balance.is_none() { + return Ok(JsValue::null()) + } + + let (index_name, credits) = prefunded_voting_balance.unwrap(); + + let js_object = js_sys::Object::new(); + + js_sys::Reflect::set( + &js_object, + &JsValue::from_str(&index_name), + &JsValue::from(credits), + )?; + + Ok(JsValue::from(js_object)) + } + _ => Ok(JsValue::null()), + } + } } impl From for DocumentTransitionWasm { From 7a04862ae26cebb19aa297401f99df39bdcfa48d Mon Sep 17 00:00:00 2001 From: pshenmic Date: Tue, 26 Nov 2024 03:43:06 +0700 Subject: [PATCH 09/20] feat(rs-dpp): add more action types in try from for DocumentTransitionActionType --- .../document_transition/action_type.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/action_type.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/action_type.rs index fd7c376f7b9..4b61c44fe55 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/action_type.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/action_type.rs @@ -39,6 +39,8 @@ impl TryFrom<&str> for DocumentTransitionActionType { "replace" => Ok(DocumentTransitionActionType::Replace), "delete" => Ok(DocumentTransitionActionType::Delete), "transfer" => Ok(DocumentTransitionActionType::Transfer), + "purchase" => Ok(DocumentTransitionActionType::Purchase), + "updatePrice" => Ok(DocumentTransitionActionType::UpdatePrice), action_type => Err(ProtocolError::Generic(format!( "unknown action type {action_type}" ))), From e3c3942fe9ea39d468f401dfa3fb09465c8ae6c6 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Tue, 26 Nov 2024 04:09:27 +0700 Subject: [PATCH 10/20] fix(wasm-dpp): fix js binding method name --- .../document_batch_transition/document_transition/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs index 8dd48046ff9..8849440e61b 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs @@ -83,7 +83,7 @@ impl DocumentTransitionWasm { } } - #[wasm_bindgen(js_name=hasPrefundedBalance)] + #[wasm_bindgen(js_name=getPrefundedVotingBalance)] pub fn get_prefunded_voting_balance(&self) -> Result { match &self.0 { DocumentTransition::Create(create_transition) => { From d7d184f85470121df94e45464e1854be6fa67c50 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Tue, 26 Nov 2024 05:35:25 +0700 Subject: [PATCH 11/20] feat(wasm-dpp): add getData for DocumentTransition --- .../document_transition/mod.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs index 8849440e61b..574268a709e 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs @@ -17,6 +17,8 @@ use dpp::{ use serde::Serialize; use serde_json::Value as JsonValue; use wasm_bindgen::prelude::*; +use dpp::platform_value::converter::serde_json::BTreeValueJsonConverter; +use dpp::state_transition::documents_batch_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods; use crate::{ buffer::Buffer, @@ -42,6 +44,24 @@ impl DocumentTransitionWasm { self.0.document_type_name().to_owned() } + #[wasm_bindgen(js_name=getData)] + pub fn get_data(&self) -> JsValue { + match &self.0 { + DocumentTransition::Create(document_create_transition) => { + let json_value = document_create_transition.data().to_json_value().unwrap(); + json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible()).unwrap() + } + DocumentTransition::Replace(document_replace_transition) => { + let json_value = document_replace_transition.data().to_json_value().unwrap(); + json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible()).unwrap() + } + DocumentTransition::Delete(document_delete_transition) => JsValue::null(), + DocumentTransition::Transfer(document_transfer_transition) => JsValue::null(), + DocumentTransition::UpdatePrice(document_update_price_transition) => JsValue::null(), + DocumentTransition::Purchase(document_purchase_transition) => JsValue::null() + } + } + #[wasm_bindgen(js_name=getAction)] pub fn get_action(&self) -> u8 { self.0.action_type() as u8 From ec0c4d588cc65789ebdec3eac041ca93c4cad64d Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 19 Dec 2024 01:57:16 +0700 Subject: [PATCH 12/20] chore(wasm-dpp): cleanup masternode vote --- .../masternode_vote_transition/mod.rs | 73 +++++++++---------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs index 62c7f32ec76..a01cabe947c 100644 --- a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs +++ b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs @@ -23,7 +23,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] -#[wasm_bindgen(js_name = MasternodeVoteTransition)] +#[wasm_bindgen(js_name=MasternodeVoteTransition)] pub struct MasternodeVoteTransitionWasm(MasternodeVoteTransition); impl From for MasternodeVoteTransitionWasm { @@ -38,7 +38,7 @@ impl From for MasternodeVoteTransition { } } -#[wasm_bindgen(js_class = MasternodeVoteTransition)] +#[wasm_bindgen(js_class=MasternodeVoteTransition)] impl MasternodeVoteTransitionWasm { #[wasm_bindgen(constructor)] pub fn new(platform_version: u32) -> Result { @@ -50,42 +50,27 @@ impl MasternodeVoteTransitionWasm { .map_err(from_dpp_err) } - #[wasm_bindgen(js_name = getOwnerId)] + #[wasm_bindgen(js_name=getOwnerId)] pub fn get_owner_id(&self) -> IdentifierWrapper { self.0.owner_id().to_owned().into() } - #[wasm_bindgen(js_name = getType)] + #[wasm_bindgen(js_name=getType)] pub fn get_type(&self) -> u8 { self.0.state_transition_type() as u8 } - #[wasm_bindgen(js_name = getProTxHash)] + #[wasm_bindgen(js_name=getProTxHash)] pub fn get_pro_tx_hash(&self) -> IdentifierWrapper { self.0.pro_tx_hash().into() } - #[wasm_bindgen(js_name = setProTxHash)] + #[wasm_bindgen(js_name=setProTxHash)] pub fn set_pro_tx_hash(&mut self, pro_tx_hash: &IdentifierWrapper) { self.0.set_pro_tx_hash(pro_tx_hash.into()); } - #[wasm_bindgen(js_name=getUserFeeIncrease)] - pub fn get_user_fee_increase(&self) -> u16 { - self.0.user_fee_increase() as u16 - } - - #[wasm_bindgen(js_name=setUserFeeIncrease)] - pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { - self.0.set_user_fee_increase(user_fee_increase); - } - - #[wasm_bindgen(js_name=getIdentityContractNonce)] - pub fn get_identity_nonce(&self) -> u64 { - self.0.nonce() - } - - #[wasm_bindgen(js_name = toObject)] + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: self::to_object::ToObjectOptions = if options.is_object() { with_js_error!(serde_wasm_bindgen::from_value(options))? @@ -143,7 +128,7 @@ impl MasternodeVoteTransitionWasm { Ok(js_object.into()) } - #[wasm_bindgen(js_name = toBuffer)] + #[wasm_bindgen(js_name=toBuffer)] pub fn to_buffer(&self) -> Result { let bytes = PlatformSerializable::serialize_to_bytes(&StateTransition::MasternodeVote( self.0.clone(), @@ -152,7 +137,7 @@ impl MasternodeVoteTransitionWasm { Ok(Buffer::from_bytes(&bytes)) } - #[wasm_bindgen(js_name = toJSON)] + #[wasm_bindgen(js_name=toJSON)] pub fn to_json(&self) -> Result { let object = self::to_object::to_object_struct(&self.0, Default::default()); let js_object = js_sys::Object::new(); @@ -206,7 +191,7 @@ impl MasternodeVoteTransitionWasm { Ok(js_object.into()) } - #[wasm_bindgen(js_name = getModifiedDataIds)] + #[wasm_bindgen(js_name=getModifiedDataIds)] pub fn modified_data_ids(&self) -> Vec { let ids = self.0.modified_data_ids(); @@ -215,27 +200,42 @@ impl MasternodeVoteTransitionWasm { .collect() } - #[wasm_bindgen(js_name = isDataContractStateTransition)] + #[wasm_bindgen(js_name=isDataContractStateTransition)] pub fn is_data_contract_state_transition(&self) -> bool { self.0.is_data_contract_state_transition() } - #[wasm_bindgen(js_name = isDocumentStateTransition)] + #[wasm_bindgen(js_name=isDocumentStateTransition)] pub fn is_document_state_transition(&self) -> bool { self.0.is_document_state_transition() } - #[wasm_bindgen(js_name = isIdentityStateTransition)] + #[wasm_bindgen(js_name=isIdentityStateTransition)] pub fn is_identity_state_transition(&self) -> bool { self.0.is_identity_state_transition() } - #[wasm_bindgen(js_name = isVotingStateTransition)] + #[wasm_bindgen(js_name=isVotingStateTransition)] pub fn is_voting_state_transition(&self) -> bool { self.0.is_voting_state_transition() } - #[wasm_bindgen(js_name = getContestedDocumentResourceVotePoll)] + #[wasm_bindgen(js_name=getUserFeeIncrease)] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() as u16 + } + + #[wasm_bindgen(js_name=setUserFeeIncrease)] + pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) { + self.0.set_user_fee_increase(user_fee_increase); + } + + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_nonce(&self) -> u64 { + self.0.nonce() + } + + #[wasm_bindgen(js_name=getContestedDocumentResourceVotePoll)] pub fn contested_document_resource_vote_poll(&self) -> Option { match self.0.vote() { Vote::ResourceVote(vote) => { @@ -304,7 +304,7 @@ impl MasternodeVoteTransitionWasm { } } - #[wasm_bindgen(js_name = signByPrivateKey)] + #[wasm_bindgen(js_name=signByPrivateKey)] pub fn sign_by_private_key( &mut self, private_key: Vec, @@ -340,22 +340,17 @@ impl MasternodeVoteTransitionWasm { Ok(()) } - #[wasm_bindgen(js_name = getSignature)] + #[wasm_bindgen(js_name=getSignature)] pub fn get_signature(&self) -> Buffer { Buffer::from_bytes(self.0.signature().as_slice()) } - #[wasm_bindgen(js_name = setSignature)] + #[wasm_bindgen(js_name=setSignature)] pub fn set_signature(&mut self, signature: Option>) { self.0 .set_signature(BinaryData::new(signature.unwrap_or_default())) } - #[wasm_bindgen(js_name=getSignaturePublicKeyId)] - pub fn get_signature_public_key_id(&self) -> u32 { - self.0.signature_public_key_id() - } - #[wasm_bindgen] pub fn sign( &mut self, @@ -383,4 +378,4 @@ impl MasternodeVoteTransitionWasm { Ok(()) } -} +} \ No newline at end of file From 0aaf02ac443144b63abb082a30eae4af43023d28 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 19 Dec 2024 02:00:19 +0700 Subject: [PATCH 13/20] chore(wasm-dpp): cleanup masternode vote --- .../state_transition/masternode_vote_transition/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs index a01cabe947c..a20288f2a4d 100644 --- a/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs +++ b/packages/wasm-dpp/src/voting/state_transition/masternode_vote_transition/mod.rs @@ -133,7 +133,7 @@ impl MasternodeVoteTransitionWasm { let bytes = PlatformSerializable::serialize_to_bytes(&StateTransition::MasternodeVote( self.0.clone(), )) - .with_js_error()?; + .with_js_error()?; Ok(Buffer::from_bytes(&bytes)) } @@ -300,7 +300,7 @@ impl MasternodeVoteTransitionWasm { Some(js_object) } } - } + }, } } @@ -319,7 +319,7 @@ impl MasternodeVoteTransitionWasm { return Err(JsError::new( format!("BLS adapter is required for BLS key type '{}'", key_type).as_str(), ) - .into()); + .into()); } let bls_adapter = if let Some(adapter) = bls { From dbbac77722dde2b2aec918ddd4b1b58f58b69784 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 19 Dec 2024 02:04:40 +0700 Subject: [PATCH 14/20] chore(wasm-dpp): remove duplicated nonce method --- .../transition.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs index eaebf1b6d4a..2b4462d1ad7 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs @@ -146,16 +146,6 @@ impl IdentityCreditWithdrawalTransitionWasm { self.0.set_user_fee_increase(user_fee_increase); } - #[wasm_bindgen(js_name=getIdentityContractNonce)] - pub fn get_identity_nonce(&self) -> u64 { - self.0.nonce() - } - - #[wasm_bindgen(js_name=setIdentityContractNonce)] - pub fn set_identity_contract_nonce(&mut self, identity_nonce: u64) -> () { - self.0.set_nonce(identity_nonce) - } - #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { From 711463ae9e167fb7627f5f88e43902a4b4747bdb Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 19 Dec 2024 02:07:28 +0700 Subject: [PATCH 15/20] chore(wasm-dpp): fix nonce method naming in credit withdrawals --- .../identity_credit_transfer_transition/transition.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs b/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs index 4f5139c1f1a..e20ec98b877 100644 --- a/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs +++ b/packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs @@ -109,14 +109,14 @@ impl IdentityCreditTransferTransitionWasm { self.0.set_user_fee_increase(user_fee_increase); } - #[wasm_bindgen(js_name=getIdentityContractNonce)] - pub fn get_identity_nonce(&self) -> u64 { + #[wasm_bindgen(js_name=getNonce)] + pub fn get_nonce(&self) -> u64 { self.0.nonce() } - #[wasm_bindgen(js_name=setIdentityContractNonce)] - pub fn set_identity_contract_nonce(&mut self, identity_nonce: u64) -> () { - self.0.set_nonce(identity_nonce) + #[wasm_bindgen(js_name=setNonce)] + pub fn set_nonce(&mut self, nonce: u64) -> () { + self.0.set_nonce(nonce) } #[wasm_bindgen(js_name=toObject)] From bab035902b4d84e775fcad1059b43da6b44f6453 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 27 Dec 2024 00:32:32 +0700 Subject: [PATCH 16/20] feat(wasm-dpp): add entropy getter for document transitions --- .../document_transition/document_create_transition.rs | 5 +++++ .../document_transition/document_delete_transition.rs | 5 +++++ .../document_transition/document_replace_transition.rs | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs index a0cd41118db..67c5f2cc687 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs @@ -83,6 +83,11 @@ impl DocumentCreateTransitionWasm { INITIAL_REVISION as u32 } + #[wasm_bindgen(js_name = getEntropy)] + pub fn get_entropy(&self) -> Vec { + Vec::from(self.inner.entropy()) + } + #[wasm_bindgen(js_name=getIdentityContractNonce)] pub fn get_identity_contract_nonce(&self) -> u64 { self.inner.base().identity_contract_nonce() as u64 diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs index 762e1fdb9a5..72614992e95 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs @@ -68,6 +68,11 @@ impl DocumentDeleteTransitionWasm { self.inner.base().document_type_name().clone() } + #[wasm_bindgen(js_name = getEntropy)] + pub fn get_entropy(&self) -> Vec { + Vec::from(self.inner.entropy()) + } + #[wasm_bindgen(js_name=getDataContractId)] pub fn data_contract_id(&self) -> IdentifierWrapper { self.inner.base().data_contract_id().into() diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs index af5711e9cd0..7ec0bf00e59 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs @@ -96,6 +96,11 @@ impl DocumentReplaceTransitionWasm { self.inner.revision() } + #[wasm_bindgen(js_name = getEntropy)] + pub fn get_entropy(&self) -> Vec { + Vec::from(self.inner.entropy()) + } + #[wasm_bindgen(js_name=getUpdatedAt)] pub fn updated_at(&self) -> Option { self.inner From 701d1b50e64d46b491e5dfac983f59af5779844f Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 27 Dec 2024 14:45:37 +0700 Subject: [PATCH 17/20] feat(wasm-dpp): add entropy getter for documenttransition --- .../document_transition/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs index 574268a709e..f8935edc9d5 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs @@ -87,6 +87,17 @@ impl DocumentTransitionWasm { JsValue::NULL } } + #[wasm_bindgen(js_name=getEntropy)] + pub fn get_revision(&self) -> Vec { + match self.0.clone() { + DocumentTransition::Create(document_transition) => Vec::from(document_transition.entropy()), + DocumentTransition::Replace(document_transition) => Vec::from(document_transition.entropy()), + DocumentTransition::Delete(document_transition) => Vec::from(document_transition.entropy()), + DocumentTransition::Transfer(document_transition) => Vec::from(document_transition.entropy()), + DocumentTransition::UpdatePrice(document_transition) => Vec::from(document_transition.entropy()), + DocumentTransition::Purchase(document_transition) => Vec::from(document_transition.entropy()), + } + } #[wasm_bindgen(js_name=setRevision)] pub fn set_revision(&mut self, revision: u32) { From d77e1aa81b18b2b22b0376590798562d9712830a Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 27 Dec 2024 20:26:50 +0700 Subject: [PATCH 18/20] feat(rs-dpp): add entropy getter in the rs dpp --- .../document_transition/mod.rs | 7 ++++++- .../document_transition/mod.rs | 11 ++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs index 448dffcfea4..cd7cea67492 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs @@ -44,7 +44,8 @@ pub trait DocumentTransitionV0Methods { fn get_dynamic_property(&self, path: &str) -> Option<&Value>; /// get the id fn get_id(&self) -> Identifier; - /// get the document type + /// get the entropy + fn entropy(&self) -> Vec; fn document_type_name(&self) -> &String; /// get the data contract id fn data_contract_id(&self) -> Identifier; @@ -167,6 +168,10 @@ impl DocumentTransitionV0Methods for DocumentTransition { self.base().document_type_name() } + fn entropy(&self) -> Vec { + self.entropy() + } + fn data_contract_id(&self) -> Identifier { self.base().data_contract_id() } diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs index f8935edc9d5..8a841f1300c 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs @@ -88,15 +88,8 @@ impl DocumentTransitionWasm { } } #[wasm_bindgen(js_name=getEntropy)] - pub fn get_revision(&self) -> Vec { - match self.0.clone() { - DocumentTransition::Create(document_transition) => Vec::from(document_transition.entropy()), - DocumentTransition::Replace(document_transition) => Vec::from(document_transition.entropy()), - DocumentTransition::Delete(document_transition) => Vec::from(document_transition.entropy()), - DocumentTransition::Transfer(document_transition) => Vec::from(document_transition.entropy()), - DocumentTransition::UpdatePrice(document_transition) => Vec::from(document_transition.entropy()), - DocumentTransition::Purchase(document_transition) => Vec::from(document_transition.entropy()), - } + pub fn get_entropy(&self) -> Vec { + self.0.entropy() } #[wasm_bindgen(js_name=setRevision)] From e21ae5318e46bce6fc6abee1ed8d20ef0329f5a5 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 27 Dec 2024 20:40:05 +0700 Subject: [PATCH 19/20] feat(dpp): move to optional --- .../document_transition/mod.rs | 13 ++++++++++--- .../document_transition/mod.rs | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs index cd7cea67492..477847b113a 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs @@ -45,7 +45,7 @@ pub trait DocumentTransitionV0Methods { /// get the id fn get_id(&self) -> Identifier; /// get the entropy - fn entropy(&self) -> Vec; + fn entropy(&self) -> Option>; fn document_type_name(&self) -> &String; /// get the data contract id fn data_contract_id(&self) -> Identifier; @@ -168,8 +168,15 @@ impl DocumentTransitionV0Methods for DocumentTransition { self.base().document_type_name() } - fn entropy(&self) -> Vec { - self.entropy() + fn entropy(&self) -> Option> { + match self { + DocumentTransition::Create(t) => Some(Vec::from(t.entropy())), + DocumentTransition::Replace(t) => None, + DocumentTransition::Delete(t) => None, + DocumentTransition::Transfer(t) => None, + DocumentTransition::UpdatePrice(t) => None, + DocumentTransition::Purchase(t) => None, + } } fn data_contract_id(&self) -> Identifier { diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs index 8a841f1300c..9b37d79d346 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs @@ -88,7 +88,7 @@ impl DocumentTransitionWasm { } } #[wasm_bindgen(js_name=getEntropy)] - pub fn get_entropy(&self) -> Vec { + pub fn get_entropy(&self) -> Option> { self.0.entropy() } From 2c9494172bd2c4326213460cc32cf18b67659fe6 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Thu, 2 Jan 2025 22:15:59 +0700 Subject: [PATCH 20/20] feat(js-sdk): getIdentityContractNonce() to document transition main file --- .../document_batch_transition/document_transition/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs index 9b37d79d346..c29852e78ad 100644 --- a/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs @@ -18,6 +18,7 @@ use serde::Serialize; use serde_json::Value as JsonValue; use wasm_bindgen::prelude::*; use dpp::platform_value::converter::serde_json::BTreeValueJsonConverter; +use dpp::state_transition::documents_batch_transition::document_base_transition::DocumentBaseTransition; use dpp::state_transition::documents_batch_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods; use crate::{ @@ -79,6 +80,11 @@ impl DocumentTransitionWasm { Ok(()) } + #[wasm_bindgen(js_name=getIdentityContractNonce)] + pub fn get_identity_contract_nonce(&self) -> JsValue { + match self.0.base() { DocumentBaseTransition::V0(v0) => JsValue::from(v0.identity_contract_nonce) } + } + #[wasm_bindgen(js_name=getRevision)] pub fn get_revision(&self) -> JsValue { if let Some(revision) = self.0.revision() {