11 #include <validation.h> 25 #ifdef HAVE_MALLOC_INFO 34 throw std::runtime_error(
35 "validateaddress \"address\"\n" 36 "\nReturn information about the given bitcoin address.\n" 37 "DEPRECATION WARNING: Parts of this command have been deprecated and moved to getaddressinfo. Clients must\n" 38 "transition to using getaddressinfo to access this information before upgrading to v0.18. The following deprecated\n" 39 "fields have moved to getaddressinfo and will only be shown here with -deprecatedrpc=validateaddress: ismine, iswatchonly,\n" 40 "script, hex, pubkeys, sigsrequired, pubkey, addresses, embedded, iscompressed, account, timestamp, hdkeypath, kdmasterkeyid.\n" 42 "1. \"address\" (string, required) The bitcoin address to validate\n" 45 " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n" 46 " \"address\" : \"address\", (string) The bitcoin address validated\n" 47 " \"scriptPubKey\" : \"hex\", (string) The hex-encoded scriptPubKey generated by the address\n" 48 " \"isscript\" : true|false, (boolean) If the key is a script\n" 49 " \"iswitness\" : true|false, (boolean) If the address is a witness address\n" 50 " \"witness_version\" : version (numeric, optional) The version number of the witness program\n" 51 " \"witness_program\" : \"hex\" (string, optional) The hex value of the witness program\n" 54 +
HelpExampleCli(
"validateaddress",
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
55 +
HelpExampleRpc(
"validateaddress",
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
81 std::string msg =
"createmultisig nrequired [\"key\",...] ( \"address_type\" )\n" 82 "\nCreates a multi-signature address with n signature of m keys required.\n" 83 "It returns a json object with the address and redeemScript.\n" 85 "1. nrequired (numeric, required) The number of required signatures out of the n keys.\n" 86 "2. \"keys\" (string, required) A json array of hex-encoded public keys\n" 88 " \"key\" (string) The hex-encoded public key\n" 91 "3. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is legacy.\n" 95 " \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n" 96 " \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n" 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\\\"]\"")
105 throw std::runtime_error(msg);
112 std::vector<CPubKey> pubkeys;
113 for (
unsigned int i = 0; i < keys.
size(); ++i) {
114 if (
IsHex(keys[i].get_str()) && (keys[i].
get_str().length() == 66 || keys[i].
get_str().length() == 130)) {
136 result.pushKV(
"redeemScript",
HexStr(inner.
begin(), inner.
end()));
144 throw std::runtime_error(
145 "verifymessage \"address\" \"signature\" \"message\"\n" 146 "\nVerify a signed message\n" 148 "1. \"address\" (string, required) The bitcoin address to use for the signature.\n" 149 "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n" 150 "3. \"message\" (string, required) The message that was signed.\n" 152 "true|false (boolean) If the signature is verified or not.\n" 154 "\nUnlock the wallet for 30 seconds\n" 156 "\nCreate the signature\n" 157 +
HelpExampleCli(
"signmessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
158 "\nVerify the signature\n" 159 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
160 "\nAs a JSON-RPC call\n" 161 +
HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\"")
175 const CKeyID *keyID = boost::get<CKeyID>(&destination);
180 bool fInvalid =
false;
181 std::vector<unsigned char> vchSig =
DecodeBase64(strSign.c_str(), &fInvalid);
194 return (pubkey.
GetID() == *keyID);
200 throw std::runtime_error(
201 "signmessagewithprivkey \"privkey\" \"message\"\n" 202 "\nSign a message with the private key of an address\n" 204 "1. \"privkey\" (string, required) The private key to sign the message with.\n" 205 "2. \"message\" (string, required) The message to create a signature of.\n" 207 "\"signature\" (string) The signature of the message encoded in base 64\n" 209 "\nCreate the signature\n" 210 +
HelpExampleCli(
"signmessagewithprivkey",
"\"privkey\" \"my message\"") +
211 "\nVerify the signature\n" 212 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
213 "\nAs a JSON-RPC call\n" 214 +
HelpExampleRpc(
"signmessagewithprivkey",
"\"privkey\", \"my message\"")
229 std::vector<unsigned char> vchSig;
239 throw std::runtime_error(
240 "setmocktime timestamp\n" 241 "\nSet the local time to given timestamp (-regtest only)\n" 243 "1. timestamp (integer, required) Unix seconds-since-epoch timestamp\n" 244 " Pass 0 to go back to using the system time." 248 throw std::runtime_error(
"setmocktime for regression testing (-regtest mode) only");
263 static UniValue RPCLockedMemoryInfo()
267 obj.pushKV(
"used", uint64_t(stats.
used));
268 obj.pushKV(
"free", uint64_t(stats.
free));
269 obj.pushKV(
"total", uint64_t(stats.
total));
270 obj.pushKV(
"locked", uint64_t(stats.
locked));
271 obj.pushKV(
"chunks_used", uint64_t(stats.
chunks_used));
272 obj.pushKV(
"chunks_free", uint64_t(stats.
chunks_free));
276 #ifdef HAVE_MALLOC_INFO 277 static std::string RPCMallocInfo()
281 FILE *f = open_memstream(&ptr, &size);
286 std::string rv(ptr, size);
301 throw std::runtime_error(
302 "getmemoryinfo (\"mode\")\n" 303 "Returns an object containing information about memory usage.\n" 305 "1. \"mode\" determines what kind of information is returned. This argument is optional, the default mode is \"stats\".\n" 306 " - \"stats\" returns general statistics about memory usage in the daemon.\n" 307 " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+).\n" 308 "\nResult (mode \"stats\"):\n" 310 " \"locked\": { (json object) Information about locked memory manager\n" 311 " \"used\": xxxxx, (numeric) Number of bytes used\n" 312 " \"free\": xxxxx, (numeric) Number of bytes available in current arenas\n" 313 " \"total\": xxxxxxx, (numeric) Total number of bytes managed\n" 314 " \"locked\": xxxxxx, (numeric) 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.\n" 315 " \"chunks_used\": xxxxx, (numeric) Number allocated chunks\n" 316 " \"chunks_free\": xxxxx, (numeric) Number unused chunks\n" 319 "\nResult (mode \"mallocinfo\"):\n" 320 "\"<malloc version=\"1\">...\"\n" 327 if (mode ==
"stats") {
329 obj.pushKV(
"locked", RPCLockedMemoryInfo());
331 }
else if (mode ==
"mallocinfo") {
332 #ifdef HAVE_MALLOC_INFO 333 return RPCMallocInfo();
342 static void EnableOrDisableLogCategories(
UniValue cats,
bool enable) {
344 for (
unsigned int i = 0; i < cats.
size(); ++i) {
345 std::string cat = cats[i].
get_str();
363 throw std::runtime_error(
364 "logging ( <include> <exclude> )\n" 365 "Gets and sets the logging configuration.\n" 366 "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n" 367 "When called with arguments, adds or removes categories from debug logging and return the lists above.\n" 368 "The arguments are evaluated in order \"include\", \"exclude\".\n" 369 "If an item is both included and excluded, it will thus end up being excluded.\n" 371 "In addition, the following are available as category names with special meanings:\n" 372 " - \"all\", \"1\" : represent all logging categories.\n" 373 " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n" 375 "1. \"include\" (array of strings, optional) A json array of categories to add debug logging\n" 377 " \"category\" (string) the valid logging category\n" 380 "2. \"exclude\" (array of strings, optional) A json array of categories to remove debug logging\n" 382 " \"category\" (string) the valid logging category\n" 386 "{ (json object where keys are the logging categories, and values indicates its status\n" 387 " \"category\": 0|1, (numeric) if being debug logged or not. 0:inactive, 1:active\n" 391 +
HelpExampleCli(
"logging",
"\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
398 EnableOrDisableLogCategories(request.
params[0],
true);
401 EnableOrDisableLogCategories(request.
params[1],
false);
404 uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
422 for (
const auto& logCatActive : vLogCatActive) {
423 result.
pushKV(logCatActive.category, logCatActive.active);
432 throw std::runtime_error(
433 "echo|echojson \"message\" ...\n" 434 "\nSimply echo back the input arguments. This command is for testing.\n" 435 "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in" 436 "bsha3-cli and the GUI. There is no server-side difference." 446 {
"control",
"getmemoryinfo", &getmemoryinfo, {
"mode"} },
447 {
"control",
"logging", &
logging, {
"include",
"exclude"}},
448 {
"util",
"validateaddress", &validateaddress, {
"address"} },
449 {
"util",
"createmultisig", &createmultisig, {
"nrequired",
"keys",
"address_type"} },
450 {
"util",
"verifymessage", &verifymessage, {
"address",
"signature",
"message"} },
451 {
"util",
"signmessagewithprivkey", &signmessagewithprivkey, {
"privkey",
"message"} },
454 {
"hidden",
"setmocktime", &setmocktime, {
"timestamp"}},
455 {
"hidden",
"echo", &echo, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
456 {
"hidden",
"echojson", &echo, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
462 for (
unsigned int vcidx = 0; vcidx <
ARRAYLEN(commands); vcidx++)
void EnableCategory(LogFlags flag)
CScript CreateMultisigRedeemscript(const int required, const std::vector< CPubKey > &pubkeys)
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
Bitcoin RPC command dispatcher.
static LockedPoolManager & Instance()
Return the current instance, or create it once.
std::string ListLogCategories()
Returns a string with the log categories.
UniValue ret(UniValue::VARR)
void SetMockTime(int64_t nMockTimeIn)
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
CPubKey HexToPubKey(const std::string &hex_in)
UniValue DescribeAddress(const CTxDestination &dest)
const std::string & get_str() const
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const UniValue & get_array() const
int64_t get_int64() const
bool pushKVs(const UniValue &obj)
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
const std::string strMessageMagic
Invalid, missing or duplicate parameter.
bool SignCompact(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Create a compact signature (65 bytes), which allows reconstructing the used public key...
bool push_back(const UniValue &val)
bool MineBlocksOnDemand() const
Make miner stop after a block is found.
boost::variant< CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
CTxDestination AddAndGetDestinationForScript(CKeyStore &keystore, const CScript &script, OutputType type)
Get a destination of the requested type (if possible) to the specified script.
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
An encapsulated public key.
bool IsHex(const std::string &str)
Unexpected type was passed as parameter.
uint32_t GetCategoryMask() const
void DisableCategory(LogFlags flag)
bool pushKV(const std::string &key, const UniValue &val)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
bool WillLogCategory(LogFlags category) const
CTxDestination DecodeDestination(const std::string &str)
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
void RegisterMiscRPCCommands(CRPCTable &t)
Register miscellaneous RPC commands.
A reference to a CKey: the Hash360 of its serialized public key.
UniValue logging(const JSONRPCRequest &request)
const UniValue NullUniValue
std::string EncodeDestination(const CTxDestination &dest)
A writer stream (for serialization) that computes a 256-bit SHA-3-256 hash.
UniValue JSONRPCError(int code, const std::string &message)
An encapsulated private key.
Stats stats() const
Get pool usage statistics.
CKey DecodeSecret(const std::string &str)
bool ParseOutputType(const std::string &type, OutputType &output_type)
std::vector< CLogCategoryActive > ListActiveLogCategories()
Returns a vector of the active log categories.
Basic key store, that keeps keys in an address->secret map.
BCLog::Logger *const g_logger
NOTE: the logger instances is leaked on exit.
std::string EncodeBase64(const unsigned char *pch, size_t len)
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
bool IsValid() const
Check whether this private key is valid.