platform icon indicating copy to clipboard operation
platform copied to clipboard

feat(sdk): add NFT actions in the JS Dash SDK

Open pshenmic opened this issue 11 months ago • 1 comments

Issue being fixed or feature implemented

WASM DPP and JS Dash SDK is missing functions for creating NFT document transactions, there are 3 of them:

  • Transfer document (from one identity to another)
  • UpdatePrice document (sets a price for a document)
  • Purchase document (buys a document from someone)

This PR implements all three missing functions making it able to perform such operations from the browsers (Web).

What was done?

  • Added createTransferStateTransition method to ExtendedDocumentWasm
  • Added document transfer method in the JS Dash SDK
  • Fixed DPP incorrect error revision mismatch message tbd.

How Has This Been Tested?

In the testnet, with JS Dash SDK

https://testnet.platform-explorer.com/transaction/42175A63E25A316B5E0666317A3FF36A407EDDBA01D844982F68A6D10CBBFAF7 https://testnet.platform-explorer.com/transaction/36F3002686CA5ED23ED1FEFAD58803493055EFE55FC07517779AB267C8151747 https://testnet.platform-explorer.com/transaction/5CA156E676FA503CA4A520831484BE73B16EBE15599BB307605DE520B623AC1A

Breaking Changes

No

Checklist:

  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I have added or updated relevant unit/integration/functional/e2e tests
  • [x] I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • [x] I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • [x] I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Expanded the state transition process to accept additional optional parameters like a recipient identifier and price, enabling enhanced operations for transfers, price updates, and purchases.
    • Introduced dedicated handling for non-transferable items with clear error feedback.
  • Documentation

    • Revised API documentation with new parameter details and usage examples for purchase, transfer, and price update operations.
  • Tests

    • Updated test cases to reflect the new, consistent document structure for broadcast operations.

pshenmic avatar Jan 26 '25 14:01 pshenmic

Walkthrough

This pull request updates the document state transition functionality across several modules. The changes introduce an optional parameter, encapsulated as DocumentTransitionParams, to the state transition creation functions in both the core Rust implementation and its WASM and JavaScript wrappers. New methods for handling transfer, update price, and purchase transitions have been added, and error handling has been enhanced to cover nontransferable documents. The tests and documentation have been updated to reflect the revised data formats and method signatures.

Changes

File(s) Change Summary
packages/rs-dpp/src/document/document_factory/mod.rs
packages/rs-dpp/src/document/document_factory/v0/mod.rs
packages/rs-dpp/src/document/errors.rs
packages/rs-dpp/src/document/mod.rs
Updated create_state_transition signatures to include an optional DocumentTransitionParams. Added new transition methods (document_transfer_transitions, document_update_price_transitions, document_purchase_transitions) and a new error variant TryingToTransferNonTransferableDocument. Introduced the public DocumentTransitionParams struct.
packages/wasm-dpp/src/document/document_facade.rs
packages/wasm-dpp/src/document/errors/mod.rs
packages/wasm-dpp/src/document/errors/trying_to_transfer_nontransferable_document_error.rs
packages/wasm-dpp/src/document/factory.rs
Modified the WASM create_state_transition to accept new optional parameters (recipient, price). Added error handling for nontransferable document transfers and updated document action extraction to handle new actions.
packages/js-dash-sdk/src/SDK/Client/Platform/methods/documents/broadcast.ts
packages/js-dash-sdk/docs/platform/documents/{broadcast, purchase, transfer, updatePrice}.md
packages/js-dash-sdk/src/SDK/Client/Client.spec.ts
packages/js-dash-sdk/src/SDK/Client/Platform/methods/names/register.ts
Enhanced the broadcast function to accept arrays of DocumentSubmittable with new optional transition parameters. Updated interfaces, documentation, and test cases to wrap document entries within an object with a document key.
packages/platform-test-suite/test/**.js
(contacts, dpns, withdrawals, DataContract, Document, Identity, featureFlags)
Standardized test payloads by wrapping documents in an object with the document key for create, replace, and delete broadcast operations.
src/calculator.py Renamed variable from old_global_var to new_global_var.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DF as DocumentFactory/V0
    participant WASM as DocumentFactoryWASM
    participant Transition as Transition Handler

    Client->>DF: create_state_transition(documents, nonce_counter, params)
    alt Action Type: Transfer
        DF->>Transition: document_transfer_transitions(documents, params, ...)
    else Action Type: UpdatePrice
        DF->>Transition: document_update_price_transitions(documents, params, ...)
    else Action Type: Purchase
        DF->>Transition: document_purchase_transitions(documents, params, ...)
    else Other
        DF->>DF: Process default transition
    end

    Client->>WASM: create_state_transition(documents, nonce_counter, recipient, price)
    WASM->>DF: Forwards call with new parameters

Possibly related PRs

  • dashpay/platform#2401: The changes in the main PR are related to those in the retrieved PR as both involve modifications to the create_state_transition method to include DocumentTransitionParams, enhancing the handling of document transitions.
  • dashpay/platform#2454: The changes in the main PR, which modify the create_state_transition method to include DocumentTransitionParams, are related to the retrieved PR as both involve enhancements to state transition handling, specifically in how parameters and errors are managed during state transitions.
  • dashpay/platform#2351: The changes in the main PR, which modify the create_state_transition method to include DocumentTransitionParams, are related to the changes in the retrieved PR, which also involve modifications to the create_state_transition method in a different context, allowing for additional parameters in document transitions.

Suggested reviewers

  • QuantumExplorer
  • shumkov

Poem

I'm a little rabbit, hopping through the code,
Found new parameters now lightening the load.
Transfers, price updates, and purchases in sight,
With bouncy transitions, everything's feeling right.
Carrots and code, a joyous blend,
Debugging by day, and at night I transcend!
Happy hops to every new change!


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4f62e7e1601fd7b9baf01e148b88b2854123039 and 51d1ee827b32e9568cb3e63925f5263c64e68089.

📒 Files selected for processing (1)
  • packages/dapi/test/unit/externalApis/drive/fetchProofForStateTransitionFactory.spec.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: Rust packages (wasm-dpp) / Detect immutable structure changes
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Formatting
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (1)
packages/dapi/test/unit/externalApis/drive/fetchProofForStateTransitionFactory.spec.js (1)

111-113: Updated document structure in state transition creation is correct

This change properly wraps each document in an object with a document key, aligning with the new DocumentTransitionParams structure that supports NFT operations like transfer, update price, and purchase. The modification ensures the test correctly uses the updated API.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jan 26 '25 14:01 coderabbitai[bot]