-
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.
feat(js-sdk): implement working document transfers
- Loading branch information
Showing
7 changed files
with
83 additions
and
61 deletions.
There are no files selected for viewing
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
32 changes: 13 additions & 19 deletions
32
packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/transfer.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 |
---|---|---|
@@ -1,40 +1,34 @@ | ||
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 {string} typeLocator - type locator | ||
* @param identity - identity | ||
* @param {Object} [data] - options | ||
* @returns {StateTransition} | ||
*/ | ||
export async function transfer( | ||
this: Platform, | ||
documentId: string, | ||
identity: any, | ||
document: ExtendedDocument, | ||
receiver: Identity, | ||
sender: Identity, | ||
): Promise<any> { | ||
this.logger.debug(`[Document#transfer] Transfer document`); | ||
this.logger.debug('[Document#transfer] Transfer document'); | ||
await this.initialize(); | ||
|
||
const { dpp } = this; | ||
|
||
const document = await this.documents.get(documentId); | ||
|
||
this.logger.silly(`[Document#create] Obtained document ${document.getId()}`); | ||
|
||
if (document === null) { | ||
throw new Error(`Document ${documentId} not found. Ensure contractId ${documentId} is correct.`); | ||
} | ||
const identityContractNonce = await this.nonceManager | ||
.bumpIdentityContractNonce(sender.getId(), document.getDataContractId()); | ||
|
||
document.setOwnerId(identity); | ||
const documentsBatchTransition = document | ||
.createTransferTransition(receiver.getId(), BigInt(identityContractNonce)); | ||
|
||
const transition = dpp.document.createStateTransition( | ||
{ transfer: [document] }, | ||
identity.getId(), | ||
); | ||
await signStateTransition(this, documentsBatchTransition, sender, 1); | ||
|
||
await broadcastStateTransition(this, transition); | ||
await broadcastStateTransition(this, documentsBatchTransition); | ||
} | ||
|
||
export default transfer; |
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
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
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
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
28 changes: 1 addition & 27 deletions
28
..._transition/document_batch_transition/document_transition/document_transfer_transition.rs
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