29 #ifdef HAVE_MALLOC_INFO 38 "\nReturn information about the given bitcoin address.\n",
61 std::string error_msg;
67 ret.pushKV(
"isvalid", isValid);
70 ret.pushKV(
"address", currentAddress);
73 ret.pushKV(
"scriptPubKey",
HexStr(scriptPubKey));
78 ret.pushKV(
"error", error_msg);
89 "\nCreates a multi-signature address with n signature of m keys required.\n" 90 "It returns a json object with the address and redeemScript.\n",
108 "\nCreate a multisig address from 2 public keys\n" 109 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"") +
110 "\nAs a JSON-RPC call\n" 111 +
HelpExampleRpc(
"createmultisig",
"2, \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"")
115 int required = request.params[0].
get_int();
119 std::vector<CPubKey> pubkeys;
120 for (
unsigned int i = 0; i < keys.
size(); ++i) {
121 if (
IsHex(keys[i].get_str()) && (keys[i].
get_str().length() == 66 || keys[i].
get_str().length() == 130)) {
130 if (!request.params[2].isNull()) {
150 result.
pushKV(
"descriptor", descriptor->ToString());
160 {
"\nAnalyses a descriptor.\n"},
171 {
RPCResult::Type::BOOL,
"hasprivatekeys",
"Whether the input descriptor contained at least one private key"},
175 "Analyse a descriptor\n" +
176 HelpExampleCli(
"getdescriptorinfo",
"\"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)\"")
184 auto desc =
Parse(request.params[0].get_str(), provider,
error);
190 result.
pushKV(
"descriptor", desc->ToString());
192 result.
pushKV(
"isrange", desc->IsRange());
193 result.
pushKV(
"issolvable", desc->IsSolvable());
194 result.
pushKV(
"hasprivatekeys", provider.
keys.size() > 0);
203 {
"\nDerives one or more addresses corresponding to an output descriptor.\n" 204 "Examples of output descriptors are:\n" 205 " pkh(<pubkey>) P2PKH outputs for the given pubkey\n" 206 " wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey\n" 207 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n" 208 " raw(<hex script>) Outputs whose scriptPubKey equals the specified hex scripts\n" 209 "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n" 210 "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n" 211 "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"},
223 "First three native segwit receive addresses\n" +
224 HelpExampleCli(
"deriveaddresses",
"\"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu\" \"[0,2]\"")
228 RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()});
229 const std::string desc_str = request.params[0].get_str();
231 int64_t range_begin = 0;
232 int64_t range_end = 0;
234 if (request.params.size() >= 2 && !request.params[1].isNull()) {
240 auto desc =
Parse(desc_str, key_provider,
error,
true);
245 if (!desc->IsRange() && request.params.size() > 1) {
249 if (desc->IsRange() && request.params.size() == 1) {
255 for (
int i = range_begin; i <= range_end; ++i) {
257 std::vector<CScript> scripts;
258 if (!desc->Expand(i, key_provider, scripts, provider)) {
262 for (
const CScript &script : scripts) {
273 if (addresses.
empty()) {
285 "\nVerify a signed message\n",
295 "\nUnlock the wallet for 30 seconds\n" 297 "\nCreate the signature\n" 298 +
HelpExampleCli(
"signmessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
299 "\nVerify the signature\n" 300 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
301 "\nAs a JSON-RPC call\n" 302 +
HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\"")
308 std::string strAddress = request.params[0].get_str();
309 std::string strSign = request.params[1].get_str();
310 std::string strMessage = request.params[2].get_str();
334 "\nSign a message with the private key of an address\n",
343 "\nCreate the signature\n" 344 +
HelpExampleCli(
"signmessagewithprivkey",
"\"privkey\" \"my message\"") +
345 "\nVerify the signature\n" 346 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
347 "\nAs a JSON-RPC call\n" 348 +
HelpExampleRpc(
"signmessagewithprivkey",
"\"privkey\", \"my message\"")
352 std::string strPrivkey = request.params[0].
get_str();
353 std::string strMessage = request.params[1].get_str();
360 std::string signature;
374 "\nSet the local time to given timestamp (-regtest only)\n",
377 "Pass 0 to go back to using the system time."},
384 throw std::runtime_error(
"setmocktime is for regression testing (-regtest mode) only");
395 const int64_t time{request.params[0].get_int64()};
400 auto node_context = util::AnyPtr<NodeContext>(request.context);
402 for (
const auto& chain_client : node_context->chain_clients) {
403 chain_client->setMockTime(time);
415 "\nBump the scheduler into the future (-regtest only)\n",
424 throw std::runtime_error(
"mockscheduler is for regression testing (-regtest mode) only");
429 int64_t delta_seconds = request.params[0].get_int64();
430 if (delta_seconds <= 0 || delta_seconds > 3600) {
431 throw std::runtime_error(
"delta_time must be between 1 and 3600 seconds (1 hr)");
434 auto node_context = util::AnyPtr<NodeContext>(request.context);
438 node_context->scheduler->MockForward(std::chrono::seconds(delta_seconds));
458 #ifdef HAVE_MALLOC_INFO 459 static std::string RPCMallocInfo()
463 FILE *f = open_memstream(&ptr, &size);
468 std::string rv(ptr, size);
483 "Returns an object containing information about memory usage.\n",
486 " - \"stats\" returns general statistics about memory usage in the daemon.\n" 487 " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+)."},
498 {
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."},
514 std::string mode = request.params[0].
isNull() ?
"stats" : request.params[0].get_str();
515 if (mode ==
"stats") {
519 }
else if (mode ==
"mallocinfo") {
520 #ifdef HAVE_MALLOC_INFO 521 return RPCMallocInfo();
534 for (
unsigned int i = 0; i < cats.
size(); ++i) {
535 std::string cat = cats[i].
get_str();
553 "Gets and sets the logging configuration.\n" 554 "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n" 555 "When called with arguments, adds or removes categories from debug logging and return the lists above.\n" 556 "The arguments are evaluated in order \"include\", \"exclude\".\n" 557 "If an item is both included and excluded, it will thus end up being excluded.\n" 559 "In addition, the following are available as category names with special meanings:\n" 560 " - \"all\", \"1\" : represent all logging categories.\n" 561 " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n" 586 if (request.params[0].isArray()) {
589 if (request.params[1].isArray()) {
593 uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
610 for (
const auto& logCatActive :
LogInstance().LogCategoriesList()) {
611 result.
pushKV(logCatActive.category, logCatActive.active);
622 "\nSimply echo back the input arguments. This command is for testing.\n" 623 "\nIt will return an internal bug report when arg9='trigger_internal_bug' is passed.\n" 624 "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in " 625 "bitcoin-cli and the GUI. There is no server-side difference.",
642 if (request.params[9].isStr()) {
643 CHECK_NONFATAL(request.params[9].get_str() !=
"trigger_internal_bug");
646 return request.params;
658 "\nEcho back the input argument, passing it through a spawned process in a multiprocess build.\n" 659 "This command is for testing.\n",
665 std::unique_ptr<interfaces::Echo>
echo;
675 auto init =
ipc->spawnProcess(
"bitcoin-node");
686 return echo->echo(request.params[0].get_str());
694 if (!index_name.empty() && index_name != summary.name)
return ret_summary;
697 entry.
pushKV(
"synced", summary.synced);
698 entry.
pushKV(
"best_block_height", summary.best_block_height);
699 ret_summary.
pushKV(summary.name, entry);
706 "\nReturns the status of one or all available indices currently running in the node.\n",
730 const std::string index_name = request.params[0].isNull() ?
"" : request.params[0].get_str();
768 {
"hidden", &
echo, },
773 for (
const auto& c : commands) {
void EnableCategory(LogFlags flag)
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
BCLog::Logger & LogInstance()
static RPCHelpMan mockscheduler()
The provided signature couldn't be parsed (maybe invalid base64).
static LockedPoolManager & Instance()
Return the current instance, or create it once.
std::unique_ptr< Echo > MakeEcho()
Return implementation of Echo interface.
static RPCHelpMan validateaddress()
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
std::map< CKeyID, CKey > keys
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
static RPCHelpMan createmultisig()
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
void ForEachBlockFilterIndex(std::function< void(BlockFilterIndex &)> fn)
Iterate over all running block filter indexes, invoking fn on each.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
const std::string & get_str() const
const UniValue & get_array() const
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg)
The message verification was successful.
interfaces::Init * init
Init interface for initializing current process and connecting to other processes.
bool pushKVs(const UniValue &obj)
static RPCHelpMan echoipc()
static RPCHelpMan deriveaddresses()
Invalid, missing or duplicate parameter.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
static RPCHelpMan echojson()
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.
static UniValue SummaryToJSON(const IndexSummary &&summary, std::string index_name)
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
UniValue JSONRPCError(int code, const std::string &message)
bool push_back(const UniValue &val)
Special string with only hex chars.
static RPCHelpMan setmocktime()
static RPCHelpMan getindexinfo()
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
Fillable signing provider that keeps keys in an address->secret map.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
bool IsHex(const std::string &str)
Unexpected type was passed as parameter.
Special type to disable type checks (for testing only)
uint32_t GetCategoryMask() const
void DisableCategory(LogFlags flag)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
General application defined errors.
bool pushKV(const std::string &key, const UniValue &val)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FillableSigningProvider &keystore, CScript &script_out)
static UniValue RPCLockedMemoryInfo()
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Optional arg that is a named argument and has a default value of null.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
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].
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 RPCHelpMan logging()
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
void RegisterMiscRPCCommands(CRPCTable &t)
Register miscellaneous RPC commands.
static RPCHelpMan getmemoryinfo()
The provided address is invalid.
const UniValue NullUniValue
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)
std::string EncodeDestination(const CTxDestination &dest)
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
NodeContext & EnsureAnyNodeContext(const std::any &context)
MessageVerificationResult MessageVerify(const std::string &address, const std::string &signature, const std::string &message)
Verify a signed message.
static RPCHelpMan verifymessage()
An encapsulated private key.
Stats stats() const
Get pool usage statistics.
Special dictionary with keys that are not literals.
CKey DecodeSecret(const std::string &str)
static RPCHelpMan getdescriptorinfo()
A public key could not be recovered from the provided signature and message.
UniValue DescribeAddress(const CTxDestination &dest)
bool IsMockableChain() const
If this chain allows time to be mocked.
bool ParseOutputType(const std::string &type, OutputType &output_type)
bool error(const char *fmt, const Args &... args)
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
The provided address is valid but does not refer to a public key.
Interface providing access to interprocess-communication (IPC) functionality.
std::string LogCategoriesString() const
Returns a string with the log categories.
CPubKey HexToPubKey(const std::string &hex_in)
#define Assert(val)
Identity function.
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
bool IsValid() const
Check whether this private key is valid.
static RPCHelpMan signmessagewithprivkey()
static RPCHelpMan echo(const std::string &name)
IndexSummary GetSummary() const
Get a summary of the index and its state.