11 #include <validation.h> 28 #ifdef HAVE_MALLOC_INFO 50 throw std::runtime_error(
52 "\nDEPRECATED. Returns an object containing various state info.\n" 55 " \"deprecation-warning\": \"...\" (string) warning that the getinfo command is deprecated and will be removed in 0.16\n" 56 " \"version\": xxxxx, (numeric) the server version\n" 57 " \"protocolversion\": xxxxx, (numeric) the protocol version\n" 58 " \"walletversion\": xxxxx, (numeric) the wallet version\n" 59 " \"balance\": xxxxxxx, (numeric) the total fabcoin balance of the wallet\n" 60 " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" 61 " \"timeoffset\": xxxxx, (numeric) the time offset\n" 62 " \"connections\": xxxxx, (numeric) the number of connections\n" 63 " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n" 64 " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" 65 " \"testnet\": true|false, (boolean) if the server is using testnet or not\n" 66 " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n" 67 " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n" 68 " \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n" 69 " \"paytxfee\": x.xxxx, (numeric) the transaction fee set in " +
CURRENCY_UNIT +
"/kB\n" 70 " \"relayfee\": x.xxxx, (numeric) minimum relay fee for transactions in " +
CURRENCY_UNIT +
"/kB\n" 71 " \"errors\": \"...\" (string) any error messages\n" 90 obj.
push_back(
Pair(
"deprecation-warning",
"WARNING: getinfo is deprecated and will be fully removed in 0.16." 91 " Projects should transition to using getblockchaininfo, getnetworkinfo, and getwalletinfo before upgrading to 0.16"));
124 class DescribeAddressVisitor :
public boost::static_visitor<UniValue>
129 DescribeAddressVisitor(
CWallet *_pwallet) : pwallet(_pwallet) {}
137 if (pwallet && pwallet->
GetPubKey(keyID, vchPubKey)) {
148 if (pwallet && pwallet->
GetCScript(scriptID, subscript)) {
149 std::vector<CTxDestination> addresses;
170 throw std::runtime_error(
171 "validateaddress \"address\"\n" 172 "\nReturn information about the given fabcoin address.\n" 174 "1. \"address\" (string, required) The fabcoin address to validate\n" 177 " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n" 178 " \"address\" : \"address\", (string) The fabcoin address validated\n" 179 " \"scriptPubKey\" : \"hex\", (string) The hex encoded scriptPubKey generated by the address\n" 180 " \"ismine\" : true|false, (boolean) If the address is yours or not\n" 181 " \"iswatchonly\" : true|false, (boolean) If the address is watchonly\n" 182 " \"isscript\" : true|false, (boolean) If the key is a script\n" 183 " \"script\" : \"type\" (string, optional) The output script type. Possible types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash, witness_v0_scripthash\n" 184 " \"hex\" : \"hex\", (string, optional) The redeemscript for the p2sh address\n" 185 " \"addresses\" (string, optional) Array of addresses associated with the known redeemscript\n" 190 " \"sigsrequired\" : xxxxx (numeric, optional) Number of signatures required to spend multisig output\n" 191 " \"pubkey\" : \"publickeyhex\", (string) The hex value of the raw public key\n" 192 " \"iscompressed\" : true|false, (boolean) If the address is compressed\n" 193 " \"account\" : \"account\" (string) DEPRECATED. The account associated with the address, \"\" is the default account\n" 194 " \"timestamp\" : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n" 195 " \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath if the key is HD and available\n" 196 " \"hdmasterkeyid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n" 199 +
HelpExampleCli(
"validateaddress",
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
200 +
HelpExampleRpc(
"validateaddress",
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
212 bool isValid =
address.IsValid();
219 std::string currentAddress =
address.ToString();
229 UniValue detail = boost::apply_visitor(DescribeAddressVisitor(pwallet), dest);
237 auto it =
address.GetKeyID(keyID) ? meta.find(keyID) : meta.end();
238 if (it == meta.end()) {
241 if (it != meta.end()) {
243 if (!it->second.hdKeypath.empty()) {
245 ret.
push_back(
Pair(
"hdmasterkeyid", it->second.hdMasterKeyID.GetHex()));
262 int nRequired = params[0].
get_int();
267 throw std::runtime_error(
"a multisignature address must require at least one key to redeem");
268 if ((
int)keys.
size() < nRequired)
269 throw std::runtime_error(
271 "(got %u keys, but need at least %d to redeem)", keys.
size(), nRequired));
272 if (keys.
size() > 16)
273 throw std::runtime_error(
"Number of addresses involved in the multisignature address creation > 16\nReduce the number");
274 std::vector<CPubKey> pubkeys;
275 pubkeys.resize(keys.
size());
276 for (
unsigned int i = 0; i < keys.
size(); i++)
278 const std::string& ks = keys[i].
get_str();
282 if (pwallet && address.
IsValid()) {
285 throw std::runtime_error(
286 strprintf(
"%s does not refer to a key",ks));
288 if (!pwallet->
GetPubKey(keyID, vchPubKey)) {
289 throw std::runtime_error(
290 strprintf(
"no full public key for address %s",ks));
293 throw std::runtime_error(
" Invalid public key: "+ks);
294 pubkeys[i] = vchPubKey;
304 throw std::runtime_error(
" Invalid public key: "+ks);
305 pubkeys[i] = vchPubKey;
309 throw std::runtime_error(
" Invalid public key: "+ks);
314 if (result.
size() > MAX_SCRIPT_ELEMENT_SIZE)
315 throw std::runtime_error(
316 strprintf(
"redeemScript exceeds size limit: %d > %d", result.
size(), MAX_SCRIPT_ELEMENT_SIZE));
326 CWallet *
const pwallet =
nullptr;
331 std::string msg =
"createmultisig nrequired [\"key\",...]\n" 332 "\nCreates a multi-signature address with n signature of m keys required.\n" 333 "It returns a json object with the address and redeemScript.\n" 336 "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n" 337 "2. \"keys\" (string, required) A json array of keys which are fabcoin addresses or hex-encoded public keys\n" 339 " \"key\" (string) fabcoin address or hex-encoded public key\n" 345 " \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n" 346 " \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n" 350 "\nCreate a multisig address from 2 addresses\n" 351 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
352 "\nAs a json rpc call\n" 353 +
HelpExampleRpc(
"createmultisig",
"2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
355 throw std::runtime_error(msg);
373 throw std::runtime_error(
374 "verifymessage \"address\" \"signature\" \"message\"\n" 375 "\nVerify a signed message\n" 377 "1. \"address\" (string, required) The fabcoin address to use for the signature.\n" 378 "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n" 379 "3. \"message\" (string, required) The message that was signed.\n" 381 "true|false (boolean) If the signature is verified or not.\n" 383 "\nUnlock the wallet for 30 seconds\n" 385 "\nCreate the signature\n" 386 +
HelpExampleCli(
"signmessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
387 "\nVerify the signature\n" 388 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
390 +
HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\"")
407 bool fInvalid =
false;
408 std::vector<unsigned char> vchSig =
DecodeBase64(strSign.c_str(), &fInvalid);
421 return (pubkey.
GetID() == keyID);
427 throw std::runtime_error(
428 "signmessagewithprivkey \"privkey\" \"message\"\n" 429 "\nSign a message with the private key of an address\n" 431 "1. \"privkey\" (string, required) The private key to sign the message with.\n" 432 "2. \"message\" (string, required) The message to create a signature of.\n" 434 "\"signature\" (string) The signature of the message encoded in base 64\n" 436 "\nCreate the signature\n" 437 +
HelpExampleCli(
"signmessagewithprivkey",
"\"privkey\" \"my message\"") +
438 "\nVerify the signature\n" 439 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
441 +
HelpExampleRpc(
"signmessagewithprivkey",
"\"privkey\", \"my message\"")
448 bool fGood = vchSecret.
SetString(strPrivkey);
459 std::vector<unsigned char> vchSig;
469 throw std::runtime_error(
470 "setmocktime timestamp\n" 471 "\nSet the local time to given timestamp (-regtest only)\n" 473 "1. timestamp (integer, required) Unix seconds-since-epoch timestamp\n" 474 " Pass 0 to go back to using the system time." 478 throw std::runtime_error(
"setmocktime for regression testing (-regtest mode) only");
493 static UniValue RPCLockedMemoryInfo()
506 #ifdef HAVE_MALLOC_INFO 507 static std::string RPCMallocInfo()
511 FILE *
f = open_memstream(&ptr, &size);
516 std::string rv(ptr, size);
531 throw std::runtime_error(
532 "getmemoryinfo (\"mode\")\n" 533 "Returns an object containing information about memory usage.\n" 535 "1. \"mode\" determines what kind of information is returned. This argument is optional, the default mode is \"stats\".\n" 536 " - \"stats\" returns general statistics about memory usage in the daemon.\n" 537 " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+).\n" 538 "\nResult (mode \"stats\"):\n" 540 " \"locked\": { (json object) Information about locked memory manager\n" 541 " \"used\": xxxxx, (numeric) Number of bytes used\n" 542 " \"free\": xxxxx, (numeric) Number of bytes available in current arenas\n" 543 " \"total\": xxxxxxx, (numeric) Total number of bytes managed\n" 544 " \"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" 545 " \"chunks_used\": xxxxx, (numeric) Number allocated chunks\n" 546 " \"chunks_free\": xxxxx, (numeric) Number unused chunks\n" 549 "\nResult (mode \"mallocinfo\"):\n" 550 "\"<malloc version=\"1\">...\"\n" 557 if (mode ==
"stats") {
561 }
else if (mode ==
"mallocinfo") {
562 #ifdef HAVE_MALLOC_INFO 563 return RPCMallocInfo();
575 for (
unsigned int i = 0; i < cats.
size(); ++i) {
577 std::string cat = cats[i].
get_str();
589 throw std::runtime_error(
590 "logging [include,...] <exclude>\n" 591 "Gets and sets the logging configuration.\n" 592 "When called without an argument, returns the list of categories that are currently being debug logged.\n" 593 "When called with arguments, adds or removes categories from debug logging.\n" 595 "libevent logging is configured on startup and cannot be modified by this RPC during runtime." 597 "1. \"include\" (array of strings) add debug logging for these categories.\n" 598 "2. \"exclude\" (array of strings) remove debug logging for these categories.\n" 599 "\nResult: <categories> (string): a list of the logging categories that are active.\n" 601 +
HelpExampleCli(
"logging",
"\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
620 uint32_t changedLogCategories = originalLogCategories ^
logCategories;
624 if (changedLogCategories == BCLog::LIBEVENT) {
632 for (
const auto& logCatActive : vLogCatActive) {
633 result.
pushKV(logCatActive.category, logCatActive.active);
642 throw std::runtime_error(
643 "echo|echojson \"message\" ...\n" 644 "\nSimply echo back the input arguments. This command is for testing.\n" 645 "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in" 646 "fabcoin-cli and the GUI. There is no server-side difference." 655 {
"control",
"getinfo", &
getinfo,
true, {} },
656 {
"control",
"getmemoryinfo", &
getmemoryinfo,
true, {
"mode"} },
658 {
"util",
"createmultisig", &
createmultisig,
true, {
"nrequired",
"keys"} },
659 {
"util",
"verifymessage", &
verifymessage,
true, {
"address",
"signature",
"message"} },
663 {
"hidden",
"setmocktime", &
setmocktime,
true, {
"timestamp"}},
664 {
"hidden",
"echo", &
echo,
true, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
665 {
"hidden",
"echojson", &
echo,
true, {
"arg0",
"arg1",
"arg2",
"arg3",
"arg4",
"arg5",
"arg6",
"arg7",
"arg8",
"arg9"}},
666 {
"hidden",
"logging", &
logging,
true, {
"include",
"exclude"}},
671 for (
unsigned int vcidx = 0; vcidx <
ARRAYLEN(commands); vcidx++)
A base58-encoded secret key.
const std::string CURRENCY_UNIT
CAmount GetFeePerK() const
Return the fee in liu for a size of 1000 bytes.
const std::string & get_str() const
std::string ListLogCategories()
Returns a string with the log categories.
bool SetString(const char *pszSecret)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
bool MineBlocksOnDemand() const
Make miner stop after a block is found.
int64_t GetOldestKeyPoolTime()
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
Fabcoin RPC command dispatcher.
UniValue createmultisig(const JSONRPCRequest &request)
static LockedPoolManager & Instance()
Return the current instance, or create it once.
std::map< CTxDestination, CAddressBookData > mapAddressBook
CCriticalSection cs_wallet
std::string ToStringIPPort() const
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
void SetMockTime(int64_t nMockTimeIn)
base58-encoded Fabcoin addresses.
UniValue ValueFromAmount(const CAmount &amount)
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
unsigned int GetKeyPoolSize()
double GetDifficulty(const CBlockIndex *blockindex)
Get the difficulty of the net wrt to the given block index, or the chain tip if not provided...
uint32_t getCategoryMask(UniValue cats)
std::map< CTxDestination, CKeyMetadata > mapKeyMetadata
Stats stats() const
Get pool usage statistics.
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are: ...
std::atomic< uint32_t > logCategories
bool pushKVs(const UniValue &obj)
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
const std::string strMessageMagic
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Invalid, missing or duplicate parameter.
UniValue getmemoryinfo(const JSONRPCRequest &request)
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
bool IsValid() const
Check whether this private key is valid.
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
UniValue getinfo(const JSONRPCRequest &request)
int Height() const
Return the maximal height in the chain.
int64_t get_int64() const
bool push_back(const UniValue &val)
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
isminetype
IsMine() return codes.
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
An encapsulated public key.
CAmount GetBalance() const
bool IsHex(const std::string &str)
Unexpected type was passed as parameter.
const char * GetTxnOutputType(txnouttype t)
UniValue logging(const JSONRPCRequest &request)
std::string ToString() const
bool pushKV(const std::string &key, const UniValue &val)
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
CScript GetScriptForDestination(const CTxDestination &dest)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValue setmocktime(const JSONRPCRequest &request)
bool IsCompressed() const
Check whether this is a compressed public key.
bool GetKeyID(CKeyID &keyID) const
UniValue validateaddress(const JSONRPCRequest &request)
void RegisterMiscRPCCommands(CRPCTable &t)
Register miscellaneous RPC commands.
UniValue signmessagewithprivkey(const JSONRPCRequest &request)
UniValue verifymessage(const JSONRPCRequest &request)
CScript _createmultisig_redeemScript(CWallet *const pwallet, const UniValue ¶ms)
Used by addmultisigaddress / createmultisig:
const UniValue & get_array() const
uint8_t const size_t const size
bool SignCompact(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Create a compact signature (65 bytes), which allows reconstructing the used public key...
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
N diff(N const &_a, N const &_b)
A reference to a CKey: the Hash160 of its serialized public key.
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid()) ...
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
std::unique_ptr< CConnman > g_connman
const UniValue NullUniValue
CWallet * GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE)
Transaction fee set by the user.
A reference to a CScript: the Hash160 of its serialization (see script.h)
static const std::string TESTNET
A writer stream (for serialization) that computes a 256-bit hash.
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
UniValue JSONRPCError(int code, const std::string &message)
struct evm_uint160be address(struct evm_env *env)
An encapsulated private key.
bool GetLogCategory(uint32_t *f, const std::string *str)
Return true if str parses as a log category and set the flags in f.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
UniValue echo(const JSONRPCRequest &request)
void mine(Client &c, int numBlocks)
std::vector< CLogCategoryActive > ListActiveLogCategories()
Returns a vector of the active log categories.
int64_t nRelockTime
Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().
std::string EncodeBase64(const unsigned char *pch, size_t len)
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
std::vector< unsigned char > ParseHex(const char *psz)