Repository navigation
refactor: drop the types module and build JSON output in each command - #396
Conversation
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
c20e5b2 to
5e09181
Compare
vadim-anfv
left a comment
There was a problem hiding this comment.
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": "..."
}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.
5e09181 to
537fbb9
Compare
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 I agree that the payjoin progress prints should be treated as a separate issue. Thank you. |
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
left a comment
There was a problem hiding this comment.
tACK 537fbb9
Key order is restored, key generate prints master's order again:
$ c r -q -- key generate
{
"xprv": "...",
"mnemonic": "...",
"fingerprint": "..."
}
Description
Since
--prettywas removed, JSON is the only output format, so the structs insrc/utils/types.rsonly existed to be serialized once. Several still carried pretty-format leftovers:TransactionDetailshad #[serde(skip)] fields nothing read, andUnspentDetails::from_local_outputtook an unused network argument.This PR removes the module and ensured that a command's JSON is built in its own
executemethod.Notes to the reviewers
AppCommand::execute / AsyncAppCommand::executereturnResult<serde_json::Value, Error>. The associatedOutputtype is dropped.skip_serializing_ifdid before. The exception ispayjoin_historyrows, which keepcompleted_at: nullso every row has the same keys.receive_payjoin,send_payjoin,resume_payjoin,payjoin_historyandresolve_dns_recipientnow print their JSON directly instead of as an escaped string in a message field.resolve_dns_recipientleaves outdescription,min_amountandmax_amountwhen they're not set.Checklists
All Submissions:
just pre-pushbefore pushing