Skip to content

Commit

Permalink
feat(wasm-dpp): add getPrice and getReceiverId
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic committed Jan 23, 2025
1 parent 2c94941 commit 9bf5f56
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ use dpp::{
use serde::Serialize;
use serde_json::Value as JsonValue;
use wasm_bindgen::prelude::*;
use dpp::fee::Credits;
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 dpp::state_transition::documents_batch_transition::document_transition::document_purchase_transition::v0::v0_methods::DocumentPurchaseTransitionV0Methods;
use dpp::state_transition::documents_batch_transition::document_transition::document_transfer_transition::v0::v0_methods::DocumentTransferTransitionV0Methods;
use dpp::state_transition::documents_batch_transition::document_transition::document_update_price_transition::v0::v0_methods::DocumentUpdatePriceTransitionV0Methods;
use crate::{
buffer::Buffer,
identifier::{identifier_from_js_value, IdentifierWrapper},
Expand Down Expand Up @@ -98,6 +101,30 @@ impl DocumentTransitionWasm {
self.0.entropy()
}

#[wasm_bindgen(js_name=get_price)]
pub fn get_price(&self) -> Option<Credits> {
match &self.0 {
DocumentTransition::Create(create) => None,
DocumentTransition::Replace(_) => None,
DocumentTransition::Delete(_) => None,
DocumentTransition::Transfer(_) => None,
DocumentTransition::UpdatePrice(update_price) => Some(update_price.price()),
DocumentTransition::Purchase(purchase) => Some(purchase.price())
}
}

#[wasm_bindgen(js_name=getReceiverId)]
pub fn get_receiver_id(&self) -> Option<IdentifierWrapper> {
match &self.0 {
DocumentTransition::Create(create) => None,
DocumentTransition::Replace(_) => None,
DocumentTransition::Delete(_) => None,
DocumentTransition::Transfer(transfer) => Some(transfer.recipient_owner_id().into()),
DocumentTransition::UpdatePrice(update_price) => None,
DocumentTransition::Purchase(purchase) => None,
}
}

#[wasm_bindgen(js_name=setRevision)]
pub fn set_revision(&mut self, revision: u32) {
self.0.set_revision(revision as u64);
Expand Down

0 comments on commit 9bf5f56

Please sign in to comment.