Skip to content

feat(labels): add BIP-329 wallet labels - #371

Open
Musab1258 wants to merge 4 commits into
bitcoindevkit:masterfrom
Musab1258:feat/bip329-label-commands
Open

Musab1258 wants to merge 4 commits into
bitcoindevkit:masterfrom
Musab1258:feat/bip329-label-commands

Conversation

@Musab1258

@Musab1258 Musab1258 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds BIP-329 wallet labels to bdk-cli, using the standalone bdk-labels crate as suggested by @notmandatory in PR #266. Fixes #184 . Supersedes #266, which I'll close very soon, as it no longer applies after the refactor.

  • label: attach a label to a transaction, a UTXO, or an address, with exactly one of --txid, --utxo, --address, and --text.
  • import_labels <file> with --strategy keep-existing|overwrite (default keep-existing), and export_labels <file>.
  • transactions, unspent and unused_address show a label field, left out when there is none.
  • Labels are stored in a BIP-329 JSONL file at <datadir>/<wallet>/labels.jsonl, owner-only, independent of the sqlite/redb wallet database.

Labels are loaded only by the commands that use them, never in OfflineOperations, which only gains wallet_name (mirroring OnlineOperations).

Notes to the reviewers

This answers the five points in @vadim-anfv's review of PR #266:

  1. — placeholder: gone. Unlabeled items have no label field, so a real — label is distinguishable (a_dash_label_is_told_apart_from_no_label).
  2. spendable: labelling a UTXO never changes it, and a coin frozen elsewhere stays frozen on a rename (labelling_a_utxo_keeps_it_spendable_or_frozen_as_it_was). It is stored and exported but not tied to lock_utxo;.
  3. Write-only address labels: unused_address shows the address label (unused_address_shows_its_label).
  4. REPL: labels can be set and shown in the REPL (labels_can_be_set_in_the_repl, labels_are_shown_in_the_repl).
  5. Corrupt labels.jsonl breaking every command: balance never reads the file. Display commands warn and carry on. label, import_labels and export_labels fail naming the file.

Other behavior worth a look:

  • Addresses are checked with require_network, not parse_address.
  • A transaction or UTXO must be known to the wallet, and the error says to sync first.
  • A bad import file imports nothing (a_bad_import_file_changes_nothing).

Testing:

  • Manually tested on regtest against a real bitcoind with the rpc backend: funded a wallet, synced, and labelled a transaction and a UTXO. transactions and unspent showed the labels (also in the REPL), lock_utxo left the label untouched, and renaming a coin with spendable:false kept it false.
  • All tests passed when I ran just pre-push
  • The display tests write transactions into a persisted wallet database instead of syncing, so they need no node.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.64179% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.05%. Comparing base (d2317d2) to head (bd6792a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/handlers/offline.rs 96.07% 4 Missing ⚠️
src/utils/labels.rs 97.03% 4 Missing ⚠️
src/main.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #371      +/-   ##
==========================================
+ Coverage   59.08%   61.05%   +1.97%     
==========================================
  Files          25       26       +1     
  Lines        4646     4894     +248     
==========================================
+ Hits         2745     2988     +243     
- Misses       1901     1906       +5     
Flag Coverage Δ
rust 61.05% <96.64%> (+1.97%) ⬆️

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.

@Olorunshogo Olorunshogo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concept ACK. Nice work fixing all five points from #266.

I tested bd6792a on regtest (Core v32.1.0, rpc backend). Labelling works, labels show up in transactions, unspent, unused_address and the REPL, and the checks for wrong txids and addresses work well. The labels file is owner-only, and a corrupt file doesn't break balance. fmt, clippy and the tests all pass.

I left two inline comments on import. Files with unknown types (like spscan in the BIP's own test vectors) fail completely. And with --strategy overwrite, a record that leaves out spendable or label wipes the existing value, so a frozen coin can become spendable again or lose its label.

This also needs a rebase. It conflicts with master in six files, including src/utils/types.rs, which #396 removed.

Happy to test again after the rebase.

Comment thread Cargo.toml
bitcoin-payment-instructions = { version = "0.7.0", optional = true}

async-hwi = { version = "0.0.35", features = ["specter", "coldcard", "ledger", "jade", "bitbox", "service"], optional = true}
bdk-labels = "0.2.2"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be behind a labels feature, like message_signer and dns_payment? Also, there's an extra blank line added above async-hwi.

Comment thread README.md
An exported file replaces any file already at that path, and is only readable by its owner. When an imported label is for something that already has a label, `--strategy keep-existing` (the default) keeps the wallet's label and `--strategy overwrite` replaces it. A file that cannot be read in full is rejected, and nothing is imported from it. Labels for things the wallet does not know about are kept, so a file from another wallet can be imported before the wallet has synced.

> [!NOTE]
> BIP-329 output labels have a `spendable` flag, which other wallets use to mark a coin as frozen. `bdk-cli` stores and exports the flag, and labelling a UTXO never changes it, but importing `spendable: false` does not lock the coin in `bdk-cli`. To stop a UTXO from being spent, use the `lock_utxo` command.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"labelling a UTXO never changes it" is true for label, but import_labels --strategy overwrite can still change spendable (see my comment on offline.rs). Might need updating once that's fixed.

Comment thread src/handlers/offline.rs
};
// The whole file is read before any label is merged, so a bad file imports nothing.
labelled
.import_labels(BufReader::new(file), self.strategy.into())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two things I hit when importing:

  1. If the file has a type that isn't one of the six known ones, the whole import fails. The BIP's own test vectors include spscan, and importing them gives unknown variant 'spscan'. The BIP says unknown types should just be skipped.
  2. With --strategy overwrite, leaving a field out wipes the existing value. An output record without spendable makes a frozen coin spendable again (it defaults to true), and one without label deletes the label. The BIP says left-out fields shouldn't change anything.

Since bdk-labels is your crate, it might be easier to fix both there.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Add BIP-329 wallet label support

2 participants