diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -188,7 +188,13 @@ } dataDir = intro.getDataDirectory(); try { - TryCreateDirectories(GUIUtil::qstringToBoostPath(dataDir)); + if (TryCreateDirectories( + GUIUtil::qstringToBoostPath(dataDir))) { + // If a new data directory has been created, make wallets + // subdirectory too + TryCreateDirectories(GUIUtil::qstringToBoostPath(dataDir) / + "wallets"); + } break; } catch (const fs::filesystem_error &) { QMessageBox::critical(0, tr(PACKAGE_NAME), diff --git a/src/util.cpp b/src/util.cpp --- a/src/util.cpp +++ b/src/util.cpp @@ -425,7 +425,10 @@ path /= BaseParams().DataDir(); } - fs::create_directories(path); + if (fs::create_directories(path)) { + // This is the first run, create wallets subdirectory too + fs::create_directories(path / "wallets"); + } return path; } diff --git a/test/functional/keypool-topup.py b/test/functional/keypool-topup.py --- a/test/functional/keypool-topup.py +++ b/test/functional/keypool-topup.py @@ -35,7 +35,7 @@ self.stop_node(1) - shutil.copyfile(self.tmpdir + "/node1/regtest/wallet.dat", + shutil.copyfile(self.tmpdir + "/node1/regtest/wallets/wallet.dat", self.tmpdir + "/wallet.bak") self.start_node(1, self.extra_args[1]) connect_nodes_bi(self.nodes[0], self.nodes[1]) @@ -60,7 +60,7 @@ self.stop_node(1) shutil.copyfile(self.tmpdir + "/wallet.bak", - self.tmpdir + "/node1/regtest/wallet.dat") + self.tmpdir + "/node1/regtest/wallets/wallet.dat") self.log.info("Verify keypool is restored and balance is correct") diff --git a/test/functional/multiwallet.py b/test/functional/multiwallet.py --- a/test/functional/multiwallet.py +++ b/test/functional/multiwallet.py @@ -29,19 +29,19 @@ 0, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.') # should not initialize if wallet file is a directory - os.mkdir(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w11')) + wallet_dir = os.path.join( + self.options.tmpdir, 'node0', 'regtest', 'wallets') + os.mkdir(os.path.join(wallet_dir, 'w11')) self.assert_start_raises_init_error( 0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.') # should not initialize if one wallet is a copy of another - shutil.copyfile(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w2'), - os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w22')) + shutil.copyfile(os.path.join(wallet_dir, 'w2'), + os.path.join(wallet_dir, 'w22')) self.assert_start_raises_init_error( 0, ['-wallet=w2', '-wallet=w22'], 'duplicates fileid') # should not initialize if wallet file is a symlink - wallet_dir = os.path.abspath(os.path.join( - self.options.tmpdir, 'node0', 'regtest')) os.symlink(os.path.join(wallet_dir, 'w1'), os.path.join(wallet_dir, 'w12')) self.assert_start_raises_init_error( @@ -51,15 +51,24 @@ self.assert_start_raises_init_error( 0, ['-walletdir=bad'], 'Error: Specified wallet directory "bad" does not exist.') - # running the node with specified walletdir should only have the default wallet in it - os.mkdir(os.path.join(self.options.tmpdir, - 'node0', 'regtest', 'walletdir')) + # if wallets/ doesn't exist, datadir should be the default wallet dir + wallet_dir2 = os.path.join( + self.options.tmpdir, 'node0', 'regtest', 'walletdir') + os.rename(wallet_dir, wallet_dir2) + self.start_node(0, ['-wallet=w4', '-wallet=w5']) + assert_equal(set(self.nodes[0].listwallets()), {"w4", "w5"}) + w5 = self.nodes[0].get_wallet_rpc("w5") + w5.generate(1) + self.stop_node(0) + + # now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded + os.rename(wallet_dir2, wallet_dir) self.start_node(0, ['-wallet=w4', '-wallet=w5', '-walletdir=' + - os.path.join(self.options.tmpdir, 'node0', 'regtest', 'walletdir')]) + os.path.join(self.options.tmpdir, 'node0', 'regtest')]) assert_equal(set(self.nodes[0].listwallets()), {"w4", "w5"}) w5 = self.nodes[0].get_wallet_rpc("w5") w5_info = w5.getwalletinfo() - assert_equal(w5_info['immature_balance'], 0) + assert_equal(w5_info['immature_balance'], 50) self.stop_node(0) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -451,7 +451,8 @@ self.disable_mocktime() for i in range(MAX_NODES): os.remove(log_filename(self.options.cachedir, i, "debug.log")) - os.remove(log_filename(self.options.cachedir, i, "db.log")) + os.remove(log_filename( + self.options.cachedir, i, "wallets/db.log")) os.remove(log_filename(self.options.cachedir, i, "peers.dat")) os.remove(log_filename( self.options.cachedir, i, "fee_estimates.dat")) diff --git a/test/functional/wallet_hd.py b/test/functional/wallet_hd.py --- a/test/functional/wallet_hd.py +++ b/test/functional/wallet_hd.py @@ -78,7 +78,7 @@ shutil.rmtree(os.path.join(tmpdir, "node1/regtest/blocks")) shutil.rmtree(os.path.join(tmpdir, "node1/regtest/chainstate")) shutil.copyfile(os.path.join(tmpdir, "hd.bak"), - os.path.join(tmpdir, "node1/regtest/wallet.dat")) + os.path.join(tmpdir, "node1/regtest/wallets/wallet.dat")) self.start_node(1) # Assert that derivation is deterministic diff --git a/test/functional/walletbackup.py b/test/functional/walletbackup.py --- a/test/functional/walletbackup.py +++ b/test/functional/walletbackup.py @@ -92,9 +92,9 @@ self.stop_node(2) def erase_three(self): - os.remove(self.options.tmpdir + "/node0/regtest/wallet.dat") - os.remove(self.options.tmpdir + "/node1/regtest/wallet.dat") - os.remove(self.options.tmpdir + "/node2/regtest/wallet.dat") + os.remove(self.options.tmpdir + "/node0/regtest/wallets/wallet.dat") + os.remove(self.options.tmpdir + "/node1/regtest/wallets/wallet.dat") + os.remove(self.options.tmpdir + "/node2/regtest/wallets/wallet.dat") def run_test(self): self.log.info("Generating initial blockchain") @@ -157,11 +157,11 @@ # Restore wallets from backup shutil.copyfile(tmpdir + "/node0/wallet.bak", - tmpdir + "/node0/regtest/wallet.dat") + tmpdir + "/node0/regtest/wallets/wallet.dat") shutil.copyfile(tmpdir + "/node1/wallet.bak", - tmpdir + "/node1/regtest/wallet.dat") + tmpdir + "/node1/regtest/wallets/wallet.dat") shutil.copyfile(tmpdir + "/node2/wallet.bak", - tmpdir + "/node2/regtest/wallet.dat") + tmpdir + "/node2/regtest/wallets/wallet.dat") self.log.info("Re-starting nodes") self.start_three() @@ -197,10 +197,10 @@ # Backup to source wallet file must fail sourcePaths = [ - tmpdir + "/node0/regtest/wallet.dat", - tmpdir + "/node0/./regtest/wallet.dat", - tmpdir + "/node0/regtest/", - tmpdir + "/node0/regtest"] + tmpdir + "/node0/regtest/wallets/wallet.dat", + tmpdir + "/node0/./regtest/wallets/wallet.dat", + tmpdir + "/node0/regtest/wallets/", + tmpdir + "/node0/regtest/wallets"] for sourcePath in sourcePaths: assert_raises_rpc_error(-4, "backup failed",