feat: implement StateTransitionJsonConvert and fix PlatformAddress map key serialization#3110
feat: implement StateTransitionJsonConvert and fix PlatformAddress map key serialization#3110
Conversation
…for StateTransition enum Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
shumkov
left a comment
There was a problem hiding this comment.
Please update wasm-dpp2 as well then
|
@copilot Please update wasm-dpp2 to match changes in this PR. |
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
Updated in commit 314a1c6. Added
Done in commit 314a1c6. Added |
…then docs Replace verbose println-based tests with proper assertion-based tests that validate both to_json() and serde_json serialization paths produce correct string keys for BTreeMap<PlatformAddress, V> fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
61a90c0 to
5a43766
Compare
Remove duplicated test functions, keep the consolidated versions with shared helper, proper assertions, and given/when/then docstrings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that StateTransition::to_json() and serde_json serialization work correctly in the wasm-dpp2 context with its enabled features, including string keys for BTreeMap<PlatformAddress, V> fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…-transition-json-conversion # Conflicts: # packages/rs-dpp/Cargo.toml # packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_transfer_to_addresses_transition/v0/mod.rs # packages/wasm-dpp2/Cargo.toml
Merge Base Report —
|
| File | Ours | Theirs | Resolution |
|---|---|---|---|
rs-dpp/Cargo.toml (dash-sdk-features) |
4 separate features: data-contract-json-conversion, identity-value-conversion, state-transition-value-conversion, state-transition-json-conversion |
Single unified json-conversion |
Theirs — unified feature subsumes all separate ones |
identity_credit_transfer_to_addresses/v0/mod.rs |
feature = "state-transition-serde-conversion" + custom platform_address_map_serde |
feature = "json-conversion" + centralized json_safe_generic_u64_value_map |
Theirs — upstream provides a better generalized serializer |
wasm-dpp2/Cargo.toml |
Many separate features + custom ones | Unified json-conversion + minimal features |
Theirs — unified feature covers everything |
Safe Changes
- rs-dpp/Cargo.toml — Unified
json-conversioncorrectly subsumes all old per-type features. Old feature names still exist as aliases, so existing#[cfg]guards still compile. - wasm-dpp2/Cargo.toml — Slimmed to unified
json-conversion. Covers all previously separate features. - identity_credit_transfer_to_addresses/v0/mod.rs — Now uses upstream's centralized
json_safe_generic_u64_value_mapserializer. Functionally equivalent forBTreeMap<PlatformAddress, Credits>. - 628 auto-merged upstream files — Disjoint from this PR's 15-file change set. No textual overlap.
⚠️ Changes Requiring Attention
-
Inconsistent serde approach — Custom
platform_address_map_serdeis still used in 7 locations across address_funds and identity transitions (topup_from_addresses,create_from_addresses,address_credit_withdrawal,address_funding_from_asset_lock,address_funds_transfer). Onlyidentity_credit_transfer_to_addresseswas switched to the upstream serializer. Same data type (BTreeMap<PlatformAddress, _>) serialized two different ways depending on which transition. -
Stale feature guards —
json_conversion.rsandvalue_conversion.rsstill use#[cfg(feature = "state-transition-json-conversion")]/#[cfg(feature = "state-transition-value-conversion")]. These work today (aliases exist in Cargo.toml), but diverge from the upstream convention of usingjson-conversion/value-conversiondirectly.
Recommended Follow-up
- Migrate remaining
platform_address_map_serdeusages tojson_safe_generic_u64_value_map(7 files) - Update
#[cfg]guards injson_conversion.rsandvalue_conversion.rsto use unified feature names - Verify if custom
platform_address_map_serdemodule can be removed after migration - Run
cargo test -p dppandcargo test -p wasm-dpp2to confirm no runtime serialization mismatches
Relevant Upstream Contributors
| Author | Key Changes |
|---|---|
| @shumkov | Unified JSON/Object conversion #3167 (root cause of all 3 conflicts), platform address WASM bindings #3147 |
🤖 Co-authored by Claudius the Magnificent AI Agent
|
replaced by #3167 |
|
✅ 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: "eff095b277c9589cd3bf250568a3eba514a575fe6e0d12791db5df995a772bf9"
)Xcode manual integration:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v3.1-dev #3110 +/- ##
============================================
+ Coverage 50.39% 56.95% +6.55%
============================================
Files 3089 1955 -1134
Lines 219104 158147 -60957
============================================
- Hits 110426 90069 -20357
+ Misses 108678 68078 -40600
🚀 New features to boost your workflow:
|
Problem
StateTransitionenum lackedStateTransitionJsonConvertimplementation, forcing manual variant matching. Additionally, JSON serialization failed for address-based state transitions containingBTreeMap<PlatformAddress, V>with error "key must be a string" becausePlatformAddress(enum with data) serializes as a complex object, violating JSON's string-key requirement.Investigation revealed both
serde_json::to_string_pretty()andto_json()fail identically sinceto_json()usesplatform_value::to_value()internally, which relies on serde.Changes
StateTransition trait implementations:
json_conversion.rs- dispatchesto_json()to variant implementationsvalue_conversion.rs- dispatches conversion methods to variantsStateTransitionFieldTypesreturning empty vectors (paths are variant-specific)state-transition-json-conversiontodash-sdk-featuresPlatformAddress map key serialization fix:
platform_address_map_serde.rs- custom serde helpers that serializePlatformAddresskeys as Display strings ("P2PKH(hex...)") and deserialize viaFromStrBTreeMap<PlatformAddress, ...>:AddressFundsTransferTransitionV0(inputs, outputs)AddressFundingFromAssetLockTransitionV0(inputs, outputs)AddressCreditWithdrawalTransitionV0(inputs)IdentityTopUpFromAddressesTransitionV0(inputs)IdentityCreateFromAddressesTransitionV0(inputs)IdentityCreditTransferToAddressesTransitionV0(recipient_addresses)WASM bindings update:
state-transition-json-conversionfeature towasm-dpp2Cargo.toml to maintain feature parity withwasm-dppResult
Both serialization paths now work:
{ "inputs": { "P2PKH(0101010101010101010101010101010101010101)": [1, 1000] } }Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.