feat: watch-only exporting for wallets #1057

Open
uqlidi wants to merge 3 commits from wallet-export-xpub into qt6 AGit
uqlidi commented 2026-10-30 11:46:10 +00:00 (Migrated from github.com)

According to https://johnny9.dev/bitcoin-gui-evidence/#feature/F05, the watch-only exporting option is missed in the QML version. this pr is implementing it by adding a new option inside wallet settings to be able to export a watch-only wallet by sharing the descriptor or the extended public key.

the user would be able to scan it by QR, copy it, and save it to a file. both for the descriptor and xpub

Screenshots

popup shows the xpub save to file option showing different address types sharing the descriptor sharing the descriptor for all addresses
According to https://johnny9.dev/bitcoin-gui-evidence/#feature/F05, the watch-only exporting option is missed in the QML version. this pr is implementing it by adding a new option inside wallet settings to be able to export a watch-only wallet by sharing the descriptor or the extended public key. the user would be able to scan it by QR, copy it, and save it to a file. both for the descriptor and xpub ## Screenshots <img width="3807" height="2067" alt="popup shows the xpub" src="https://git.fish.foo/attachments/95a050e1-54cb-416c-a6c3-1c72f26d1561" /> <img width="3807" height="2067" alt="save to file option" src="https://git.fish.foo/attachments/25487023-8e4a-413d-9c2f-12d95fcc4dd5" /> <img width="3807" height="2067" alt="showing different address types" src="https://git.fish.foo/attachments/4c3f0f47-f500-40ef-baed-f23715ae17a9" /> <img width="3807" height="2067" alt="sharing the descriptor" src="https://git.fish.foo/attachments/3fa71314-8cc3-40e8-8351-3ad869c35114" /> <img width="3807" height="2067" alt="sharing the descriptor for all addresses" src="https://git.fish.foo/attachments/82485537-7089-4404-b227-d94ba12127ec" />
ValeraFinebits commented 2026-10-31 12:53:47 +00:00 (Migrated from github.com)

I'm testing this PR on Windows. “Save to file” opens in the application's working directory. Could we explicitly set currentFolder and construct both URLs with QUrl::fromLocalFile()? The QFileDialog wrapper also needs selectFile() for local file preselection before the native dialog opens.

I'm testing this PR on Windows. “Save to file” opens in the application's working directory. Could we explicitly set `currentFolder` and construct both URLs with `QUrl::fromLocalFile()`? The `QFileDialog` wrapper also needs `selectFile()` for local file preselection before the native dialog opens.
ValeraFinebits commented 2026-10-31 13:32:20 +00:00 (Migrated from github.com)

Encrypting an existing wallet generates a new HD seed and makes the previous descriptors inactive, but those descriptors can still hold funds. Exporting only active descriptors therefore makes “Complete watch-only wallet” incomplete: it can miss funds received before encryption. Could we include the relevant inactive descriptors and add a regression test with funds received before encryption?

Encrypting an existing wallet generates a new HD seed and makes the previous descriptors inactive, but those descriptors can still hold funds. Exporting only active descriptors therefore makes “Complete watch-only wallet” incomplete: it can miss funds received before encryption. Could we include the relevant inactive descriptors and add a regression test with funds received before encryption?
ValeraFinebits commented 2026-10-31 13:41:25 +00:00 (Migrated from github.com)

On Windows, the focus outline around “Address type” is clipped at the top and sides (see screenshot). ListRow draws the outline outside its bounds, while the enclosing FormSection clips it. Could we keep the full focus outline visible here?

image
On Windows, the focus outline around “Address type” is clipped at the top and sides (see screenshot). `ListRow` draws the outline outside its bounds, while the enclosing `FormSection` clips it. Could we keep the full focus outline visible here? <img width="878" height="1712" alt="image" src="https://git.fish.foo/attachments/c9dfbc86-b76c-48c8-8a20-9de452a2bd68" />
ValeraFinebits commented 2026-10-31 14:26:13 +00:00 (Migrated from github.com)

I found a race on Windows when opening the export while another wallet is loading:

  1. Have wallet A selected and wallet B unloaded.
  2. Select B from the wallet menu to start loading it.
  3. Click the wallet selector button again to close the menu.
  4. Immediately click “Export watch-only wallet” while A is still selected.

