33 "Return information about the given bitcoin address.\n",
48 {
RPCResult::Type::ARR,
"error_locations",
true,
"Indices of likely error locations in address, if known (e.g. Bech32 errors)",
67 ret.pushKV(
"isvalid", isValid);
73 ret.pushKV(
"scriptPubKey",
HexStr(scriptPubKey));
93 "Creates a multi-signature address with n signatures of m keys required.\n"
94 "It returns a json object with the address and redeemScript.\n",
109 {
RPCResult::Type::ARR,
"warnings",
true,
"Any warnings resulting from the creation of this multisig",
116 "\nCreate a multisig address from 2 public keys\n"
117 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"") +
118 "\nAs a JSON-RPC call\n"
119 +
HelpExampleRpc(
"createmultisig",
"2, [\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\",\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\"]")
127 std::vector<CPubKey> pubkeys;
129 for (
unsigned int i = 0; i < keys.size(); ++i) {
152 result.
pushKV(
"descriptor", descriptor->ToString());
155 if (descriptor->GetOutputType() !=
output_type.value()) {
157 warnings.
push_back(
"Unable to make chosen address type, please ensure no uncompressed public keys are present.");
168 const std::string
EXAMPLE_DESCRIPTOR =
"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)";
172 "Analyses a descriptor.\n",
179 {
RPCResult::Type::STR,
"descriptor",
"The descriptor in canonical form, without private keys. For a multipath descriptor, only the first will be returned."},
180 {
RPCResult::Type::ARR,
"multipath_expansion",
true,
"All descriptors produced by expanding multipath derivation elements. Only if the provided descriptor specifies multipath derivation elements.",
187 {
RPCResult::Type::BOOL,
"hasprivatekeys",
"Whether the input descriptor contained at least one private key"},
191 "Analyse a descriptor\n" +
199 auto descs =
Parse(
self.Arg<std::string_view>(
"descriptor"), provider, error);
205 result.
pushKV(
"descriptor",
descs.at(0)->ToString());
207 if (
descs.size() > 1) {
209 for (
const auto& d :
descs) {
217 result.
pushKV(
"issolvable",
descs.at(0)->IsSolvable());
218 result.
pushKV(
"hasprivatekeys", provider.
keys.size() > 0);
230 std::vector<CScript> scripts;
240 if (scripts.size() > 1 && std::get_if<PubKeyDestination>(&dest)) {
260 const std::string
EXAMPLE_DESCRIPTOR =
"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";
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",
279 RPCResult{
"for single derivation descriptors",
286 RPCResult::Type::ARR,
"",
"The derived addresses for each of the multipath expansions of the descriptor, in multipath specifier order",
298 "First three native segwit receive addresses\n" +
304 auto desc_str{
self.Arg<std::string_view>(
"descriptor")};
309 if (request.params.size() >= 2 && !request.params[1].isNull()) {
319 auto& desc =
descs.at(0);
320 if (!desc->IsRange() && request.params.size() > 1) {
324 if (desc->IsRange() && request.params.size() == 1) {
330 if (
descs.size() == 1) {
336 for (
size_t i = 1; i <
descs.size(); ++i) {
353 t.appendCommand(
c.name, &
c);
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
#define CHECK_NONFATAL(condition)
Identity function.
Serialized script, used inside transaction inputs and outputs.
void push_back(UniValue val)
const UniValue & get_array() const
void reserve(size_t new_cap)
void pushKV(std::string key, UniValue val)
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
std::string EncodeDestination(const CTxDestination &dest)
static RPCHelpMan getdescriptorinfo()
void RegisterOutputScriptRPCCommands(CRPCTable &t)
static RPCHelpMan deriveaddresses()
static UniValue DeriveAddresses(const Descriptor *desc, int64_t range_begin, int64_t range_end, FlatSigningProvider &key_provider)
static RPCHelpMan createmultisig()
static RPCHelpMan validateaddress()
std::optional< OutputType > ParseOutputType(std::string_view type)
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_MISC_ERROR
General application defined errors.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
void PushWarnings(const UniValue &warnings, UniValue &obj)
Push warning messages to an RPC "warnings" field as a JSON array of strings.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
CPubKey HexToPubKey(const std::string &hex_in)
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FlatSigningProvider &keystore, CScript &script_out)
UniValue DescribeAddress(const CTxDestination &dest)
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
Interface for parsed descriptor objects.
virtual bool Expand(int pos, const SigningProvider &provider, std::vector< CScript > &output_scripts, FlatSigningProvider &out, DescriptorCache *write_cache=nullptr) const =0
Expand a descriptor at a specified position.
std::map< CKeyID, CKey > keys
@ RANGE
Special type that is a NUM or [NUM,NUM].
@ STR_HEX
Special type that is a STR with only hex chars.
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
@ STR_HEX
Special string with only hex chars.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.