Skip to content

Commit 8263f6a

Browse files
committed
Create walletdir if datadir doesn't exist and fix tests
1 parent 9587a9c commit 8263f6a

File tree

11 files changed

+45
-34
lines changed

11 files changed

+45
-34
lines changed

src/bitcoind.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ bool AppInit(int argc, char* argv[])
101101
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
102102
return false;
103103
}
104-
if (gArgs.IsArgSet("-walletdir") && !fs::is_directory(GetWalletDir())) {
105-
fprintf(stderr, "Error: Specified wallet directory \"%s\" does not exist.\n", gArgs.GetArg("-walletdir", "").c_str());
106-
return false;
107-
}
108104
try
109105
{
110106
gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));

src/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12201220
LogPrintf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()));
12211221
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string());
12221222
LogPrintf("Using data directory %s\n", GetDataDir().string());
1223-
LogPrintf("Using wallet directory %s\n", GetWalletDir().string());
12241223
LogPrintf("Using config file %s\n", GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)).string());
12251224
LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);
12261225

src/qt/bitcoin.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,6 @@ int main(int argc, char *argv[])
626626
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
627627
return EXIT_FAILURE;
628628
}
629-
if (gArgs.IsArgSet("-walletdir") && !fs::is_directory(GetWalletDir())) {
630-
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
631-
QObject::tr("Error: Specified wallet directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-walletdir", ""))));
632-
return EXIT_FAILURE;
633-
}
634629
try {
635630
gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
636631
} catch (const std::exception& e) {

src/qt/intro.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ bool Intro::pickDataDirectory()
214214
}
215215
dataDir = intro.getDataDirectory();
216216
try {
217-
TryCreateDirectories(GUIUtil::qstringToBoostPath(dataDir));
217+
if (TryCreateDirectories(GUIUtil::qstringToBoostPath(dataDir))) {
218+
// If a new data directory has been created, make wallets subdirectory too
219+
TryCreateDirectories(GUIUtil::qstringToBoostPath(dataDir) / "wallets");
220+
}
218221
break;
219222
} catch (const fs::filesystem_error&) {
220223
QMessageBox::critical(0, tr(PACKAGE_NAME),

src/util.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,10 @@ const fs::path &GetDataDir(bool fNetSpecific)
574574
if (fNetSpecific)
575575
path /= BaseParams().DataDir();
576576

577-
fs::create_directories(path);
577+
if (fs::create_directories(path)) {
578+
// This is the first run, create wallets subdirectory too
579+
fs::create_directories(path / "wallets");
580+
}
578581

579582
return path;
580583
}

src/wallet/init.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ bool VerifyWallets()
193193
return true;
194194
}
195195

196+
if (gArgs.IsArgSet("-walletdir") && !fs::is_directory(GetWalletDir())) {
197+
return InitError(strprintf(_("Error: Specified wallet directory \"%s\" does not exist."), gArgs.GetArg("-walletdir", "").c_str()));
198+
}
199+
200+
LogPrintf("Using wallet directory %s\n", GetWalletDir().string());
201+
196202
uiInterface.InitMessage(_("Verifying wallet(s)..."));
197203

198204
// Keep track of each wallet absolute path to detect duplicates.

test/functional/keypool-topup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def run_test(self):
3333

3434
self.stop_node(1)
3535

36-
shutil.copyfile(self.tmpdir + "/node1/regtest/wallet.dat", self.tmpdir + "/wallet.bak")
36+
shutil.copyfile(self.tmpdir + "/node1/regtest/wallets/wallet.dat", self.tmpdir + "/wallet.bak")
3737
self.start_node(1, self.extra_args[1])
3838
connect_nodes_bi(self.nodes, 0, 1)
3939

@@ -56,7 +56,7 @@ def run_test(self):
5656

5757
self.stop_node(1)
5858

59-
shutil.copyfile(self.tmpdir + "/wallet.bak", self.tmpdir + "/node1/regtest/wallet.dat")
59+
shutil.copyfile(self.tmpdir + "/wallet.bak", self.tmpdir + "/node1/regtest/wallets/wallet.dat")
6060

