MCPcopy Create free account
hub / github.com/ElementsProject/elements / generatetoaddress

Function generatetoaddress

src/rpc/mining.cpp:281–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281static RPCHelpMan generatetoaddress()
282{
283 return RPCHelpMan{"generatetoaddress",
284 "Mine to a specified address and return the block hashes.",
285 {
286 {"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated."},
287 {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address to send the newly generated bitcoin to."},
288 {"maxtries", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_MAX_TRIES}, "How many iterations to try."},
289 },
290 RPCResult{
291 RPCResult::Type::ARR, "", "hashes of blocks generated",
292 {
293 {RPCResult::Type::STR_HEX, "", "blockhash"},
294 }},
295 RPCExamples{
296 "\nGenerate 11 blocks to myaddress\n"
297 + HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
298 + "If you are using the " PACKAGE_NAME " wallet, you can get a new address to send the newly generated bitcoin to with:\n"
299 + HelpExampleCli("getnewaddress", "")
300 },
301 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
302{
303 const int num_blocks{request.params[0].get_int()};
304 const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()};
305
306 CTxDestination destination = DecodeDestination(request.params[1].get_str());
307 if (!IsValidDestination(destination)) {
308 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address");
309 }
310
311 NodeContext& node = EnsureAnyNodeContext(request.context);
312 const CTxMemPool& mempool = EnsureMemPool(node);
313 ChainstateManager& chainman = EnsureChainman(node);
314
315 CScript coinbase_script = GetScriptForDestination(destination);
316
317 return generateBlocks(chainman, mempool, coinbase_script, num_blocks, max_tries);
318},
319 };
320}
321
322static RPCHelpMan generateblock()
323{

Callers 1

WalletBalanceFunction · 0.50

Calls 8

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

Tested by

no test coverage detected