Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wasm-dpp): add extra methods for state transitions #2401

Open
wants to merge 20 commits into
base: v1.8-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6196555
feat(wasm-dpp): add resource vote choice
pshenmic Nov 21, 2024
b69bcc6
feat(wasm-dpp): implement userFeeIncrease
pshenmic Nov 25, 2024
6744f4e
feat(wasm-dpp): add identity and identity contract nonces
pshenmic Nov 25, 2024
699c633
feat(wasm-dpp): ensure signature and signature public key id in each …
pshenmic Nov 25, 2024
dc5aedb
fix(wasm-dpp): remove duplicated
pshenmic Nov 25, 2024
797e75b
fix(wasm-dpp): remove duplicated
pshenmic Nov 25, 2024
cacc5e7
fix(wasm-dpp): add prefundedVotingBalance in create document transition
pshenmic Nov 25, 2024
23c0672
feat(wasm-dpp): add prefundedVotingBalance in document transition
pshenmic Nov 25, 2024
7a04862
feat(rs-dpp): add more action types in try from for DocumentTransitio…
pshenmic Nov 25, 2024
e3c3942
fix(wasm-dpp): fix js binding method name
pshenmic Nov 25, 2024
d7d184f
feat(wasm-dpp): add getData for DocumentTransition
pshenmic Nov 25, 2024
5901158
Merge branch 'refs/heads/temp' into feat/wasm-extra-fields
pshenmic Dec 17, 2024
ec0c4d5
chore(wasm-dpp): cleanup masternode vote
pshenmic Dec 18, 2024
0aaf02a
chore(wasm-dpp): cleanup masternode vote
pshenmic Dec 18, 2024
dbbac77
chore(wasm-dpp): remove duplicated nonce method
pshenmic Dec 18, 2024
711463a
chore(wasm-dpp): fix nonce method naming in credit withdrawals
pshenmic Dec 18, 2024
bab0359
feat(wasm-dpp): add entropy getter for document transitions
pshenmic Dec 26, 2024
701d1b5
feat(wasm-dpp): add entropy getter for documenttransition
pshenmic Dec 27, 2024
d77e1aa
feat(rs-dpp): add entropy getter in the rs dpp
pshenmic Dec 27, 2024
e21ae53
feat(dpp): move to optional
pshenmic Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
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<Vec<u8>>;
fn document_type_name(&self) -> &String;
/// get the data contract id
fn data_contract_id(&self) -> Identifier;
Expand Down Expand Up @@ -167,6 +168,17 @@
self.base().document_type_name()
}

