From cbc86c42891aa051085944149cb75e25ca70fd60 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Sun, 26 Jan 2025 21:07:57 +0700 Subject: [PATCH] feat(js-dash-sdk): uncomment --- .../Platform/methods/documents/purchase.ts | 36 +++++++++++++++++++ .../Platform/methods/documents/updatePrice.ts | 33 +++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/purchase.ts create mode 100644 packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/updatePrice.ts diff --git a/packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/purchase.ts b/packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/purchase.ts new file mode 100644 index 0000000000..e1c593ffed --- /dev/null +++ b/packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/purchase.ts @@ -0,0 +1,36 @@ +import { Identity, ExtendedDocument } from '@dashevo/wasm-dpp'; +import { Platform } from '../../Platform'; +import broadcastStateTransition from '../../broadcastStateTransition'; +import { signStateTransition } from '../../signStateTransition'; +/** + * Transfer document in the platform + * + * @param {Platform} this - bound instance class + * @param {ExtendedDocument} document - document from the DAPI + * @param {Identifier} receiver - identifier of the document recipient ownership + * @param {Identifier} sender - identifier of the document owner + */ +export async function purchase( + this: Platform, + document: ExtendedDocument, + amount: number, + buyer: Identity, + seller: Identity, +): Promise { + this.logger.debug(`[Document#transfer] Update price for document ${document.getId().toString()} to ${amount}`); + await this.initialize(); + + const identityContractNonce = await this.nonceManager + .bumpIdentityContractNonce(buyer.getId(), document.getDataContractId()); + + const documentsBatchTransition = document + .createPurchaseStateTransition(buyer.getId(), amount, BigInt(identityContractNonce)); + + await signStateTransition(this, documentsBatchTransition, buyer, 1); + + console.log(documentsBatchTransition.toBuffer().toString('hex')); + + await broadcastStateTransition(this, documentsBatchTransition); +} + +export default purchase; diff --git a/packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/updatePrice.ts b/packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/updatePrice.ts new file mode 100644 index 0000000000..1216bc98bf --- /dev/null +++ b/packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/updatePrice.ts @@ -0,0 +1,33 @@ +import { Identity, ExtendedDocument } from '@dashevo/wasm-dpp'; +import { Platform } from '../../Platform'; +import broadcastStateTransition from '../../broadcastStateTransition'; +import { signStateTransition } from '../../signStateTransition'; +/** + * Transfer document in the platform + * + * @param {Platform} this - bound instance class + * @param {ExtendedDocument} document - document from the DAPI + * @param {Identifier} receiver - identifier of the document recipient ownership + * @param {Identifier} sender - identifier of the document owner + */ +export async function updatePrice( + this: Platform, + document: ExtendedDocument, + amount: number, + identity: Identity, +): Promise { + this.logger.debug(`[Document#transfer] Update price for document ${document.getId().toString()} to ${amount}`); + await this.initialize(); + + const identityContractNonce = await this.nonceManager + .bumpIdentityContractNonce(identity.getId(), document.getDataContractId()); + + const documentsBatchTransition = document + .createUpdatePriceStateTransition(amount, BigInt(identityContractNonce)); + + await signStateTransition(this, documentsBatchTransition, identity, 1); + + await broadcastStateTransition(this, documentsBatchTransition); +} + +export default updatePrice;