Skip to content

Commit 652c45f

Browse files
committed
Merge #15454: Remove the automatic creation and loading of the default wallet
d26f064 Tell users how to load or create a wallet when no wallet is loaded (Andrew Chow) 1bee1e6 Do not create default wallet (Andrew Chow) Pull request description: Instead of automatically creating and loading a default wallet, users should instead explicitly create their wallet or load it on start. Builds on #19754 which provides the `load_on_startup` behavior for the GUI. ACKs for top commit: jnewbery: Manual test and very light code review ACK d26f064 ryanofsky: Code review ACK d26f064. Just suggested changes to first commit (reusing MakeWalletDatabase and adding release notes), no changes to second commit jonatack: ACK d26f064 light code review, debug build, ran tests, did manual testing with testnet, rebased on master, on linux debian. Tree-SHA512: 091d785aef64736f7df661c576e815a87f3d029cfa32f3a75ba86fc25795f10b022ab3ae15c5b61a10b8cee16f5650f15cd79cbd6127e5e3ccbef631966d3c30
2 parents be3af4f + d26f064 commit 652c45f

21 files changed

+96
-45
lines changed

doc/release-notes-15454.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Wallet
2+
------
3+
4+
Bitcoin Core will no longer create an unnamed `""` wallet by default when no wallet is specified on the command line or in the configuration files.
5+
For backwards compatibility, if an unnamed `""` wallet already exists and would have been loaded previously, then it will still be loaded.
6+
Users without an unnamed `""` wallet and without any other wallets to be loaded on startup will be prompted to either choose a wallet to load, or to create a new wallet.

src/interfaces/wallet.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,7 @@ class WalletImpl : public Wallet
488488
class WalletClientImpl : public WalletClient
489489
{
490490
public:
491-
WalletClientImpl(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
492-
: m_wallet_filenames(std::move(wallet_filenames))
491+
WalletClientImpl(Chain& chain, ArgsManager& args)
493492
{
494493
m_context.chain = &chain;
495494
m_context.args = &args;
@@ -506,8 +505,8 @@ class WalletClientImpl : public WalletClient
506505
m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
507506
}
508507
}
509-
bool verify() override { return VerifyWallets(*m_context.chain, m_wallet_filenames); }
510-
bool load() override { return LoadWallets(*m_context.chain, m_wallet_filenames); }
508+
bool verify() override { return VerifyWallets(*m_context.chain); }
509+
bool load() override { return LoadWallets(*m_context.chain); }
511510
void start(CScheduler& scheduler) override { return StartWallets(scheduler, *Assert(m_context.args)); }
512511
void flush() override { return FlushWallets(); }
513512
void stop() override { return StopWallets(); }
@@ -566,9 +565,9 @@ class WalletClientImpl : public WalletClient
566565

567566
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }
568567

569-
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
568+
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args)
570569
{
571-
return MakeUnique<WalletClientImpl>(chain, args, std::move(wallet_filenames));
570+
return MakeUnique<WalletClientImpl>(chain, args);
572571
}
573572

574573
} // namespace interfaces

src/interfaces/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet);
411411

412412
//! Return implementation of ChainClient interface for a wallet client. This
413413
//! function will be undefined in builds where ENABLE_WALLET is false.
414-
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames);
414+
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args);
415415

416416
} // namespace interfaces
417417

src/qt/bitcoingui.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
660660
}
661661
}
662662

663+
WalletController* BitcoinGUI::getWalletController()
664+
{
665+
return m_wallet_controller;
666+
}
667+
663668
void BitcoinGUI::addWallet(WalletModel* walletModel)
664669
{
665670
if (!walletFrame) return;

src/qt/bitcoingui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class BitcoinGUI : public QMainWindow
7979
void setClientModel(ClientModel *clientModel = nullptr, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
8080
#ifdef ENABLE_WALLET
8181
void setWalletController(WalletController* wallet_controller);
82+
WalletController* getWalletController();
8283
#endif
8384

8485
#ifdef ENABLE_WALLET

src/qt/walletframe.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <qt/createwalletdialog.h>
6+
#include <qt/walletcontroller.h>
57
#include <qt/walletframe.h>
68
#include <qt/walletmodel.h>
79

@@ -10,8 +12,11 @@
1012

1113
#include <cassert>
1214

15+
#include <QGroupBox>
1316
#include <QHBoxLayout>
1417
#include <QLabel>
18+
#include <QPushButton>
19+
#include <QVBoxLayout>
1520

1621
WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui) :
1722
QFrame(_gui),
@@ -25,9 +30,25 @@ WalletFrame::WalletFrame(const PlatformStyle *_platformStyle, BitcoinGUI *_gui)
2530
walletFrameLayout->setContentsMargins(0,0,0,0);
2631
walletFrameLayout->addWidget(walletStack);
2732

28-
QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
33+
// hbox for no wallet
34+
QGroupBox* no_wallet_group = new QGroupBox(walletStack);
35+
QVBoxLayout* no_wallet_layout = new QVBoxLayout(no_wallet_group);
36+
37+
QLabel *noWallet = new QLabel(tr("No wallet has been loaded.\nGo to File > Open Wallet to load a wallet.\n- OR -"));
2938
noWallet->setAlignment(Qt::AlignCenter);
30-
walletStack->addWidget(noWallet);
39+
no_wallet_layout->addWidget(noWallet, 0, Qt::AlignHCenter | Qt::AlignBottom);
40+
41+
// A button for create wallet dialog
42+
QPushButton* create_wallet_button = new QPushButton(tr("Create a new wallet"), walletStack);
43+
connect(create_wallet_button, &QPushButton::clicked, [this] {
44+
auto activity = new CreateWalletActivity(gui->getWalletController(), this);
45+
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
46+
activity->create();
47+
});
48+
no_wallet_layout->addWidget(create_wallet_button, 0, Qt::AlignHCenter | Qt::AlignTop);
49+
no_wallet_group->setLayout(no_wallet_layout);
50+
51+
walletStack->addWidget(no_wallet_group);
3152
}
3253

