The createwalletdescriptor
was introduced in #29130 to let users add a tr()
descriptor to an existing SegWit wallet. The new addhdkey
method from #29136 introduces a new potential workflow: start from a blank wallet, generate an HD and then add only the descriptors you need, e.g.:
0bitcoin rpc createwallet TaprootMaxi blank=true
1bitcoin rpc addhdkey
2bitcoin rpc createwalletdescriptor bech32m
Before this PR the last line would fail, requiring the user to call gethdkeys
and copy-paste the xpub.
This PR makes createwalletdescriptor
a bit smarter so it just finds the unused(KEY)
generated by hdkey
and uses that.
If multiple unused(KEY)
descriptors are present the user still has to pick one.
A potential followup is to make our multisig tutorial slightly safer to use. Rather than creating a full wallet, the instruction could be changed to start with a blank wallet and only generate the default legacy descriptor. This avoids accidental use of single sig p2sh-segwit
and bech32
addresses.
(I might do that in #32784, which introduces some other improvements to the tutorial. The situation is still not great; ideally the importdescriptors
RPC is enhanced to detect when an xpub
is a child of an hd key and then treats it as if an xpriv was imported.)
Builds on #29136.