Browse Source

rpc: Update `generate` for developer notes

Fix nits by John Newbery.
0.15
Wladimir J. van der Laan 8 years ago
parent
commit
2a962834fe
  1. 28
      src/wallet/rpcwallet.cpp

28
src/wallet/rpcwallet.cpp

@ -2927,10 +2927,11 @@ UniValue generate(const JSONRPCRequest& request) @@ -2927,10 +2927,11 @@ UniValue generate(const JSONRPCRequest& request)
{
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue;
}
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
throw std::runtime_error(
"generate nblocks ( maxtries )\n"
"\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n"
@ -2943,25 +2944,28 @@ UniValue generate(const JSONRPCRequest& request) @@ -2943,25 +2944,28 @@ UniValue generate(const JSONRPCRequest& request)
"\nGenerate 11 blocks\n"
+ HelpExampleCli("generate", "11")
);
}
int nGenerate = request.params[0].get_int();
uint64_t nMaxTries = 1000000;
if (request.params.size() > 1) {
nMaxTries = request.params[1].get_int();
int num_generate = request.params[0].get_int();
uint64_t max_tries = 1000000;
if (request.params.size() > 1 && !request.params[1].isNull()) {
max_tries = request.params[1].get_int();
}
std::shared_ptr<CReserveScript> coinbaseScript;
pwallet->GetScriptForMining(coinbaseScript);
std::shared_ptr<CReserveScript> coinbase_script;
pwallet->GetScriptForMining(coinbase_script);
// If the keypool is exhausted, no script is returned at all. Catch this.
if (!coinbaseScript)
if (!coinbase_script) {
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
}
//throw an error if no script was provided
if (coinbaseScript->reserveScript.empty())
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available (mining requires a wallet)");
if (coinbase_script->reserveScript.empty()) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available");
}
return generateBlocks(coinbaseScript, nGenerate, nMaxTries, true);
return generateBlocks(coinbase_script, num_generate, max_tries, true);
}
extern UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp

Loading…
Cancel
Save