Browse Source

Move nWalletUnlockTime to CWallet::nRelockTime, and name timed task unique per CWallet

pull/1/head
Luke Dashjr 6 years ago
parent
commit
2e518e313b
  1. 2
      src/rpc/misc.cpp
  2. 1
      src/rpc/server.h
  3. 21
      src/wallet/rpcwallet.cpp
  4. 3
      src/wallet/wallet.h

2
src/rpc/misc.cpp

@ -102,7 +102,7 @@ UniValue getinfo(const JSONRPCRequest& request) @@ -102,7 +102,7 @@ UniValue getinfo(const JSONRPCRequest& request)
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
}
if (pwallet && pwallet->IsCrypted())
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
#endif
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));

1
src/rpc/server.h

@ -190,7 +190,6 @@ extern uint256 ParseHashO(const UniValue& o, std::string strKey); @@ -190,7 +190,6 @@ extern uint256 ParseHashO(const UniValue& o, std::string strKey);
extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
extern int64_t nWalletUnlockTime;
extern CAmount AmountFromValue(const UniValue& value);
extern UniValue ValueFromAmount(const CAmount& amount);
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);

21
src/wallet/rpcwallet.cpp

@ -29,9 +29,6 @@ @@ -29,9 +29,6 @@
using namespace std;
int64_t nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime;
CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
{
return pwalletMain;
@ -2004,8 +2001,8 @@ UniValue keypoolrefill(const JSONRPCRequest& request) @@ -2004,8 +2001,8 @@ UniValue keypoolrefill(const JSONRPCRequest& request)
static void LockWallet(CWallet* pWallet)
{
LOCK(cs_nWalletUnlockTime);
nWalletUnlockTime = 0;
LOCK(pWallet->cs_wallet);
pWallet->nRelockTime = 0;
pWallet->Lock();
}
@ -2063,9 +2060,8 @@ UniValue walletpassphrase(const JSONRPCRequest& request) @@ -2063,9 +2060,8 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
pwallet->TopUpKeyPool();
int64_t nSleepTime = request.params[1].get_int64();
LOCK(cs_nWalletUnlockTime);
nWalletUnlockTime = GetTime() + nSleepTime;
RPCRunLater("lockwallet", boost::bind(LockWallet, pwallet), nSleepTime);
pwallet->nRelockTime = GetTime() + nSleepTime;
RPCRunLater(strprintf("lockwallet_%u", uintptr_t(pwallet)), boost::bind(LockWallet, pwallet), nSleepTime);
return NullUniValue;
}
@ -2150,11 +2146,8 @@ UniValue walletlock(const JSONRPCRequest& request) @@ -2150,11 +2146,8 @@ UniValue walletlock(const JSONRPCRequest& request)
if (!pwallet->IsCrypted())
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
{
LOCK(cs_nWalletUnlockTime);
pwallet->Lock();
nWalletUnlockTime = 0;
}
pwallet->Lock();
pwallet->nRelockTime = 0;
return NullUniValue;
}
@ -2430,7 +2423,7 @@ UniValue getwalletinfo(const JSONRPCRequest& request) @@ -2430,7 +2423,7 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
if (pwallet->IsCrypted())
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID;
if (!masterKeyID.IsNull())

3
src/wallet/wallet.h

@ -768,6 +768,9 @@ public: @@ -768,6 +768,9 @@ public:
//! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
bool LoadWatchOnly(const CScript &dest);
//! Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().
int64_t nRelockTime;
bool Unlock(const SecureString& strWalletPassphrase);
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
bool EncryptWallet(const SecureString& strWalletPassphrase);

Loading…
Cancel
Save