-
Couldn't load subscription status.
- Fork 44
feat(sdk): add sdk wrappers for easily pushing document transitions for create, delete, purchase, replace, set price, and transfer to platform #2659
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
Conversation
… set price, and transfer
WalkthroughThis update restructures the platform SDK's document handling by introducing a new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Sdk
participant Signer
participant Platform
Client->>Sdk: Build Transition (e.g., DocumentCreateTransitionBuilder)
Sdk->>Signer: Sign Transition
Signer-->>Sdk: Signed Transition
Sdk->>Platform: Broadcast Transition
Platform-->>Sdk: Proof Result
Sdk-->>Client: Return Result (e.g., DocumentCreateResult)
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
packages/rs-sdk/src/platform/documents/transitions/transfer.rs (1)
83-97:⚠️ Potential issueVerify the hardcoded revision value for document transfer.
Similar to the delete transition, the minimal document is created with
revision: Some(1). This might not match the actual document revision and could cause validation failures.packages/rs-sdk/src/platform/documents/transitions/set_price.rs (1)
84-98:⚠️ Potential issueVerify the hardcoded revision value for price updates.
The minimal document creation has the same hardcoded
revision: Some(1)issue as the other transition builders.
🧹 Nitpick comments (3)
packages/rs-sdk/src/platform/documents/transitions/mod.rs (1)
14-14: Add trailing newlinepub use transfer::{DocumentTransferResult, DocumentTransferTransitionBuilder}; +packages/rs-sdk/src/platform/documents/transitions/replace.rs (1)
216-216: Add trailing newline} } +packages/rs-sdk/src/platform/documents/transitions/create.rs (1)
220-220: Add trailing newline} } +
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
packages/rs-sdk/src/platform.rs(1 hunks)packages/rs-sdk/src/platform/documents/document_query.rs(1 hunks)packages/rs-sdk/src/platform/documents/mod.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/create.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/delete.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/mod.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/purchase.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/replace.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/set_price.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/transfer.rs(1 hunks)packages/rs-sdk/src/platform/fetch_many.rs(2 hunks)packages/rs-sdk/src/platform/query.rs(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: QuantumExplorer
PR: dashpay/platform#2257
File: packages/rs-drive-abci/src/mimic/test_quorum.rs:159-164
Timestamp: 2024-11-20T16:16:01.830Z
Learning: QuantumExplorer prefers not to receive auto-generated messages asking to post on social media.
🧬 Code Graph Analysis (4)
packages/rs-sdk/src/platform/documents/transitions/create.rs (5)
packages/rs-sdk/src/platform/documents/transitions/delete.rs (6)
state_transition(234-235)new(44-59)with_token_payment_info(95-98)with_user_fee_increase(109-112)with_settings(123-126)sign(141-188)packages/rs-sdk/src/platform/documents/transitions/purchase.rs (6)
state_transition(245-246)new(47-64)with_token_payment_info(118-121)with_user_fee_increase(132-135)with_settings(146-149)sign(164-196)packages/rs-sdk/src/platform/documents/transitions/replace.rs (6)
state_transition(187-188)new(41-54)with_token_payment_info(65-68)with_user_fee_increase(79-82)with_settings(93-96)sign(111-141)packages/rs-sdk/src/platform/documents/transitions/transfer.rs (6)
state_transition(235-236)new(44-59)with_token_payment_info(111-114)with_user_fee_increase(125-128)with_settings(139-142)sign(157-188)packages/rs-sdk/src/platform/documents/transitions/set_price.rs (6)
state_transition(236-237)new(45-60)with_token_payment_info(112-115)with_user_fee_increase(126-129)with_settings(140-143)sign(158-189)
packages/rs-sdk/src/platform/documents/transitions/set_price.rs (5)
packages/rs-sdk/src/platform/documents/transitions/create.rs (6)
state_transition(191-192)new(43-58)with_token_payment_info(69-72)with_user_fee_increase(83-86)with_settings(97-100)sign(115-146)packages/rs-sdk/src/platform/documents/transitions/delete.rs (6)
state_transition(234-235)new(44-59)with_token_payment_info(95-98)with_user_fee_increase(109-112)with_settings(123-126)sign(141-188)packages/rs-sdk/src/platform/documents/transitions/purchase.rs (7)
state_transition(245-246)new(47-64)from_document_info(80-107)with_token_payment_info(118-121)with_user_fee_increase(132-135)with_settings(146-149)sign(164-196)packages/rs-sdk/src/platform/documents/transitions/replace.rs (6)
state_transition(187-188)new(41-54)with_token_payment_info(65-68)with_user_fee_increase(79-82)with_settings(93-96)sign(111-141)packages/rs-sdk/src/platform/documents/transitions/transfer.rs (7)
state_transition(235-236)new(44-59)from_document_info(74-100)with_token_payment_info(111-114)with_user_fee_increase(125-128)with_settings(139-142)sign(157-188)
packages/rs-sdk/src/platform/documents/transitions/delete.rs (5)
packages/rs-sdk/src/platform/documents/transitions/create.rs (6)
state_transition(191-192)new(43-58)with_token_payment_info(69-72)with_user_fee_increase(83-86)with_settings(97-100)sign(115-146)packages/rs-sdk/src/platform/documents/transitions/purchase.rs (6)
state_transition(245-246)new(47-64)with_token_payment_info(118-121)with_user_fee_increase(132-135)with_settings(146-149)sign(164-196)packages/rs-sdk/src/platform/documents/transitions/replace.rs (6)
state_transition(187-188)new(41-54)with_token_payment_info(65-68)with_user_fee_increase(79-82)with_settings(93-96)sign(111-141)packages/rs-sdk/src/platform/documents/transitions/transfer.rs (6)
state_transition(235-236)new(44-59)with_token_payment_info(111-114)with_user_fee_increase(125-128)with_settings(139-142)sign(157-188)packages/rs-sdk/src/platform/documents/transitions/set_price.rs (6)
state_transition(236-237)new(45-60)with_token_payment_info(112-115)with_user_fee_increase(126-129)with_settings(140-143)sign(158-189)
packages/rs-sdk/src/platform/documents/transitions/transfer.rs (4)
packages/rs-sdk/src/platform/documents/transitions/create.rs (6)
state_transition(191-192)new(43-58)with_token_payment_info(69-72)with_user_fee_increase(83-86)with_settings(97-100)sign(115-146)packages/rs-sdk/src/platform/documents/transitions/delete.rs (6)
state_transition(234-235)new(44-59)with_token_payment_info(95-98)with_user_fee_increase(109-112)with_settings(123-126)sign(141-188)packages/rs-sdk/src/platform/documents/transitions/purchase.rs (7)
state_transition(245-246)new(47-64)from_document_info(80-107)with_token_payment_info(118-121)with_user_fee_increase(132-135)with_settings(146-149)sign(164-196)packages/rs-sdk/src/platform/documents/transitions/replace.rs (6)
state_transition(187-188)new(41-54)with_token_payment_info(65-68)with_user_fee_increase(79-82)with_settings(93-96)sign(111-141)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: Rust packages (dash-sdk) / Tests
- GitHub Check: Rust packages (dash-sdk) / Check each feature
- GitHub Check: Rust packages (dash-sdk) / Linting
- GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
- GitHub Check: Build JS packages / Build JS
🔇 Additional comments (19)
packages/rs-sdk/src/platform/documents/document_query.rs (1)
30-30: Use absolute import forFetch.Switching to
crate::platform::Fetchaligns with the new module hierarchy and ensures consistency across imports.packages/rs-sdk/src/platform/documents/mod.rs (1)
1-2: Exposedocument_queryandtransitionsmodules.Adding these public modules organizes document-related functionality under a cohesive namespace.
packages/rs-sdk/src/platform/fetch_many.rs (2)
9-10: UpdateDocumentQueryimport to new module path.Importing from
crate::platform::documents::document_query::DocumentQueryreflects the reorganized module structure.
313-313: Refresh documentation forDocumentQuerypath.The doc comment now correctly references the relocated
DocumentQuerytype.packages/rs-sdk/src/platform/query.rs (1)
6-7: Adjust imports forErrorandDocumentQuery.Importing
ErrorandDocumentQueryfrom their updated locations maintains consistency after the module refactor.packages/rs-sdk/src/platform.rs (2)
19-19: Introduce top-leveldocumentsmodule.Exposing
documentshere surfaces all document-related functionality, including queries and transitions.
23-24: Re-exportprotoalias andDocumentQuery.Simplified
protoalias and re-exportingDocumentQueryensures backward compatibility with existing SDK consumers.packages/rs-sdk/src/platform/documents/transitions/mod.rs (1)
1-13: Well-structured module organization!The module declarations and re-exports follow a consistent pattern, making the API surface clear and discoverable. Each transition type properly exports its builder and result types.
packages/rs-sdk/src/platform/documents/transitions/replace.rs (2)
19-142: Excellent builder pattern implementation!The
DocumentReplaceTransitionBuilderfollows the established pattern with proper documentation, fluent API methods, and async signing. The implementation is consistent with other transition builders in the codebase.
151-215: Comprehensive SDK method with proper error handling!The
document_replacemethod provides excellent documentation, handles all error cases appropriately, and returns descriptive error messages. The pattern matching onStateTransitionProofResultis thorough.packages/rs-sdk/src/platform/documents/transitions/create.rs (2)
19-147: Well-implemented create transition builder!The
DocumentCreateTransitionBuildercorrectly includes the requireddocument_state_transition_entropyfield for document creation and follows the established pattern. The implementation is consistent with other transition builders.
156-219: Robust document creation method!The
document_createmethod properly handles the document creation flow with appropriate error handling and clear documentation. The implementation matches the pattern established by other transition methods.packages/rs-sdk/src/platform/documents/transitions/delete.rs (1)
238-252: Well-implemented proof result handling for document deletion.The logic correctly expects
Nonein theVerifiedDocumentsresult to confirm deletion, with appropriate error handling for unexpected cases.packages/rs-sdk/src/platform/documents/transitions/transfer.rs (1)
157-188: Correct implementation of document transfer signing.The sign method properly retrieves the identity contract nonce using the document owner's ID and creates the transfer transition with all necessary parameters.
packages/rs-sdk/src/platform/documents/transitions/set_price.rs (1)
26-26: Appropriate use of Credits type for price values.The use of the
Creditstype for price values provides type safety and clarity for monetary operations.Also applies to: 49-49, 70-70, 80-80, 178-178
packages/rs-sdk/src/platform/documents/transitions/purchase.rs (4)
22-31: Well-structured builder pattern implementation.The struct properly encapsulates all necessary fields for a document purchase transition with appropriate use of Option types for optional configuration.
151-197: Correct implementation of the sign method.The method properly handles async nonce fetching and state transition creation with appropriate default handling for optional parameters.
233-273: Well-implemented document purchase method with comprehensive error handling.The method correctly handles the purchase flow from signing through broadcasting to result verification. The assumption that
VerifiedDocumentscontains a single document (line 251) is appropriate for a purchase operation.
80-107:❓ Verification inconclusive
Verify the hardcoded revision value in
from_document_info.The method creates a minimal document with
revision: Some(1)on line 94. The comment indicates it "will be updated during transition", but this could cause issues if:
- The actual document has a different revision number
- The platform validates revision numbers for optimistic locking
- The transition process doesn't actually update this value
Consider fetching the actual document revision or accepting it as a parameter to ensure correctness.
Let me verify how the revision is handled in the batch transition:
🏁 Script executed:
#!/bin/bash # Check how BatchTransition::new_document_purchase_transition_from_document handles document revision ast-grep --pattern 'new_document_purchase_transition_from_document($$$)' -A 20Length of output: 80
I’ll dig deeper into how
from_document_infois used and whether that hardcoded revision ever gets overwritten:
🏁 Script executed:
#!/bin/bash # 1. Locate and list all pub fn declarations in purchase.rs rg -n "^pub fn" packages/rs-sdk/src/platform/documents/transitions/purchase.rs # 2. Find any references to from_document_info across the repo rg -n "from_document_info" -n . # 3. Search for a builder or factory that consumes this to create a purchase transition rg -n "purchase_transition" -n . # 4. Look for any code paths that set or update a document’s revision in transitions rg -n "revision" -n packages/rs-sdk/src/platform/documents/transitionsLength of output: 60196
Review hardcoded revision in
from_document_infoIt looks like
from_document_infoinpackages/rs-sdk/src/platform/documents/transitions/purchase.rs(lines 80–107)—and similarly inset_price.rs,transfer.rs,delete.rs—builds a minimalDocumentV0with
•revision: Some(1)
• all timestamps set toNone
and relies on a comment// Will be updated during transition.Risk: if the actual document revision differs, or if the dpp transition builder doesn’t overwrite these placeholders correctly (e.g. for optimistic-locking or revision-increment checks), the state transition may be invalid.
Actions:
- Confirm how
DocumentPurchaseTransition::from_document(in rs-dpp) and the SDK’sBatchTransition::new_document_purchase_transition_from_documenthandle/overwrite the placeholderrevisionand timestamps.- If they don’t fetch and apply the real document’s current revision (and increment it), consider:
- Passing the real revision into
from_document_infoinstead of1.- Fetching the full document prior to building the transition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
packages/rs-sdk/src/platform/documents/transitions/set_price.rs (1)
75-101:⚠️ Potential issueSame concern about minimal document creation
This method follows the same pattern as in
transfer.rs, creating a minimal document with default values. The same concerns apply about potential validation issues or state transition failures.Consider either:
- Fetching the actual document before creating the transition
- Documenting that the platform handles document resolution internally
- Ensuring the state transition methods can work with minimal document data
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
packages/rs-sdk/src/platform/documents/transitions/create.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/delete.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/purchase.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/replace.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/set_price.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/transfer.rs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/rs-sdk/src/platform/documents/transitions/replace.rs
- packages/rs-sdk/src/platform/documents/transitions/delete.rs
- packages/rs-sdk/src/platform/documents/transitions/purchase.rs
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: QuantumExplorer
PR: dashpay/platform#2257
File: packages/rs-drive-abci/src/mimic/test_quorum.rs:159-164
Timestamp: 2024-11-20T16:16:01.830Z
Learning: QuantumExplorer prefers not to receive auto-generated messages asking to post on social media.
🧬 Code Graph Analysis (1)
packages/rs-sdk/src/platform/documents/transitions/create.rs (2)
packages/rs-sdk/src/platform/documents/transitions/replace.rs (6)
state_transition(192-193)new(41-54)with_token_payment_info(65-68)with_user_fee_increase(79-82)with_settings(93-96)sign(111-146)packages/rs-sdk/src/platform/documents/document_query.rs (1)
new(59-77)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Rust packages (dash-sdk) / Linting
- GitHub Check: Build JS packages / Build JS
🔇 Additional comments (1)
packages/rs-sdk/src/platform/documents/transitions/create.rs (1)
1-224: Well-structured document creation transition implementation!The builder pattern is well implemented with proper error handling and comprehensive documentation. The inclusion of entropy for state transitions and the handling of proof results are correctly implemented.
|
Same as #2657 I recommend including an argument We're also introducing some duplicate code here - we should delete files like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
packages/rs-sdk/src/platform/documents/transitions/create.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/delete.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/purchase.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/replace.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/set_price.rs(1 hunks)packages/rs-sdk/src/platform/documents/transitions/transfer.rs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
- packages/rs-sdk/src/platform/documents/transitions/purchase.rs
- packages/rs-sdk/src/platform/documents/transitions/replace.rs
- packages/rs-sdk/src/platform/documents/transitions/create.rs
- packages/rs-sdk/src/platform/documents/transitions/delete.rs
- packages/rs-sdk/src/platform/documents/transitions/transfer.rs
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: QuantumExplorer
PR: dashpay/platform#2257
File: packages/rs-drive-abci/src/mimic/test_quorum.rs:159-164
Timestamp: 2024-11-20T16:16:01.830Z
Learning: QuantumExplorer prefers not to receive auto-generated messages asking to post on social media.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
- GitHub Check: Build JS packages / Build JS
🔇 Additional comments (7)
packages/rs-sdk/src/platform/documents/transitions/set_price.rs (7)
1-20: LGTM: Clean imports and dependenciesThe import statements are well-organized and include all necessary dependencies for the document set price transition functionality.
21-31: LGTM: Well-structured builder with comprehensive configuration optionsThe builder struct includes all necessary fields for document set price transitions, with proper optional parameters for flexibility. The inclusion of
state_transition_creation_optionsaddresses the PR feedback about adding configurable options.
46-62: LGTM: Standard builder constructor with proper initializationThe constructor properly initializes all fields with sensible defaults for optional parameters.
114-162: LGTM: Fluent builder methods with proper chainingAll builder methods follow the standard fluent API pattern correctly, allowing for method chaining and clear configuration of optional parameters.
176-211: LGTM: Comprehensive async signing implementationThe sign method properly handles:
- Identity contract nonce retrieval
- Document type validation
- State transition creation with all configured parameters
- Appropriate error handling and propagation
214-219: LGTM: Simple and focused result enumThe result enum is appropriately minimal for this operation type, containing just the updated document.
246-286: LGTM: Robust SDK method implementation with comprehensive error handlingThe method implements the complete workflow:
- Proper signing delegation to the builder
- Broadcasting with settings
- Result verification with specific error messages
- Appropriate error types for different failure scenarios
The error handling covers both unexpected result types and missing documents in the response.
Issue being fixed or feature implemented
This update introduces new document transition functionalities to the SDK, allowing for the creation, deletion, purchase, replacement, price setting, and transfer of documents.
What was done?
DocumentCreateTransitionBuilderfor creating documents.DocumentDeleteTransitionBuilderfor deleting documents.DocumentPurchaseTransitionBuilderfor purchasing documents.DocumentReplaceTransitionBuilderfor replacing documents.DocumentSetPriceTransitionBuilderfor setting document prices.DocumentTransferTransitionBuilderfor transferring document ownership.documentsmodule to include these new functionalities.How Has This Been Tested?
The new functionalities have been integrated into the existing SDK and tested through unit tests to ensure they perform as expected.
Breaking Changes
None
Checklist
For repository code-owners and collaborators only
Summary by CodeRabbit
New Features
Refactor