typedef Value(*rpcfn_type)(const Array& params, bool fHelp);
extern map<string, rpcfn_type> mapCallTable;
+static int64 nWalletUnlockTime;
+static CCriticalSection cs_nWalletUnlockTime;
+
Object JSONRPCError(int code, const string& message)
{
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
+ if (pwalletMain->IsCrypted())
+ obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
void ThreadCleanWalletPassphrase(void* parg)
{
- static int64 nWakeTime;
int64 nMyWakeTime = GetTime() + *((int*)parg);
- static CCriticalSection cs_nWakeTime;
- if (nWakeTime == 0)
+ if (nWalletUnlockTime == 0)
{
- CRITICAL_BLOCK(cs_nWakeTime)
+ CRITICAL_BLOCK(cs_nWalletUnlockTime)
{
- nWakeTime = nMyWakeTime;
+ nWalletUnlockTime = nMyWakeTime;
}
- while (GetTime() < nWakeTime)
- Sleep(GetTime() - nWakeTime);
+ while (GetTime() < nWalletUnlockTime)
+ Sleep(GetTime() - nWalletUnlockTime);
- CRITICAL_BLOCK(cs_nWakeTime)
+ CRITICAL_BLOCK(cs_nWalletUnlockTime)
{
- nWakeTime = 0;
+ nWalletUnlockTime = 0;
}
}
else
{
- CRITICAL_BLOCK(cs_nWakeTime)
+ CRITICAL_BLOCK(cs_nWalletUnlockTime)
{
- if (nWakeTime < nMyWakeTime)
- nWakeTime = nMyWakeTime;
+ if (nWalletUnlockTime < nMyWakeTime)
+ nWalletUnlockTime = nMyWakeTime;
}
free(parg);
return;
}
+Value walletlock(const Array& params, bool fHelp)
+{
+ if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0))
+ throw runtime_error(
+ "walletlock\n"
+ "Removes the wallet encryption key from memory, locking the wallet.\n"
+ "After calling this method, you will need to call walletpassphrase again\n"
+ "before being able to call any methods which require the wallet to be unlocked.");
+ if (fHelp)
+ return true;
+ if (!pwalletMain->IsCrypted())
+ throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
+
+ pwalletMain->Lock();
+ CRITICAL_BLOCK(cs_nWalletUnlockTime)
+ {
+ nWalletUnlockTime = 0;
+ }
+
+ return Value::null;
+}
+
+
Value encryptwallet(const Array& params, bool fHelp)
{
if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1))
make_pair("keypoolrefill", &keypoolrefill),
make_pair("walletpassphrase", &walletpassphrase),
make_pair("walletpassphrasechange", &walletpassphrasechange),
+ make_pair("walletlock", &walletlock),
make_pair("encryptwallet", &encryptwallet),
make_pair("validateaddress", &validateaddress),
make_pair("getbalance", &getbalance),
"backupwallet",
"keypoolrefill",
"walletpassphrase",
+ "walletlock",
"validateaddress",
"getwork",
};