diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/misc.cpp | 2 | ||||
-rw-r--r-- | src/rpc/server.h | 1 | ||||
-rw-r--r-- | src/wallet/rpcwallet.cpp | 21 | ||||
-rw-r--r-- | src/wallet/wallet.h | 3 |
4 files changed, 11 insertions, 16 deletions
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index c9bbce856d..746189a2ae 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -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()))); diff --git a/src/rpc/server.h b/src/rpc/server.h index b8f0373acc..72ffc76520 100644 --- a/src/rpc/server.h +++ b/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> 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); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 478d92cda3..b36a99013e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -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) 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) 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) 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) 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()) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 98e4fb87b9..176063c27f 100644 --- a/src/wallet/wallet.h +++ b/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) 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); |