3354
WalletFrame::~WalletFrame()

src/wallet/init.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,7 @@ void WalletInit::Construct(NodeContext& node) const
107107
LogPrintf("Wallet disabled!\n");
108108
return;
109109
}
110-
// If there's no -wallet setting with a list of wallets to load, set it to
111-
// load the default "" wallet.
112-
if (!args.IsArgSet("wallet")) {
113-
args.LockSettings([&](util::Settings& settings) {
114-
util::SettingsValue wallets(util::SettingsValue::VARR);
115-
wallets.push_back(""); // Default wallet name is ""
116-
settings.rw_settings["wallet"] = wallets;
117-
});
118-
}
119-
auto wallet_client = interfaces::MakeWalletClient(*node.chain, args, args.GetArgs("-wallet"));
110+
auto wallet_client = interfaces::MakeWalletClient(*node.chain, args);
120111
node.wallet_client = wallet_client.get();
121112
node.chain_clients.emplace_back(std::move(wallet_client));
122113
}

src/wallet/load.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <univalue.h>
1818

19-
bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
19+
bool VerifyWallets(interfaces::Chain& chain)
2020
{
2121
if (gArgs.IsArgSet("-walletdir")) {
2222
fs::path wallet_dir = gArgs.GetArg("-walletdir", "");
@@ -41,10 +41,27 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
4141

4242
chain.initMessage(_("Verifying wallet(s)...").translated);
4343

44+
// For backwards compatibility if an unnamed top level wallet exists in the
45+
// wallets directory, include it in the default list of wallets to load.
46+
if (!gArgs.IsArgSet("wallet")) {
47+
DatabaseOptions options;
48+
DatabaseStatus status;
49+
bilingual_str error_string;
50+
options.require_existing = true;
51+
options.verify = false;
52+
if (MakeWalletDatabase("", options, status, error_string)) {
53+
gArgs.LockSettings([&](util::Settings& settings) {
54+
util::SettingsValue wallets(util::SettingsValue::VARR);
55+
wallets.push_back(""); // Default wallet name is ""
56+
settings.rw_settings["wallet"] = wallets;
57+
});
58+
}
59+
}
60+
4461
// Keep track of each wallet absolute path to detect duplicates.
4562
std::set<fs::path> wallet_paths;
4663

47-
for (const auto& wallet_file : wallet_files) {
64+
for (const auto& wallet_file : gArgs.GetArgs("-wallet")) {
4865
const fs::path path = fs::absolute(wallet_file, GetWalletDir());
4966

5067
if (!wallet_paths.insert(path).second) {
@@ -65,10 +82,10 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
6582
return true;
6683
}
6784

68-
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
85+
bool LoadWallets(interfaces::Chain& chain)
6986
{
7087
try {
71-
for (const std::string& name : wallet_files) {
88+
for (const std::string& name : gArgs.GetArgs("-wallet")) {
7289
DatabaseOptions options;
7390
DatabaseStatus status;
7491
options.verify = false; // No need to verify, assuming verified earlier in VerifyWallets()

src/wallet/load.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class Chain;
1717
} // namespace interfaces
1818

1919
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
20-
bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files);
20+
bool VerifyWallets(interfaces::Chain& chain);
2121

2222
//! Load wallet databases.
23-
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files);
23+
bool LoadWallets(interfaces::Chain& chain);
2424

2525
//! Complete startup of wallets.
2626
void StartWallets(CScheduler& scheduler, const ArgsManager& args);

src/wallet/test/init_test_fixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
1212
{
13-
m_wallet_client = MakeWalletClient(*m_chain, *Assert(m_node.args), {});
13+
m_wallet_client = MakeWalletClient(*m_chain, *Assert(m_node.args));
1414

1515
std::string sep;
1616
sep += fs::path::preferred_separator;

0 commit comments

Comments
 (0)