Skip to content

Commit cc965fe

Browse files
luke-jrrandom-zebra
authored andcommitted
Move nWalletUnlockTime to CWallet::nRelockTime, and name timed task
unique per CWallet
1 parent 22f8507 commit cc965fe

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

src/rpc/misc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ UniValue getinfo(const JSONRPCRequest& request)
143143
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
144144
}
145145
if (pwallet && pwallet->IsCrypted())
146-
obj.pushKV("unlocked_until", nWalletUnlockTime);
146+
obj.pushKV("unlocked_until", pwallet->nRelockTime);
147147
obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()));
148148
#endif
149149
obj.pushKV("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 std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKe
190190
extern int ParseInt(const UniValue& o, std::string strKey);
191191
extern bool ParseBool(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: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535
#include <univalue.h>
3636

37-
int64_t nWalletUnlockTime;
38-
static RecursiveMutex cs_nWalletUnlockTime;
37+
3938

4039
CWallet* GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
4140
{
@@ -3352,8 +3351,8 @@ UniValue keypoolrefill(const JSONRPCRequest& request)
33523351

33533352
static void LockWallet(CWallet* pWallet)
33543353
{
3355-
LOCK(cs_nWalletUnlockTime);
3356-
nWalletUnlockTime = 0;
3354+
LOCK(pWallet->cs_wallet);
3355+
pWallet->nRelockTime = 0;
33573356
pWallet->fWalletUnlockStaking = false;
33583357
pWallet->Lock();
33593358
}
@@ -3429,7 +3428,7 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
34293428
pwallet->TopUpKeyPool();
34303429

34313430
if (nSleepTime > 0) {
3432-
nWalletUnlockTime = GetTime () + nSleepTime;
3431+
pwallet->nRelockTime = GetTime () + nSleepTime;
34333432
RPCRunLater ("lockwallet", std::bind (LockWallet, pwallet), nSleepTime);
34343433
}
34353434

@@ -3520,11 +3519,8 @@ UniValue walletlock(const JSONRPCRequest& request)
35203519
if (!pwallet->IsCrypted())
35213520
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
35223521

3523-
{
3524-
LOCK(cs_nWalletUnlockTime);
3525-
pwallet->Lock();
3526-
nWalletUnlockTime = 0;
3527-
}
3522+
pwallet->Lock();
3523+
pwallet->nRelockTime = 0;
35283524

35293525
return NullUniValue;
35303526
}
@@ -4058,8 +4054,8 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
40584054
}
40594055

40604056
if (pwallet->IsCrypted())
4061-
obj.pushKV("unlocked_until", nWalletUnlockTime);
4062-
obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()));
4057+
obj.pushKV("unlocked_until", pwallet->nRelockTime);
4058+
obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()));
40634059
obj.pushKV("last_processed_block", pwallet->GetLastBlockHeight());
40644060
return obj;
40654061
}

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,12 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
934934
bool LoadWatchOnly(const CScript& dest);
935935

936936
//! Lock Wallet
937+
//! Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().
938+
int64_t nRelockTime;
937939
bool Lock();
938940
bool Unlock(const SecureString& strWalletPassphrase, bool anonimizeOnly = false);
939941
bool Unlock(const CKeyingMaterial& vMasterKeyIn);
942+
940943
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
941944
bool EncryptWallet(const SecureString& strWalletPassphrase);
942945

0 commit comments

Comments
 (0)