35 #ifdef HAVE_MALLOC_INFO
44 "Return information about the given bitcoin address.\n",
47 "The bitcoin address to validate"},
55 "If the address is valid or not. If not, this is the only "
56 "property returned."},
58 "The bitcoin address validated"},
60 "The hex-encoded scriptPubKey generated by the address"},
68 config.GetChainParams());
72 ret.
pushKV(
"isvalid", isValid);
75 if (ret[
"address"].
isNull()) {
76 std::string currentAddress =
78 ret.
pushKV(
"address", currentAddress);
95 "Creates a multi-signature address with n signature of m keys "
97 "It returns a json object with the address and redeemScript.\n",
100 "The number of required signatures out of the n keys."},
104 "The hex-encoded public keys.",
107 "The hex-encoded public key"},
116 "The value of the new multisig address."},
118 "The string value of the hex-encoded redemption script."},
120 "The descriptor for this multisig"},
123 "\nCreate a multisig address from 2 public keys\n" +
127 "\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd3"
128 "42cf11ae157a7ace5fd\\\","
129 "\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e1"
130 "7e107ef3f6aa5a61626\\\"]\"") +
131 "\nAs a JSON-RPC call\n" +
135 "\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd3"
136 "42cf11ae157a7ace5fd\\\","
137 "\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e1"
138 "7e107ef3f6aa5a61626\\\"]\"")},
141 int required = request.params[0].
get_int();
145 std::vector<CPubKey> pubkeys;
146 for (
size_t i = 0; i < keys.
size(); ++i) {
147 if ((keys[i].get_str().length() ==
150 IsHex(keys[i].get_str())) {
166 required, pubkeys, output_type, keystore, inner);
169 std::unique_ptr<Descriptor> descriptor =
175 result.
pushKV(
"descriptor", descriptor->ToString());
185 {
"Analyses a descriptor.\n"},
196 "The descriptor in canonical form, without private keys"},
198 "The checksum for the input descriptor"},
200 "Whether the descriptor is ranged"},
202 "Whether the descriptor is solvable"},
204 "Whether the input descriptor contained at least one private "
209 "\"pkh([d34db33f/84h/0h/"
211 "0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2"
212 "dce28d959f2815b16f81798)\"")},
219 auto desc =
Parse(request.params[0].get_str(), provider,
error);
225 result.
pushKV(
"descriptor", desc->ToString());
228 result.
pushKV(
"isrange", desc->IsRange());
229 result.
pushKV(
"issolvable", desc->IsSolvable());
230 result.
pushKV(
"hasprivatekeys", provider.
keys.size() > 0);
239 {
"Derives one or more addresses corresponding to an output "
241 "Examples of output descriptors are:\n"
242 " pkh(<pubkey>) P2PKH outputs for the given "
244 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for "
245 "the given threshold and pubkeys\n"
246 " raw(<hex script>) Outputs whose scriptPubKey "
247 "equals the specified hex scripts\n"
248 "\nIn the above, <pubkey> either refers to a fixed public key in "
249 "hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
250 "or more path elements separated by \"/\", where \"h\" represents a "
251 "hardened child key.\n"
252 "For more information on output descriptors, see the documentation in "
253 "the doc/descriptors.md file.\n"},
258 "If a ranged descriptor is used, this specifies the end or the "
259 "range (in [begin,end] notation) to derive."},
268 RPCExamples{
"First three pkh receive addresses\n" +
271 "\"pkh([d34db33f/84h/0h/0h]"
272 "xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8P"
273 "hqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKE"
274 "u3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#3vhfv5h5\" \"[0,2]\"")},
278 RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()});
279 const std::string desc_str = request.params[0].get_str();
281 int64_t range_begin = 0;
282 int64_t range_end = 0;
284 if (request.params.size() >= 2 && !request.params[1].isNull()) {
285 std::tie(range_begin, range_end) =
291 auto desc =
Parse(desc_str, key_provider,
error,
297 if (!desc->IsRange() && request.params.size() > 1) {
299 "Range should not be specified for an "
300 "un-ranged descriptor");
303 if (desc->IsRange() && request.params.size() == 1) {
306 "Range must be specified for a ranged descriptor");
311 for (
int i = range_begin; i <= range_end; ++i) {
313 std::vector<CScript> scripts;
314 if (!desc->Expand(i, key_provider, scripts, provider)) {
317 strprintf(
"Cannot derive script without private keys"));
320 for (
const CScript &script : scripts) {
326 "corresponding address"));
334 if (addresses.
empty()) {
346 "Verify a signed message\n",
349 "The bitcoin address to use for the signature."},
351 "The signature provided by the signer in base 64 encoding (see "
354 "The message that was signed."},
357 "If the signature is verified or not."},
359 "\nUnlock the wallet for 30 seconds\n" +
361 "\nCreate the signature\n" +
364 "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
365 "\nVerify the signature\n" +
366 HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4"
367 "XX\" \"signature\" \"my "
369 "\nAs a JSON-RPC call\n" +
370 HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4"
371 "XX\", \"signature\", \"my "
377 std::string strAddress = request.params[0].get_str();
378 std::string strSign = request.params[1].get_str();
379 std::string strMessage = request.params[2].get_str();
381 switch (
MessageVerify(config.GetChainParams(), strAddress, strSign,
387 "Address does not refer to key");
390 "Malformed base64 encoding");
405 "signmessagewithprivkey",
406 "Sign a message with the private key of an address\n",
409 "The private key to sign the message with."},
411 "The message to create a signature of."},
414 "The signature of the message encoded in base 64"},
417 "\"privkey\" \"my message\"") +
418 "\nVerify the signature\n" +
420 "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" "
421 "\"signature\" \"my message\"") +
422 "\nAs a JSON-RPC call\n" +
424 "\"privkey\", \"my message\"")},
427 std::string strPrivkey = request.params[0].
get_str();
428 std::string strMessage = request.params[1].get_str();
433 "Invalid private key");
436 std::string signature;
450 "Set the local time to given timestamp (-regtest only)\n",
454 "Pass 0 to go back to using the system time."},
460 if (!config.GetChainParams().IsMockableChain()) {
461 throw std::runtime_error(
462 "setmocktime for regression testing (-regtest mode) only");
473 const int64_t time{request.params[0].get_int64()};
477 strprintf(
"Mocktime can not be negative: %s.", time));
480 auto node_context = util::AnyPtr<NodeContext>(request.context);
482 for (
const auto &chain_client : node_context->chain_clients) {
483 chain_client->setMockTime(time);
495 "Bump the scheduler into the future (-regtest only)\n",
498 "Number of seconds to forward the scheduler into the future."},
505 throw std::runtime_error(
"mockscheduler is for regression "
506 "testing (-regtest mode) only");
511 int64_t delta_seconds = request.params[0].get_int64();
512 if ((delta_seconds <= 0) || (delta_seconds > 3600)) {
513 throw std::runtime_error(
514 "delta_time must be between 1 and 3600 seconds (1 hr)");
521 node_context->scheduler->MockForward(
522 std::chrono::seconds(delta_seconds));
541 #ifdef HAVE_MALLOC_INFO
542 static std::string RPCMallocInfo() {
545 FILE *f = open_memstream(&ptr, &size);
550 std::string rv(ptr, size);
565 "Returns an object containing information about memory usage.\n",
568 "determines what kind of information is returned.\n"
569 " - \"stats\" returns general statistics about memory usage in "
571 " - \"mallocinfo\" returns an XML string describing low-level "
572 "heap state (only available if compiled with glibc 2.10+)."},
583 "Information about locked memory manager",
587 "Number of bytes available in current arenas"},
589 "Total number of bytes managed"},
591 "Amount of bytes that succeeded locking. If this "
592 "number is smaller than total, locking pages failed "
593 "at some point and key data could be swapped to "
596 "Number allocated chunks"},
598 "Number unused chunks"},
602 "\"<malloc version=\"1\">...\""},
608 std::string mode = request.params[0].
isNull()
610 : request.params[0].get_str();
611 if (mode ==
"stats") {
615 }
else if (mode ==
"mallocinfo") {
616 #ifdef HAVE_MALLOC_INFO
617 return RPCMallocInfo();
620 "mallocinfo is only available when compiled "
625 "unknown mode " + mode);
633 for (
size_t i = 0; i < cats.
size(); ++i) {
634 std::string cat = cats[i].
get_str();
645 "unknown logging category " + cat);
653 "Gets and sets the logging configuration.\n"
654 "When called without an argument, returns the list of categories with "
655 "status that are currently being debug logged or not.\n"
656 "When called with arguments, adds or removes categories from debug "
657 "logging and return the lists above.\n"
658 "The arguments are evaluated in order \"include\", \"exclude\".\n"
659 "If an item is both included and excluded, it will thus end up being "
661 "The valid logging categories are: " +
664 "In addition, the following are available as category names with "
665 "special meanings:\n"
666 " - \"all\", \"1\" : represent all logging categories.\n"
667 " - \"none\", \"0\" : even if other logging categories are "
668 "specified, ignore all of them.\n",
673 "The categories to add to debug logging",
681 "The categories to remove from debug logging",
690 "keys are the logging categories, and values indicates its status",
693 "if being debug logged or not. false:inactive, true:active"},
696 HelpExampleCli(
"logging",
"\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") +
701 if (request.params[0].isArray()) {
705 if (request.params[1].isArray()) {
710 uint32_t changed_log_categories =
711 original_log_categories ^ updated_log_categories;
727 "libevent logging cannot be updated when "
728 "using libevent before v2.1.1.");
734 for (
const auto &logCatActive :
LogInstance().LogCategoriesList()) {
735 result.
pushKV(logCatActive.category, logCatActive.active);
746 "Simply echo back the input arguments. This command is for "
748 "\nIt will return an internal bug report when "
749 "arg9='trigger_internal_bug' is passed.\n"
750 "\nThe difference between echo and echojson is that echojson has "
751 "argument conversion enabled in the client-side table in "
752 "bitcoin-cli and the GUI. There is no server-side difference.",
779 if (request.params[9].isStr()) {
781 "trigger_internal_bug");
784 return request.params;
793 return echo(
"echojson");
799 "Returns an object containing information about the currency.\n",
809 "Number of satoshis per base unit"},
811 "Number of digits to the right of the decimal point."},
830 std::string index_name) {
832 if (!index_name.empty() && index_name != summary.name) {
837 entry.
pushKV(
"synced", summary.synced);
838 entry.
pushKV(
"best_block_height", summary.best_block_height);
839 ret_summary.
pushKV(summary.name, entry);
846 "Returns the status of one or all available indices currently "
847 "running in the node.\n",
851 "Filter results for an index with a specific name."},
860 "The name of the index",
863 "Whether the index is synced or not"},
865 "The block height to which the index is synced"},
876 const std::string index_name =
877 request.params[0].isNull() ?
"" : request.params[0].get_str();
902 "Returns the node time information\n",
911 "The time offset gathered from the other nodes on the "
914 "The adjusted timestamp of this node"},
954 for (
const auto &c : commands) {
static constexpr Amount SATOSHI
void ForEachBlockFilterIndex(std::function< void(BlockFilterIndex &)> fn)
Iterate over all running block filter indexes, invoking fn on each.
RecursiveMutex cs_main
Global state.
const CChainParams & Params()
Return the currently selected parameters.
#define CHECK_NONFATAL(condition)
Identity function.
void DisableCategory(LogFlags category)
void EnableCategory(LogFlags category)
uint32_t GetCategoryMask() const
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
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 secp256k1 private key.
bool IsValid() const
Check whether this private key is valid.
static constexpr unsigned int COMPRESSED_SIZE
static constexpr unsigned int SIZE
secp256k1:
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::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
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, const Config &config)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
CKey DecodeSecret(const std::string &str)
BCLog::Logger & LogInstance()
MessageVerificationResult MessageVerify(const CChainParams ¶ms, const std::string &address, const std::string &signature, const std::string &message)
Verify a signed message.
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a 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)
static void EnableOrDisableLogCategories(UniValue cats, bool enable)
static UniValue RPCLockedMemoryInfo()
static RPCHelpMan mockscheduler()
static RPCHelpMan getmemoryinfo()
static RPCHelpMan getcurrencyinfo()
static RPCHelpMan getdescriptorinfo()
static RPCHelpMan echo(const std::string &name)
static UniValue SummaryToJSON(const IndexSummary &&summary, std::string index_name)
static RPCHelpMan gettime()
static RPCHelpMan echojson()
static RPCHelpMan deriveaddresses()
static RPCHelpMan signmessagewithprivkey()
static RPCHelpMan createmultisig()
static RPCHelpMan verifymessage()
static RPCHelpMan validateaddress()
static RPCHelpMan getindexinfo()
static bool isNull(const AnyVoteItem &item)
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_MISC_ERROR
General application defined errors std::exception thrown in command handling.
@ 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.
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)
const std::string EXAMPLE_ADDRESS
Example CashAddr address used in multiple RPCExamples.
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)
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 > 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)
Returns true if each character in str is a hex character, and has an even number of hex digits.
static const Currency & get()
std::map< CKeyID, CKey > keys
@ 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.
NodeContext struct containing references to chain state and connection state.
bool error(const char *fmt, const Args &...args)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
int64_t GetAdjustedTime()
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are:
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
const UniValue NullUniValue