After B finishes loading and becomes selected, the popup can remain open with A’s descriptors. In my testing, skipping step 3 makes the popup close normally.

This seems to happen when the wallet changes during the enter transition, while opened is still false. Could we check visible instead to cover that interval?

I found a race on Windows when opening the export while another wallet is loading: 1. Have wallet A selected and wallet B unloaded. 2. Select B from the wallet menu to start loading it. 3. Click the wallet selector button again to close the menu. 4. Immediately click “Export watch-only wallet” while A is still selected. After B finishes loading and becomes selected, the popup can remain open with A’s descriptors. In my testing, skipping step 3 makes the popup close normally. This seems to happen when the wallet changes during the enter transition, while `opened` is still false. Could we check `visible` instead to cover that interval?
johnny9 (Migrated from github.com) reviewed 2026-11-03 15:47:09 +00:00
johnny9 (Migrated from github.com) left a comment

Reviewed 71947071a5. I think the dialog looks good. I found an additional issue with extended-key export. I also reproduced the four issues already reported by ValeraFinebits.

Reviewed 71947071a56e45ee9f597a6bc67ddbdff4da5c4e. I think the dialog looks good. I found an additional issue with extended-key export. I also reproduced the four issues already reported by ValeraFinebits.
johnny9 (Migrated from github.com) commented 2026-11-03 15:47:09 +00:00

When the receive and change descriptors use different xpubs, “Extended key” exports only the receive key, so the imported wallet misses change funds. I reproduced 99.9999859 BTC in the source wallet versus 50 BTC after import. Disable this format when one key cannot represent both descriptor branches, and extend watchOnlyExportsJoinReceiveAndChange to cover this case.

When the receive and change descriptors use different xpubs, “Extended key” exports only the receive key, so the imported wallet misses change funds. I reproduced 99.9999859 BTC in the source wallet versus 50 BTC after import. Disable this format when one key cannot represent both descriptor branches, and extend `watchOnlyExportsJoinReceiveAndChange` to cover this case.
rreview commented 2026-11-03 17:12:36 +00:00 (Migrated from github.com)

Review failed for 780a6a245a3c. The review did not finish successfully. No findings are published for this attempt.

Attempted head: 780a6a245a3c · Attempt report

Previous completed review: 598abdbeb3a5

