| 3385 | } |
| 3386 | |
| 3387 | UniValue generate(const UniValue& params, bool fHelp) |
| 3388 | { |
| 3389 | if (!EnsureWalletIsAvailable(fHelp)) { |
| 3390 | return NullUniValue; |
| 3391 | } |
| 3392 | |
| 3393 | if (fHelp || params.size() < 1 || params.size() > 2) { |
| 3394 | throw std::runtime_error( |
| 3395 | "generate nblocks ( maxtries )\n" |
| 3396 | "\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n" |
| 3397 | "\nArguments:\n" |
| 3398 | "1. nblocks (numeric, required) How many blocks are generated immediately.\n" |
| 3399 | "2. maxtries (numeric, optional) How many iterations to try (default = 1000000).\n" |
| 3400 | "\nResult:\n" |
| 3401 | "[ blockhashes ] (array) hashes of blocks generated\n" |
| 3402 | "\nExamples:\n" |
| 3403 | "\nGenerate 11 blocks\n" |
| 3404 | + HelpExampleCli("generate", "11") |
| 3405 | ); |
| 3406 | } |
| 3407 | |
| 3408 | int num_generate = params[0].get_int(); |
| 3409 | uint64_t max_tries = 1000000; |
| 3410 | if (!params[1].isNull()) { |
| 3411 | max_tries = params[1].get_int(); |
| 3412 | } |
| 3413 | |
| 3414 | std::shared_ptr<CReserveScript> coinbase_script; |
| 3415 | pwalletMain->GetScriptForMining(coinbase_script); |
| 3416 | |
| 3417 | // If the keypool is exhausted, no script is returned at all. Catch this. |
| 3418 | if (!coinbase_script) { |
| 3419 | throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); |
| 3420 | } |
| 3421 | |
| 3422 | //throw an error if no script was provided |
| 3423 | if (coinbase_script->reserveScript.empty()) { |
| 3424 | throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available"); |
| 3425 | } |
| 3426 | |
| 3427 | return generateBlocks(coinbase_script, num_generate, max_tries, true); |
| 3428 | } |
nothing calls this directly
no test coverage detected