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 fd7c376f7b..4b61c44fe5 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}" ))), 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 448dffcfea..477847b113 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) -> Option>; fn document_type_name(&self) -> &String; /// get the data contract id fn data_contract_id(&self) -> Identifier; @@ -167,6 +168,17 @@ impl DocumentTransitionV0Methods for DocumentTransition { self.base().document_type_name() } + 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 { self.base().data_contract_id() } 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 536995f2b1..23a3b157fb 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,27 @@ 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=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 02fa59c0b1..994835a5b6 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,11 +73,36 @@ 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 } + #[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=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/document_transition/document_create_transition.rs b/packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs index 8cf7b5d0b9..67c5f2cc68 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,47 @@ 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 + } + + #[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 = 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 { 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 df92c0605d..72614992e9 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,11 +68,30 @@ 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() } + #[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 e0fcdbaeb3..7ec0bf00e5 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 @@ -189,6 +194,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/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 a26d579d7d..9b37d79d34 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 @@ -67,6 +87,10 @@ impl DocumentTransitionWasm { JsValue::NULL } } + #[wasm_bindgen(js_name=getEntropy)] + pub fn get_entropy(&self) -> Option> { + self.0.entropy() + } #[wasm_bindgen(js_name=setRevision)] pub fn set_revision(&mut self, revision: u32) { @@ -82,6 +106,32 @@ impl DocumentTransitionWasm { _ => false, } } + + #[wasm_bindgen(js_name=getPrefundedVotingBalance)] + 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 { 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 d0ebb9ae56..41634b985a 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 86681592df..b4c4e88053 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 40fcf84fb9..e20ec98b87 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,26 @@ 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=getNonce)] + pub fn get_nonce(&self) -> u64 { + self.0.nonce() + } + + #[wasm_bindgen(js_name=setNonce)] + pub fn set_nonce(&mut self, nonce: u64) -> () { + self.0.set_nonce(nonce) + } + #[wasm_bindgen(js_name=toObject)] pub fn to_object(&self, options: JsValue) -> Result { let opts: super::to_object::ToObjectOptions = if options.is_object() { @@ -318,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 3de33cb834..2b4462d1ad 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() { @@ -400,6 +410,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 5455e12edc..ff79eb2479 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 1d8988ba6f..52e7e9e9d3 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,26 @@ 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=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() { @@ -412,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 4ee92d0023..a20288f2a4 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 @@ -220,58 +220,85 @@ impl MasternodeVoteTransitionWasm { self.0.is_voting_state_transition() } + #[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) => 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) + } } }, } @@ -351,4 +378,4 @@ impl MasternodeVoteTransitionWasm { Ok(()) } -} +} \ No newline at end of file