Skip to content

Commit 79ed4c9

Browse files
committed
remove scheduler from postInitProcess, add LoadWalletFromFile and use in loadwallet rpc function
1 parent 2107e32 commit 79ed4c9

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

src/wallet/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ bool WalletInit::Open(const CChainParams &chainParams, const SecureString& walle
442442

443443
void WalletInit::Start(CScheduler &scheduler) const {
444444
for (const std::shared_ptr<CWallet> &pwallet : GetWallets()) {
445-
pwallet->postInitProcess(scheduler);
445+
pwallet->postInitProcess();
446446
}
447447
}
448448

src/wallet/rpcdump.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ bool GetWalletAddressesForKey(const Config &config, CWallet *const pwallet,
8787

8888
static const int64_t TIMESTAMP_MIN = 0;
8989

90+
#ifdef NOT_USED_YET
9091
static void RescanWallet(CWallet &wallet, const WalletRescanReserver &reserver,
9192
int64_t time_begin = TIMESTAMP_MIN,
9293
bool update = true) {
@@ -99,6 +100,7 @@ static void RescanWallet(CWallet &wallet, const WalletRescanReserver &reserver,
99100
"Some transactions may be missing.");
100101
}
101102
}
103+
#endif
102104

103105
UniValue abortrescan(const Config &config, const JSONRPCRequest &request) {
104106
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);

src/wallet/rpcwallet.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,29 +3409,27 @@ static UniValue listwallets(const Config &config,
34093409
}
34103410

34113411
UniValue loadwallet(const Config &config, const JSONRPCRequest &request) {
3412-
if (request.fHelp || request.params.size() > 2 || request.params.size() < 1) {
3412+
if (request.fHelp || request.params.size() != 1) {
34133413
throw std::runtime_error(
34143414
"loadwallet \"filename\"\n"
34153415
"\nLoads a wallet from a wallet file or directory."
34163416
"\nNote that all wallet command-line options used when starting devaultd/DeVault-Core will be"
34173417
"\napplied to the new wallet (eg -zapwallettxes, upgradewallet, rescan, etc).\n"
34183418
"\nArguments:\n"
34193419
"1. \"filename\" (string, required) The wallet directory or .dat file.\n"
3420-
"2. \"password\" (string, optional) The wallet password or empty for none.\n"
34213420
"\nResult:\n"
34223421
"{\n"
34233422
" \"name\" : <wallet_name>, (string) The wallet name if loaded successfully.\n"
34243423
" \"warning\" : <warning>, (string) Warning message if wallet was not loaded cleanly.\n"
34253424
"}\n"
34263425
"\nExamples:\n" +
3427-
HelpExampleCli("loadwallet", "\"test.dat\" \"password\"") +
3428-
HelpExampleRpc("loadwallet", "\"test.dat\" \"password\""));
3426+
HelpExampleCli("loadwallet", "\"test.dat\"") +
3427+
HelpExampleRpc("loadwallet", "\"test.dat\""));
34293428
}
34303429

34313430
const CChainParams &chainParams = config.GetChainParams();
34323431

34333432
std::string wallet_file = request.params[0].get_str();
3434-
std::string password = request.params[1].get_str();
34353433
std::string error;
34363434
WalletLocation location(wallet_file);
34373435

@@ -3446,23 +3444,13 @@ UniValue loadwallet(const Config &config, const JSONRPCRequest &request) {
34463444
"Wallet file verification failed: " + error);
34473445
}
34483446

3449-
SecureString pass(password);
3450-
3451-
// Since Wallet should exist, then `words` are not used
3452-
std::vector<std::string> words;
3453-
bool use_bls = false;
3454-
3455-
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile(
3456-
chainParams, location,
3457-
pass,
3458-
words,
3459-
use_bls);
3447+
std::shared_ptr<CWallet> const wallet = CWallet::LoadWalletFromFile(chainParams, location);
34603448
if (!wallet) {
34613449
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading failed.");
34623450
}
34633451
AddWallet(wallet);
34643452

3465-
//// wallet->postInitProcess();
3453+
wallet->postInitProcess();
34663454

34673455
UniValue obj(UniValue::VOBJ);
34683456
obj.pushKV("name", wallet->GetName());

src/wallet/wallet.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4754,7 +4754,7 @@ bool CWallet::Verify(const CChainParams &chainParams,
47544754
// 2. Path to an existing directory.
47554755
// 3. Path to a symlink to a directory.
47564756
// 4. For backwards compatibility, the name of a data file in -walletdir.
4757-
// LOCK(cs_wallet); -- HACK CHECK LATER
4757+
// LOCK(cs_wallet); -- not yet since static
47584758
const fs::path &wallet_path = location.GetPath();
47594759
fs::file_type path_type = fs::symlink_status(wallet_path).type();
47604760
#ifdef NO_BOOST_FILESYSTEM
@@ -4840,6 +4840,16 @@ void CWallet::MarkPreSplitKeys() {
48404840
}
48414841
#endif
48424842

4843+
std::shared_ptr<CWallet>
4844+
CWallet::LoadWalletFromFile(const CChainParams &chainParams,
4845+
const WalletLocation &location) {
4846+
4847+
auto ret = CreateWalletFromFile(chainParams, location, SecureString(""),
4848+
std::vector<std::string>(), false);
4849+
return ret;
4850+
}
4851+
4852+
48434853
std::shared_ptr<CWallet>
48444854
CWallet::CreateWalletFromFile(const CChainParams &chainParams,
48454855
const WalletLocation &location,
@@ -5104,20 +5114,10 @@ CWallet::CreateWalletFromFile(const CChainParams &chainParams,
51045114

51055115
std::atomic<bool> CWallet::fFlushScheduled(false);
51065116

5107-
void CWallet::postInitProcess(CScheduler &scheduler) {
5117+
void CWallet::postInitProcess() {
51085118
// Add wallet transactions that aren't already in a block to mempool.
51095119
// Do this here as mempool requires genesis block to be loaded.
51105120
ReacceptWalletTransactions();
5111-
5112-
// Run a thread to flush wallet periodically.
5113-
if (!CWallet::fFlushScheduled.exchange(true)) {
5114-
scheduler.scheduleEvery(
5115-
[]() {
5116-
MaybeCompactWalletDB();
5117-
return true;
5118-
},
5119-
500);
5120-
}
51215121
}
51225122

51235123
bool CWallet::BackupWallet(const std::string &strDest) {

src/wallet/wallet.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,13 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface {
12191219
const WalletLocation &location, bool salvage_wallet,
12201220
std::string &error_string, std::string &warning_string);
12211221

1222+
/**
1223+
* Load the wallet from a file assuming it exists, returns a new CWallet instance or a null pointer
1224+
* in case of an error.
1225+
*/
1226+
static std::shared_ptr<CWallet>
1227+
LoadWalletFromFile(const CChainParams &chainParams,
1228+
const WalletLocation &location);
12221229
/**
12231230
* Initializes the wallet, returns a new CWallet instance or a null pointer
12241231
* in case of an error.
@@ -1235,7 +1242,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface {
12351242
* Gives the wallet a chance to register repetitive tasks and complete
12361243
* post-init tasks
12371244
*/
1238-
void postInitProcess(CScheduler &scheduler);
1245+
void postInitProcess();
12391246

12401247
bool BackupWallet(const std::string &strDest);
12411248

0 commit comments

Comments
 (0)