-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/purchase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<any> { | ||
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; |
33 changes: 33 additions & 0 deletions
33
packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/updatePrice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<any> { | ||
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; |