Skip to content

Commit

Permalink
feat(wasm-dpp): add getData for DocumentTransition
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic committed Nov 25, 2024
1 parent e3c3942 commit d7d184f
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit d7d184f

Please sign in to comment.