29 #ifdef HAVE_MALLOC_INFO 37 "Return information about the given bitcoin address.\n",
40 "The bitcoin address to validate"},
48 "If the address is valid or not. If not, this is the only " 49 "property returned."},
51 "The bitcoin address validated"},
53 "The hex-encoded scriptPubKey generated by the address"},
66 ret.
pushKV(
"isvalid", isValid);
69 if (ret[
"address"].isNull()) {
71 ret.
pushKV(
"address", currentAddress);
88 "Creates a multi-signature address with n signature of m keys " 90 "It returns a json object with the address and redeemScript.\n",
93 "The number of required signatures out of the n keys."},
97 "The hex-encoded public keys.",
100 "The hex-encoded public key"},
109 "The value of the new multisig address."},
111 "The string value of the hex-encoded redemption script."},
113 "The descriptor for this multisig"},
116 "\nCreate a multisig address from 2 public keys\n" +
120 "\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd3" 121 "42cf11ae157a7ace5fd\\\"," 122 "\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e1" 123 "7e107ef3f6aa5a61626\\\"]\"") +
124 "\nAs a JSON-RPC call\n" +
128 "\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd3" 129 "42cf11ae157a7ace5fd\\\"," 130 "\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e1" 131 "7e107ef3f6aa5a61626\\\"]\"")},
139 std::vector<CPubKey> pubkeys;
140 for (
size_t i = 0; i < keys.
size(); ++i) {
143 IsHex(keys[i].get_str())) {
148 strprintf(
"Invalid public key: %s\n", keys[i].get_str()));
159 required, pubkeys, output_type, keystore, inner);
162 std::unique_ptr<Descriptor> descriptor =
168 result.
pushKV(
"descriptor", descriptor->ToString());
177 {
"Analyses a descriptor.\n"},
188 "The descriptor in canonical form, without private keys"},
190 "The checksum for the input descriptor"},
192 "Whether the descriptor is ranged"},
194 "Whether the descriptor is solvable"},
196 "Whether the input descriptor contained at least one private " 201 "\"pkh([d34db33f/84h/0h/" 203 "0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2" 204 "dce28d959f2815b16f81798)\"")}}
217 result.
pushKV(
"descriptor", desc->ToString());
220 result.
pushKV(
"isrange", desc->IsRange());
221 result.
pushKV(
"issolvable", desc->IsSolvable());
222 result.
pushKV(
"hasprivatekeys", provider.
keys.size() > 0);
229 {
"Derives one or more addresses corresponding to an output " 231 "Examples of output descriptors are:\n" 232 " pkh(<pubkey>) P2PKH outputs for the given " 234 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for " 235 "the given threshold and pubkeys\n" 236 " raw(<hex script>) Outputs whose scriptPubKey " 237 "equals the specified hex scripts\n" 238 "\nIn the above, <pubkey> either refers to a fixed public key in " 239 "hexadecimal notation, or to an xpub/xprv optionally followed by one\n" 240 "or more path elements separated by \"/\", where \"h\" represents a " 241 "hardened child key.\n" 242 "For more information on output descriptors, see the documentation in " 243 "the doc/descriptors.md file.\n"},
248 "If a ranged descriptor is used, this specifies the end or the " 249 "range (in [begin,end] notation) to derive."},
258 RPCExamples{
"First three pkh receive addresses\n" +
261 "\"pkh([d34db33f/84h/0h/0h]" 262 "xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8P" 263 "hqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKE" 264 "u3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#3vhfv5h5\" \"[0,2]\"")}}
271 int64_t range_begin = 0;
272 int64_t range_end = 0;
275 std::tie(range_begin, range_end) =
282 Parse(desc_str, key_provider, error,
true);
287 if (!desc->IsRange() && request.
params.
size() > 1) {
290 "Range should not be specified for an un-ranged descriptor");
293 if (desc->IsRange() && request.
params.
size() == 1) {
295 "Range must be specified for a ranged descriptor");
300 for (
int i = range_begin; i <= range_end; ++i) {
302 std::vector<CScript> scripts;
303 if (!desc->Expand(i, key_provider, scripts, provider)) {
306 strprintf(
"Cannot derive script without private keys"));
309 for (
const CScript &script : scripts) {
315 "Descriptor does not have a corresponding address"));
323 if (addresses.
empty()) {
334 "Verify a signed message\n",
337 "The bitcoin address to use for the signature."},
339 "The signature provided by the signer in base 64 encoding (see " 342 "The message that was signed."},
345 "If the signature is verified or not."},
347 "\nUnlock the wallet for 30 seconds\n" +
349 "\nCreate the signature\n" +
352 "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
353 "\nVerify the signature\n" +
354 HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" 355 "XX\" \"signature\" \"my " 357 "\nAs a JSON-RPC call\n" +
358 HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" 359 "XX\", \"signature\", \"my " 378 "Malformed base64 encoding");
392 "signmessagewithprivkey",
393 "Sign a message with the private key of an address\n",
396 "The private key to sign the message with."},
398 "The message to create a signature of."},
401 "The signature of the message encoded in base 64"},
404 "\"privkey\" \"my message\"") +
405 "\nVerify the signature\n" +
407 "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" " 408 "\"signature\" \"my message\"") +
409 "\nAs a JSON-RPC call\n" +
411 "\"privkey\", \"my message\"")},
423 std::string signature;
436 "Set the local time to given timestamp (-regtest only)\n",
441 " Pass 0 to go back to using the system time."},
449 throw std::runtime_error(
450 "setmocktime for regression testing (-regtest mode) only");
464 "Timestamp must be 0 or greater");
468 for (
const auto &chain_client :
470 chain_client->setMockTime(time);
481 "Bump the scheduler into the future (-regtest only)\n",
484 "Number of seconds to forward the scheduler into the future."},
491 if (!
Params().IsMockableChain()) {
492 throw std::runtime_error(
493 "mockscheduler is for regression testing (-regtest mode) only");
499 if ((delta_seconds <= 0) || (delta_seconds > 3600)) {
500 throw std::runtime_error(
501 "delta_time must be between 1 and 3600 seconds (1 hr)");
508 node.
scheduler->MockForward(std::chrono::seconds(delta_seconds));
525 #ifdef HAVE_MALLOC_INFO 526 static std::string RPCMallocInfo() {
529 FILE *f = open_memstream(&ptr, &size);
534 std::string rv(ptr, size);
550 "Returns an object containing information about memory usage.\n",
553 "determines what kind of information is returned.\n" 554 " - \"stats\" returns general statistics about memory usage in " 556 " - \"mallocinfo\" returns an XML string describing low-level " 557 "heap state (only available if compiled with glibc 2.10+)."},
568 "Information about locked memory manager",
572 "Number of bytes available in current arenas"},
574 "Total number of bytes managed"},
576 "Amount of bytes that succeeded locking. If this " 577 "number is smaller than total, locking pages failed " 578 "at some point and key data could be swapped to " 581 "Number allocated chunks"},
583 "Number unused chunks"},
587 "\"<malloc version=\"1\">...\""},
596 if (mode ==
"stats") {
600 }
else if (mode ==
"mallocinfo") {
601 #ifdef HAVE_MALLOC_INFO 602 return RPCMallocInfo();
606 "mallocinfo is only available when compiled with glibc 2.10+");
615 for (
size_t i = 0; i < cats.
size(); ++i) {
616 std::string cat = cats[i].
get_str();
627 "unknown logging category " + cat);
635 "Gets and sets the logging configuration.\n" 636 "When called without an argument, returns the list of categories with " 637 "status that are currently being debug logged or not.\n" 638 "When called with arguments, adds or removes categories from debug " 639 "logging and return the lists above.\n" 640 "The arguments are evaluated in order \"include\", \"exclude\".\n" 641 "If an item is both included and excluded, it will thus end up being " 643 "The valid logging categories are: " +
646 "In addition, the following are available as category names with " 647 "special meanings:\n" 648 " - \"all\", \"1\" : represent all logging categories.\n" 649 " - \"none\", \"0\" : even if other logging categories are " 650 "specified, ignore all of them.\n",
655 "The categories to add to debug logging",
663 "The categories to remove from debug logging",
672 "keys are the logging categories, and values indicates its status",
675 "if being debug logged or not. false:inactive, true:active"},
678 HelpExampleCli(
"logging",
"\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") +
693 uint32_t changed_log_categories =
694 original_log_categories ^ updated_log_categories;
707 if (changed_log_categories == BCLog::LIBEVENT) {
709 "libevent logging cannot be updated when " 710 "using libevent before v2.1.1.");
717 for (
const auto &logCatActive : vLogCatActive) {
718 result.
pushKV(logCatActive.category, logCatActive.active);
728 "Simply echo back the input arguments. This command is for " 730 "\nThe difference between echo and echojson is that echojson has " 731 "argument conversion enabled in the client-side table in " 732 "bitcoin-cli and the GUI. There is no server-side difference.",
735 "Returns whatever was passed in"},
752 {
"control",
"logging",
logging, {
"include",
"exclude"} },
754 {
"util",
"createmultisig",
createmultisig, {
"nrequired",
"keys"} },
755 {
"util",
"deriveaddresses",
deriveaddresses, {
"descriptor",
"range"} },
757 {
"util",
"verifymessage",
verifymessage, {
"address",
"signature",
"message"} },
761 {
"hidden",
"setmocktime",
setmocktime, {
"timestamp"}},
763 {
"hidden",
"echo",
echo, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
764 {
"hidden",
"echojson",
echo, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
768 for (
unsigned int vcidx = 0; vcidx <
ARRAYLEN(commands); vcidx++) {
const util::Ref & context
std::vector< std::unique_ptr< interfaces::ChainClient > > chain_clients
static constexpr unsigned int SIZE
secp256k1:
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
BCLog::Logger & LogInstance()
Bitcoin RPC command dispatcher.
void EnableCategory(LogFlags category)
The provided signature couldn't be parsed (maybe invalid base64).
static LockedPoolManager & Instance()
Return the current instance, or create it once.
static UniValue verifymessage(const Config &config, const JSONRPCRequest &request)
std::map< CKeyID, CKey > keys
const std::string EXAMPLE_ADDRESS
Example CashAddr address used in multiple RPCExamples.
std::string ListLogCategories()
Returns a string with the log categories.
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
#define ARRAYLEN(array)
Utilities for converting data from/to strings.
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CPubKey HexToPubKey(const std::string &hex_in)
UniValue DescribeAddress(const CTxDestination &dest)
const std::string & get_str() const
const UniValue & get_array() const
std::string EncodeDestination(const CTxDestination &dest, const Config &config)
The message verification was successful.
int64_t get_int64() const
bool pushKVs(const UniValue &obj)
void DisableCategory(LogFlags category)
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
virtual const CChainParams & GetChainParams() const =0
Invalid, missing or duplicate parameter.
static UniValue logging(const Config &config, const JSONRPCRequest &request)
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
void SetMockTime(int64_t nMockTimeIn)
For testing.
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FillableSigningProvider &keystore, CScript &script_out)
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
Special type that is a STR with only hex chars.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
static constexpr unsigned int COMPRESSED_SIZE
UniValue JSONRPCError(int code, const std::string &message)
bool push_back(const UniValue &val)
Special string with only hex chars.
NodeContext struct containing references to chain state and connection state.
Fillable signing provider that keeps keys in an address->secret map.
bool IsHex(const std::string &str)
Returns true if each character in str is a hex character, and has an even number of hex digits...
Unexpected type was passed as parameter.
uint32_t GetCategoryMask() const
RecursiveMutex cs_main
Global state.
General application defined errors std::exception thrown in command handling.
bool pushKV(const std::string &key, const UniValue &val)
static UniValue setmocktime(const Config &config, const JSONRPCRequest &request)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
static UniValue RPCLockedMemoryInfo()
MessageVerificationResult MessageVerify(const CChainParams ¶ms, const std::string &address, const std::string &signature, const std::string &message)
Verify a signed message.
Optional arg that is a named argument and has a default value of null.
The message was not signed with the private key of the provided address.
static void EnableOrDisableLogCategories(UniValue cats, bool enable)
Special type that is a NUM or [NUM,NUM].
static UniValue signmessagewithprivkey(const Config &config, const JSONRPCRequest &request)
Optional argument with default value omitted because they are implicitly clear.
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
static UniValue mockscheduler(const Config &config, const JSONRPCRequest &request)
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
void RegisterMiscRPCCommands(CRPCTable &t)
Register miscellaneous RPC commands.
The provided address is invalid.
static UniValue createmultisig(const Config &config, const JSONRPCRequest &request)
std::string HexStr(const T itbegin, const T itend)
const UniValue NullUniValue
static UniValue getmemoryinfo(const Config &config, const JSONRPCRequest &request)
An encapsulated secp256k1 private key.
Stats stats() const
Get pool usage statistics.
UniValue deriveaddresses(const Config &config, const JSONRPCRequest &request)
Special dictionary with keys that are not literals.
CKey DecodeSecret(const std::string &str)
A public key could not be recovered from the provided signature and message.
bool IsMockableChain() const
If this chain allows time to be mocked.
static UniValue validateaddress(const Config &config, const JSONRPCRequest &request)
UniValue getdescriptorinfo(const Config &config, const JSONRPCRequest &request)
bool error(const char *fmt, const Args &... args)
std::vector< CLogCategoryActive > ListActiveLogCategories()
Returns a vector of the active log categories.
static UniValue echo(const Config &config, const JSONRPCRequest &request)
The provided address is valid but does not refer to a public key.
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
bool IsValid() const
Check whether this private key is valid.
std::unique_ptr< CScheduler > scheduler
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.