Skip to content

Commit b27dcfe

Browse files
luke-jrrandom-zebra
authored andcommitted
Wallet: Support loading multiple wallets if -wallet used more than once
1 parent d10acd5 commit b27dcfe

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

src/init.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,11 +1337,8 @@ bool AppInitMain()
13371337
}
13381338
}
13391339

1340-
// ********************************************************* Step 5: Backup wallet and verify wallet database integrity
1340+
// ********************************************************* Step 5: Verify wallet database integrity
13411341
#ifdef ENABLE_WALLET
1342-
if (!InitAutoBackupWallet()) {
1343-
return false;
1344-
}
13451342
if (!CWallet::Verify()) {
13461343
return false;
13471344
}
@@ -1729,7 +1726,7 @@ bool AppInitMain()
17291726
mempool.ReadFeeEstimates(est_filein);
17301727
fFeeEstimatesInitialized = true;
17311728

1732-
// ********************************************************* Step 8: load wallet
1729+
// ********************************************************* Step 8: Backup and Load wallet
17331730
#ifdef ENABLE_WALLET
17341731
if (!CWallet::InitLoadWallet())
17351732
return false;

src/wallet/wallet.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4348,19 +4348,29 @@ bool CWallet::InitLoadWallet()
43484348
return true;
43494349
}
43504350

4351-
std::string walletFile = gArgs.GetArg("-wallet", DEFAULT_WALLET_DAT);
4351+
gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
43524352

4353-
if (walletFile.find_first_of("/\\") != std::string::npos) {
4354-
return UIError(_("-wallet parameter must only specify a filename (not a path)"));
4355-
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
4356-
return UIError(_("Invalid characters in -wallet filename"));
4357-
}
4353+
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
4354+
if (fs::path(walletFile).filename() != walletFile) {
4355+
return UIError(_("-wallet parameter must only specify a filename (not a path)"));
4356+
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
4357+
return UIError(_("Invalid characters in -wallet filename"));
4358+
}
43584359

4359-
CWallet * const pwallet = CreateWalletFromFile(walletFile);
4360-
if (!pwallet) {
4361-
return false;
4360+
// automatic backups
4361+
std::string strWarning, strError;
4362+
if(!AutoBackupWallet(walletFile, strWarning, strError)) {
4363+
if (!strWarning.empty()) UIWarning(strWarning);
4364+
if (!strError.empty()) return UIError(strError);
4365+
}
4366+
4367+
CWallet * const pwallet = CreateWalletFromFile(walletFile);
4368+
if (!pwallet) {
4369+
return false;
4370+
}
4371+
vpwallets.emplace_back(pwallet);
43624372
}
4363-
vpwallets.emplace_back(pwallet);
4373+
43644374
return true;
43654375
}
43664376

@@ -4885,19 +4895,3 @@ CStakeableOutput::CStakeableOutput(const CWalletTx* txIn, int iIn, int nDepthIn,
48854895
const CBlockIndex*& _pindex) : COutput(txIn, iIn, nDepthIn, fSpendableIn, fSolvableIn),
48864896
pindex(_pindex) {}
48874897

4888-
bool InitAutoBackupWallet()
4889-
{
4890-
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
4891-
return true;
4892-
}
4893-
4894-
std::string strWalletFile = gArgs.GetArg("-wallet", DEFAULT_WALLET_DAT);
4895-
4896-
std::string strWarning, strError;
4897-
if(!AutoBackupWallet(strWalletFile, strWarning, strError)) {
4898-
if (!strWarning.empty()) UIWarning(strWarning);
4899-
if (!strError.empty()) return UIError(strError);
4900-
}
4901-
4902-
return true;
4903-
}

src/wallet/wallet.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,4 @@ class WalletRescanReserver
12761276
}
12771277
};
12781278

1279-
// !TODO: move to wallet/init.*
1280-
bool InitAutoBackupWallet();
1281-
12821279
#endif // PIVX_WALLET_H

0 commit comments

Comments
 (0)