| 293 | } |
| 294 | |
| 295 | static RPCMethod generatetoaddress() |
| 296 | { |
| 297 | return RPCMethod{"generatetoaddress", |
| 298 | "Mine to a specified address and return the block hashes.", |
| 299 | { |
| 300 | {"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated."}, |
| 301 | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address to send the newly generated bitcoin to."}, |
| 302 | {"maxtries", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_MAX_TRIES}, "How many iterations to try."}, |
| 303 | }, |
| 304 | RPCResult{ |
| 305 | RPCResult::Type::ARR, "", "hashes of blocks generated", |
| 306 | { |
| 307 | {RPCResult::Type::STR_HEX, "", "blockhash"}, |
| 308 | }}, |
| 309 | RPCExamples{ |
| 310 | "\nGenerate 11 blocks to myaddress\n" |
| 311 | + HelpExampleCli("generatetoaddress", "11 \"myaddress\"") |
| 312 | + "If you are using the " CLIENT_NAME " wallet, you can get a new address to send the newly generated bitcoin to with:\n" |
| 313 | + HelpExampleCli("getnewaddress", "") |
| 314 | }, |
| 315 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 316 | { |
| 317 | const int num_blocks{request.params[0].getInt<int>()}; |
| 318 | const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt<int>()}; |
| 319 | |
| 320 | CTxDestination destination = DecodeDestination(request.params[1].get_str()); |
| 321 | if (!IsValidDestination(destination)) { |
| 322 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address"); |
| 323 | } |
| 324 | |
| 325 | NodeContext& node = EnsureAnyNodeContext(request.context); |
| 326 | Mining& miner = EnsureMining(node); |
| 327 | ChainstateManager& chainman = EnsureChainman(node); |
| 328 | |
| 329 | CScript coinbase_output_script = GetScriptForDestination(destination); |
| 330 | |
| 331 | return generateBlocks(chainman, miner, coinbase_output_script, num_blocks, max_tries); |
| 332 | }, |
| 333 | }; |
| 334 | } |
| 335 | |
| 336 | static RPCMethod generateblock() |
| 337 | { |
no test coverage detected