fn entropy(&self) -> Option<Vec<u8>> {
match self {
DocumentTransition::Create(t) => Some(Vec::from(t.entropy())),
DocumentTransition::Replace(t) => None,

Check warning on line 174 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:174:41 | 174 | DocumentTransition::Replace(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t` | = note: `#[warn(unused_variables)]` on by default

Check warning on line 174 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:174:41 | 174 | DocumentTransition::Replace(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t` | = note: `#[warn(unused_variables)]` on by default

Check warning on line 174 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:174:41 | 174 | DocumentTransition::Replace(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t` | = note: `#[warn(unused_variables)]` on by default

Check warning on line 174 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:174:41 | 174 | DocumentTransition::Replace(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t` | = note: `#[warn(unused_variables)]` on by default

Check warning on line 174 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:174:41 | 174 | DocumentTransition::Replace(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t` | = note: `#[warn(unused_variables)]` on by default
DocumentTransition::Delete(t) => None,

Check warning on line 175 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:175:40 | 175 | DocumentTransition::Delete(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 175 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:175:40 | 175 | DocumentTransition::Delete(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 175 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:175:40 | 175 | DocumentTransition::Delete(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 175 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:175:40 | 175 | DocumentTransition::Delete(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 175 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:175:40 | 175 | DocumentTransition::Delete(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`
DocumentTransition::Transfer(t) => None,

Check warning on line 176 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:176:42 | 176 | DocumentTransition::Transfer(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 176 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:176:42 | 176 | DocumentTransition::Transfer(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 176 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:176:42 | 176 | DocumentTransition::Transfer(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 176 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:176:42 | 176 | DocumentTransition::Transfer(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 176 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:176:42 | 176 | DocumentTransition::Transfer(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`
DocumentTransition::UpdatePrice(t) => None,

Check warning on line 177 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:177:45 | 177 | DocumentTransition::UpdatePrice(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 177 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:177:45 | 177 | DocumentTransition::UpdatePrice(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 177 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:177:45 | 177 | DocumentTransition::UpdatePrice(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 177 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:177:45 | 177 | DocumentTransition::UpdatePrice(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 177 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:177:45 | 177 | DocumentTransition::UpdatePrice(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`
DocumentTransition::Purchase(t) => None,

Check warning on line 178 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:178:42 | 178 | DocumentTransition::Purchase(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 178 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:178:42 | 178 | DocumentTransition::Purchase(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 178 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:178:42 | 178 | DocumentTransition::Purchase(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 178 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:178:42 | 178 | DocumentTransition::Purchase(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`

Check warning on line 178 in packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused variable: `t`

warning: unused variable: `t` --> packages/rs-dpp/src/state_transition/state_transitions/document/documents_batch_transition/document_transition/mod.rs:178:42 | 178 | DocumentTransition::Purchase(t) => None, | ^ help: if this is intentional, prefix it with an underscore: `_t`
}
}

fn data_contract_id(&self) -> Identifier {
self.base().data_contract_id()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>) -> Result<JsValue, JsValue> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>) -> Result<JsValue, JsValue> {
// let serializer = serde_wasm_bindgen::Serializer::json_compatible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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)]
Expand Down Expand Up @@ -81,6 +83,47 @@
INITIAL_REVISION as u32
}

#[wasm_bindgen(js_name = getEntropy)]
pub fn get_entropy(&self) -> Vec<u8> {
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

Check warning on line 93 in packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

casting to the same type is unnecessary (`u64` -> `u64`)

warning: casting to the same type is unnecessary (`u64` -> `u64`) --> packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs:93:9 | 93 | self.inner.base().identity_contract_nonce() as u64 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `self.inner.base().identity_contract_nonce()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
}

#[wasm_bindgen(js_name=setIdentityContractNonce)]
pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: u64) -> () {

Check warning on line 97 in packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unneeded unit return type

warning: unneeded unit return type --> packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs:97:80 | 97 | pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: u64) -> () { | ^^^^^^ help: remove the `-> ()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit = note: `#[warn(clippy::unused_unit)]` on by default
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<JsValue, JsValue> {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,30 @@ impl DocumentDeleteTransitionWasm {
self.inner.base().document_type_name().clone()
}

#[wasm_bindgen(js_name = getEntropy)]
pub fn get_entropy(&self) -> Vec<u8> {
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<JsValue, JsValue> {
let _ = path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ impl DocumentReplaceTransitionWasm {
self.inner.revision()
}

#[wasm_bindgen(js_name = getEntropy)]
pub fn get_entropy(&self) -> Vec<u8> {
Vec::from(self.inner.entropy())
}

#[wasm_bindgen(js_name=getUpdatedAt)]
pub fn updated_at(&self) -> Option<js_sys::Date> {
self.inner
Expand Down Expand Up @@ -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<JsValue, JsValue> {
let document_data = if let Some(ref data) = self.inner.data() {
Expand Down
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()
}
}
Comment on lines +47 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for JSON conversion.

While the implementation is generally good, the unwrap calls on JSON conversion could lead to runtime panics.

Consider handling potential conversion errors:

     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()
+                document_create_transition.data()
+                    .to_json_value()
+                    .and_then(|json_value| 
+                        json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
+                    )
+                    .unwrap_or(JsValue::null())
             }
             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()
+                document_replace_transition.data()
+                    .to_json_value()
+                    .and_then(|json_value| 
+                        json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
+                    )
+                    .unwrap_or(JsValue::null())
             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[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=getData)]
pub fn get_data(&self) -> JsValue {
match &self.0 {
DocumentTransition::Create(document_create_transition) => {
document_create_transition.data()
.to_json_value()
.and_then(|json_value|
json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
)
.unwrap_or(JsValue::null())
}
DocumentTransition::Replace(document_replace_transition) => {
document_replace_transition.data()
.to_json_value()
.and_then(|json_value|
json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
)
.unwrap_or(JsValue::null())
}
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 All @@ -67,6 +87,10 @@ impl DocumentTransitionWasm {
JsValue::NULL
}
}
#[wasm_bindgen(js_name=getEntropy)]
pub fn get_entropy(&self) -> Option<Vec<u8>> {
self.0.entropy()
}

#[wasm_bindgen(js_name=setRevision)]
pub fn set_revision(&mut self, revision: u32) {
Expand All @@ -82,6 +106,32 @@ impl DocumentTransitionWasm {
_ => false,
}
}

#[wasm_bindgen(js_name=getPrefundedVotingBalance)]
pub fn get_prefunded_voting_balance(&self) -> Result<JsValue, JsValue> {
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<DocumentTransition> for DocumentTransitionWasm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsValue, JsValue> {
let opts: super::to_object::ToObjectOptions = if options.is_object() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@
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

Check warning on line 104 in packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

casting to the same type is unnecessary (`u16` -> `u16`)

warning: casting to the same type is unnecessary (`u16` -> `u16`) --> packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs:104:9 | 104 | self.0.user_fee_increase() as u16 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `self.0.user_fee_increase()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
}

#[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) -> () {

Check warning on line 118 in packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unneeded unit return type

warning: unneeded unit return type --> packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs:118:44 | 118 | pub fn set_nonce(&mut self, nonce: u64) -> () { | ^^^^^^ help: remove the `-> ()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
self.0.set_nonce(nonce)
}

#[wasm_bindgen(js_name=toObject)]
pub fn to_object(&self, options: JsValue) -> Result<JsValue, JsValue> {
let opts: super::to_object::ToObjectOptions = if options.is_object() {
Expand Down Expand Up @@ -318,6 +338,11 @@
.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
Loading
Loading