-
Notifications
You must be signed in to change notification settings - Fork 44
fix(dpp): deserialization of data contract JSON with token configuration #2857
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
WalkthroughCustom deserializers were added to accept numeric or string keys for distribution maps, normalizing them into BTreeMap<u64, ...> shapes for stepwise and timestamped pre-programmed distributions. Two unit tests verify deserialization succeeds with string-key inputs. Changes
Sequence Diagram(s)sequenceDiagram
participant JSON as JSON Input
participant Serde as serde deserializer
participant Norm as Normalizer
participant Map as BTreeMap Output
JSON->>Serde: deserialize field (Stepwise / distributions)
Serde->>Norm: receive either U64-map or Str-map (untagged enum)
alt U64 map
Norm->>Map: return BTreeMap<u64, Value> unchanged
else Str map
Norm->>Norm: parse each string key -> u64 (error on parse fail)
Norm->>Map: construct normalized BTreeMap<u64, Value>
end
Map-->>Serde: normalized map returned to struct
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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: 0
🧹 Nitpick comments (1)
packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rs (1)
564-601: Well-implemented custom deserializer with clear documentation.The deserializer correctly normalizes both numeric and string JSON keys into
BTreeMap<u64, TokenAmount>, with proper error handling for invalid string keys.Note: This deserializer follows a nearly identical pattern to
deserialize_ts_to_id_amount_mapintoken_pre_programmed_distribution/v0/mod.rs. If this pattern is used elsewhere in the future, consider extracting a generic helper to reduce duplication. For now, the duplication is minimal and acceptable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rs(2 hunks)packages/rs-dpp/src/data_contract/associated_token/token_pre_programmed_distribution/v0/mod.rs(2 hunks)packages/rs-dpp/src/data_contract/conversion/json/mod.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.rs: Format Rust code with cargo fmt
Run Clippy linter for Rust code
Files:
packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rspackages/rs-dpp/src/data_contract/conversion/json/mod.rspackages/rs-dpp/src/data_contract/associated_token/token_pre_programmed_distribution/v0/mod.rs
🧠 Learnings (4)
📓 Common learnings
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/dapi-grpc/src/mock.rs:125-145
Timestamp: 2024-10-29T14:16:00.141Z
Learning: Using `serde_json` encoding produces deterministic output required to identify requests and responses by hash, therefore `serde_json` is used as the basic serialization algorithm for mocking.
📚 Learning: 2025-04-11T09:08:05.652Z
Learnt from: pauldelucia
Repo: dashpay/platform PR: 2523
File: packages/rs-drive/src/drive/contract/update/update_contract/v1/update_description/v1/mod.rs:147-151
Timestamp: 2025-04-11T09:08:05.652Z
Learning: Description length validation for data contracts is already handled in the data contract validation process, specifically in packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs.
Applied to files:
packages/rs-dpp/src/data_contract/conversion/json/mod.rs
📚 Learning: 2024-12-10T10:56:26.215Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2030
File: packages/rs-sdk/tests/vectors/test_asset_lock_proof/quorum_pubkey-100-4ce7fd81273c2b394c0f32367374fc5b09ba912e017aacb366d2171e9ca6f9d5.json:1-1
Timestamp: 2024-12-10T10:56:26.215Z
Learning: In the `packages/rs-sdk/tests/vectors/test_asset_lock_proof/` directory, files with the `.json` extension are mock data that may not follow standard JSON format; this is intentional and acceptable within the project's testing framework.
Applied to files:
packages/rs-dpp/src/data_contract/conversion/json/mod.rs
📚 Learning: 2024-10-29T14:16:00.141Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/dapi-grpc/src/mock.rs:125-145
Timestamp: 2024-10-29T14:16:00.141Z
Learning: Using `serde_json` encoding produces deterministic output required to identify requests and responses by hash, therefore `serde_json` is used as the basic serialization algorithm for mocking.
Applied to files:
packages/rs-dpp/src/data_contract/associated_token/token_pre_programmed_distribution/v0/mod.rs
🧬 Code graph analysis (1)
packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rs (3)
packages/rs-dpp/src/data_contract/v0/serialization/mod.rs (1)
deserialize(26-45)packages/rs-dpp/src/identity/state_transition/asset_lock_proof/mod.rs (1)
deserialize(58-84)packages/rs-dpp/src/data_contract/associated_token/token_pre_programmed_distribution/v0/mod.rs (1)
k(66-66)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
- GitHub Check: Rust packages (drive-abci) / Tests
- GitHub Check: Rust packages (drive) / Tests
- GitHub Check: Rust packages (wasm-dpp2) / Tests
- GitHub Check: Rust packages (wasm-sdk) / Tests
- GitHub Check: Rust packages (rs-sdk-ffi) / Tests
- GitHub Check: Rust packages (dash-sdk) / Tests
- GitHub Check: Rust packages (wasm-dpp) / Tests
- GitHub Check: Rust packages (dpp) / Check each feature
- GitHub Check: Rust packages (dpp) / Tests
- GitHub Check: Rust packages (dpp) / Unused dependencies
- GitHub Check: Rust packages (dpp) / Linting
- GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
- GitHub Check: Build Docker images (RS-DAPI, rs-dapi, rs-dapi) / Build RS-DAPI image
- GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
- GitHub Check: Build JS packages / Build JS
- GitHub Check: Rust crates security audit
- GitHub Check: Swift SDK and Example build (warnings as errors)
🔇 Additional comments (4)
packages/rs-dpp/src/data_contract/conversion/json/mod.rs (1)
56-341: LGTM! Comprehensive test coverage for string key deserialization.The tests correctly validate that both stepwise distributions (with string step keys) and preprogrammed distributions (with string timestamp keys) are accepted by
from_json. Usingfull_validation = trueensures the deserialized contracts pass all validation rules.packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rs (1)
162-165: LGTM! Proper application of custom deserializer.The custom deserializer is correctly applied to the
Stepwisevariant, enabling acceptance of both numeric and string keys in JSON input.packages/rs-dpp/src/data_contract/associated_token/token_pre_programmed_distribution/v0/mod.rs (2)
31-72: LGTM! Clean implementation of timestamp key deserializer.The deserializer correctly normalizes both numeric and string timestamp keys into the expected
BTreeMap<TimestampMillis, BTreeMap<Identifier, TokenAmount>>structure, with proper error handling.
13-14: LGTM! Correct deserializer application.The custom deserializer is properly applied to the
distributionsfield, enabling flexible JSON input with either numeric or string timestamp keys.
|
✅ DashSDKFFI.xcframework built for this PR.
SwiftPM (host the zip at a stable URL, then use): .binaryTarget(
name: "DashSDKFFI",
url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
checksum: "66dbfc66abb1b6ba939903d97706b858ab068ced56c8aba5fa9a7f0b66d1e4cb"
)Xcode manual integration:
|
Issue being fixed or feature implemented
JSON doesn't support integer as a key for object
What was done?
How Has This Been Tested?
With test
Breaking Changes
None
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit
New Features
Tests