Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7d5d168
feat(wasm-dpp): add resource vote choice
pshenmic Nov 21, 2024
0fc7fbd
feat(wasm-dpp): implement userFeeIncrease
pshenmic Nov 25, 2024
c30cac3
feat(wasm-dpp): add identity and identity contract nonces
pshenmic Nov 25, 2024
ee4acd8
feat(wasm-dpp): ensure signature and signature public key id in each …
pshenmic Nov 25, 2024
5eca1f9
fix(wasm-dpp): remove duplicated
pshenmic Nov 25, 2024
ce44de6
fix(wasm-dpp): remove duplicated
pshenmic Nov 25, 2024
0431456
fix(wasm-dpp): add prefundedVotingBalance in create document transition
pshenmic Nov 25, 2024
3fe5506
feat(wasm-dpp): add prefundedVotingBalance in document transition
pshenmic Nov 25, 2024
2157a60
feat(rs-dpp): add more action types in try from for DocumentTransitio…
pshenmic Nov 25, 2024
33619d9
fix(wasm-dpp): fix js binding method name
pshenmic Nov 25, 2024
af61a1c
feat(wasm-dpp): add getData for DocumentTransition
pshenmic Nov 25, 2024
b62ca47
chore(wasm-dpp): cleanup masternode vote
pshenmic Dec 18, 2024
63f6266
chore(wasm-dpp): cleanup masternode vote
pshenmic Dec 18, 2024
3ad70b8
chore(wasm-dpp): remove duplicated nonce method
pshenmic Dec 18, 2024
e0340fe
chore(wasm-dpp): fix nonce method naming in credit withdrawals
pshenmic Dec 18, 2024
987d392
feat(wasm-dpp): add entropy getter for document transitions
pshenmic Dec 26, 2024
dfd4b2e
feat(wasm-dpp): add entropy getter for documenttransition
pshenmic Dec 27, 2024
77fc187
feat(rs-dpp): add entropy getter in the rs dpp
pshenmic Dec 27, 2024
4798b94
feat(dpp): move to optional
pshenmic Dec 27, 2024
2d6f9a5
feat(js-sdk): getIdentityContractNonce() to document transition main …
pshenmic Jan 2, 2025
20fdaac
fix(wasm-dpp): rust lint fix
pshenmic Jan 26, 2025
5debb6c
Merge remote-tracking branch 'origin/master' into feat/wasm-extra-fie…
pshenmic Feb 14, 2025
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 @@ 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<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 @@ impl DocumentTransitionV0Methods for DocumentTransition {
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,
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()
}
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 @@ -4,6 +4,8 @@ use dpp::state_transition::documents_batch_transition::document_create_transitio

use dpp::document::INITIAL_REVISION;

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;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(js_name=DocumentCreateTransition)]
Expand Down Expand Up @@ -81,6 +83,45 @@ impl DocumentCreateTransitionWasm {
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
}

#[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<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,9 @@ 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_base_transition::DocumentBaseTransition;
use dpp::state_transition::documents_batch_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods;

use crate::{
buffer::Buffer,
Expand All @@ -42,6 +45,28 @@ 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 All @@ -59,6 +84,13 @@ impl DocumentTransitionWasm {
Ok(())
}

#[wasm_bindgen(js_name=getIdentityContractNonce)]
pub fn get_identity_contract_nonce(&self) -> JsValue {
match self.0.base() {
DocumentBaseTransition::V0(v0) => JsValue::from(v0.identity_contract_nonce),
}
}

#[wasm_bindgen(js_name=getRevision)]
pub fn get_revision(&self) -> JsValue {
if let Some(revision) = self.0.revision() {
Expand All @@ -67,6 +99,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 +118,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 @@ -167,6 +167,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 @@ 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<JsValue, JsValue> {
let opts: super::to_object::ToObjectOptions = if options.is_object() {
Expand Down Expand Up @@ -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,
Expand Down
Loading