Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/misc.cpp
Show First 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"hexadecimal notation, or to an xpub/xprv optionally followed by one\n" | "hexadecimal notation, or to an xpub/xprv optionally followed by one\n" | ||||
"or more path elements separated by \"/\", where \"h\" represents a " | "or more path elements separated by \"/\", where \"h\" represents a " | ||||
"hardened child key.\n" | "hardened child key.\n" | ||||
"For more information on output descriptors, see the documentation in " | "For more information on output descriptors, see the documentation in " | ||||
"the doc/descriptors.md file.\n"}, | "the doc/descriptors.md file.\n"}, | ||||
{ | { | ||||
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, | {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The descriptor."}, | "The descriptor."}, | ||||
{"begin", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, | {"range", RPCArg::Type::RANGE, RPCArg::Optional::OMITTED_NAMED_ARG, | ||||
"If a ranged descriptor is used, this specifies the beginning of " | "If a ranged descriptor is used, this specifies the end or the " | ||||
"the range to import."}, | "range (in [begin,end] notation) to derive."}, | ||||
{"end", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, | |||||
"If a ranged descriptor is used, this specifies the end of the " | |||||
"range to import."}, | |||||
}, | }, | ||||
RPCResult{"[ address ] (array) the derived addresses\n"}, | RPCResult{"[ address ] (array) the derived addresses\n"}, | ||||
RPCExamples{ | RPCExamples{"First three pkh receive addresses\n" + | ||||
"First three pkh receive addresses\n" + | HelpExampleCli( | ||||
HelpExampleCli("deriveaddresses", | "deriveaddresses", | ||||
"\"pkh([d34db33f/84h/0h/0h]" | "\"pkh([d34db33f/84h/0h/0h]" | ||||
"xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8P" | "xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8P" | ||||
"hqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKE" | "hqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKE" | ||||
"u3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#3vhfv5h5\" 0 2")}} | "u3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#3vhfv5h5\" \"[0,2]\"")}} | ||||
.Check(request); | .Check(request); | ||||
RPCTypeCheck(request.params, | // Range argument is checked later | ||||
{UniValue::VSTR, UniValue::VNUM, UniValue::VNUM}); | RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()}); | ||||
const std::string desc_str = request.params[0].get_str(); | const std::string desc_str = request.params[0].get_str(); | ||||
int range_begin = 0; | int64_t range_begin = 0; | ||||
int range_end = 0; | int64_t range_end = 0; | ||||
if (request.params.size() >= 2) { | if (request.params.size() >= 2 && !request.params[1].isNull()) { | ||||
if (request.params.size() == 2) { | auto range = ParseRange(request.params[1]); | ||||
if (range.first < 0) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Missing range end parameter"); | "Range should be greater or equal than 0"); | ||||
} | } | ||||
range_begin = request.params[1].get_int(); | if ((range.second >> 31) != 0) { | ||||
range_end = request.params[2].get_int(); | |||||
if (range_begin < 0) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Range should be greater or equal than 0"); | "End of range is too high"); | ||||
} | } | ||||
if (range_begin > range_end) { | if (range.second >= range.first + 1000000) { | ||||
throw JSONRPCError( | throw JSONRPCError(RPC_INVALID_PARAMETER, "Range is too large"); | ||||
RPC_INVALID_PARAMETER, | |||||
"Range end should be equal to or greater than begin"); | |||||
} | } | ||||
range_begin = range.first; | |||||
range_end = range.second; | |||||
} | } | ||||
FlatSigningProvider provider; | FlatSigningProvider provider; | ||||
auto desc = Parse(desc_str, provider, /* require_checksum = */ true); | auto desc = Parse(desc_str, provider, /* require_checksum = */ true); | ||||
if (!desc) { | if (!desc) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
strprintf("Invalid descriptor")); | strprintf("Invalid descriptor")); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 480 Lines • Show Last 20 Lines |