6161
self.log.info("Verify keypool is restored and balance is correct")
6262

test/functional/multiwallet.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,37 @@ def run_test(self):
2727
self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.')
2828

2929
# should not initialize if wallet file is a directory
30-
os.mkdir(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w11'))
30+
wallet_dir = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'wallets')
31+
os.mkdir(os.path.join(wallet_dir, 'w11'))
3132
self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')
3233

3334
# should not initialize if one wallet is a copy of another
34-
shutil.copyfile(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w2'),
35-
os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w22'))
35+
shutil.copyfile(os.path.join(wallet_dir, 'w2'), os.path.join(wallet_dir, 'w22'))
3636
self.assert_start_raises_init_error(0, ['-wallet=w2', '-wallet=w22'], 'duplicates fileid')
3737

3838
# should not initialize if wallet file is a symlink
39-
os.symlink(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w1'), os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w12'))
39+
os.symlink(os.path.join(wallet_dir, 'w1'), os.path.join(wallet_dir, 'w12'))
4040
self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')
4141

4242
# should not initialize if the specified walletdir does not exist
4343
self.assert_start_raises_init_error(0, ['-walletdir=bad'], 'Error: Specified wallet directory "bad" does not exist.')
4444

45-
# running the node with specified walletdir should only have the default wallet in it
46-
os.mkdir(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'walletdir'))
47-
self.start_node(0, ['-wallet=w4', '-wallet=w5', '-walletdir=' + os.path.join(self.options.tmpdir, 'node0', 'regtest', 'walletdir')])
45+
# if wallets/ doesn't exist, datadir should be the default wallet dir
46+
wallet_dir2 = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'walletdir')
47+
os.rename(wallet_dir, wallet_dir2)
48+
self.start_node(0, ['-wallet=w4', '-wallet=w5'])
49+
assert_equal(set(self.nodes[0].listwallets()), {"w4", "w5"})
50+
w5 = self.nodes[0].get_wallet_rpc("w5")
51+
w5.generate(1)
52+
self.stop_node(0)
53+
54+
# now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded
55+
os.rename(wallet_dir2, wallet_dir)
56+
self.start_node(0, ['-wallet=w4', '-wallet=w5', '-walletdir=' + os.path.join(self.options.tmpdir, 'node0', 'regtest')])
4857
assert_equal(set(self.nodes[0].listwallets()), {"w4", "w5"})
4958
w5 = self.nodes[0].get_wallet_rpc("w5")
5059
w5_info = w5.getwalletinfo()
51-
assert_equal(w5_info['immature_balance'], 0)
60+
assert_equal(w5_info['immature_balance'], 50)
5261

5362
self.stop_node(0)
5463

test/functional/test_framework/test_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def _initialize_chain(self):
432432
self.disable_mocktime()
433433
for i in range(MAX_NODES):
434434
os.remove(log_filename(self.options.cachedir, i, "debug.log"))
435-
os.remove(log_filename(self.options.cachedir, i, "db.log"))
435+
os.remove(log_filename(self.options.cachedir, i, "wallets/db.log"))
436436
os.remove(log_filename(self.options.cachedir, i, "peers.dat"))
437437
os.remove(log_filename(self.options.cachedir, i, "fee_estimates.dat"))
438438

test/functional/wallet-hd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def run_test (self):
7373
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
7474
shutil.rmtree(os.path.join(tmpdir, "node1/regtest/blocks"))
7575
shutil.rmtree(os.path.join(tmpdir, "node1/regtest/chainstate"))
76-
shutil.copyfile(os.path.join(tmpdir, "hd.bak"), os.path.join(tmpdir, "node1/regtest/wallet.dat"))
76+
shutil.copyfile(os.path.join(tmpdir, "hd.bak"), os.path.join(tmpdir, "node1/regtest/wallets/wallet.dat"))
7777
self.start_node(1)
7878

7979
# Assert that derivation is deterministic

0 commit comments

Comments
 (0)