aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-06-28 08:32:21 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-06-29 12:02:44 +0200
commit2a962834febc9f56126ef06cf1bd5e1b02370278 (patch)
treeceab0a93b505e6c9af7dbb18ce99b3f35bc3269e /src
parentdf7e2f057b6c9f0f7c950f9077dc63a577f54117 (diff)
rpc: Update `generate` for developer notes
Fix nits by John Newbery.
Diffstat (limited to 'src')
-rw-r--r--src/wallet/rpcwallet.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 93d3920d21..e0c7ab9f0f 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -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)
"\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