MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / generatetoaddress

Function generatetoaddress

src/rpc/mining.cpp:295–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293}
294
295static 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
336static RPCMethod generateblock()
337{

Callers 1

WalletBalanceFunction · 0.50

Calls 7

HelpExampleCliFunction · 0.85
DecodeDestinationFunction · 0.85
IsValidDestinationFunction · 0.85
JSONRPCErrorFunction · 0.85
GetScriptForDestinationFunction · 0.85
generateBlocksFunction · 0.85
isNullMethod · 0.80

Tested by

no test coverage detected