<!-- ralph-major:bitcoin-core/gui-qml --> Review failed for `780a6a245a3c`. The review did not finish successfully. No findings are published for this attempt. Attempted head: [`780a6a245a3c`](<https://github.com/bitcoin-core/gui-qml/commit/780a6a245a3ce263bf4bbd9de14e44818784ba6d>) · [Attempt report](<https://review.fish.foo/report/gui/1057-780a6a245a3ce263bf4bbd9de14e44818784ba6d-3110-7.html>) Previous completed review: [`598abdbeb3a5`](<https://review.fish.foo/report/gui/1057-598abdbeb3a5abc2db4083646cf609590e5f955c-3097-6.html>)
pseudoramdom (Migrated from github.com) requested changes 2026-11-04 23:20:45 +00:00
pseudoramdom (Migrated from github.com) left a comment

I don't think we should be showing descriptors for each output type unless someone is planning to export to a non-BitcoinCore wallet.
The right way to do it would be to export to a file which the BitcoinCore v32.1 GUI & exportwatchonlywallet RPC does.

Saving descriptors as text loses metadata such as creation times, ranges, and next indices. It also omits transactions, labels, wallet flags, and the best-block locator that can avoid a rescan when the wallet is restored.

We should also use interfaces::Wallet::exportWatchOnlyWallet(destination) for this flow.

Showing descriptors for each output type seems more appropriate for a separate flow intended for importing into other wallets. Maybe we can avoid this flow and such users can use the RPC instead?

I don't think we should be showing descriptors for each output type unless someone is planning to export to a non-BitcoinCore wallet. The right way to do it would be to export to a file which the BitcoinCore v32.1 GUI & `exportwatchonlywallet` RPC does. Saving descriptors as text loses metadata such as creation times, ranges, and next indices. It also omits transactions, labels, wallet flags, and the best-block locator that can avoid a rescan when the wallet is restored. We should also use [interfaces::Wallet::exportWatchOnlyWallet(destination)](https://github.com/bitcoin/bitcoin/blob/master/src/interfaces/wallet.h#L317-L318) for this flow. Showing descriptors for each output type seems more appropriate for a separate flow intended for importing into other wallets. Maybe we can avoid this flow and such users can use the RPC instead?
uqlidi commented 2026-11-05 22:15:48 +00:00 (Migrated from github.com)

I don't think we should be showing descriptors for each output type unless someone is planning to export to a non-BitcoinCore wallet. The right way to do it would be to export to a file which the BitcoinCore v32.1 GUI & exportwatchonlywallet RPC does.

Saving descriptors as text loses metadata such as creation times, ranges, and next indices. It also omits transactions, labels, wallet flags, and the best-block locator that can avoid a rescan when the wallet is restored.

We should also use interfaces::Wallet::exportWatchOnlyWallet(destination) for this flow.

Showing descriptors for each output type seems more appropriate for a separate flow intended for importing into other wallets. Maybe we can avoid this flow and such users can use the RPC instead?

Agreed for Core to Core, the file keeps birth times, labels and the best-block locator, and our Import flow already restores it through restoreWallet. Our submodule doesn't have exportWatchOnlyWallet yet though (bitcoin/bitcoin#32489 landed after dc282ff31d), so this needs a bump first. Should I do the bump here or wait for a separate one?

For other wallets I'd still keep the descriptor/xpub view, but as a separate action. Most GUI users won't use the RPC, especially on mobile. WDYT?

> I don't think we should be showing descriptors for each output type unless someone is planning to export to a non-BitcoinCore wallet. The right way to do it would be to export to a file which the BitcoinCore v32.1 GUI & `exportwatchonlywallet` RPC does. > > Saving descriptors as text loses metadata such as creation times, ranges, and next indices. It also omits transactions, labels, wallet flags, and the best-block locator that can avoid a rescan when the wallet is restored. > > We should also use [interfaces::Wallet::exportWatchOnlyWallet(destination)](https://github.com/bitcoin/bitcoin/blob/master/src/interfaces/wallet.h#L317-L318) for this flow. > > Showing descriptors for each output type seems more appropriate for a separate flow intended for importing into other wallets. Maybe we can avoid this flow and such users can use the RPC instead? Agreed for Core to Core, the file keeps birth times, labels and the best-block locator, and our Import flow already restores it through `restoreWallet`. Our submodule doesn't have `exportWatchOnlyWallet` yet though (bitcoin/bitcoin#32489 landed after `dc282ff31d`), so this needs a bump first. Should I do the bump here or wait for a separate one? For other wallets I'd still keep the descriptor/xpub view, but as a separate action. Most GUI users won't use the RPC, especially on mobile. WDYT?
uqlidi commented 2026-11-11 06:21:03 +00:00 (Migrated from github.com)

Updates about the flow and the design

Instead of "Export watch-only wallet" option that shows the descriptor and the xpubs, now there's "Descriptors" option and we moved exporting the wallet it self to "Backup or Export wallet" option:

2026-11-11-072650_hyprshot

Now, if you go to "Backup or Export wallet", you will would be able to export a full backup with private keys or view-only wallet that contains the public keys only:

2026-11-11-072639_hyprshot 2026-11-11-072631_hyprshot

if you go to "Descriptors", you will see the the descriptors and would be able to copy all of them as json format like that:

[
  {
    "desc": "pkh([621f5481/44h/1h/0h]tpubDDRSiyFUdgY2HfVGwaVds9TfYRth5yHH1jFEzVM7nDMFrEwaut8vTtbiAUuZJk9f4Mga4NZ2Jumr5ofrmAEU6fchWM4x2oGbd2ypqF6jkbY/0/*)#6fesew6t",
    "timestamp": 1791549918,
    "active": true,
    "internal": false,
    "range": [
      0,
      999
    ],
    "next_index": 0
  },
 ...
]
2026-11-11-075502_hyprshot

or would be able to copy specific type:
2026-11-11-072712_hyprshot

also, you can get the extended public keys for different address types
2026-11-11-072717_hyprshot

Updates about the flow and the design Instead of "Export watch-only wallet" option that shows the descriptor and the xpubs, now there's "Descriptors" option and we moved exporting the wallet it self to "Backup or Export wallet" option: <img width="3807" height="2067" alt="2026-11-11-072650_hyprshot" src="https://git.fish.foo/attachments/38d38df8-5a03-49e5-8c0a-d94bef5e5aa4" /> Now, if you go to "Backup or Export wallet", you will would be able to export a full backup with private keys or view-only wallet that contains the public keys only: <img width="3807" height="2067" alt="2026-11-11-072639_hyprshot" src="https://git.fish.foo/attachments/d5789ce1-0db8-47c7-9263-19b7746355c7" /> <img width="3807" height="2067" alt="2026-11-11-072631_hyprshot" src="https://git.fish.foo/attachments/a22236f7-a040-481b-a4b5-aee13a7c0f7c" /> if you go to "Descriptors", you will see the the descriptors and would be able to copy all of them as json format like that: ```json [ { "desc": "pkh([621f5481/44h/1h/0h]tpubDDRSiyFUdgY2HfVGwaVds9TfYRth5yHH1jFEzVM7nDMFrEwaut8vTtbiAUuZJk9f4Mga4NZ2Jumr5ofrmAEU6fchWM4x2oGbd2ypqF6jkbY/0/*)#6fesew6t", "timestamp": 1791549918, "active": true, "internal": false, "range": [ 0, 999 ], "next_index": 0 }, ... ] ``` <img width="3807" height="2067" alt="2026-11-11-075502_hyprshot" src="https://git.fish.foo/attachments/93271cf1-98f1-4885-ada7-c3b777ea7c1a" /> or would be able to copy specific type: <img width="3807" height="2067" alt="2026-11-11-072712_hyprshot" src="https://git.fish.foo/attachments/ffe76929-70c8-4a3e-a1b1-1e5f92e0d31e" /> also, you can get the extended public keys for different address types <img width="3807" height="2067" alt="2026-11-11-072717_hyprshot" src="https://git.fish.foo/attachments/3f6c2fdc-3572-4674-b57c-ff1f912e9539" />
johnny9 (Migrated from github.com) reviewed 2026-11-11 21:17:42 +00:00
johnny9 (Migrated from github.com) left a comment

Reviewed fc657610b8. I independently confirmed two findings already identified by rreview:

  • Replace can overwrite another loaded wallet's database. The destination check protects the wallet directory and selected wallet, but not other loaded wallets outside that directory. A focused probe confirmed that such a destination is offered for replacement. On POSIX, the subsequent rename can replace the live database, bypassing SQLite's locks. I did not run an end-to-end destructive reproduction.
  • Unsupported change descriptors are treated as absent. If the receive descriptor parses but an existing change descriptor does not, descriptorExports() omits the change descriptor and can still enable extended-key export. This can produce a watch-only view that misses change funds. Confirmed by tracing the parser and export logic against Core's independently activated receive/change managers.

These confirm rreview's existing findings rather than adding new ones: GitHub summary and run archive (adversarial:2 for the unsupported-change finding).

Reviewed fc657610b860654e914e140f6a54fc16bf0ecc83. I independently confirmed two findings already identified by rreview: - **Replace can overwrite another loaded wallet's database.** The destination check protects the wallet directory and selected wallet, but not other loaded wallets outside that directory. A focused probe confirmed that such a destination is offered for replacement. On POSIX, the subsequent rename can replace the live database, bypassing SQLite's locks. I did not run an end-to-end destructive reproduction. - **Unsupported change descriptors are treated as absent.** If the receive descriptor parses but an existing change descriptor does not, `descriptorExports()` omits the change descriptor and can still enable extended-key export. This can produce a watch-only view that misses change funds. Confirmed by tracing the parser and export logic against Core's independently activated receive/change managers. These confirm rreview's existing findings rather than adding new ones: [GitHub summary](https://github.com/bitcoin-core/gui-qml/pull/1057#issuecomment-6610568921) and [run archive](https://review.fish.foo/traces/gui/1057-fc657610b860654e914e140f6a54fc16bf0ecc83-2506-4.html) (`adversarial:2` for the unsupported-change finding).
Sign in to join this conversation.
No description provided.