Skip to content

refactor: drop the types module and build JSON output in each command - #396

Merged
tvpeter merged 3 commits into
bitcoindevkit:masterfrom
tvpeter:refactor/drop-types-module
Dec 3, 2026
Merged

tvpeter merged 3 commits into
bitcoindevkit:masterfrom
tvpeter:refactor/drop-types-module

Conversation

@tvpeter

@tvpeter tvpeter commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Description

Since --pretty was removed, JSON is the only output format, so the structs in src/utils/types.rs only existed to be serialized once. Several still carried pretty-format leftovers: TransactionDetails had #[serde(skip)] fields nothing read, and UnspentDetails::from_local_output took an unused network argument.

This PR removes the module and ensured that a command's JSON is built in its own execute method.

Notes to the reviewers

  • AppCommand::execute / AsyncAppCommand::execute return Result<serde_json::Value, Error>. The associated Output type is dropped.
  • Helpers return domain values, not JSON
  • Absent values are left out, as skip_serializing_if did before. The exception is payjoin_history rows, which keep completed_at: null so every row has the same keys.
  • NEW_FEATURE.md "Step 2" is rewritten for the new convention.
  • receive_payjoin, send_payjoin, resume_payjoin, payjoin_history and resolve_dns_recipient now print their JSON directly instead of as an escaped string in a message field. resolve_dns_recipient leaves out description, min_amount and max_amount when they're not set.

Checklists

All Submissions:

@github-project-automation github-project-automation Bot moved this to Todo in BDK-CLI Nov 30, 2026
@tvpeter tvpeter self-assigned this Nov 30, 2026
@tvpeter tvpeter added this to the CLI 4.1.0 milestone Nov 30, 2026
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.09589% with 99 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.42%. Comparing base (767592c) to head (537fbb9).
⚠️ Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
src/handlers/online.rs 29.50% 43 Missing ⚠️
src/handlers/dns/mod.rs 7.69% 24 Missing ⚠️
src/handlers/payjoin/mod.rs 18.75% 13 Missing ⚠️
src/utils/descriptors.rs 57.14% 9 Missing ⚠️
src/handlers/descriptor.rs 83.87% 5 Missing ⚠️
src/handlers/hwi.rs 0.00% 2 Missing ⚠️
src/handlers/config.rs 92.85% 1 Missing ⚠️
src/handlers/payjoin/db.rs 90.00% 1 Missing ⚠️
src/utils/common.rs 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #396      +/-   ##
==========================================
- Coverage   59.86%   59.42%   -0.45%     
==========================================
  Files          25       24       -1     
  Lines        4550     4498      -52     
==========================================
- Hits         2724     2673      -51     
+ Misses       1826     1825       -1     
Flag Coverage Δ
rust 59.42% <66.09%> (-0.45%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

JSON is the only output format, so the result structs in
src/utils/types.rs were only intermediate shapes. execute() now
returns serde_json::Value and each command builds its output with
json! in its own handler, so a command's output is defined in one
place.

Helpers in src/utils return domain values instead of output structs:
the descriptor helpers return KeychainDescriptors (descriptors,
keymap, fingerprint), and the handler decides what to print.
… string

receive_payjoin, send_payjoin, resume_payjoin, payjoin_history and
resolve_dns_recipient serialized their result to a string and wrapped
it in {"message": ...}, so consumers had to parse JSON twice.

PayjoinManager now returns domain values (Txid, ResumeOutcome,
Vec<SessionHistoryRow>) and the handlers build the JSON.
resolve_dns_recipient leaves out description, min_amount and
max_amount when they are not set.
@tvpeter
tvpeter force-pushed the refactor/drop-types-module branch from c20e5b2 to 5e09181 Compare December 1, 2026 11:09

@vadim-anfv vadim-anfv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key order of the JSON output changes for every command, not only for the five listed in the CHANGELOG: json! orders keys alphabetically, while the structs kept their declaration order.

key generate on master:

{
  "xprv": "...",
  "mnemonic": "...",
  "fingerprint": "..."
}

The same command on this branch:

{
  "fingerprint": "...",
  "mnemonic": "...",
  "xprv": "..."
}

balance, wallets list and descriptor reshuffle the same way. With one line in Cargo.toml:

serde_json = { version = "1.0", features = ["preserve_order"] }

json! keeps the insertion order, and the branch prints master's order again:

{
  "xprv": "...",
  "mnemonic": "...",
  "fingerprint": "..."
}

Comment thread src/handlers/config.rs Resolved
Comment thread src/handlers/config.rs Resolved
Comment thread src/handlers/online.rs Resolved
Comment thread src/handlers/offline.rs Resolved
It returns domain values (Xpriv, Fingerprint) and is not tied to a
command, so it belongs with the other helpers in src/utils, next to
is_mnemonic.
@tvpeter
tvpeter force-pushed the refactor/drop-types-module branch from 5e09181 to 537fbb9 Compare December 1, 2026 18:21
@tvpeter

tvpeter commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

The key order of the JSON output changes for every command, not only for the five listed in the CHANGELOG: json! orders keys alphabetically, while the structs kept their declaration order.

Thank you for noting this. I saw it earlier but assumed it may not be relevant but some users may be accessing the json values by position, so it is ideal that the order is preserved.

I have also updated the indentations. I thought that cargo fmt will handle indentations but I just learned that it only formats a macro call when everything inside it parses as ordinary Rust which json! does not.

I agree that the payjoin progress prints should be treated as a separate issue.

Thank you.

@vadim-anfv

Copy link
Copy Markdown
Collaborator

I have also updated the indentations. I thought that cargo fmt will handle indentations but I just learned that it only formats a macro call when everything inside it parses as ordinary Rust which json! does not.

Yeah, I also thought fmt would format this, but it turns out it doesn't. I haven't found a way to do it other than manually yet.

@vadim-anfv vadim-anfv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 537fbb9

Key order is restored, key generate prints master's order again:

$ c r -q -- key generate
{
  "xprv": "...",
  "mnemonic": "...",
  "fingerprint": "..."
}

@tvpeter
tvpeter merged commit 06191e5 into bitcoindevkit:master Dec 3, 2026
9 of 10 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in BDK-CLI Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants