26 #ifdef HAVE_MALLOC_INFO
35 "\nReturn information about the given bitcoin address.\n",
42 {
RPCResult::Type::BOOL,
"isvalid",
"If the address is valid or not. If not, this is the only property returned."},
61 ret.
pushKV(
"isvalid", isValid);
65 ret.
pushKV(
"address", currentAddress);
81 "\nCreates a multi-signature address with n signature of m keys required.\n"
82 "It returns a json object with the address and redeemScript.\n",
89 {
"address_type",
RPCArg::Type::STR,
"legacy",
"The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
100 "\nCreate a multisig address from 2 public keys\n"
101 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"") +
102 "\nAs a JSON-RPC call\n"
103 +
HelpExampleRpc(
"createmultisig",
"2, \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"")
107 int required = request.params[0].
get_int();
111 std::vector<CPubKey> pubkeys;
112 for (
unsigned int i = 0; i < keys.
size(); ++i) {
113 if (
IsHex(keys[i].get_str()) && (keys[i].
get_str().length() == 66 || keys[i].
get_str().length() == 130)) {
122 if (!request.params[2].isNull()) {
139 result.
pushKV(
"descriptor", descriptor->ToString());
149 {
"\nAnalyses a descriptor.\n"},
160 {
RPCResult::Type::BOOL,
"hasprivatekeys",
"Whether the input descriptor contained at least one private key"},
164 "Analyse a descriptor\n" +
165 HelpExampleCli(
"getdescriptorinfo",
"\"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)\"")
173 auto desc =
Parse(request.params[0].get_str(), provider,
error);
179 result.
pushKV(
"descriptor", desc->ToString());
181 result.
pushKV(
"isrange", desc->IsRange());
182 result.
pushKV(
"issolvable", desc->IsSolvable());
183 result.
pushKV(
"hasprivatekeys", provider.
keys.size() > 0);
192 {
"\nDerives one or more addresses corresponding to an output descriptor.\n"
193 "Examples of output descriptors are:\n"
194 " pkh(<pubkey>) P2PKH outputs for the given pubkey\n"
195 " wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey\n"
196 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n"
197 " raw(<hex script>) Outputs whose scriptPubKey equals the specified hex scripts\n"
198 "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
199 "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
200 "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"},
212 "First three native segwit receive addresses\n" +
213 HelpExampleCli(
"deriveaddresses",
"\"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu\" \"[0,2]\"")
217 RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()});
218 const std::string desc_str = request.params[0].get_str();
220 int64_t range_begin = 0;
221 int64_t range_end = 0;
223 if (request.params.size() >= 2 && !request.params[1].isNull()) {
229 auto desc =
Parse(desc_str, key_provider, error,
true);
234 if (!desc->IsRange() && request.params.size() > 1) {
238 if (desc->IsRange() && request.params.size() == 1) {
244 for (
int i = range_begin; i <= range_end; ++i) {
246 std::vector<CScript> scripts;
247 if (!desc->Expand(i, key_provider, scripts, provider)) {
251 for (
const CScript &script : scripts) {
262 if (addresses.
empty()) {
274 "\nVerify a signed message\n",
284 "\nUnlock the wallet for 30 seconds\n"
286 "\nCreate the signature\n"
287 +
HelpExampleCli(
"signmessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
288 "\nVerify the signature\n"
289 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
290 "\nAs a JSON-RPC call\n"
291 +
HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\"")
297 std::string strAddress = request.params[0].get_str();
298 std::string strSign = request.params[1].get_str();
299 std::string strMessage = request.params[2].get_str();
323 "\nSign a message with the private key of an address\n",
332 "\nCreate the signature\n"
333 +
HelpExampleCli(
"signmessagewithprivkey",
"\"privkey\" \"my message\"") +
334 "\nVerify the signature\n"
335 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
336 "\nAs a JSON-RPC call\n"
337 +
HelpExampleRpc(
"signmessagewithprivkey",
"\"privkey\", \"my message\"")
341 std::string strPrivkey = request.params[0].
get_str();
342 std::string strMessage = request.params[1].get_str();
345 if (!key.IsValid()) {
349 std::string signature;
363 "\nSet the local time to given timestamp (-regtest only)\n",
366 "Pass 0 to go back to using the system time."},
373 throw std::runtime_error(
"setmocktime is for regression testing (-regtest mode) only");
384 const int64_t time{request.params[0].get_int64()};
391 chain_client->setMockTime(time);
403 "\nBump the scheduler into the future (-regtest only)\n",
412 throw std::runtime_error(
"mockscheduler is for regression testing (-regtest mode) only");
417 int64_t delta_seconds = request.params[0].get_int64();
418 if ((delta_seconds <= 0) || (delta_seconds > 3600)) {
419 throw std::runtime_error(
"delta_time must be between 1 and 3600 seconds (1 hr)");
426 node.
scheduler->MockForward(std::chrono::seconds(delta_seconds));
446 #ifdef HAVE_MALLOC_INFO
447 static std::string RPCMallocInfo()
451 FILE *f = open_memstream(&ptr, &size);
456 std::string rv(ptr, size);
471 "Returns an object containing information about memory usage.\n",
473 {
"mode",
RPCArg::Type::STR,
"\"stats\"",
"determines what kind of information is returned.\n"
474 " - \"stats\" returns general statistics about memory usage in the daemon.\n"
475 " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+)."},
486 {
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."},
502 std::string mode = request.params[0].
isNull() ?
"stats" : request.params[0].get_str();
503 if (mode ==
"stats") {
507 }
else if (mode ==
"mallocinfo") {
508 #ifdef HAVE_MALLOC_INFO
509 return RPCMallocInfo();
522 for (
unsigned int i = 0; i < cats.
size(); ++i) {
523 std::string cat = cats[i].
get_str();
541 "Gets and sets the logging configuration.\n"
542 "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
543 "When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
544 "The arguments are evaluated in order \"include\", \"exclude\".\n"
545 "If an item is both included and excluded, it will thus end up being excluded.\n"
547 "In addition, the following are available as category names with special meanings:\n"
548 " - \"all\", \"1\" : represent all logging categories.\n"
549 " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
574 if (request.params[0].isArray()) {
577 if (request.params[1].isArray()) {
581 uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
591 if (changed_log_categories == BCLog::LIBEVENT) {
598 for (
const auto& logCatActive :
LogInstance().LogCategoriesList()) {
599 result.
pushKV(logCatActive.category, logCatActive.active);
610 "\nSimply echo back the input arguments. This command is for testing.\n"
611 "\nIt will return an internal bug report when arg9='trigger_internal_bug' is passed.\n"
612 "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
613 "bitcoin-cli and the GUI. There is no server-side difference.",
630 if (request.fHelp)
throw std::runtime_error(
self.
ToString());
632 if (request.params[9].isStr()) {
633 CHECK_NONFATAL(request.params[9].get_str() !=
"trigger_internal_bug");
636 return request.params;
647 if (!index_name.empty() && index_name != summary.name)
return ret_summary;
650 entry.
pushKV(
"synced", summary.synced);
651 entry.
pushKV(
"best_block_height", summary.best_block_height);
652 ret_summary.
pushKV(summary.name, entry);
659 "\nReturns the status of one or all available indices currently running in the node.\n",
683 const std::string index_name = request.params[0].isNull() ?
"" : request.params[0].get_str();
705 {
"control",
"logging", &
logging, {
"include",
"exclude"}},
707 {
"util",
"createmultisig", &
createmultisig, {
"nrequired",
"keys",
"address_type"} },
708 {
"util",
"deriveaddresses", &
deriveaddresses, {
"descriptor",
"range"} },
710 {
"util",
"verifymessage", &
verifymessage, {
"address",
"signature",
"message"} },
712 {
"util",
"getindexinfo", &
getindexinfo, {
"index_name"} },
715 {
"hidden",
"setmocktime", &
setmocktime, {
"timestamp"}},
716 {
"hidden",
"mockscheduler", &
mockscheduler, {
"delta_time"}},
717 {
"hidden",
"echo", &
echo, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
718 {
"hidden",
"echojson", &
echojson, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
721 for (
const auto& c : commands) {
void EnableCategory(LogFlags flag)
const std::string & get_str() const
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
std::vector< std::unique_ptr< interfaces::ChainClient > > chain_clients
List of all chain clients (wallet processes or other client) connected to node.
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.
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.
uint32_t GetCategoryMask() const
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.
The message verification was successful.
Stats stats() const
Get pool usage statistics.
bool pushKVs(const UniValue &obj)
static RPCHelpMan deriveaddresses()
Invalid, missing or duplicate parameter.
void SetMockTime(int64_t nMockTimeIn)
For testing.
static RPCHelpMan echojson()
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
std::string ToString(const T &t)
Locale-independent version of std::to_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.
bool error(const char *fmt, const Args &...args)
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.
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)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Unexpected type was passed as parameter.
void DisableCategory(LogFlags flag)
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.
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.
CTxDestination DecodeDestination(const std::string &str)
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
const UniValue & get_array() const
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()
IndexSummary GetSummary() const
Get a summary of the index and its state.
The provided address is invalid.
std::string LogCategoriesString()
Returns a string with the log categories.
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)
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.
Special dictionary with keys that are not literals.
CKey DecodeSecret(const std::string &str)
static RPCHelpMan getdescriptorinfo()
bool IsMockableChain() const
If this chain allows time to be mocked.
A public key could not be recovered from the provided signature and message.
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
UniValue DescribeAddress(const CTxDestination &dest)
bool ParseOutputType(const std::string &type, OutputType &output_type)
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.
CPubKey HexToPubKey(const std::string &hex_in)
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
static RPCHelpMan signmessagewithprivkey()
static RPCHelpMan echo(const std::string &name)
std::unique_ptr< CScheduler > scheduler