Skip to content

Commit 0c61dd9

Browse files
committed
Save loaded wallets to bitcoin_rw.conf
On close, whatever wallets were loaded are saved to bitcoin_rw.conf. When starting again, those wallets will be loaded again.
1 parent 2522c4e commit 0c61dd9

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/wallet/init.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,16 @@ void WalletInit::Construct(InitInterfaces& interfaces) const
188188
if (default_wallet.Exists()) {
189189
gArgs.SoftSetArg("-wallet", "");
190190
}
191-
interfaces.chain_clients.emplace_back(interfaces::MakeWalletClient(*interfaces.chain, gArgs.GetArgs("-wallet")));
191+
std::vector<std::string> wallets = gArgs.GetArgs("-wallet");
192+
std::stringstream ss(gArgs.GetArg("-loadedwallet", ""));
193+
std::string loaded_wallet;
194+
while (std::getline(ss, loaded_wallet, ',')) {
195+
if (std::find(wallets.begin(), wallets.end(), loaded_wallet) == wallets.end()) {
196+
wallets.push_back(loaded_wallet);
197+
}
198+
}
199+
200+
interfaces.chain_clients.emplace_back(interfaces::MakeWalletClient(*interfaces.chain, wallets));
192201
}
193202

194203
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
@@ -231,10 +240,19 @@ void StopWallets()
231240
void UnloadWallets()
232241
{
233242
auto wallets = GetWallets();
243+
std::string loaded_wallets = "";
234244
while (!wallets.empty()) {
235245
auto wallet = wallets.back();
246+
247+
// Write the wallet name to rw conf
248+
if (!loaded_wallets.empty()) {
249+
loaded_wallets += ",";
250+
}
251+
loaded_wallets += wallet->GetName();
252+
236253
wallets.pop_back();
237254
RemoveWallet(wallet);
238255
UnloadWallet(std::move(wallet));
239256
}
257+
gArgs.ModifyRWConfigFile("loadedwallet", loaded_wallets);
240258
}

0 commit comments

Comments
 (0)