rpcwallet: use EnsureWalletIsUnlocked() where possible

- replaces a pwalletMain->IsLocked() check
- in keypoolrefill init kpSize to 0 as we have the logic to determine max
  kpSize in pwalletMain->TopUpKeyPool() anyway
This commit is contained in:
Philip Kaufmann 2013-10-28 11:58:39 +01:00
parent 6694f4a7a2
commit f914c7a1a4

View File

@ -334,8 +334,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
wtx.mapValue["to"] = params[3].get_str(); wtx.mapValue["to"] = params[3].get_str();
if (pwalletMain->IsLocked()) EnsureWalletIsUnlocked();
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
if (strError != "") if (strError != "")
@ -1657,15 +1656,15 @@ Value keypoolrefill(const Array& params, bool fHelp)
+ HelpExampleRpc("keypoolrefill", "") + HelpExampleRpc("keypoolrefill", "")
); );
unsigned int kpSize = max(GetArg("-keypool", 100), (int64_t) 0); // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
unsigned int kpSize = 0;
if (params.size() > 0) { if (params.size() > 0) {
if (params[0].get_int() < 0) if (params[0].get_int() < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
kpSize = (unsigned int) params[0].get_int(); kpSize = (unsigned int)params[0].get_int();
} }
EnsureWalletIsUnlocked(); EnsureWalletIsUnlocked();
pwalletMain->TopUpKeyPool(kpSize); pwalletMain->TopUpKeyPool(kpSize);
if (pwalletMain->GetKeyPoolSize() < kpSize) if (pwalletMain->GetKeyPoolSize() < kpSize)