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();
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 int64_t time = request.params[0].get_int64();
388 chain_client->setMockTime(time);
400 "\nBump the scheduler into the future (-regtest only)\n",
409 throw std::runtime_error(
"mockscheduler is for regression testing (-regtest mode) only");
414 int64_t delta_seconds = request.params[0].get_int64();
415 if ((delta_seconds <= 0) || (delta_seconds > 3600)) {
416 throw std::runtime_error(
"delta_time must be between 1 and 3600 seconds (1 hr)");
423 node.
scheduler->MockForward(std::chrono::seconds(delta_seconds));
443 #ifdef HAVE_MALLOC_INFO
444 static std::string RPCMallocInfo()
448 FILE *f = open_memstream(&ptr, &size);
453 std::string rv(ptr, size);
468 "Returns an object containing information about memory usage.\n",
470 {
"mode",
RPCArg::Type::STR,
"\"stats\"",
"determines what kind of information is returned.\n"
471 " - \"stats\" returns general statistics about memory usage in the daemon.\n"
472 " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+)."},
483 {
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."},
499 std::string mode = request.params[0].
isNull() ?
"stats" : request.params[0].get_str();
500 if (mode ==
"stats") {
504 }
else if (mode ==
"mallocinfo") {
505 #ifdef HAVE_MALLOC_INFO
506 return RPCMallocInfo();
519 for (
unsigned int i = 0; i < cats.
size(); ++i) {
520 std::string cat = cats[i].
get_str();
538 "Gets and sets the logging configuration.\n"
539 "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
540 "When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
541 "The arguments are evaluated in order \"include\", \"exclude\".\n"
542 "If an item is both included and excluded, it will thus end up being excluded.\n"
544 "In addition, the following are available as category names with special meanings:\n"
545 " - \"all\", \"1\" : represent all logging categories.\n"
546 " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
571 if (request.params[0].isArray()) {
574 if (request.params[1].isArray()) {
578 uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
595 for (
const auto& logCatActive :
LogInstance().LogCategoriesList()) {
596 result.
pushKV(logCatActive.category, logCatActive.active);
607 "\nSimply echo back the input arguments. This command is for testing.\n"
608 "\nIt will return an internal bug report when arg9='trigger_internal_bug' is passed.\n"
609 "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
610 "bitcoin-cli and the GUI. There is no server-side difference.",
627 if (request.fHelp)
throw std::runtime_error(
self.
ToString());
629 if (request.params[9].isStr()) {
630 CHECK_NONFATAL(request.params[9].get_str() !=
"trigger_internal_bug");
633 return request.params;
644 if (!index_name.empty() && index_name != summary.name)
return ret_summary;
647 entry.
pushKV(
"synced", summary.synced);
648 entry.
pushKV(
"best_block_height", summary.best_block_height);
649 ret_summary.
pushKV(summary.name, entry);
656 "\nReturns the status of one or all available indices currently running in the node.\n",
680 const std::string index_name = request.params[0].isNull() ?
"" : request.params[0].get_str();
702 {
"control",
"logging", &
logging, {
"include",
"exclude"}},
704 {
"util",
"createmultisig", &
createmultisig, {
"nrequired",
"keys",
"address_type"} },
705 {
"util",
"deriveaddresses", &
deriveaddresses, {
"descriptor",
"range"} },
707 {
"util",
"verifymessage", &
verifymessage, {
"address",
"signature",
"message"} },
709 {
"util",
"getindexinfo", &
getindexinfo, {
"index_name"} },
712 {
"hidden",
"setmocktime", &
setmocktime, {
"timestamp"}},
713 {
"hidden",
"mockscheduler", &
mockscheduler, {
"delta_time"}},
714 {
"hidden",
"echo", &
echo, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
715 {
"hidden",
"echojson", &
echojson, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
718 for (
const auto& c : commands) {
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)
std::string LogCategoriesString()
Returns a string with the log categories.
uint32_t GetCategoryMask() const
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.
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)
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
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)
BCLog::Logger & LogInstance()
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.
@ 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 signmessagewithprivkey()
static RPCHelpMan createmultisig()
static RPCHelpMan verifymessage()
static RPCHelpMan validateaddress()
static RPCHelpMan getindexinfo()
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
bool ParseOutputType(const std::string &type, OutputType &output_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.
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.
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, 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::string ToString(const T &t)
Locale-independent version of std::to_string.
std::map< CKeyID, CKey > keys
NodeContext struct containing references to chain state and connection state.
std::unique_ptr< CScheduler > scheduler
std::vector< std::unique_ptr< interfaces::ChainClient > > chain_clients
List of all chain clients (wallet processes or other client) connected to node.
@ 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.
@ 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)
For testing.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
const UniValue NullUniValue
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
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)