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

Function deriveaddresses

src/rpc/output_script.cpp:258–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258static RPCMethod deriveaddresses()
259{
260 const std::string EXAMPLE_DESCRIPTOR = "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";
261
262 return RPCMethod{
263 "deriveaddresses",
264 "Derives one or more addresses corresponding to an output descriptor.\n"
265 "Examples of output descriptors are:\n"
266 " pkh(<pubkey>) P2PKH outputs for the given pubkey\n"
267 " wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey\n"
268 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n"
269 " raw(<hex script>) Outputs whose output script equals the specified hex-encoded bytes\n"
270 " tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-multisig outputs for the given threshold and pubkeys\n"
271 "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
272 "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
273 "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n",
274 {
275 {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor."},
276 {"range", RPCArg::Type::RANGE, RPCArg::Optional::OMITTED, "If a ranged descriptor is used, this specifies the end or the range (in [begin,end] notation) to derive."},
277 },
278 {
279 RPCResult{"for single derivation descriptors",
280 RPCResult::Type::ARR, "", "",
281 {
282 {RPCResult::Type::STR, "address", "the derived addresses"},
283 }
284 },
285 RPCResult{"for multipath descriptors",
286 RPCResult::Type::ARR, "", "The derived addresses for each of the multipath expansions of the descriptor, in multipath specifier order",
287 {
288 {
289 RPCResult::Type::ARR, "", "The derived addresses for a multipath descriptor expansion",
290 {
291 {RPCResult::Type::STR, "address", "the derived address"},
292 },
293 },
294 },
295 },
296 },
297 RPCExamples{
298 "First three native segwit receive addresses\n" +
299 HelpExampleCli("deriveaddresses", "\"" + EXAMPLE_DESCRIPTOR + "\" \"[0,2]\"") +
300 HelpExampleRpc("deriveaddresses", "\"" + EXAMPLE_DESCRIPTOR + "\", \"[0,2]\"")
301 },
302 [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
303 {
304 auto desc_str{self.Arg<std::string_view>("descriptor")};
305
306 int64_t range_begin = 0;
307 int64_t range_end = 0;
308
309 if (request.params.size() >= 2 && !request.params[1].isNull()) {
310 std::tie(range_begin, range_end) = ParseDescriptorRange(request.params[1]);
311 }
312
313 FlatSigningProvider key_provider;
314 std::string error;
315 auto descs = Parse(desc_str, key_provider, error, /* require_checksum = */ true);

Callers

nothing calls this directly

Calls 13

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
ParseDescriptorRangeFunction · 0.85
JSONRPCErrorFunction · 0.85
DeriveAddressesFunction · 0.85
isNullMethod · 0.80
ParseFunction · 0.70
sizeMethod · 0.45
emptyMethod · 0.45
atMethod · 0.45
IsRangeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected