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(sdk): add NFT actions in the JS Dash SDK #2444

Open
wants to merge 36 commits into
base: v2.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3b511ce
feat(wasm-dpp): add transfer transition to documents batch wip
pshenmic Oct 5, 2024
d3383a1
feat(js-dash-sk): add transfer to document broadcast
pshenmic Oct 5, 2024
fae5915
fix(dpp): add missing import
pshenmic Oct 5, 2024
fd48355
feat(js-dash-sdk): add transfer function wip
pshenmic Oct 5, 2024
e17f1a1
Merge remote-tracking branch 'refs/remotes/origin/v1.7-dev' into feat…
pshenmic Dec 1, 2024
5fd4329
Merge remote-tracking branch 'refs/remotes/origin/v1.7-dev' into feat…
pshenmic Dec 3, 2024
10998f7
Merge remote-tracking branch 'origin/v1.8-dev' into feat/document-tra…
pshenmic Dec 23, 2024
fbe5dbc
feat(js-sdk): implement working document transfers
pshenmic Dec 24, 2024
8f79b69
chore(js-sdk): cleanup
pshenmic Dec 24, 2024
9925a68
chore(js-sdk): cleanup
pshenmic Dec 24, 2024
e8defe8
chore(wasm-dpp): cleanup
pshenmic Dec 24, 2024
1f0f7c6
chore(js-sdk): cleanup
pshenmic Dec 24, 2024
43cc7f1
chore(js-sdk): revert
pshenmic Dec 24, 2024
cf99fe6
chore(js-sdk): cleanup
pshenmic Dec 24, 2024
44df2e6
chore(js-sdk): cleanup
pshenmic Dec 24, 2024
5894a7f
chore(js-sdk): cleanup
pshenmic Dec 24, 2024
d7d5d90
chore(js-sdk): update doc
pshenmic Dec 24, 2024
2131f00
chore(wasm-dpp): cleanup
pshenmic Dec 24, 2024
9bca0cd
feat(wasm-dpp): add nft operations
pshenmic Jan 20, 2025
9dad661
feat(js-sdk): add transfer def in Platform.ts
pshenmic Jan 20, 2025
9c9c913
Merge branch 'refs/heads/feat/document-transfer' into feat/wasm-dpp-nft
pshenmic Jan 26, 2025
cbc86c4
feat(js-dash-sdk): uncomment
pshenmic Jan 26, 2025
7940a09
feat(wasm-dpp): move nft create state transition from extended docume…
pshenmic Jan 30, 2025
dac6932
fix(js-dash-sdk): fix types
pshenmic Jan 30, 2025
b7da382
fix(js-dash-sdk): finalize nft transitions
pshenmic Jan 31, 2025
ccf0921
Merge branch 'v2.0-dev' into feat/wasm-dpp-nft
pshenmic Jan 31, 2025
1a2520e
fix(wasm-dpp): lint fix
pshenmic Jan 31, 2025
dbf1b7c
chore(wasm-dpp): remove unused
pshenmic Jan 31, 2025
1207597
feat(js-dash-sdk): add NFT state transitions docs
pshenmic Jan 31, 2025
3443b3f
chore(wasm-dpp): fix lint
pshenmic Jan 31, 2025
16e2a50
chore(rs-dpp): fix lint
pshenmic Jan 31, 2025
cfe2b60
fix(rs-dpp): fix features
pshenmic Jan 31, 2025
eb4c953
fix(rs-dpp): lint fix
pshenmic Jan 31, 2025
30e86b7
fix(sdk): fix clippy warnings
pshenmic Feb 7, 2025
e0798b5
fix(wasm-dpp): revert some lint
pshenmic Feb 8, 2025
c79d7e3
fix(wasm-dpp): lint fix
pshenmic Feb 8, 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
9 changes: 9 additions & 0 deletions packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import createAssetLockTransaction from './createAssetLockTransaction';

import broadcastDocument from './methods/documents/broadcast';
import createDocument from './methods/documents/create';
import transferDocument from './methods/documents/transfer';
import updatePriceDocument from './methods/documents/updatePrice';
import purchaseDocument from './methods/documents/purchase';
import getDocument from './methods/documents/get';

