31#ifdef HAVE_MALLOC_INFO
40 "\nReturn information about the given bitcoin address.\n",
63 std::string error_msg;
69 ret.
pushKV(
"isvalid", isValid);
72 ret.
pushKV(
"address", currentAddress);
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",
110 "\nCreate a multisig address from 2 public keys\n"
111 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"") +
112 "\nAs a JSON-RPC call\n"
113 +
HelpExampleRpc(
"createmultisig",
"2, [\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\",\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\"]")
117 int required = request.params[0].
get_int();
121 std::vector<CPubKey> pubkeys;
122 for (
unsigned int i = 0; i < keys.
size(); ++i) {
123 if (
IsHex(keys[i].get_str()) && (keys[i].
get_str().length() == 66 || keys[i].
get_str().length() == 130)) {
132 if (!request.params[2].isNull()) {
133 std::optional<OutputType> parsed =
ParseOutputType(request.params[2].get_str());
139 output_type = parsed.value();
153 result.
pushKV(
"descriptor", descriptor->ToString());
162 const std::string EXAMPLE_DESCRIPTOR =
"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)";
165 {
"\nAnalyses a descriptor.\n"},
176 {
RPCResult::Type::BOOL,
"hasprivatekeys",
"Whether the input descriptor contained at least one private key"},
180 "Analyse a descriptor\n" +
181 HelpExampleCli(
"getdescriptorinfo",
"\"" + EXAMPLE_DESCRIPTOR +
"\"") +
182 HelpExampleRpc(
"getdescriptorinfo",
"\"" + EXAMPLE_DESCRIPTOR +
"\"")
190 auto desc =
Parse(request.params[0].get_str(), provider,
error);
196 result.
pushKV(
"descriptor", desc->ToString());
198 result.
pushKV(
"isrange", desc->IsRange());
199 result.
pushKV(
"issolvable", desc->IsSolvable());
200 result.
pushKV(
"hasprivatekeys", provider.
keys.size() > 0);
208 const std::string EXAMPLE_DESCRIPTOR =
"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";
211 {
"\nDerives one or more addresses corresponding to an output descriptor.\n"
212 "Examples of output descriptors are:\n"
213 " pkh(<pubkey>) P2PKH outputs for the given pubkey\n"
214 " wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey\n"
215 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n"
216 " raw(<hex script>) Outputs whose scriptPubKey equals the specified hex scripts\n"
217 "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
218 "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
219 "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"},
231 "First three native segwit receive addresses\n" +
232 HelpExampleCli(
"deriveaddresses",
"\"" + EXAMPLE_DESCRIPTOR +
"\" \"[0,2]\"") +
233 HelpExampleRpc(
"deriveaddresses",
"\"" + EXAMPLE_DESCRIPTOR +
"\", \"[0,2]\"")
237 RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()});
238 const std::string desc_str = request.params[0].get_str();
240 int64_t range_begin = 0;
241 int64_t range_end = 0;
243 if (request.params.size() >= 2 && !request.params[1].isNull()) {
249 auto desc =
Parse(desc_str, key_provider,
error,
true);
254 if (!desc->IsRange() && request.params.size() > 1) {
258 if (desc->IsRange() && request.params.size() == 1) {
264 for (
int i = range_begin; i <= range_end; ++i) {
266 std::vector<CScript> scripts;
267 if (!desc->Expand(i, key_provider, scripts, provider)) {
271 for (
const CScript &script : scripts) {
282 if (addresses.
empty()) {
294 "\nVerify a signed message\n",
304 "\nUnlock the wallet for 30 seconds\n"
306 "\nCreate the signature\n"
307 +
HelpExampleCli(
"signmessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
308 "\nVerify the signature\n"
309 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
310 "\nAs a JSON-RPC call\n"
311 +
HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\"")
317 std::string strAddress = request.params[0].get_str();
318 std::string strSign = request.params[1].get_str();
319 std::string strMessage = request.params[2].get_str();
343 "\nSign a message with the private key of an address\n",
352 "\nCreate the signature\n"
353 +
HelpExampleCli(
"signmessagewithprivkey",
"\"privkey\" \"my message\"") +
354 "\nVerify the signature\n"
355 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
356 "\nAs a JSON-RPC call\n"
357 +
HelpExampleRpc(
"signmessagewithprivkey",
"\"privkey\", \"my message\"")
361 std::string strPrivkey = request.params[0].
get_str();
362 std::string strMessage = request.params[1].get_str();
369 std::string signature;
383 "\nSet the local time to given timestamp (-regtest only)\n",
386 "Pass 0 to go back to using the system time."},
393 throw std::runtime_error(
"setmocktime is for regression testing (-regtest mode) only");
404 const int64_t time{request.params[0].get_int64()};
409 auto node_context = util::AnyPtr<NodeContext>(request.context);
411 for (
const auto& chain_client : node_context->chain_clients) {
412 chain_client->setMockTime(time);
421#if defined(USE_SYSCALL_SANDBOX)
425 "invokedisallowedsyscall",
426 "\nInvoke a disallowed syscall to trigger a syscall sandbox violation. Used for testing purposes.\n",
433 throw std::runtime_error(
"invokedisallowedsyscall is used for testing only.");
435 TestDisallowedSandboxCall();
445 "\nBump the scheduler into the future (-regtest only)\n",
454 throw std::runtime_error(
"mockscheduler is for regression testing (-regtest mode) only");
459 int64_t delta_seconds = request.params[0].get_int64();
460 if (delta_seconds <= 0 || delta_seconds > 3600) {
461 throw std::runtime_error(
"delta_time must be between 1 and 3600 seconds (1 hr)");
464 auto node_context = util::AnyPtr<NodeContext>(request.context);
468 node_context->scheduler->MockForward(std::chrono::seconds(delta_seconds));
488#ifdef HAVE_MALLOC_INFO
489static std::string RPCMallocInfo()
493 FILE *f = open_memstream(&ptr, &size);
498 std::string rv(ptr, size);
513 "Returns an object containing information about memory usage.\n",
516 " - \"stats\" returns general statistics about memory usage in the daemon.\n"
517 " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+)."},
528 {
RPCResult::Type::NUM,
"locked",
"Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk."},
544 std::string mode = request.params[0].
isNull() ?
"stats" : request.params[0].get_str();
545 if (mode ==
"stats") {
549 }
else if (mode ==
"mallocinfo") {
550#ifdef HAVE_MALLOC_INFO
551 return RPCMallocInfo();
564 for (
unsigned int i = 0; i < cats.
size(); ++i) {
565 std::string cat = cats[i].
get_str();
583 "Gets and sets the logging configuration.\n"
584 "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
585 "When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
586 "The arguments are evaluated in order \"include\", \"exclude\".\n"
587 "If an item is both included and excluded, it will thus end up being excluded.\n"
589 "In addition, the following are available as category names with special meanings:\n"
590 " - \"all\", \"1\" : represent all logging categories.\n"
591 " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
616 if (request.params[0].isArray()) {
619 if (request.params[1].isArray()) {
623 uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
640 for (
const auto& logCatActive :
LogInstance().LogCategoriesList()) {
641 result.
pushKV(logCatActive.category, logCatActive.active);
652 "\nSimply echo back the input arguments. This command is for testing.\n"
653 "\nIt will return an internal bug report when arg9='trigger_internal_bug' is passed.\n"
654 "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
655 "bitcoin-cli and the GUI. There is no server-side difference.",
672 if (request.params[9].isStr()) {
673 CHECK_NONFATAL(request.params[9].get_str() !=
"trigger_internal_bug");
676 return request.params;
688 "\nEcho back the input argument, passing it through a spawned process in a multiprocess build.\n"
689 "This command is for testing.\n",
696 std::unique_ptr<interfaces::Echo>
echo;
706 auto init =
ipc->spawnProcess(
"bitcoin-node");
717 return echo->echo(request.params[0].get_str());
725 if (!index_name.empty() && index_name != summary.name)
return ret_summary;
728 entry.
pushKV(
"synced", summary.synced);
729 entry.
pushKV(
"best_block_height", summary.best_block_height);
730 ret_summary.
pushKV(summary.name, entry);
737 "\nReturns the status of one or all available indices currently running in the node.\n",
761 const std::string index_name = request.params[0].isNull() ?
"" : request.params[0].get_str();
799 {
"hidden", &
echo, },
802#if defined(USE_SYSCALL_SANDBOX)
803 {
"hidden", &invokedisallowedsyscall, },
807 for (
const auto& c : commands) {
NodeContext & EnsureAnyNodeContext(const std::any &context)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
void ForEachBlockFilterIndex(std::function< void(BlockFilterIndex &)> fn)
Iterate over all running block filter indexes, invoking fn on each.
const CChainParams & Params()
Return the currently selected parameters.
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
void EnableCategory(LogFlags flag)
uint32_t GetCategoryMask() const
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
void DisableCategory(LogFlags flag)
IndexSummary GetSummary() const
Get a summary of the index and its state.
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
bool IsMockableChain() const
If this chain allows time to be mocked.
bool IsTestChain() const
If this chain is exclusively used for testing.
An encapsulated private key.
bool IsValid() const
Check whether this private key is valid.
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Serialized script, used inside transaction inputs and outputs.
Fillable signing provider that keeps keys in an address->secret map.
Stats stats() const
Get pool usage statistics.
static LockedPoolManager & Instance()
Return the current instance, or create it once.
const std::string & get_str() const
bool pushKVs(const UniValue &obj)
bool push_back(const UniValue &val)
const UniValue & get_array() const
bool pushKV(const std::string &key, const UniValue &val)
Initial interface created when a process is first started, and used to give and get access to other i...
virtual std::unique_ptr< Echo > makeEcho()
Interface providing access to interprocess-communication (IPC) functionality.
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
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::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
std::string EncodeDestination(const CTxDestination &dest)
CKey DecodeSecret(const std::string &str)
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg)
BCLog::Logger & LogInstance()
@ ERR_MALFORMED_SIGNATURE
The provided signature couldn't be parsed (maybe invalid base64).
@ ERR_INVALID_ADDRESS
The provided address is invalid.
@ ERR_ADDRESS_NO_KEY
The provided address is valid but does not refer to a public key.
@ ERR_NOT_SIGNED
The message was not signed with the private key of the provided address.
@ OK
The message verification was successful.
@ ERR_PUBKEY_NOT_RECOVERED
A public key could not be recovered from the provided signature and message.
static RPCHelpMan logging()
static RPCHelpMan setmocktime()
void RegisterMiscRPCCommands(CRPCTable &t)
Register miscellaneous RPC commands.
static void EnableOrDisableLogCategories(UniValue cats, bool enable)
static UniValue RPCLockedMemoryInfo()
static RPCHelpMan mockscheduler()
static RPCHelpMan getmemoryinfo()
static RPCHelpMan getdescriptorinfo()
static RPCHelpMan echo(const std::string &name)
static UniValue SummaryToJSON(const IndexSummary &&summary, std::string index_name)
static RPCHelpMan echojson()
static RPCHelpMan deriveaddresses()
static RPCHelpMan echoipc()
static RPCHelpMan signmessagewithprivkey()
static RPCHelpMan createmultisig()
static RPCHelpMan verifymessage()
static RPCHelpMan validateaddress()
static RPCHelpMan getindexinfo()
std::optional< OutputType > ParseOutputType(const std::string &type)
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_MISC_ERROR
General application defined errors.
@ RPC_TYPE_ERROR
Unexpected type was passed as parameter.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
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)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
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::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool IsHex(const std::string &str)
std::map< CKeyID, CKey > keys
interfaces::Init * init
Init interface for initializing current process and connecting to other processes.
@ RANGE
Special type that is a NUM or [NUM,NUM].
@ STR_HEX
Special type that is a STR with only hex chars.
@ OMITTED_NAMED_ARG
Optional arg that is a named argument and has a default value of null.
@ OMITTED
Optional argument with default value omitted because they are implicitly clear.
@ ANY
Special type to disable type checks (for testing only)
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
bool error(const char *fmt, const Args &... args)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
const UniValue NullUniValue
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
MessageVerificationResult MessageVerify(const std::string &address, const std::string &signature, const std::string &message)
Verify a signed message.