| 256 | } |
| 257 | |
| 258 | static 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); |
nothing calls this directly
no test coverage detected