Skip to content

Make bech32m the default for RPC, opt-in for GUI #22260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/qt/receivecoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
wallet->m_default_address_type = OutputType::BECH32;
wallet->LoadWallet();
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
{
Expand Down
1 change: 1 addition & 0 deletions src/qt/test/wallettests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
wallet->m_default_address_type = OutputType::BECH32;
wallet->LoadWallet();
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
{
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/wallet/test/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key)
{
auto wallet = std::make_unique<CWallet>(&chain, "", CreateMockWalletDatabase());
wallet->m_default_address_type = OutputType::BECH32;
{
LOCK2(wallet->cs_wallet, ::cs_main);
wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash());
Expand Down
1 change: 1 addition & 0 deletions src/wallet/test/wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
WalletContext context;
context.args = &gArgs;
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(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);
Expand Down
6 changes: 6 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,12 @@ std::shared_ptr<CWallet> 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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down