diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp index cbf3ccd1ec..03276d47fa 100644 --- a/src/wallet/test/util.cpp +++ b/src/wallet/test/util.cpp @@ -23,6 +23,7 @@ std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, CChain& cc { LOCK2(wallet->cs_wallet, ::cs_main); wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash()); + wallet->m_default_address_type = OutputType::BECH32M; } { LOCK(wallet->cs_wallet); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a1db1b3318..04281488c5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2285,7 +2285,7 @@ OutputType CWallet::TransactionChangeType(const std::optional& chang } const bool has_bech32m_spkman(GetScriptPubKeyMan(OutputType::BECH32M, /*internal=*/true)); - if (has_bech32m_spkman && any_tr) { + if (has_bech32m_spkman && any_tr && m_default_address_type == OutputType::BECH32M) { // Currently tr is the only type supported by the BECH32M spkman return OutputType::BECH32M; } @@ -2305,6 +2305,16 @@ OutputType CWallet::TransactionChangeType(const std::optional& chang // Currently pkh is the only type supported by the LEGACY spkman return OutputType::LEGACY; } + if (!GetScriptPubKeyMan(m_default_address_type, /*internal=*/true)) { + // Default type not available, so look for anything else to fallback to + // NOTE: Sane behaviour assumes OUTPUT_TYPES is sorted oldest to newest + for (const auto& ot : OUTPUT_TYPES) { + if (GetScriptPubKeyMan(ot, /*internal=*/true)) { + return ot; + } + } + } + return m_default_address_type; if (has_bech32m_spkman) { return OutputType::BECH32M; diff --git a/test/functional/wallet_taproot.py b/test/functional/wallet_taproot.py index 79b60e9c4b..d90304bfde 100755 --- a/test/functional/wallet_taproot.py +++ b/test/functional/wallet_taproot.py @@ -194,6 +194,8 @@ class WalletTaprootTest(BitcoinTestFramework): self.num_nodes = 2 self.setup_clean_chain = True self.extra_args = [['-keypool=100'], ['-keypool=100']] + for ea in self.extra_args: + ea.append('-addresstype=bech32m') self.supports_cli = False def skip_test_if_missing_module(self):