import publishContract from './methods/contracts/publish';
Expand Down Expand Up @@ -58,6 +61,9 @@ export interface PlatformOpts {
interface Records {
broadcast: Function,
create: Function,
transfer: Function,
updatePrice: Function,
purchase: Function,
pshenmic marked this conversation as resolved.
Show resolved Hide resolved
get: Function,
}

Expand Down Expand Up @@ -165,6 +171,9 @@ export class Platform {
this.documents = {
broadcast: broadcastDocument.bind(this),
create: createDocument.bind(this),
transfer: transferDocument.bind(this),
updatePrice: updatePriceDocument.bind(this),
purchase: purchaseDocument.bind(this),
get: getDocument.bind(this),
};
this.contracts = {
Expand Down
86 changes: 85 additions & 1 deletion packages/wasm-dpp/src/document/extended_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dpp::document::{
use serde_json::Value as JsonValue;

use dpp::platform_value::{Bytes32, Value};
use dpp::prelude::{Identifier, Revision, TimestampMillis};
use dpp::prelude::{Identifier, IdentityNonce, Revision, TimestampMillis};

use dpp::util::json_value::JsonValueExt;

Expand All @@ -16,12 +16,15 @@ use dpp::ProtocolError;
use serde::{Deserialize, Serialize};
use std::convert::TryInto;
use wasm_bindgen::prelude::*;
use dpp::state_transition::documents_batch_transition::document_transition::{DocumentPurchaseTransition, DocumentTransferTransition, DocumentUpdatePriceTransition};
use dpp::state_transition::documents_batch_transition::{DocumentsBatchTransition, DocumentsBatchTransitionV0};

use crate::buffer::Buffer;
use crate::data_contract::DataContractWasm;
#[allow(deprecated)] // BinaryType is unsed in unused code below
use crate::document::BinaryType;
use crate::document::{ConversionOptions, DocumentWasm};
use crate::document_batch_transition::DocumentsBatchTransitionWasm;
use crate::errors::RustConversionError;
use crate::identifier::{identifier_from_js_value, IdentifierWrapper};
use crate::lodash::lodash_set;
Expand Down Expand Up @@ -235,6 +238,87 @@ impl ExtendedDocumentWasm {
.set_created_at(ts.map(|t| t.get_time() as TimestampMillis));
}

#[wasm_bindgen(js_name=createTransferStateTransition)]
pub fn create_transfer_state_transition(&mut self, recipient: IdentifierWrapper, identity_contract_nonce: IdentityNonce) -> DocumentsBatchTransitionWasm {
let mut cloned_document = self.0.document().clone();

cloned_document.set_revision(Some(cloned_document.revision().unwrap() + 1));

let transfer_transition = DocumentTransferTransition::from_document(
cloned_document,
self.0.document_type().unwrap(),
identity_contract_nonce,
recipient.into(),
PlatformVersion::latest(),
None,
None,
).unwrap();

let documents_batch_transition: DocumentsBatchTransition = DocumentsBatchTransitionV0 {
owner_id: self.0.owner_id(),
transitions: vec![transfer_transition.into()],
user_fee_increase: Default::default(),
signature_public_key_id: Default::default(),
signature: Default::default(),
}.into();

documents_batch_transition.into()
}
pshenmic marked this conversation as resolved.
Show resolved Hide resolved

#[wasm_bindgen(js_name=createUpdatePriceStateTransition)]
pub fn create_update_price_state_transition(&mut self, amount: u32, identity_contract_nonce: IdentityNonce) -> DocumentsBatchTransitionWasm {
let mut cloned_document = self.0.document().clone();

cloned_document.set_revision(Some(cloned_document.revision().unwrap() + 1));

let update_price_transition = DocumentUpdatePriceTransition::from_document(
cloned_document,
self.0.document_type().unwrap(),
amount as u64,
identity_contract_nonce,
PlatformVersion::latest(),
None,
None,
).unwrap();

let documents_batch_transition: DocumentsBatchTransition = DocumentsBatchTransitionV0 {
owner_id: self.0.owner_id(),
transitions: vec![update_price_transition.into()],
user_fee_increase: Default::default(),
signature_public_key_id: Default::default(),
signature: Default::default(),
}.into();

documents_batch_transition.into()
}
pshenmic marked this conversation as resolved.
Show resolved Hide resolved

#[wasm_bindgen(js_name=createPurchaseStateTransition)]
pub fn create_update_purchase_transition(&mut self, buyer: IdentifierWrapper, amount: u32, identity_contract_nonce: IdentityNonce) -> DocumentsBatchTransitionWasm {
let mut cloned_document = self.0.document().clone();

cloned_document.set_revision(Some(cloned_document.revision().unwrap() + 1));

let purchase_transition = DocumentPurchaseTransition::from_document(
cloned_document,
self.0.document_type().unwrap(),
amount as u64,
identity_contract_nonce,
PlatformVersion::latest(),
None,
None,
).unwrap();

let documents_batch_transition: DocumentsBatchTransition = DocumentsBatchTransitionV0 {
owner_id: buyer.into(),
transitions: vec![purchase_transition.into()],
user_fee_increase: Default::default(),
signature_public_key_id: Default::default(),
signature: Default::default(),
}.into();

documents_batch_transition.into()
}
pshenmic marked this conversation as resolved.
Show resolved Hide resolved
pshenmic marked this conversation as resolved.
Show resolved Hide resolved

#[wasm_bindgen(js_name=setUpdatedAt)]
pub fn set_updated_at(&mut self, ts: Option<js_sys::Date>) {
self.0
Expand Down
Loading