Skip to content

Commit 2e518e3

Browse files
committed
Move nWalletUnlockTime to CWallet::nRelockTime, and name timed task unique per CWallet
1 parent d77ad6d commit 2e518e3

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

src/rpc/misc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ UniValue getinfo(const JSONRPCRequest& request)
102102
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
103103
}
104104
if (pwallet && pwallet->IsCrypted())
105-
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
105+
obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
106106
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
107107
#endif
108108
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));

src/rpc/server.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ extern uint256 ParseHashO(const UniValue& o, std::string strKey);
190190
extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
191191
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
192192

193-
extern int64_t nWalletUnlockTime;
194193
extern CAmount AmountFromValue(const UniValue& value);
195194
extern UniValue ValueFromAmount(const CAmount& amount);
196195
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);

src/wallet/rpcwallet.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
using namespace std;
3131

32-
int64_t nWalletUnlockTime;
33-
static CCriticalSection cs_nWalletUnlockTime;
34-
3532
CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
3633
{
3734
return pwalletMain;
@@ -2004,8 +2001,8 @@ UniValue keypoolrefill(const JSONRPCRequest& request)
20042001

20052002
static void LockWallet(CWallet* pWallet)
20062003
{
2007-
LOCK(cs_nWalletUnlockTime);
2008-
nWalletUnlockTime = 0;
2004+
LOCK(pWallet->cs_wallet);
2005+
pWallet->nRelockTime = 0;
20092006
pWallet->Lock();
20102007
}
20112008

@@ -2063,9 +2060,8 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
20632060
pwallet->TopUpKeyPool();
20642061

20652062
int64_t nSleepTime = request.params[1].get_int64();
2066-
LOCK(cs_nWalletUnlockTime);
2067-
nWalletUnlockTime = GetTime() + nSleepTime;
2068-
RPCRunLater("lockwallet", boost::bind(LockWallet, pwallet), nSleepTime);
2063+
pwallet->nRelockTime = GetTime() + nSleepTime;
2064+
RPCRunLater(strprintf("lockwallet_%u", uintptr_t(pwallet)), boost::bind(LockWallet, pwallet), nSleepTime);
20692065

20702066
return NullUniValue;
20712067
}
@@ -2150,11 +2146,8 @@ UniValue walletlock(const JSONRPCRequest& request)
21502146
if (!pwallet->IsCrypted())
21512147
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
21522148

2153-
{
2154-
LOCK(cs_nWalletUnlockTime);
2155-
pwallet->Lock();
2156-
nWalletUnlockTime = 0;
2157-
}
2149+
pwallet->Lock();
2150+
pwallet->nRelockTime = 0;
21582151

21592152
return NullUniValue;
21602153
}
@@ -2430,7 +2423,7 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
24302423
obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime()));
24312424
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
24322425
if (pwallet->IsCrypted())
2433-
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
2426+
obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
24342427
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
24352428
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID;
24362429
if (!masterKeyID.IsNull())

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
768768
//! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
769769
bool LoadWatchOnly(const CScript &dest);
770770

771+
//! Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().
772+
int64_t nRelockTime;
773+
771774
bool Unlock(const SecureString& strWalletPassphrase);
772775
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
773776
bool EncryptWallet(const SecureString& strWalletPassphrase);

0 commit comments

Comments
 (0)