Skip to content

feat(key-wallet,key-wallet-manager): add serde derives for AssetLockFundingType and DerivedAddress#761

Open
lklimek wants to merge 1 commit into
v0.42-devfrom
feat/key-wallet-serde-derives
Open

feat(key-wallet,key-wallet-manager): add serde derives for AssetLockFundingType and DerivedAddress#761
lklimek wants to merge 1 commit into
v0.42-devfrom
feat/key-wallet-serde-derives

Conversation

@lklimek
Copy link
Copy Markdown
Contributor

@lklimek lklimek commented May 13, 2026

What this PR does

Adds optional serde derives behind a serde feature gate on two types:

  • key_wallet::wallet::managed_wallet_info::asset_lock_builder::AssetLockFundingType (enum)
  • key_wallet_manager::DerivedAddress (struct)

key-wallet already had a serde feature — just the derive line was added. key-wallet-manager had no serde feature, so this PR also adds one: optional serde dep, [features] serde = ["dep:serde", "key-wallet/serde", "dashcore/serde"].

DerivedAddress::public_key: [u8; 33] needs a tiny local with = adapter (serde_pubkey33) because serde only ships built-in array impls up to length 32. The adapter writes a flat 33-element byte sequence — same shape serde would have produced for [u8; 32] — and the new derived_address_serde_json_roundtrip test locks that in.

Why

Downstream consumers in dashpay/platform (specifically PR #3637 — rs-platform-wallet serde support) currently work around these missing derives:

  1. A custom serde_adapters::asset_lock_funding_type module re-implements derive-equivalent serialization with a stable u8 wire-tag. Once this PR lands, the adapter becomes deletable (with one caveat the platform PR will resolve: wire-tag stability for pre-serde on-disk blobs).
  2. The PlatformAddressChangeSet::addresses_derived field is #[serde(skip)] because DerivedAddress can't be serialized through. Once this PR lands, the skip can be removed and the field can round-trip normally.

Verification

  • cargo fmt --all -- --check clean
  • cargo check -p key-wallet --no-default-features and --features serde both pass
  • cargo check -p key-wallet-manager --no-default-features and --features serde both pass
  • cargo clippy -p key-wallet -p key-wallet-manager --tests --all-features --no-deps -- -D warnings clean
  • cargo test -p key-wallet -p key-wallet-manager --features serde — 557 tests pass (includes the new round-trip)

Companion PR

dashpay/platform#3637 will pick up these derives once this lands; the platform PR is currently working around their absence.

🤖 Co-authored by Claudius the Magnificent AI Agent

Summary by CodeRabbit

  • New Features

    • Added optional serialization support for wallet data structures via a new feature.
  • Tests

    • Added JSON serialization/deserialization round-trip tests.
  • Chores

    • Introduced feature wiring and development dependency updates to support optional serialization.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Warning

Rate limit exceeded

@lklimek has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 52 minutes and 38 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 36489cd1-c173-46cb-8b2d-edf13b4065e1

📥 Commits

Reviewing files that changed from the base of the PR and between 4dbe0b5 and 954eb92.

📒 Files selected for processing (3)
  • key-wallet-manager/Cargo.toml
  • key-wallet-manager/src/events.rs
  • key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs
📝 Walkthrough

Walkthrough

Adds an optional serde feature to key-wallet-manager, conditionally derives serde traits for DerivedAddress and AssetLockFundingType, and adds serde-enabled dev test wiring plus a JSON round-trip test for DerivedAddress.

Changes

Serde serialization support for wallet types

Layer / File(s) Summary
Feature flag and dependency configuration
key-wallet-manager/Cargo.toml
Adds a serde feature that forwards to the optional serde dependency and to key-wallet/serde and dashcore/serde; enables serde features in dev-dependencies and adds serde_json for tests.
DerivedAddress conditional serde and tests
key-wallet-manager/src/events.rs
DerivedAddress gains conditional Serialize/Deserialize derives under the serde feature; adds a serde_tests module (cfg(test, feature = "serde")) that verifies JSON serialize/deserialize round-trip using serde_json.
AssetLockFundingType serde derives
key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs
AssetLockFundingType conditionally derives serde::Serialize and serde::Deserialize when the serde feature is enabled.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • dashpay/rust-dashcore#765: Modifies DerivedAddress shape and parsing; changes may interact with the serde derives and tests added here.

Poem

🐰 In burrows of code I nibble the bytes,
A feature gate opens to serde's delights.
DerivedAddress hums, JSON round-trips with glee,
Asset locks whisper in serial harmony.
Hop, hop—tiny rabbit: serialized and free!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding serde derives for two specific types across two crates, which matches the primary objective of the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/key-wallet-serde-derives

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.28%. Comparing base (1288884) to head (954eb92).

Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #761      +/-   ##
=============================================
+ Coverage      72.27%   72.28%   +0.01%     
=============================================
  Files            320      320              
  Lines          70271    70271              
=============================================
+ Hits           50786    50794       +8     
+ Misses         19485    19477       -8     
Flag Coverage Δ
core 76.30% <ø> (ø)
ffi 46.10% <ø> (+0.01%) ⬆️
rpc 20.00% <ø> (ø)
spv 89.80% <ø> (+0.04%) ⬆️
wallet 71.27% <ø> (ø)
Files with missing lines Coverage Δ
key-wallet-manager/src/events.rs 68.81% <ø> (ø)
...c/wallet/managed_wallet_info/asset_lock_builder.rs 82.77% <ø> (ø)

... and 5 files with indirect coverage changes

@lklimek lklimek force-pushed the feat/key-wallet-serde-derives branch from 807bc50 to 56a8440 Compare May 13, 2026 14:11
@lklimek lklimek marked this pull request as ready for review May 13, 2026 14:21
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 13, 2026
@github-actions github-actions Bot added ready-for-review CodeRabbit has approved this PR merge-conflict The PR conflicts with the target branch. and removed ready-for-review CodeRabbit has approved this PR labels May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@lklimek lklimek force-pushed the feat/key-wallet-serde-derives branch from 13e9698 to 4dbe0b5 Compare May 14, 2026 14:36
@github-actions github-actions Bot removed merge-conflict The PR conflicts with the target branch. ready-for-review CodeRabbit has approved this PR labels May 14, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 14, 2026
…undingType and DerivedAddress

Expose optional serde Serialize/Deserialize on two types so downstream
consumers can drop hand-rolled adapters:

  * `key_wallet::wallet::managed_wallet_info::asset_lock_builder::AssetLockFundingType`
    (enum) — derives are gated on the existing `serde` feature.
  * `key_wallet_manager::DerivedAddress` (struct) — `key-wallet-manager`
    previously had no `serde` feature, so this adds one wired to
    `key-wallet/serde` and `dashcore/serde`. The struct's `public_key`
    field is `dashcore::PublicKey`, which already implements serde under
    the `dashcore/serde` feature, so no custom adapter is needed.

Motivation: dashpay/platform PR #3637 (rs-platform-wallet serde support)
currently works around the missing derives with a custom
`serde_adapters::asset_lock_funding_type` module and a
`#[serde(skip)]` on a `PlatformAddressChangeSet::addresses_derived`
field. Once this lands, both workarounds become deletable.

Round-trip test (`derived_address_serde_json_roundtrip`) locks down the
JSON wire shape for `DerivedAddress` so future regressions are caught.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant