32 "\nReturn information about the given bitcoin address.\n",
47 {
RPCResult::Type::ARR,
"error_locations",
true,
"Indices of likely error locations in address, if known (e.g. Bech32 errors)",
59 std::string error_msg;
60 std::vector<int> error_locations;
66 ret.pushKV(
"isvalid", isValid);
69 ret.pushKV(
"address", currentAddress);
72 ret.pushKV(
"scriptPubKey",
HexStr(scriptPubKey));
78 for (
int i : error_locations) error_indices.
push_back(i);
79 ret.pushKV(
"error_locations", std::move(error_indices));
80 ret.pushKV(
"error", error_msg);
91 "\nCreates a multi-signature address with n signature of m keys required.\n"
92 "It returns a json object with the address and redeemScript.\n",
107 {
RPCResult::Type::ARR,
"warnings",
true,
"Any warnings resulting from the creation of this multisig",
114 "\nCreate a multisig address from 2 public keys\n"
115 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"") +
116 "\nAs a JSON-RPC call\n"
117 +
HelpExampleRpc(
"createmultisig",
"2, [\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\",\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\"]")
121 int required = request.params[0].
getInt<
int>();
125 std::vector<CPubKey> pubkeys;
126 pubkeys.reserve(keys.size());
127 for (
unsigned int i = 0; i < keys.size(); ++i) {
133 if (!request.params[2].isNull()) {
134 std::optional<OutputType> parsed =
ParseOutputType(request.params[2].get_str());
140 output_type = parsed.value();
153 result.
pushKV(
"descriptor", descriptor->ToString());
156 if (descriptor->GetOutputType() != output_type) {
158 warnings.
push_back(
"Unable to make chosen address type, please ensure no uncompressed public keys are present.");
169 const std::string EXAMPLE_DESCRIPTOR =
"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)";
172 {
"\nAnalyses 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" +
192 HelpExampleCli(
"getdescriptorinfo",
"\"" + EXAMPLE_DESCRIPTOR +
"\"") +
193 HelpExampleRpc(
"getdescriptorinfo",
"\"" + EXAMPLE_DESCRIPTOR +
"\"")
199 auto descs =
Parse(request.params[0].get_str(), provider, error);
205 result.
pushKV(
"descriptor", descs.at(0)->ToString());
207 if (descs.size() > 1) {
209 for (
const auto& d : descs) {
210 multipath_descs.
push_back(d->ToString());
212 result.
pushKV(
"multipath_expansion", multipath_descs);
216 result.
pushKV(
"isrange", descs.at(0)->IsRange());
217 result.
pushKV(
"issolvable", descs.at(0)->IsSolvable());
218 result.
pushKV(
"hasprivatekeys", provider.
keys.size() > 0);
228 for (int64_t i = range_begin; i <= range_end; ++i) {
230 std::vector<CScript> scripts;
231 if (!desc->
Expand(i, key_provider, scripts, provider)) {
240 if (scripts.size() > 1 && std::get_if<PubKeyDestination>(&dest)) {
251 if (addresses.
empty()) {
260 const std::string EXAMPLE_DESCRIPTOR =
"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";
263 {
"\nDerives one or more addresses corresponding to an output descriptor.\n"
264 "Examples of output descriptors are:\n"
265 " pkh(<pubkey>) P2PKH outputs for the given pubkey\n"
266 " wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey\n"
267 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n"
268 " raw(<hex script>) Outputs whose output script equals the specified hex-encoded bytes\n"
269 " tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-multisig outputs for the given threshold and pubkeys\n"
270 "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
271 "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
272 "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"},
278 RPCResult{
"for single derivation descriptors",
285 RPCResult::Type::ARR,
"",
"The derived addresses for each of the multipath expansions of the descriptor, in multipath specifier order",
297 "First three native segwit receive addresses\n" +
298 HelpExampleCli(
"deriveaddresses",
"\"" + EXAMPLE_DESCRIPTOR +
"\" \"[0,2]\"") +
299 HelpExampleRpc(
"deriveaddresses",
"\"" + EXAMPLE_DESCRIPTOR +
"\", \"[0,2]\"")
303 const std::string desc_str = request.params[0].
get_str();
305 int64_t range_begin = 0;
306 int64_t range_end = 0;
308 if (request.params.size() >= 2 && !request.params[1].isNull()) {
314 auto descs =
Parse(desc_str, key_provider, error,
true);
318 auto& desc = descs.at(0);
319 if (!desc->IsRange() && request.params.size() > 1) {
323 if (desc->IsRange() && request.params.size() == 1) {
329 if (descs.size() == 1) {
334 ret.push_back(addresses);
335 for (
size_t i = 1; i < descs.size(); ++i) {
336 ret.push_back(
DeriveAddresses(descs.at(i).get(), range_begin, range_end, key_provider));
351 for (
const auto& c : commands) {
352 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 std::string & get_str() const
const UniValue & get_array() const
void pushKV(std::string key, UniValue val)
static UniValue Parse(std::string_view raw)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
std::string HexStr(const 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(const std::string &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.