feat(sdk): token claim state transition#2522
Conversation
WalkthroughThe pull request makes changes across several packages. In the tokens consensus module, the error message for an invalid token claim has been rewritten and the parameter order adjusted. In a token transition, recipient resolution was modified from a contract owner identity to a general identity representation. Additionally, documentation was refined in a token transition action, and state transition verification was enhanced by dynamically setting ignored fields. A new token claim transition builder and accompanying module were introduced in the SDK, while the token history contract JSON schema was updated to enforce specific enumerated values. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Builder as TokenClaimTransitionBuilder
participant NonceSvc as IdentityNonceRetriever
participant TransitionCreator as BatchTransitionCreator
User->>Builder: Initialize builder with parameters
User->>Builder: Configure via with_public_note/with_user_fee_increase/with_settings
User->>Builder: Call sign()
Builder->>NonceSvc: Retrieve identity contract nonce
Builder->>TransitionCreator: Compute token ID and create BatchTransition
TransitionCreator-->>Builder: Return StateTransition
Builder-->>User: Return signed StateTransition
sequenceDiagram
participant Verifier as verify_state_transition_was_executed_with_proof_v0
participant Transition as TokenTransition
participant Document as Document
Verifier->>Transition: Check token transition type
alt DestroyFrozenFunds
Transition-->>Verifier: Set ignore_fields = ["destroyedAmount"]
else Claim
Transition-->>Verifier: Set ignore_fields = ["amount"]
else Other
Transition-->>Verifier: Set ignore_fields = None
end
Verifier->>Document: Compare with is_equal_ignoring_time_based_fields(ignore_fields)
Document-->>Verifier: Return comparison result
Suggested reviewers
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs (1)
142-142: Fixed documentation comment for build_historical_document method.The comment is now more accurate, correctly reflecting that the method builds a complete historical document rather than just an ID.
packages/rs-dpp/src/errors/consensus/state/token/invalid_token_claim_wrong_claimant.rs (1)
13-16: Fix the minor spelling issue in the error message.The updated error message incorrectly spells "claimant" as "claimaint".
Apply the following diff to correct the spelling:
- "Token claim error: Identity '{}' is not a valid claimant for this distribution type of token '{}'. The valid claimaint is '{}'." + "Token claim error: Identity '{}' is not a valid claimant for this distribution type of token '{}'. The valid claimant is '{}'."packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs (1)
40-57: Address the TODO comment for validating token position.Currently, the constructor includes a TODO indicating that token position validation is needed. Implementing this validation can help detect invalid positions at an early stage.
If you need help implementing the validation logic, I can provide a reference or open a new issue to track this task.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
packages/rs-dpp/src/errors/consensus/state/token/invalid_token_claim_wrong_claimant.rs(1 hunks)packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs(1 hunks)packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs(1 hunks)packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs(1 hunks)packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs(1 hunks)packages/rs-sdk/src/platform/transition/fungible_tokens/mod.rs(1 hunks)packages/token-history-contract/schema/v1/token-history-contract-documents.json(3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs (2)
packages/rs-dpp/src/errors/consensus/state/token/invalid_token_claim_wrong_claimant.rs (3)
new(27-37)token_id(40-42)from(57-59)packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs (4)
token_id(182-182)token_id(285-287)identity_contract_nonce(188-188)identity_contract_nonce(293-295)
⏰ Context from checks skipped due to timeout of 90000ms (19)
- GitHub Check: Rust packages (dpp) / Formatting
- GitHub Check: Rust packages (dpp) / Linting
- GitHub Check: Rust packages (dpp) / Tests
- GitHub Check: Rust packages (dash-sdk) / Linting
- GitHub Check: Rust packages (dpp) / Check each feature
- GitHub Check: Rust packages (dash-sdk) / Unused dependencies
- GitHub Check: Rust packages (dash-sdk) / Check each feature
- GitHub Check: Rust packages (dash-sdk) / Tests
- 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) / Linting
- GitHub Check: Rust packages (wasm-dpp) / Linting
- GitHub Check: Rust packages (wasm-dpp) / Tests
- GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
- GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
- GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
- GitHub Check: Build JS packages / Build JS
🔇 Additional comments (8)
packages/rs-sdk/src/platform/transition/fungible_tokens/mod.rs (1)
4-4: LGTM: New claim module added correctly.The addition of the
claimmodule follows the alphabetical ordering pattern of the other modules in this file, and aligns with the PR objective of enabling token claim transition functionality in the SDK.packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs (1)
425-425: Updated recipient resolution to use Identity type instead of ContractOwnerIdentity.This change properly alters how token distribution recipients of type
Identityare resolved in the claim transition, switching from a specific contract owner context to a more generalized identity representation.packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs (1)
359-372: Improved verification with dynamic field exclusion based on token transition type.The modification correctly handles different token transition types by dynamically determining which fields to ignore during document verification. Now both
TokenTransition::DestroyFrozenFundsandTokenTransition::Claimhave specific fields ignored that are populated by the drive system.packages/token-history-contract/schema/v1/token-history-contract-documents.json (2)
596-599: Enumerating distributionType ensures clarity and correctness.The introduction of an enum helps strongly validate the distribution type in claims, preventing invalid values.
680-680: Documentation update looks good.Changing the description to "The action we are performing (0: Pause, 1: Resume)" provides clarity on the possible values.
packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs (3)
16-25: Builder pattern for token claim transitions is well-structured.The builder struct neatly encapsulates the parameters required for a token claim transition, promoting code clarity and maintainability.
59-99: Chained configuration methods are concise and intuitive.The
with_public_note,with_user_fee_increase, andwith_settingsmethods effectively follow the builder pattern, allowing for flexible incremental configuration of the transition.
101-152: Thesignmethod ensures robust error handling and clarity.Invoking
sdk.get_identity_contract_noncewithin this async method is appropriate, and returning aResultfosters safe usage. This design aligns well with the rest of the SDK's error handling conventions.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/dashmate/package.json (1)
74-74: Update dockerode dependency to ^4.0.5The dependency update to dockerode from version ^3.3.5 to ^4.0.5 is a major version bump. Please ensure that all usages of dockerode in the codebase align with the new API and that any potential breaking changes are addressed. It would be useful to review the dockerode changelog and verify that integration tests cover all relevant functionality for this dependency.
.pnp.cjs (1)
13456-13463: Long package version update review.
There is an update involving thelongpackage where a new entry for version5.3.1is specified alongside an earlier version (5.2.0). Please check if both versions are required by different dependencies or if deduplication is possible.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (11)
.yarn/cache/@grpc-grpc-js-npm-1.13.2-2010829daa-80b7bebc1d.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/@grpc-proto-loader-npm-0.7.13-be5b6af1c1-7e2d842c20.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/@js-sdsl-ordered-map-npm-4.4.2-158f6c6b74-ac64e3f061.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/docker-modem-npm-5.0.6-ba160bac18-4977797814.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/dockerode-npm-4.0.5-291e46ef8d-a300e5fdcf.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/long-npm-5.3.1-c44e0933f0-7713e10b4f.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/nan-npm-2.22.2-bb092bb459-bee49de633.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/ssh2-npm-1.16.0-bee6b5f04c-0951c22d9c.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/tar-fs-npm-2.1.2-4231292dd1-623f7e8e58.zipis excluded by!**/.yarn/**,!**/*.zip.yarn/cache/uuid-npm-10.0.0-4872b46ff8-35aa606148.zipis excluded by!**/.yarn/**,!**/*.zipyarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (2)
.pnp.cjs(11 hunks)packages/dashmate/package.json(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
- GitHub Check: Rust packages (drive) / Linting
- GitHub Check: Rust packages (wasm-dpp) / Linting
- GitHub Check: Rust packages (wasm-dpp) / Unused dependencies
- GitHub Check: Rust packages (wasm-dpp) / Tests
- GitHub Check: Rust packages (token-history-contract) / Unused dependencies
- GitHub Check: Rust packages (token-history-contract) / Linting
- GitHub Check: Rust packages (dpp) / Tests
- GitHub Check: Rust packages (dpp) / Linting
- GitHub Check: Rust packages (dpp) / Unused dependencies
- GitHub Check: Rust packages (dpp) / Check each feature
- GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
- GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
- GitHub Check: Build JS packages / Build JS
🔇 Additional comments (10)
.pnp.cjs (10)
3159-3168: @grpc/grpc-js entry added correctly.
This new entry for@grpc/grpc-js(version1.13.2) is set up with the appropriate package location and dependencies (including@grpc/proto-loaderand@js-sdsl/ordered-map). The structure looks consistent with Yarn Plug'n'Play metadata.
3200-3211: Updated @grpc/proto-loader dependency block.
A new block for@grpc/proto-loader(version0.7.13) is introduced with its package location and a complete dependency list. Notably, the version foryargsused here is17.7.2(instead of an earlier version), so please ensure that this upgrade is compatible with the consumers of this package.
3470-3478: @js-sdsl/ordered-map entry added.
The new entry for@js-sdsl/ordered-mapwith version4.4.2is added with the correct package location, dependency specification, andlinkTypeset toHARD. This matches the project’s dependency configuration style.
8509-8512: Dockerode version update detected.
The dependency fordockerodehas been updated to version4.0.5in this block. This aligns with the corresponding update in other configuration files (for example, inpackages/dashmate/package.json). Verify that all consumers ofdockerodeare compatible with the new version.
9070-9081: New docker-modem entry introduced.
A new block fordocker-modemversion5.0.6is added with its package location and an updated dependency list – notably, it now depends onssh2version1.16.0. The structure is proper; however, please double-check the dependency tree to ensure no conflicts arise with other packages.
9093-9107: New dockerode package block with expanded dependencies.
This block fordockerode(version4.0.5) now clearly lists all required dependencies such as@balena/dockerignore, the gRPC packages,docker-modem,protobufjs,tar-fs, anduuid. The configuration is comprehensive and appears correct. Consider verifying that multiple entries fordockerode(if present) are intentional.
14392-14400: New nan package entry added.
The configuration now includes a new entry fornanat version2.22.2, complete with its package location and dependency onnode-gypversion10.0.1. This aligns with the updated requirements, and the format is correct.
17727-17738: ssh2 dependency updated with nan update.
The block forssh2now referencesnanat version2.22.2(updating what was previously2.17.0), and it correctly lists its other dependencies (includingasn1,bcrypt-pbkdf, and a URL-based dependency forcpu-features). Please confirm that the dependency URL forcpu-featuresis intentional and supported.
18168-18179: Updated tar-fs entry with complete dependency list.
Thetar-fsblock is updated to version2.1.2and now clearly includes its dependencies – such astar-streamversion2.2.0,chownr,mkdirp-classic, andpump. The structured format adheres to Yarn Plug'n'Play specifications.
19483-19489: New uuid entry for version 10.0.0 added.
A new block foruuid(version10.0.0) is added with its package location and dependency details, while an existing entry for version3.4.0remains in the configuration. Please verify if both versions are necessary or if consolidation is possible to avoid potential version conflicts.
Issue being fixed or feature implemented
We would like to broadcast the token claim transition using SDK.
What was done?
How Has This Been Tested?
With DET against local network
Breaking Changes
None
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit
Bug Fixes
New Features
Chores