In preparation for descriptor based wallets (e.g. #15487) it’s useful to distinguish between base58 and base32 addresses. One descriptor could be associated with getnewaddress "" bech32
and another with getnewaddress "" legacy
(which is interpreted as “base58”, rather than as non-SegWit).
This PR introduces a new enum AddressType
, along with a parser that returns an Optional. A new method GetAddressType()
is added to Descriptor
instances. The only purpose of AddressType
is compatibility with other wallets, not a way to toggle SegWit.
Reusing OutputType
would not be ideal for this, because the distinction between OutputType::LEGACY
(-addresstype=legacy
) and OutputType::P2SH_SEGWIT
(-addresstype=p2sh-segwit
) is irrelevant in descriptor based wallets. Instead, if someone does not wish to use SegWit, they can create a wallet with only a non-SegWit descriptor.
This is also useful for importing keys from a hardware wallet. In the current WIP #14912 there is a method signerfetchkeys
which asks the device (driver) to return a set of descriptors. This returns e.g. three descriptors: one for BIP44 (legacy), one for BIP49 (p2sh-segwit) and one for BIP84 (native segwit). It can then associate the BIP84 descriptor with getnewaddress "" bech32
.
It can then use either the BIP44 or BIP49 descriptor with getnewaddress "" legacy
. To distinguish those, this PR adds IsSegWit()
to Descriptor instances.
The boost/optional/optional_io.hpp
IO include allows for a more compact notation in the tests: BOOST_CHECK_EQUAL(ParseAddressType("bech32"), AddressType::BECH32)
.