Feat: Add bip329 wallet labels#266
Conversation
- Loads the \'Labels\' state from \'<wallet>.labels.jsonl\' after \'load_wallet_config\'. - Updates \'handle_offline_wallet_subcommand\' to accept mutable label state. - Exports and saves the in-memory labels to disk before the command return.
- Injects label lookups into the `unspent` and `transactions` match arms. - Updates the `--pretty` table formatting to include a new 'Label' column (using an em dash for missing labels). - Appends the label string to the standard JSON output
- Introduces the `Label` variant to `OfflineWalletSubCommand` with strict `clap` conflict rules. - Adds a `parse_txid` helper to utils.rs. - Implements an `add_or_add_update_label` helper in `handlers.rs` to mutate the in-memory label state in place.
|
Hi @tvpeter, I am done with this. You can check it out when you are free. I will start working on the follow-up PR to add import and export of label files. |
- Introduces `ImportLabels` and `ExportLabels` variants to `OfflineWalletSubCommand` for CLI parsing. - Implements label merging from external JSONL files using `try_from_file` and `add_or_update_label`. - Enables backing up the current label state to a user-specified path using `export_to_file`.
|
Hi @tvpeter, I eventually decided to add the import and export of BIP-329 JSONL files' implementation here when, after I was done with the implementation, I saw that it was something that could fit into this PR without bloating it. So, instead of creating a second PR and having reviewers go through the stress of reviewing two PRs that can probably fit into one, I decided to make it one PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #266 +/- ##
==========================================
- Coverage 11.13% 10.59% -0.55%
==========================================
Files 8 8
Lines 2488 2615 +127
==========================================
Hits 277 277
- Misses 2211 2338 +127
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
This PR adds BIP-329 wallet label support to
bdk-cli, to fix #184. It uses the[bip329]crate to manage label data, persists it in a separatelabels.jsonlfile within the wallet's data directory (e.g.~/.bdk-bitcoin/<wallet_name>/labels.jsonl), and keeps it decoupled from the wallet's SQLite/redb database. It also exports and imports label files.This PR includes the following functionality:
labeloffline subcommand to attach a human-readable label to either a transaction ID, address, or UTXO (outpoint).unspentandtransactionscommands now include aLabelcolumn in both--prettytable output and standard JSON output, showing the stored label or an em dash if none exists.import_labelssubcommand merges labels from an external BIP-329 JSONL file into the wallet's current label state. If a label for the same item already exists, it is overwritten by the imported one.export_labelssubcommand writes the wallet's current label state to a user-specified BIP-329 JSONL file, suitable for backup or use in other BIP-329 compliant wallets.Notes to the reviewers
labels.jsonlfile rather than inside the wallet database. This keeps the label format portable and interoperable with other BIP-329 compliant wallets.Labelimport frombip329is aliased asBipLabelinhandlers.rsto avoid a name clash with theOfflineWalletSubCommand::Labelvariant brought into scope viause crate::commands::OfflineWalletSubCommand::*.import_labelscommand uses the existingadd_or_update_labelhelper to merge incoming labels one at a time, new label references are inserted, and existing label references are overwritten by the imported value.export_labelscommand writes to a user-specified path, which is independent of the wallet's internallabels.jsonlfile. The internal file is always managed automatically by the save-on-exit mechanism, so the two files remain separate.Changelog notice
Added
labelsubcommand toOfflineWalletSubCommandfor tagging transactions, addresses, and UTXOs with human-readable labels.import_labelssubcommand to merge labels from an external BIP-329 JSONL file into the wallet's current label state.export_labelssubcommand to back up the wallet's current label state to a user-specified BIP-329 JSONL file.labels.jsonlfile in the wallet data directory.Labelcolumn inunspentandtransactionsoutput (both--prettyand JSON).parse_txidhelper inutils.rs.bip329 = "0.4.0"dependency inCargo.toml.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features:
CHANGELOG.mdBugfixes: