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

Function generatetodescriptor

src/rpc/mining.cpp:250–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250static RPCMethod generatetodescriptor()
251{
252 return RPCMethod{
253 "generatetodescriptor",
254 "Mine to a specified descriptor and return the block hashes.",
255 {
256 {"num_blocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated."},
257 {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor to send the newly generated bitcoin to."},
258 {"maxtries", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_MAX_TRIES}, "How many iterations to try."},
259 },
260 RPCResult{
261 RPCResult::Type::ARR, "", "hashes of blocks generated",
262 {
263 {RPCResult::Type::STR_HEX, "", "blockhash"},
264 }
265 },
266 RPCExamples{
267 "\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
268 [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
269{
270 const auto num_blocks{self.Arg<int>("num_blocks")};
271 const auto max_tries{self.Arg<uint64_t>("maxtries")};
272
273 CScript coinbase_output_script;
274 std::string error;
275 if (!getScriptFromDescriptor(self.Arg<std::string_view>("descriptor"), coinbase_output_script, error)) {
276 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error);
277 }
278
279 NodeContext& node = EnsureAnyNodeContext(request.context);
280 Mining& miner = EnsureMining(node);
281 ChainstateManager& chainman = EnsureChainman(node);
282
283 return generateBlocks(chainman, miner, coinbase_output_script, num_blocks, max_tries);
284},
285 };
286}
287
288static RPCMethod generate()
289{

Callers

nothing calls this directly

Calls 4

HelpExampleCliFunction · 0.85
getScriptFromDescriptorFunction · 0.85
JSONRPCErrorFunction · 0.85
generateBlocksFunction · 0.85

Tested by

no test coverage detected