Browse Source

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

0.15
Luke Dashjr 8 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)
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize())); obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
} }
if (pwallet && pwallet->IsCrypted()) 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()))); obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
#endif #endif
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()))); 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);
extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName); 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 std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
extern int64_t nWalletUnlockTime;
extern CAmount AmountFromValue(const UniValue& value); extern CAmount AmountFromValue(const UniValue& value);
extern UniValue ValueFromAmount(const CAmount& amount); extern UniValue ValueFromAmount(const CAmount& amount);
extern double GetDifficulty(const CBlockIndex* blockindex = NULL); extern double GetDifficulty(const CBlockIndex* blockindex = NULL);

21
src/wallet/rpcwallet.cpp

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

3
src/wallet/wallet.h

@ -768,6 +768,9 @@ public:
//! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) //! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
bool LoadWatchOnly(const CScript &dest); 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 Unlock(const SecureString& strWalletPassphrase);
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
bool EncryptWallet(const SecureString& strWalletPassphrase); bool EncryptWallet(const SecureString& strWalletPassphrase);

Loading…
Cancel
Save