diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index d47ee95826f4..6c3baf711735 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -87,7 +87,7 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model) &QItemSelectionModel::selectionChanged, this, &ReceiveCoinsDialog::recentRequestsView_selectionChanged); - if (model->wallet().getDefaultAddressType() == OutputType::BECH32) { + if (model->wallet().getDefaultAddressType() == OutputType::BECH32 || model->wallet().getDefaultAddressType() == OutputType::BECH32M) { ui->useBech32->setCheckState(Qt::Checked); } else { ui->useBech32->setCheckState(Qt::Unchecked); @@ -144,12 +144,14 @@ void ReceiveCoinsDialog::on_receiveButton_clicked() QString address; QString label = ui->reqLabel->text(); /* Generate new receiving address */ - OutputType address_type; + OutputType address_type = model->wallet().getDefaultAddressType(); + if (ui->useBech32->isChecked()) { - address_type = OutputType::BECH32; + if (address_type != OutputType::BECH32 && address_type != OutputType::BECH32M) { + address_type = OutputType::BECH32; + } } else { - address_type = model->wallet().getDefaultAddressType(); - if (address_type == OutputType::BECH32) { + if (address_type == OutputType::BECH32 || address_type == OutputType::BECH32M) { address_type = OutputType::P2SH_SEGWIT; } } diff --git a/src/qt/test/addressbooktests.cpp b/src/qt/test/addressbooktests.cpp index 729957699aab..1177d8624380 100644 --- a/src/qt/test/addressbooktests.cpp +++ b/src/qt/test/addressbooktests.cpp @@ -64,6 +64,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node) test.m_node.wallet_client = wallet_client.get(); node.setContext(&test.m_node); std::shared_ptr wallet = std::make_shared(node.context()->chain.get(), "", CreateMockWalletDatabase()); + wallet->m_default_address_type = OutputType::BECH32; wallet->LoadWallet(); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); { diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp index c74c8f25b36c..979b09c4dc45 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -142,6 +142,7 @@ void TestGUI(interfaces::Node& node) test.m_node.wallet_client = wallet_client.get(); node.setContext(&test.m_node); std::shared_ptr wallet = std::make_shared(node.context()->chain.get(), "", CreateMockWalletDatabase()); + wallet->m_default_address_type = OutputType::BECH32; wallet->LoadWallet(); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); { diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 9b09bc23d680..2fbe289a2fe8 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1555,6 +1555,10 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c // Taproot is not active, raise an error throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import tr() descriptor when Taproot is not active"); } + // When importing an active taproot descriptor, change the default address type to bech32m + if (active && wallet.m_default_address_type == OutputType::BECH32) { + wallet.m_default_address_type = OutputType::BECH32M; + } } // If private keys are enabled, check some things. diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp index 2990fc8f8db7..8ade8d81b706 100644 --- a/src/wallet/test/util.cpp +++ b/src/wallet/test/util.cpp @@ -18,6 +18,7 @@ std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key) { auto wallet = std::make_unique(&chain, "", CreateMockWalletDatabase()); + wallet->m_default_address_type = OutputType::BECH32; { LOCK2(wallet->cs_wallet, ::cs_main); wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash()); diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 0965128ade92..8726515fc023 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -275,6 +275,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) WalletContext context; context.args = &gArgs; std::shared_ptr wallet = std::make_shared(m_node.chain.get(), "", CreateDummyWalletDatabase()); + wallet->m_default_address_type = OutputType::BECH32; { auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan(); LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 803e88cda21f..330dfef76a49 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2628,6 +2628,12 @@ std::shared_ptr CWallet::Create(WalletContext& context, const std::stri return nullptr; } walletInstance->m_default_address_type = parsed.value(); + } else { + // Set default type to bech32 for legacy wallets and descriptor wallets without taproot + auto spk_man = walletInstance->GetScriptPubKeyMan(OutputType::BECH32M, false); + if (walletInstance->IsLegacy() || spk_man == nullptr) { + walletInstance->m_default_address_type = OutputType::BECH32; + } } if (!args.GetArg("-changetype", "").empty()) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 767b24adbb33..04e42c523b31 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -113,7 +113,7 @@ enum class FeeEstimateMode; class ReserveDestination; //! Default for -addresstype -constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::BECH32}; +constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::BECH32M}; static constexpr uint64_t KNOWN_WALLET_FLAGS = WALLET_FLAG_AVOID_REUSE