Skip to content

Commit

Permalink
chore(wasm-dpp): cleanup masternode vote
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic committed Dec 18, 2024
1 parent 5901158 commit ec0c4d5
Showing 1 changed file with 34 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<MasternodeVoteTransition> for MasternodeVoteTransitionWasm {
Expand All @@ -38,7 +38,7 @@ impl From<MasternodeVoteTransitionWasm> for MasternodeVoteTransition {
}
}

#[wasm_bindgen(js_class = MasternodeVoteTransition)]
#[wasm_bindgen(js_class=MasternodeVoteTransition)]
impl MasternodeVoteTransitionWasm {
#[wasm_bindgen(constructor)]
pub fn new(platform_version: u32) -> Result<MasternodeVoteTransitionWasm, JsValue> {
Expand All @@ -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<JsValue, JsValue> {
let opts: self::to_object::ToObjectOptions = if options.is_object() {
with_js_error!(serde_wasm_bindgen::from_value(options))?
Expand Down Expand Up @@ -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<Buffer, JsValue> {
let bytes = PlatformSerializable::serialize_to_bytes(&StateTransition::MasternodeVote(
self.0.clone(),
Expand All @@ -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<JsValue, JsValue> {
let object = self::to_object::to_object_struct(&self.0, Default::default());
let js_object = js_sys::Object::new();
Expand Down Expand Up @@ -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<JsValue> {
let ids = self.0.modified_data_ids();

Expand All @@ -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<Object> {
match self.0.vote() {
Vote::ResourceVote(vote) => {
Expand Down Expand Up @@ -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<u8>,
Expand Down Expand Up @@ -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<Vec<u8>>) {
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,
Expand Down Expand Up @@ -383,4 +378,4 @@ impl MasternodeVoteTransitionWasm {

Ok(())
}
}
}

0 comments on commit ec0c4d5

Please sign in to comment.