mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-09 05:14:22 +01:00
wallet: Handle duplicate fileid exception
This commit is contained in:
parent
9a2b5f22c1
commit
ee9e88ba27
3 changed files with 32 additions and 23 deletions
|
@ -66,6 +66,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
|
||||||
|
|
||||||
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
|
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
for (const std::string& walletFile : wallet_files) {
|
for (const std::string& walletFile : wallet_files) {
|
||||||
std::string error;
|
std::string error;
|
||||||
std::vector<std::string> warnings;
|
std::vector<std::string> warnings;
|
||||||
|
@ -77,8 +78,11 @@ bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& walle
|
||||||
}
|
}
|
||||||
AddWallet(pwallet);
|
AddWallet(pwallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} catch (const std::runtime_error& e) {
|
||||||
|
chain.initError(e.what());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartWallets(CScheduler& scheduler)
|
void StartWallets(CScheduler& scheduler)
|
||||||
|
|
|
@ -148,6 +148,7 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
|
||||||
|
|
||||||
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::vector<std::string>& warnings)
|
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::vector<std::string>& warnings)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
if (!CWallet::Verify(chain, location, false, error, warnings)) {
|
if (!CWallet::Verify(chain, location, false, error, warnings)) {
|
||||||
error = "Wallet file verification failed: " + error;
|
error = "Wallet file verification failed: " + error;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -161,6 +162,10 @@ std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocati
|
||||||
AddWallet(wallet);
|
AddWallet(wallet);
|
||||||
wallet->postInitProcess();
|
wallet->postInitProcess();
|
||||||
return wallet;
|
return wallet;
|
||||||
|
} catch (const std::runtime_error& e) {
|
||||||
|
error = e.what();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::vector<std::string>& warnings)
|
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::vector<std::string>& warnings)
|
||||||
|
|
|
@ -236,10 +236,10 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-4, "Wallet file verification failed: Error loading wallet wallet.dat. Duplicate -wallet filename specified.", self.nodes[0].loadwallet, 'wallet.dat')
|
assert_raises_rpc_error(-4, "Wallet file verification failed: Error loading wallet wallet.dat. Duplicate -wallet filename specified.", self.nodes[0].loadwallet, 'wallet.dat')
|
||||||
|
|
||||||
# Fail to load if one wallet is a copy of another
|
# Fail to load if one wallet is a copy of another
|
||||||
assert_raises_rpc_error(-1, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
assert_raises_rpc_error(-4, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
||||||
|
|
||||||
# Fail to load if one wallet is a copy of another, test this twice to make sure that we don't re-introduce #14304
|
# Fail to load if one wallet is a copy of another, test this twice to make sure that we don't re-introduce #14304
|
||||||
assert_raises_rpc_error(-1, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
assert_raises_rpc_error(-4, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
||||||
|
|
||||||
|
|
||||||
# Fail to load if wallet file is a symlink
|
# Fail to load if wallet file is a symlink
|
||||||
|
|
Loading…
Add table
Reference in a new issue