RPC: keypoolrefill gains optional size parameter

This commit is contained in:
Jeff Garzik 2013-06-25 16:21:42 -04:00
parent 13dd2d090e
commit 36bd46f1c4
2 changed files with 12 additions and 4 deletions

View File

@ -1199,6 +1199,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]); if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "keypoolrefill" && n > 0) ConvertTo<boost::int64_t>(params[0]);
return params; return params;
} }

View File

@ -1253,17 +1253,24 @@ Value backupwallet(const Array& params, bool fHelp)
Value keypoolrefill(const Array& params, bool fHelp) Value keypoolrefill(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() > 0) if (fHelp || params.size() > 1)
throw runtime_error( throw runtime_error(
"keypoolrefill\n" "keypoolrefill [new-size]\n"
"Fills the keypool." "Fills the keypool."
+ HelpRequiringPassphrase()); + HelpRequiringPassphrase());
unsigned int kpSize = max(GetArg("-keypool", 100), 0LL);
if (params.size() > 0) {
if (params[0].get_int() < 0)
throw JSONRPCError(-8, "Invalid parameter, expected valid size");
kpSize = (unsigned int) params[0].get_int();
}
EnsureWalletIsUnlocked(); EnsureWalletIsUnlocked();
pwalletMain->TopUpKeyPool(); pwalletMain->TopUpKeyPool(kpSize);
if (pwalletMain->GetKeyPoolSize() < GetArg("-keypool", 100)) if (pwalletMain->GetKeyPoolSize() < kpSize)
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
return Value::null; return Value::null;