33 "\nReturn 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)",
60 std::string error_msg;
61 std::vector<int> error_locations;
67 ret.pushKV(
"isvalid", isValid);
70 ret.pushKV(
"address", currentAddress);
73 ret.pushKV(
"scriptPubKey",
HexStr(scriptPubKey));
79 for (
int i : error_locations) error_indices.
push_back(i);
80 ret.pushKV(
"error_locations", error_indices);
81 ret.pushKV(
"error", error_msg);
92 "\nCreates a multi-signature address with n signature of m keys required.\n"
93 "It returns a json object with the address and redeemScript.\n",
108 {
RPCResult::Type::ARR,
"warnings",
true,
"Any warnings resulting from the creation of this multisig",
115 "\nCreate a multisig address from 2 public keys\n"
116 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"") +
117 "\nAs a JSON-RPC call\n"
118 +
HelpExampleRpc(
"createmultisig",
"2, [\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\",\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\"]")
122 int required = request.params[0].
getInt<
int>();
126 std::vector<CPubKey> pubkeys;
127 for (
unsigned int i = 0; i < keys.size(); ++i) {
128 if (
IsHex(keys[i].get_str()) && (keys[i].get_str().length() == 66 || keys[i].get_str().length() == 130)) {
137 if (!request.params[2].isNull()) {
138 std::optional<OutputType> parsed =
ParseOutputType(request.params[2].get_str());
144 output_type = parsed.value();
158 result.
pushKV(
"descriptor", descriptor->ToString());
161 if (descriptor->GetOutputType() != output_type) {
163 warnings.
push_back(
"Unable to make chosen address type, please ensure no uncompressed public keys are present.");
174 const std::string EXAMPLE_DESCRIPTOR =
"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)";
177 {
"\nAnalyses a descriptor.\n"},
188 {
RPCResult::Type::BOOL,
"hasprivatekeys",
"Whether the input descriptor contained at least one private key"},
192 "Analyse a descriptor\n" +
193 HelpExampleCli(
"getdescriptorinfo",
"\"" + EXAMPLE_DESCRIPTOR +
"\"") +
194 HelpExampleRpc(
"getdescriptorinfo",
"\"" + EXAMPLE_DESCRIPTOR +
"\"")
200 auto desc =
Parse(request.params[0].get_str(), provider,
error);
206 result.
pushKV(
"descriptor", desc->ToString());
208 result.
pushKV(
"isrange", desc->IsRange());
209 result.
pushKV(
"issolvable", desc->IsSolvable());
210 result.
pushKV(
"hasprivatekeys", provider.
keys.size() > 0);
218 const std::string EXAMPLE_DESCRIPTOR =
"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";
221 {
"\nDerives one or more addresses corresponding to an output descriptor.\n"
222 "Examples of output descriptors are:\n"
223 " pkh(<pubkey>) P2PKH outputs for the given pubkey\n"
224 " wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey\n"
225 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n"
226 " raw(<hex script>) Outputs whose scriptPubKey equals the specified hex scripts\n"
227 " tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-multisig outputs for the given threshold and pubkeys\n"
228 "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
229 "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
230 "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"},
242 "First three native segwit receive addresses\n" +
243 HelpExampleCli(
"deriveaddresses",
"\"" + EXAMPLE_DESCRIPTOR +
"\" \"[0,2]\"") +
244 HelpExampleRpc(
"deriveaddresses",
"\"" + EXAMPLE_DESCRIPTOR +
"\", \"[0,2]\"")
248 const std::string desc_str = request.params[0].
get_str();
250 int64_t range_begin = 0;
251 int64_t range_end = 0;
253 if (request.params.size() >= 2 && !request.params[1].isNull()) {
259 auto desc =
Parse(desc_str, key_provider,
error,
true);
264 if (!desc->IsRange() && request.params.size() > 1) {
268 if (desc->IsRange() && request.params.size() == 1) {
274 for (int64_t i = range_begin; i <= range_end; ++i) {
276 std::vector<CScript> scripts;
277 if (!desc->Expand(i, key_provider, scripts, provider)) {
281 for (
const CScript& script : scripts) {
292 if (addresses.
empty()) {
309 for (
const auto& c : commands) {
310 t.appendCommand(c.name, &c);
#define CHECK_NONFATAL(condition)
Identity function.
Serialized script, used inside transaction inputs and outputs.
Fillable signing provider that keeps keys in an address->secret map.
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 GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
std::string EncodeDestination(const CTxDestination &dest)
bool error(const char *fmt, const Args &... args)
static RPCHelpMan getdescriptorinfo()
void RegisterOutputScriptRPCCommands(CRPCTable &t)
static RPCHelpMan deriveaddresses()
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)
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FillableSigningProvider &keystore, CScript &script_out)
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.
UniValue DescribeAddress(const CTxDestination &dest)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
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.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool IsHex(std::string_view str)