Raven Core  3.0.0
P2P Digital Currency
misc.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "base58.h"
8 #include "chain.h"
9 #include "clientversion.h"
10 #include "core_io.h"
11 #include "init.h"
12 #include "validation.h"
13 #include "httpserver.h"
14 #include "net.h"
15 #include "netbase.h"
16 #include "rpc/blockchain.h"
17 #include "rpc/server.h"
18 #include "timedata.h"
19 #include "txmempool.h"
20 #include "util.h"
21 #include "utilstrencodings.h"
22 #ifdef ENABLE_WALLET
23 #include "wallet/rpcwallet.h"
24 #include "wallet/wallet.h"
25 #include "wallet/walletdb.h"
26 #endif
27 #include "warnings.h"
28 
29 #include <stdint.h>
30 #ifdef HAVE_MALLOC_INFO
31 #include <malloc.h>
32 #endif
33 
34 #include <univalue.h>
35 
50 {
51  if (request.fHelp || request.params.size() != 0)
52  throw std::runtime_error(
53  "getinfo\n"
54  "\nDEPRECATED. Returns an object containing various state info.\n"
55  "\nResult:\n"
56  "{\n"
57  " \"deprecation-warning\": \"...\" (string) warning that the getinfo command is deprecated and will be removed in 0.16\n"
58  " \"version\": xxxxx, (numeric) the server version\n"
59  " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
60  " \"walletversion\": xxxxx, (numeric) the wallet version\n"
61  " \"balance\": xxxxxxx, (numeric) the total Ravencoin balance of the wallet\n"
62  " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
63  " \"timeoffset\": xxxxx, (numeric) the time offset\n"
64  " \"connections\": xxxxx, (numeric) the number of connections\n"
65  " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
66  " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
67  " \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
68  " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n"
69  " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
70  " \"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"
71  " \"paytxfee\": x.xxxx, (numeric) the transaction fee set in " + CURRENCY_UNIT + "/kB\n"
72  " \"relayfee\": x.xxxx, (numeric) minimum relay fee for transactions in " + CURRENCY_UNIT + "/kB\n"
73  " \"errors\": \"...\" (string) any error messages\n"
74  "}\n"
75  "\nExamples:\n"
76  + HelpExampleCli("getinfo", "")
77  + HelpExampleRpc("getinfo", "")
78  );
79 
80 #ifdef ENABLE_WALLET
81  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
82 
83  LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : nullptr);
84 #else
85  LOCK(cs_main);
86 #endif
87 
88  proxyType proxy;
89  GetProxy(NET_IPV4, proxy);
90 
92  obj.push_back(Pair("deprecation-warning", "WARNING: getinfo is deprecated and will be fully removed in 0.16."
93  " Projects should transition to using getblockchaininfo, getnetworkinfo, and getwalletinfo before upgrading to 0.16"));
94  obj.push_back(Pair("version", CLIENT_VERSION));
95  obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
96 #ifdef ENABLE_WALLET
97  if (pwallet) {
98  obj.push_back(Pair("walletversion", pwallet->GetVersion()));
99  obj.push_back(Pair("balance", ValueFromAmount(pwallet->GetBalance())));
100  }
101 #endif
102  obj.push_back(Pair("blocks", (int)chainActive.Height()));
103  obj.push_back(Pair("timeoffset", GetTimeOffset()));
104  if(g_connman)
105  obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
106  obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : std::string())));
107  obj.push_back(Pair("difficulty", (double)GetDifficulty()));
108  obj.push_back(Pair("testnet", Params().NetworkIDString() == CBaseChainParams::TESTNET));
109 #ifdef ENABLE_WALLET
110  if (pwallet) {
111  obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime()));
112  obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
113  }
114  if (pwallet && pwallet->IsCrypted()) {
115  obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
116  }
117  obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
118 #endif
119  obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
120  obj.push_back(Pair("errors", GetWarnings("statusbar")));
121  return obj;
122 }
123 
124 
125 #ifdef ENABLE_WALLET
126 class DescribeAddressVisitor : public boost::static_visitor<UniValue>
127 {
128 public:
129  CWallet * const pwallet;
130 
131  explicit DescribeAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {}
132 
133  UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }
134 
135  UniValue operator()(const CKeyID &keyID) const {
137  CPubKey vchPubKey;
138  obj.push_back(Pair("isscript", false));
139  if (pwallet && pwallet->GetPubKey(keyID, vchPubKey)) {
140  obj.push_back(Pair("pubkey", HexStr(vchPubKey)));
141  obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed()));
142  }
143  return obj;
144  }
145 
146  UniValue operator()(const CScriptID &scriptID) const {
148  CScript subscript;
149  obj.push_back(Pair("isscript", true));
150  if (pwallet && pwallet->GetCScript(scriptID, subscript)) {
151  std::vector<CTxDestination> addresses;
152  txnouttype whichType;
153  int nRequired;
154  ExtractDestinations(subscript, whichType, addresses, nRequired);
155  obj.push_back(Pair("script", GetTxnOutputType(whichType)));
156  obj.push_back(Pair("hex", HexStr(subscript.begin(), subscript.end())));
158  for (const CTxDestination& addr : addresses) {
159  a.push_back(EncodeDestination(addr));
160  }
161  obj.push_back(Pair("addresses", a));
162  if (whichType == TX_MULTISIG)
163  obj.push_back(Pair("sigsrequired", nRequired));
164  }
165  return obj;
166  }
167 };
168 #endif
169 
171 {
172  if (request.fHelp || request.params.size() != 1)
173  throw std::runtime_error(
174  "validateaddress \"address\"\n"
175  "\nReturn information about the given raven address.\n"
176  "\nArguments:\n"
177  "1. \"address\" (string, required) The raven address to validate\n"
178  "\nResult:\n"
179  "{\n"
180  " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n"
181  " \"address\" : \"address\", (string) The raven address validated\n"
182  " \"scriptPubKey\" : \"hex\", (string) The hex encoded scriptPubKey generated by the address\n"
183  " \"ismine\" : true|false, (boolean) If the address is yours or not\n"
184  " \"iswatchonly\" : true|false, (boolean) If the address is watchonly\n"
185  " \"isscript\" : true|false, (boolean) If the key is a script\n"
186  " \"script\" : \"type\" (string, optional) The output script type. Possible types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash, witness_v0_scripthash\n"
187  " \"hex\" : \"hex\", (string, optional) The redeemscript for the p2sh address\n"
188  " \"addresses\" (string, optional) Array of addresses associated with the known redeemscript\n"
189  " [\n"
190  " \"address\"\n"
191  " ,...\n"
192  " ]\n"
193  " \"sigsrequired\" : xxxxx (numeric, optional) Number of signatures required to spend multisig output\n"
194  " \"pubkey\" : \"publickeyhex\", (string) The hex value of the raw public key\n"
195  " \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
196  " \"account\" : \"account\" (string) DEPRECATED. The account associated with the address, \"\" is the default account\n"
197  " \"timestamp\" : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
198  " \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath if the key is HD and available\n"
199  " \"hdmasterkeyid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n"
200  "}\n"
201  "\nExamples:\n"
202  + HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
203  + HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
204  );
205 
206 #ifdef ENABLE_WALLET
207  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
208 
209  LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : nullptr);
210 #else
211  LOCK(cs_main);
212 #endif
213 
214  CTxDestination dest = DecodeDestination(request.params[0].get_str());
215  bool isValid = IsValidDestination(dest);
216 
218  ret.push_back(Pair("isvalid", isValid));
219  if (isValid)
220  {
221  std::string currentAddress = EncodeDestination(dest);
222  ret.push_back(Pair("address", currentAddress));
223 
224  CScript scriptPubKey = GetScriptForDestination(dest);
225  ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
226 
227 #ifdef ENABLE_WALLET
228  isminetype mine = pwallet ? IsMine(*pwallet, dest) : ISMINE_NO;
229  ret.push_back(Pair("ismine", bool(mine & ISMINE_SPENDABLE)));
230  ret.push_back(Pair("iswatchonly", bool(mine & ISMINE_WATCH_ONLY)));
231  UniValue detail = boost::apply_visitor(DescribeAddressVisitor(pwallet), dest);
232  ret.pushKVs(detail);
233  if (pwallet && pwallet->mapAddressBook.count(dest)) {
234  ret.push_back(Pair("account", pwallet->mapAddressBook[dest].name));
235  }
236  if (pwallet) {
237  const auto& meta = pwallet->mapKeyMetadata;
238  const CKeyID *keyID = boost::get<CKeyID>(&dest);
239  auto it = keyID ? meta.find(*keyID) : meta.end();
240  if (it == meta.end()) {
241  it = meta.find(CScriptID(scriptPubKey));
242  }
243  if (it != meta.end()) {
244  ret.push_back(Pair("timestamp", it->second.nCreateTime));
245  if (!it->second.hdKeypath.empty()) {
246  ret.push_back(Pair("hdkeypath", it->second.hdKeypath));
247  ret.push_back(Pair("hdseedid", it->second.hd_seed_id.GetHex()));
248  }
249  }
250  }
251 #endif
252  }
253  return ret;
254 }
255 
256 // Needed even with !ENABLE_WALLET, to pass (ignored) pointers around
257 class CWallet;
258 
262 CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& params)
263 {
264  int nRequired = params[0].get_int();
265  const UniValue& keys = params[1].get_array();
266 
267  // Gather public keys
268  if (nRequired < 1)
269  throw std::runtime_error("a multisignature address must require at least one key to redeem");
270  if ((int)keys.size() < nRequired)
271  throw std::runtime_error(
272  strprintf("not enough keys supplied "
273  "(got %u keys, but need at least %d to redeem)", keys.size(), nRequired));
274  if (keys.size() > 16)
275  throw std::runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number");
276  std::vector<CPubKey> pubkeys;
277  pubkeys.resize(keys.size());
278  for (unsigned int i = 0; i < keys.size(); i++)
279  {
280  const std::string& ks = keys[i].get_str();
281 #ifdef ENABLE_WALLET
282  // Case 1: Raven address and we have full public key:
284  if (pwallet && IsValidDestination(dest)) {
285  const CKeyID *keyID = boost::get<CKeyID>(&dest);
286  if (!keyID) {
287  throw std::runtime_error(strprintf("%s does not refer to a key", ks));
288  }
289  CPubKey vchPubKey;
290  if (!pwallet->GetPubKey(*keyID, vchPubKey)) {
291  throw std::runtime_error(strprintf("no full public key for address %s", ks));
292  }
293  if (!vchPubKey.IsFullyValid())
294  throw std::runtime_error(" Invalid public key: "+ks);
295  pubkeys[i] = vchPubKey;
296  }
297 
298  // Case 2: hex public key
299  else
300 #endif
301  if (IsHex(ks))
302  {
303  CPubKey vchPubKey(ParseHex(ks));
304  if (!vchPubKey.IsFullyValid())
305  throw std::runtime_error(" Invalid public key: "+ks);
306  pubkeys[i] = vchPubKey;
307  }
308  else
309  {
310  throw std::runtime_error(" Invalid public key: "+ks);
311  }
312  }
313  CScript result = GetScriptForMultisig(nRequired, pubkeys);
314 
315  if (result.size() > MAX_SCRIPT_ELEMENT_SIZE)
316  throw std::runtime_error(
317  strprintf("redeemScript exceeds size limit: %d > %d", result.size(), MAX_SCRIPT_ELEMENT_SIZE));
318 
319  return result;
320 }
321 
323 {
324 #ifdef ENABLE_WALLET
325  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
326 #else
327  CWallet * const pwallet = nullptr;
328 #endif
329 
330  if (request.fHelp || request.params.size() < 2 || request.params.size() > 2)
331  {
332  std::string msg = "createmultisig nrequired [\"key\",...]\n"
333  "\nCreates a multi-signature address with n signature of m keys required.\n"
334  "It returns a json object with the address and redeemScript.\n"
335 
336  "\nArguments:\n"
337  "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
338  "2. \"keys\" (string, required) A json array of keys which are raven addresses or hex-encoded public keys\n"
339  " [\n"
340  " \"key\" (string) raven address or hex-encoded public key\n"
341  " ,...\n"
342  " ]\n"
343 
344  "\nResult:\n"
345  "{\n"
346  " \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n"
347  " \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n"
348  "}\n"
349 
350  "\nExamples:\n"
351  "\nCreate a multisig address from 2 addresses\n"
352  + HelpExampleCli("createmultisig", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
353  "\nAs a json rpc call\n"
354  + HelpExampleRpc("createmultisig", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
355  ;
356  throw std::runtime_error(msg);
357  }
358 
359  // Construct using pay-to-script-hash:
360  CScript inner = _createmultisig_redeemScript(pwallet, request.params);
361  CScriptID innerID(inner);
362 
363  UniValue result(UniValue::VOBJ);
364  result.push_back(Pair("address", EncodeDestination(innerID)));
365  result.push_back(Pair("redeemScript", HexStr(inner.begin(), inner.end())));
366 
367  return result;
368 }
369 
371 {
372  if (request.fHelp || request.params.size() != 3)
373  throw std::runtime_error(
374  "verifymessage \"address\" \"signature\" \"message\"\n"
375  "\nVerify a signed message\n"
376  "\nArguments:\n"
377  "1. \"address\" (string, required) The raven 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"
380  "\nResult:\n"
381  "true|false (boolean) If the signature is verified or not.\n"
382  "\nExamples:\n"
383  "\nUnlock the wallet for 30 seconds\n"
384  + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
385  "\nCreate the signature\n"
386  + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
387  "\nVerify the signature\n"
388  + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
389  "\nAs json rpc\n"
390  + HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\"")
391  );
392 
393  LOCK(cs_main);
394 
395  std::string strAddress = request.params[0].get_str();
396  std::string strSign = request.params[1].get_str();
397  std::string strMessage = request.params[2].get_str();
398 
399  CTxDestination destination = DecodeDestination(strAddress);
400  if (!IsValidDestination(destination)) {
401  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
402  }
403 
404  const CKeyID *keyID = boost::get<CKeyID>(&destination);
405  if (!keyID) {
406  throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
407  }
408 
409  bool fInvalid = false;
410  std::vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
411 
412  if (fInvalid)
413  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
414 
415  CHashWriter ss(SER_GETHASH, 0);
416  ss << strMessageMagic;
417  ss << strMessage;
418 
419  CPubKey pubkey;
420  if (!pubkey.RecoverCompact(ss.GetHash(), vchSig))
421  return false;
422 
423  return (pubkey.GetID() == *keyID);
424 }
425 
427 {
428  if (request.fHelp || request.params.size() != 2)
429  throw std::runtime_error(
430  "signmessagewithprivkey \"privkey\" \"message\"\n"
431  "\nSign a message with the private key of an address\n"
432  "\nArguments:\n"
433  "1. \"privkey\" (string, required) The private key to sign the message with.\n"
434  "2. \"message\" (string, required) The message to create a signature of.\n"
435  "\nResult:\n"
436  "\"signature\" (string) The signature of the message encoded in base 64\n"
437  "\nExamples:\n"
438  "\nCreate the signature\n"
439  + HelpExampleCli("signmessagewithprivkey", "\"privkey\" \"my message\"") +
440  "\nVerify the signature\n"
441  + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
442  "\nAs json rpc\n"
443  + HelpExampleRpc("signmessagewithprivkey", "\"privkey\", \"my message\"")
444  );
445 
446  std::string strPrivkey = request.params[0].get_str();
447  std::string strMessage = request.params[1].get_str();
448 
449  CRavenSecret vchSecret;
450  bool fGood = vchSecret.SetString(strPrivkey);
451  if (!fGood)
452  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
453  CKey key = vchSecret.GetKey();
454  if (!key.IsValid())
455  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
456 
457  CHashWriter ss(SER_GETHASH, 0);
458  ss << strMessageMagic;
459  ss << strMessage;
460 
461  std::vector<unsigned char> vchSig;
462  if (!key.SignCompact(ss.GetHash(), vchSig))
463  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
464 
465  return EncodeBase64(vchSig.data(), vchSig.size());
466 }
467 
469 {
470  if (request.fHelp || request.params.size() != 1)
471  throw std::runtime_error(
472  "setmocktime timestamp\n"
473  "\nSet the local time to given timestamp (-regtest only)\n"
474  "\nArguments:\n"
475  "1. timestamp (integer, required) Unix seconds-since-epoch timestamp\n"
476  " Pass 0 to go back to using the system time."
477  );
478 
479  if (!Params().MineBlocksOnDemand())
480  throw std::runtime_error("setmocktime for regression testing (-regtest mode) only");
481 
482  // For now, don't change mocktime if we're in the middle of validation, as
483  // this could have an effect on mempool time-based eviction, as well as
484  // IsCurrentForFeeEstimation() and IsInitialBlockDownload().
485  // TODO: figure out the right way to synchronize around mocktime, and
486  // ensure all call sites of GetTime() are accessing this safely.
487  LOCK(cs_main);
488 
489  RPCTypeCheck(request.params, {UniValue::VNUM});
490  SetMockTime(request.params[0].get_int64());
491 
492  return NullUniValue;
493 }
494 
495 static UniValue RPCLockedMemoryInfo()
496 {
499  obj.push_back(Pair("used", uint64_t(stats.used)));
500  obj.push_back(Pair("free", uint64_t(stats.free)));
501  obj.push_back(Pair("total", uint64_t(stats.total)));
502  obj.push_back(Pair("locked", uint64_t(stats.locked)));
503  obj.push_back(Pair("chunks_used", uint64_t(stats.chunks_used)));
504  obj.push_back(Pair("chunks_free", uint64_t(stats.chunks_free)));
505  return obj;
506 }
507 
508 #ifdef HAVE_MALLOC_INFO
509 static std::string RPCMallocInfo()
510 {
511  char *ptr = nullptr;
512  size_t size = 0;
513  FILE *f = open_memstream(&ptr, &size);
514  if (f) {
515  malloc_info(0, f);
516  fclose(f);
517  if (ptr) {
518  std::string rv(ptr, size);
519  free(ptr);
520  return rv;
521  }
522  }
523  return "";
524 }
525 #endif
526 
528 {
529  /* Please, avoid using the word "pool" here in the RPC interface or help,
530  * as users will undoubtedly confuse it with the other "memory pool"
531  */
532  if (request.fHelp || request.params.size() > 1)
533  throw std::runtime_error(
534  "getmemoryinfo (\"mode\")\n"
535  "Returns an object containing information about memory usage.\n"
536  "Arguments:\n"
537  "1. \"mode\" determines what kind of information is returned. This argument is optional, the default mode is \"stats\".\n"
538  " - \"stats\" returns general statistics about memory usage in the daemon.\n"
539  " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+).\n"
540  "\nResult (mode \"stats\"):\n"
541  "{\n"
542  " \"locked\": { (json object) Information about locked memory manager\n"
543  " \"used\": xxxxx, (numeric) Number of bytes used\n"
544  " \"free\": xxxxx, (numeric) Number of bytes available in current arenas\n"
545  " \"total\": xxxxxxx, (numeric) Total number of bytes managed\n"
546  " \"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"
547  " \"chunks_used\": xxxxx, (numeric) Number allocated chunks\n"
548  " \"chunks_free\": xxxxx, (numeric) Number unused chunks\n"
549  " }\n"
550  "}\n"
551  "\nResult (mode \"mallocinfo\"):\n"
552  "\"<malloc version=\"1\">...\"\n"
553  "\nExamples:\n"
554  + HelpExampleCli("getmemoryinfo", "")
555  + HelpExampleRpc("getmemoryinfo", "")
556  );
557 
558  std::string mode = request.params[0].isNull() ? "stats" : request.params[0].get_str();
559  if (mode == "stats") {
561  obj.push_back(Pair("locked", RPCLockedMemoryInfo()));
562  return obj;
563  } else if (mode == "mallocinfo") {
564 #ifdef HAVE_MALLOC_INFO
565  return RPCMallocInfo();
566 #else
567  throw JSONRPCError(RPC_INVALID_PARAMETER, "mallocinfo is only available when compiled with glibc 2.10+");
568 #endif
569  } else {
570  throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown mode " + mode);
571  }
572 }
573 
574 uint32_t getCategoryMask(UniValue cats) {
575  cats = cats.get_array();
576  uint32_t mask = 0;
577  for (unsigned int i = 0; i < cats.size(); ++i) {
578  uint32_t flag = 0;
579  std::string cat = cats[i].get_str();
580  if (!GetLogCategory(&flag, &cat)) {
581  throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown logging category " + cat);
582  }
583  mask |= flag;
584  }
585  return mask;
586 }
587 
589 {
590  if (request.fHelp || request.params.size() > 2) {
591  throw std::runtime_error(
592  "logging [include,...] <exclude>\n"
593  "Gets and sets the logging configuration.\n"
594  "When called without an argument, returns the list of categories that are currently being debug logged.\n"
595  "When called with arguments, adds or removes categories from debug logging.\n"
596  "The valid logging categories are: " + ListLogCategories() + "\n"
597  "libevent logging is configured on startup and cannot be modified by this RPC during runtime."
598  "Arguments:\n"
599  "1. \"include\" (array of strings) add debug logging for these categories.\n"
600  "2. \"exclude\" (array of strings) remove debug logging for these categories.\n"
601  "\nResult: <categories> (string): a list of the logging categories that are active.\n"
602  "\nExamples:\n"
603  + HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
604  + HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")
605  );
606  }
607 
608  uint32_t originalLogCategories = logCategories;
609  if (request.params[0].isArray()) {
610  logCategories |= getCategoryMask(request.params[0]);
611  }
612 
613  if (request.params[1].isArray()) {
614  logCategories &= ~getCategoryMask(request.params[1]);
615  }
616 
617  // Update libevent logging if BCLog::LIBEVENT has changed.
618  // If the library version doesn't allow it, UpdateHTTPServerLogging() returns false,
619  // in which case we should clear the BCLog::LIBEVENT flag.
620  // Throw an error if the user has explicitly asked to change only the libevent
621  // flag and it failed.
622  uint32_t changedLogCategories = originalLogCategories ^ logCategories;
623  if (changedLogCategories & BCLog::LIBEVENT) {
624  if (!UpdateHTTPServerLogging(logCategories & BCLog::LIBEVENT)) {
625  logCategories &= ~BCLog::LIBEVENT;
626  if (changedLogCategories == BCLog::LIBEVENT) {
627  throw JSONRPCError(RPC_INVALID_PARAMETER, "libevent logging cannot be updated when using libevent before v2.1.1.");
628  }
629  }
630  }
631 
632  UniValue result(UniValue::VOBJ);
633  std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories();
634  for (const auto& logCatActive : vLogCatActive) {
635  result.pushKV(logCatActive.category, logCatActive.active);
636  }
637 
638  return result;
639 }
640 
641 UniValue echo(const JSONRPCRequest& request)
642 {
643  if (request.fHelp)
644  throw std::runtime_error(
645  "echo|echojson \"message\" ...\n"
646  "\nSimply echo back the input arguments. This command is for testing.\n"
647  "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in"
648  "raven-cli and the GUI. There is no server-side difference."
649  );
650 
651  return request.params;
652 }
653 
654 bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address)
655 {
656  if (type == 2) {
657  address = CRavenAddress(CScriptID(hash)).ToString();
658  } else if (type == 1) {
659  address = CRavenAddress(CKeyID(hash)).ToString();
660  } else {
661  return false;
662  }
663  return true;
664 }
665 
666 bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint160, int> > &addresses)
667 {
668  if (params[0].isStr()) {
669  CRavenAddress address(params[0].get_str());
670  uint160 hashBytes;
671  int type = 0;
672  if (!address.GetIndexKey(hashBytes, type)) {
673  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
674  }
675  addresses.push_back(std::make_pair(hashBytes, type));
676  } else if (params[0].isObject()) {
677 
678  UniValue addressValues = find_value(params[0].get_obj(), "addresses");
679  if (!addressValues.isArray()) {
680  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Addresses is expected to be an array");
681  }
682 
683  std::vector<UniValue> values = addressValues.getValues();
684 
685  for (std::vector<UniValue>::iterator it = values.begin(); it != values.end(); ++it) {
686 
687  CRavenAddress address(it->get_str());
688  uint160 hashBytes;
689  int type = 0;
690  if (!address.GetIndexKey(hashBytes, type)) {
691  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
692  }
693  addresses.push_back(std::make_pair(hashBytes, type));
694  }
695  } else {
696  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
697  }
698 
699  return true;
700 }
701 
702 bool heightSort(std::pair<CAddressUnspentKey, CAddressUnspentValue> a,
703  std::pair<CAddressUnspentKey, CAddressUnspentValue> b) {
704  return a.second.blockHeight < b.second.blockHeight;
705 }
706 
707 bool timestampSort(std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> a,
708  std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> b) {
709  return a.second.time < b.second.time;
710 }
711 
713 {
714  if (request.fHelp || request.params.size() > 2)
715  throw std::runtime_error(
716  "getaddressmempool\n"
717  "\nReturns all mempool deltas for an address (requires addressindex to be enabled).\n"
718  "\nArguments:\n"
719  "{\n"
720  " \"addresses\"\n"
721  " [\n"
722  " \"address\" (string) The base58check encoded address\n"
723  " ,...\n"
724  " ]\n"
725  "},\n"
726  "\"includeAssets\" (boolean, optional, default false) If true this will return an expanded result which includes asset deltas\n"
727  "\nResult:\n"
728  "[\n"
729  " {\n"
730  " \"address\" (string) The base58check encoded address\n"
731  " \"assetName\" (string) The name of the associated asset (RVN for Ravencoin)\n"
732  " \"txid\" (string) The related txid\n"
733  " \"index\" (number) The related input or output index\n"
734  " \"satoshis\" (number) The difference of satoshis\n"
735  " \"timestamp\" (number) The time the transaction entered the mempool (seconds)\n"
736  " \"prevtxid\" (string) The previous txid (if spending)\n"
737  " \"prevout\" (string) The previous transaction output index (if spending)\n"
738  " }\n"
739  "]\n"
740  "\nExamples:\n"
741  + HelpExampleCli("getaddressmempool", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
742  + HelpExampleRpc("getaddressmempool", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
743  + HelpExampleCli("getaddressmempool", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}', true")
744  + HelpExampleRpc("getaddressmempool", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}, true")
745  );
746 
747  std::vector<std::pair<uint160, int> > addresses;
748 
749  if (!getAddressesFromParams(request.params, addresses)) {
750  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
751  }
752 
753  bool includeAssets = false;
754  if (request.params.size() > 1) {
755  includeAssets = request.params[1].get_bool();
756  }
757 
758  if (includeAssets)
759  if (!AreAssetsDeployed())
760  throw JSONRPCError(RPC_INVALID_PARAMETER, "Assets aren't active. includeAssets can't be true.");
761 
762  std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > indexes;
763 
764  if (includeAssets) {
765  if (!mempool.getAddressIndex(addresses, indexes)) {
766  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
767  }
768  } else {
769  if (!mempool.getAddressIndex(addresses, RVN, indexes)) {
770  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
771  }
772  }
773 
774  std::sort(indexes.begin(), indexes.end(), timestampSort);
775 
776  UniValue result(UniValue::VARR);
777 
778  for (std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> >::iterator it = indexes.begin();
779  it != indexes.end(); it++) {
780 
781  std::string address;
782  if (!getAddressFromIndex(it->first.type, it->first.addressBytes, address)) {
783  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown address type");
784  }
785 
786  UniValue delta(UniValue::VOBJ);
787  delta.push_back(Pair("address", address));
788  delta.push_back(Pair("assetName", it->first.asset));
789  delta.push_back(Pair("txid", it->first.txhash.GetHex()));
790  delta.push_back(Pair("index", (int)it->first.index));
791  delta.push_back(Pair("satoshis", it->second.amount));
792  delta.push_back(Pair("timestamp", it->second.time));
793  if (it->second.amount < 0) {
794  delta.push_back(Pair("prevtxid", it->second.prevhash.GetHex()));
795  delta.push_back(Pair("prevout", (int)it->second.prevout));
796  }
797  result.push_back(delta);
798  }
799 
800  return result;
801 }
802 
804 {
805  if (request.fHelp || request.params.size() != 1)
806  throw std::runtime_error(
807  "getaddressutxos\n"
808  "\nReturns all unspent outputs for an address (requires addressindex to be enabled).\n"
809  "\nArguments:\n"
810  "{\n"
811  " \"addresses\"\n"
812  " [\n"
813  " \"address\" (string) The base58check encoded address\n"
814  " ,...\n"
815  " ],\n"
816  " \"chainInfo\", (boolean, optional, default false) Include chain info with results\n"
817  " \"assetName\" (string, optional) Get UTXOs for a particular asset instead of RVN ('*' for all assets).\n"
818  "}\n"
819  "\nResult\n"
820  "[\n"
821  " {\n"
822  " \"address\" (string) The address base58check encoded\n"
823  " \"assetName\" (string) The asset associated with the UTXOs (RVN for Ravencoin)\n"
824  " \"txid\" (string) The output txid\n"
825  " \"height\" (number) The block height\n"
826  " \"outputIndex\" (number) The output index\n"
827  " \"script\" (strin) The script hex encoded\n"
828  " \"satoshis\" (number) The number of satoshis of the output\n"
829  " }\n"
830  "]\n"
831  "\nExamples:\n"
832  + HelpExampleCli("getaddressutxos", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
833  + HelpExampleRpc("getaddressutxos", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
834  + HelpExampleCli("getaddressutxos", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"],\"assetName\":\"MY_ASSET\"}'")
835  + HelpExampleRpc("getaddressutxos", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"],\"assetName\":\"MY_ASSET\"}")
836  );
837 
838  bool includeChainInfo = false;
839  std::string assetName = RVN;
840  if (request.params[0].isObject()) {
841  UniValue chainInfo = find_value(request.params[0].get_obj(), "chainInfo");
842  if (chainInfo.isBool()) {
843  includeChainInfo = chainInfo.get_bool();
844  }
845  UniValue assetNameParam = find_value(request.params[0].get_obj(), "assetName");
846  if (assetNameParam.isStr()) {
847  if (!AreAssetsDeployed())
848  throw JSONRPCError(RPC_INVALID_PARAMETER, "Assets aren't active. assetName can't be specified.");
849  assetName = assetNameParam.get_str();
850  }
851  }
852 
853  std::vector<std::pair<uint160, int> > addresses;
854 
855  if (!getAddressesFromParams(request.params, addresses)) {
856  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
857  }
858 
859  std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
860 
861  for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++) {
862  if (assetName == "*") {
863  if (!GetAddressUnspent((*it).first, (*it).second, unspentOutputs)) {
864  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
865  }
866  } else {
867  if (!GetAddressUnspent((*it).first, (*it).second, assetName, unspentOutputs)) {
868  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
869  }
870  }
871  }
872 
873  std::sort(unspentOutputs.begin(), unspentOutputs.end(), heightSort);
874 
875  UniValue utxos(UniValue::VARR);
876 
877  for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) {
878  UniValue output(UniValue::VOBJ);
879  std::string address;
880  if (!getAddressFromIndex(it->first.type, it->first.hashBytes, address)) {
881  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown address type");
882  }
883 
884  std::string assetNameOut = "RVN";
885  if (assetName != "RVN") {
886  CAmount _amount;
887  if (!GetAssetInfoFromScript(it->second.script, assetNameOut, _amount)) {
888  throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't decode asset script");
889  }
890  }
891 
892  output.push_back(Pair("address", address));
893  output.push_back(Pair("assetName", assetNameOut));
894  output.push_back(Pair("txid", it->first.txhash.GetHex()));
895  output.push_back(Pair("outputIndex", (int)it->first.index));
896  output.push_back(Pair("script", HexStr(it->second.script.begin(), it->second.script.end())));
897  output.push_back(Pair("satoshis", it->second.satoshis));
898  output.push_back(Pair("height", it->second.blockHeight));
899  utxos.push_back(output);
900  }
901 
902  if (includeChainInfo) {
903  UniValue result(UniValue::VOBJ);
904  result.push_back(Pair("utxos", utxos));
905 
906  LOCK(cs_main);
907  result.push_back(Pair("hash", chainActive.Tip()->GetBlockHash().GetHex()));
908  result.push_back(Pair("height", (int)chainActive.Height()));
909  return result;
910  } else {
911  return utxos;
912  }
913 }
914 
916 {
917  if (request.fHelp || request.params.size() != 1 || !request.params[0].isObject())
918  throw std::runtime_error(
919  "getaddressdeltas\n"
920  "\nReturns all changes for an address (requires addressindex to be enabled).\n"
921  "\nArguments:\n"
922  "{\n"
923  " \"addresses\"\n"
924  " [\n"
925  " \"address\" (string) The base58check encoded address\n"
926  " ,...\n"
927  " ]\n"
928  " \"start\" (number) The start block height\n"
929  " \"end\" (number) The end block height\n"
930  " \"chainInfo\" (boolean) Include chain info in results, only applies if start and end specified\n"
931  " \"assetName\" (string, optional) Get deltas for a particular asset instead of RVN.\n"
932  "}\n"
933  "\nResult:\n"
934  "[\n"
935  " {\n"
936  " \"assetName\" (string) The asset associated with the deltas (RVN for Ravencoin)\n"
937  " \"satoshis\" (number) The difference of satoshis\n"
938  " \"txid\" (string) The related txid\n"
939  " \"index\" (number) The related input or output index\n"
940  " \"height\" (number) The block height\n"
941  " \"address\" (string) The base58check encoded address\n"
942  " }\n"
943  "]\n"
944  "\nExamples:\n"
945  + HelpExampleCli("getaddressdeltas", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
946  + HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
947  + HelpExampleCli("getaddressdeltas", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"],\"assetName\":\"MY_ASSET\"}'")
948  + HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"],\"assetName\":\"MY_ASSET\"}")
949  );
950 
951 
952  UniValue startValue = find_value(request.params[0].get_obj(), "start");
953  UniValue endValue = find_value(request.params[0].get_obj(), "end");
954 
955  UniValue chainInfo = find_value(request.params[0].get_obj(), "chainInfo");
956  bool includeChainInfo = false;
957  if (chainInfo.isBool()) {
958  includeChainInfo = chainInfo.get_bool();
959  }
960 
961  std::string assetName = RVN;
962  UniValue assetNameParam = find_value(request.params[0].get_obj(), "assetName");
963  if (assetNameParam.isStr()) {
964  if (!AreAssetsDeployed())
965  throw JSONRPCError(RPC_INVALID_PARAMETER, "Assets aren't active. assetName can't be specified.");
966  assetName = assetNameParam.get_str();
967  }
968 
969  int start = 0;
970  int end = 0;
971 
972  if (startValue.isNum() && endValue.isNum()) {
973  start = startValue.get_int();
974  end = endValue.get_int();
975  if (start <= 0 || end <= 0) {
976  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Start and end is expected to be greater than zero");
977  }
978  if (end < start) {
979  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "End value is expected to be greater than start");
980  }
981  }
982 
983  std::vector<std::pair<uint160, int> > addresses;
984 
985  if (!getAddressesFromParams(request.params, addresses)) {
986  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
987  }
988 
989  std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
990 
991  for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++) {
992  if (start > 0 && end > 0) {
993  if (!GetAddressIndex((*it).first, (*it).second, assetName, addressIndex, start, end)) {
994  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
995  }
996  } else {
997  if (!GetAddressIndex((*it).first, (*it).second, assetName, addressIndex)) {
998  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
999  }
1000  }
1001  }
1002 
1003  UniValue deltas(UniValue::VARR);
1004 
1005  for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) {
1006  std::string address;
1007  if (!getAddressFromIndex(it->first.type, it->first.hashBytes, address)) {
1008  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown address type");
1009  }
1010 
1011  UniValue delta(UniValue::VOBJ);
1012  delta.push_back(Pair("assetName", it->first.asset));
1013  delta.push_back(Pair("satoshis", it->second));
1014  delta.push_back(Pair("txid", it->first.txhash.GetHex()));
1015  delta.push_back(Pair("index", (int)it->first.index));
1016  delta.push_back(Pair("blockindex", (int)it->first.txindex));
1017  delta.push_back(Pair("height", it->first.blockHeight));
1018  delta.push_back(Pair("address", address));
1019  deltas.push_back(delta);
1020  }
1021 
1022  UniValue result(UniValue::VOBJ);
1023 
1024  if (includeChainInfo && start > 0 && end > 0) {
1025  LOCK(cs_main);
1026 
1027  if (start > chainActive.Height() || end > chainActive.Height()) {
1028  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Start or end is outside chain range");
1029  }
1030 
1031  CBlockIndex* startIndex = chainActive[start];
1032  CBlockIndex* endIndex = chainActive[end];
1033 
1034  UniValue startInfo(UniValue::VOBJ);
1035  UniValue endInfo(UniValue::VOBJ);
1036 
1037  startInfo.push_back(Pair("hash", startIndex->GetBlockHash().GetHex()));
1038  startInfo.push_back(Pair("height", start));
1039 
1040  endInfo.push_back(Pair("hash", endIndex->GetBlockHash().GetHex()));
1041  endInfo.push_back(Pair("height", end));
1042 
1043  result.push_back(Pair("deltas", deltas));
1044  result.push_back(Pair("start", startInfo));
1045  result.push_back(Pair("end", endInfo));
1046 
1047  return result;
1048  } else {
1049  return deltas;
1050  }
1051 }
1052 
1054 {
1055  if (request.fHelp || request.params.size() > 2)
1056  throw std::runtime_error(
1057  "getaddressbalance\n"
1058  "\nReturns the balance for an address(es) (requires addressindex to be enabled).\n"
1059  "\nArguments:\n"
1060  "{\n"
1061  " \"addresses:\"\n"
1062  " [\n"
1063  " \"address\" (string) The base58check encoded address\n"
1064  " ,...\n"
1065  " ]\n"
1066  "},\n"
1067  "\"includeAssets\" (boolean, optional, default false) If true this will return an expanded result which includes asset balances\n"
1068  "\n"
1069  "\nResult:\n"
1070  "{\n"
1071  " \"balance\" (string) The current balance in satoshis\n"
1072  " \"received\" (string) The total number of satoshis received (including change)\n"
1073  "}\n"
1074  "OR\n"
1075  "[\n"
1076  " {\n"
1077  " \"assetName\" (string) The asset associated with the balance (RVN for Ravencoin)\n"
1078  " \"balance\" (string) The current balance in satoshis\n"
1079  " \"received\" (string) The total number of satoshis received (including change)\n"
1080  " },...\n"
1081  "\n]"
1082  "\nExamples:\n"
1083  + HelpExampleCli("getaddressbalance", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
1084  + HelpExampleCli("getaddressbalance", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}', true")
1085  + HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
1086  + HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}, true")
1087  );
1088 
1089  std::vector<std::pair<uint160, int> > addresses;
1090 
1091  if (!getAddressesFromParams(request.params, addresses)) {
1092  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
1093  }
1094 
1095  bool includeAssets = false;
1096  if (request.params.size() > 1) {
1097  includeAssets = request.params[1].get_bool();
1098  }
1099 
1100  if (includeAssets) {
1101  if (!AreAssetsDeployed())
1102  throw JSONRPCError(RPC_INVALID_PARAMETER, "Assets aren't active. includeAssets can't be true.");
1103 
1104  std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
1105 
1106  for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++) {
1107  if (!GetAddressIndex((*it).first, (*it).second, addressIndex)) {
1108  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
1109  }
1110  }
1111 
1112  //assetName -> (received, balance)
1113  std::map<std::string, std::pair<CAmount, CAmount>> balances;
1114 
1115  for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it = addressIndex.begin();
1116  it != addressIndex.end(); it++) {
1117  std::string assetName = it->first.asset;
1118  if (balances.count(assetName) == 0) {
1119  balances[assetName] = std::make_pair(0, 0);
1120  }
1121  if (it->second > 0) {
1122  balances[assetName].first += it->second;
1123  }
1124  balances[assetName].second += it->second;
1125  }
1126 
1127  UniValue result(UniValue::VARR);
1128 
1129  for (std::map<std::string, std::pair<CAmount, CAmount>>::const_iterator it = balances.begin();
1130  it != balances.end(); it++) {
1131  UniValue balance(UniValue::VOBJ);
1132  balance.push_back(Pair("assetName", it->first));
1133  balance.push_back(Pair("balance", it->second.second));
1134  balance.push_back(Pair("received", it->second.first));
1135  result.push_back(balance);
1136  }
1137 
1138  return result;
1139 
1140  } else {
1141  std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
1142 
1143  for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++) {
1144  if (!GetAddressIndex((*it).first, (*it).second, RVN, addressIndex)) {
1145  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
1146  }
1147  }
1148 
1149  CAmount balance = 0;
1150  CAmount received = 0;
1151 
1152  for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it = addressIndex.begin();
1153  it != addressIndex.end(); it++) {
1154  if (it->second > 0) {
1155  received += it->second;
1156  }
1157  balance += it->second;
1158  }
1159 
1160  UniValue result(UniValue::VOBJ);
1161  result.push_back(Pair("balance", balance));
1162  result.push_back(Pair("received", received));
1163 
1164  return result;
1165  }
1166 
1167 }
1168 
1170 {
1171  if (request.fHelp || request.params.size() > 2)
1172  throw std::runtime_error(
1173  "getaddresstxids\n"
1174  "\nReturns the txids for an address(es) (requires addressindex to be enabled).\n"
1175  "\nArguments:\n"
1176  "{\n"
1177  " \"addresses\"\n"
1178  " [\n"
1179  " \"address\" (string) The base58check encoded address\n"
1180  " ,...\n"
1181  " ]\n"
1182  " \"start\" (number, optional) The start block height\n"
1183  " \"end\" (number, optional) The end block height\n"
1184  "},\n"
1185  "\"includeAssets\" (boolean, optional, default false) If true this will return an expanded result which includes asset transactions\n"
1186  "\nResult:\n"
1187  "[\n"
1188  " \"transactionid\" (string) The transaction id\n"
1189  " ,...\n"
1190  "]\n"
1191  "\nExamples:\n"
1192  + HelpExampleCli("getaddresstxids", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
1193  + HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
1194  + HelpExampleCli("getaddresstxids", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}', true")
1195  + HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}, true")
1196  );
1197 
1198  std::vector<std::pair<uint160, int> > addresses;
1199 
1200  if (!getAddressesFromParams(request.params, addresses)) {
1201  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
1202  }
1203 
1204  int start = 0;
1205  int end = 0;
1206  if (request.params[0].isObject()) {
1207  UniValue startValue = find_value(request.params[0].get_obj(), "start");
1208  UniValue endValue = find_value(request.params[0].get_obj(), "end");
1209  if (startValue.isNum() && endValue.isNum()) {
1210  start = startValue.get_int();
1211  end = endValue.get_int();
1212  }
1213  }
1214 
1215  bool includeAssets = false;
1216  if (request.params.size() > 1) {
1217  includeAssets = request.params[1].get_bool();
1218  }
1219 
1220  if (includeAssets)
1221  if (!AreAssetsDeployed())
1222  throw JSONRPCError(RPC_INVALID_PARAMETER, "Assets aren't active. includeAssets can't be true.");
1223 
1224  std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
1225 
1226  for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++) {
1227  if (includeAssets) {
1228  if (start > 0 && end > 0) {
1229  if (!GetAddressIndex((*it).first, (*it).second, addressIndex, start, end)) {
1230  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
1231  }
1232  } else {
1233  if (!GetAddressIndex((*it).first, (*it).second, addressIndex)) {
1234  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
1235  }
1236  }
1237  } else {
1238  if (start > 0 && end > 0) {
1239  if (!GetAddressIndex((*it).first, (*it).second, RVN, addressIndex, start, end)) {
1240  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
1241  }
1242  } else {
1243  if (!GetAddressIndex((*it).first, (*it).second, RVN, addressIndex)) {
1244  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
1245  }
1246  }
1247  }
1248  }
1249 
1250  std::set<std::pair<int, std::string> > txids;
1251  UniValue result(UniValue::VARR);
1252 
1253  for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) {
1254  int height = it->first.blockHeight;
1255  std::string txid = it->first.txhash.GetHex();
1256 
1257  if (addresses.size() > 1) {
1258  txids.insert(std::make_pair(height, txid));
1259  } else {
1260  if (txids.insert(std::make_pair(height, txid)).second) {
1261  result.push_back(txid);
1262  }
1263  }
1264  }
1265 
1266  if (addresses.size() > 1) {
1267  for (std::set<std::pair<int, std::string> >::const_iterator it=txids.begin(); it!=txids.end(); it++) {
1268  result.push_back(it->second);
1269  }
1270  }
1271 
1272  return result;
1273 
1274 }
1275 
1277 {
1278 
1279  if (request.fHelp || request.params.size() != 1 || !request.params[0].isObject())
1280  throw std::runtime_error(
1281  "getspentinfo\n"
1282  "\nReturns the txid and index where an output is spent.\n"
1283  "\nArguments:\n"
1284  "{\n"
1285  " \"txid\" (string) The hex string of the txid\n"
1286  " \"index\" (number) The start block height\n"
1287  "}\n"
1288  "\nResult:\n"
1289  "{\n"
1290  " \"txid\" (string) The transaction id\n"
1291  " \"index\" (number) The spending input index\n"
1292  " ,...\n"
1293  "}\n"
1294  "\nExamples:\n"
1295  + HelpExampleCli("getspentinfo", "'{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}'")
1296  + HelpExampleRpc("getspentinfo", "{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}")
1297  );
1298 
1299  UniValue txidValue = find_value(request.params[0].get_obj(), "txid");
1300  UniValue indexValue = find_value(request.params[0].get_obj(), "index");
1301 
1302  if (!txidValue.isStr() || !indexValue.isNum()) {
1303  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid txid or index");
1304  }
1305 
1306  uint256 txid = ParseHashV(txidValue, "txid");
1307  int outputIndex = indexValue.get_int();
1308 
1309  CSpentIndexKey key(txid, outputIndex);
1310  CSpentIndexValue value;
1311 
1312  if (!GetSpentIndex(key, value)) {
1313  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to get spent info");
1314  }
1315 
1316  UniValue obj(UniValue::VOBJ);
1317  obj.push_back(Pair("txid", value.txid.GetHex()));
1318  obj.push_back(Pair("index", (int)value.inputIndex));
1319  obj.push_back(Pair("height", value.blockHeight));
1320 
1321  return obj;
1322 }
1323 
1324 static const CRPCCommand commands[] =
1325 { // category name actor (function) argNames
1326  // --------------------- ------------------------ ----------------------- ----------
1327  { "control", "getinfo", &getinfo, {} }, /* uses wallet if enabled */
1328  { "control", "getmemoryinfo", &getmemoryinfo, {"mode"} },
1329  { "util", "validateaddress", &validateaddress, {"address"} }, /* uses wallet if enabled */
1330  { "util", "createmultisig", &createmultisig, {"nrequired","keys"} },
1331  { "util", "verifymessage", &verifymessage, {"address","signature","message"} },
1332  { "util", "signmessagewithprivkey", &signmessagewithprivkey, {"privkey","message"} },
1333 
1334  /* Address index */
1335  { "addressindex", "getaddressmempool", &getaddressmempool, {"addresses","includeAssets"} },
1336  { "addressindex", "getaddressutxos", &getaddressutxos, {"addresses"} },
1337  { "addressindex", "getaddressdeltas", &getaddressdeltas, {"addresses"} },
1338  { "addressindex", "getaddresstxids", &getaddresstxids, {"addresses","includeAssets"} },
1339  { "addressindex", "getaddressbalance", &getaddressbalance, {"addresses","includeAssets"} },
1340 
1341  /* Blockchain */
1342  { "blockchain", "getspentinfo", &getspentinfo, {} },
1343 
1344  /* Not shown in help */
1345  { "hidden", "setmocktime", &setmocktime, {"timestamp"}},
1346  { "hidden", "echo", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
1347  { "hidden", "echojson", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
1348  { "hidden", "logging", &logging, {"include", "exclude"}},
1349 };
1350 
1352 {
1353  for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
1354  t.appendCommand(commands[vcidx].name, &commands[vcidx]);
1355 }
CTxMemPool mempool
bool isObject() const
Definition: univalue.h:86
std::string ListLogCategories()
Returns a string with the log categories.
Definition: util.cpp:277
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:89
bool isBool() const
Definition: univalue.h:82
const std::vector< UniValue > & getValues() const
int64_t GetOldestKeyPoolTime()
Definition: wallet.cpp:4090
bool GetAddressIndex(uint160 addressHash, int type, std::string assetName, std::vector< std::pair< CAddressIndexKey, CAmount > > &addressIndex, int start, int end)
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
Raven RPC command dispatcher.
Definition: server.h:143
bool get_bool() const
static LockedPoolManager & Instance()
Return the current instance, or create it once.
Definition: lockedpool.h:214
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:829
CCriticalSection cs_wallet
Definition: wallet.h:751
Definition: util.h:82
unsigned int inputIndex
Definition: spentindex.h:42
#define strprintf
Definition: tinyformat.h:1054
bool IsCrypted() const
Definition: crypter.h:143
bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
Definition: keystore.cpp:56
int Height() const
Return the maximal height in the chain.
Definition: chain.h:479
void SetMockTime(int64_t nMockTimeIn)
Definition: utiltime.cpp:30
CCriticalSection cs_main
Global state.
Definition: validation.cpp:72
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:402
CTxDestination DecodeDestination(const std::string &str)
Definition: base58.cpp:333
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
Definition: ismine.cpp:32
const std::string & get_str() const
bool isNum() const
Definition: univalue.h:84
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:527
const UniValue & get_array() const
const std::string CURRENCY_UNIT
Definition: feerate.cpp:11
bool isStr() const
Definition: univalue.h:83
unsigned int GetKeyPoolSize()
Definition: wallet.h:1101
UniValue verifymessage(const JSONRPCRequest &request)
Definition: misc.cpp:370
double GetDifficulty(const CBlockIndex *blockindex)
Get the difficulty of the net wrt to the given block index, or the chain tip if not provided...
Definition: blockchain.cpp:56
int64_t get_int64() const
bool getAddressIndex(std::vector< std::pair< uint160, int > > &addresses, std::string assetName, std::vector< std::pair< CMempoolAddressDeltaKey, CMempoolAddressDelta > > &results)
Definition: txmempool.cpp:505
std::map< CTxDestination, CKeyMetadata > mapKeyMetadata
Definition: wallet.h:776
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are: ...
Definition: timedata.cpp:30
std::atomic< uint32_t > logCategories
bool pushKVs(const UniValue &obj)
Definition: univalue.cpp:148
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:41
UniValue ValueFromAmount(const CAmount &amount, const int8_t units)
Definition: core_write.cpp:38
CKey GetKey()
Definition: base58.cpp:301
UniValue getaddressbalance(const JSONRPCRequest &request)
Definition: misc.cpp:1053
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:299
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:143
const std::string strMessageMagic
Definition: validation.cpp:117
bool GetAddressUnspent(uint160 addressHash, int type, std::string assetName, std::vector< std::pair< CAddressUnspentKey, CAddressUnspentValue > > &unspentOutputs)
CAmount GetBalance() const
Definition: wallet.cpp:2010
void RPCTypeCheck(const UniValue &params, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: server.cpp:58
unsigned char * end()
Definition: uint256.h:62
Invalid, missing or duplicate parameter.
Definition: protocol.h:54
UniValue createmultisig(const JSONRPCRequest &request)
Definition: misc.cpp:322
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: server.cpp:125
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
Definition: crypter.cpp:260
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:236
bool GetIndexKey(uint160 &hashBytes, int &type) const
Definition: base58.cpp:276
bool SignCompact(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Create a compact signature (65 bytes), which allows reconstructing the used public key...
Definition: key.cpp:190
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Parse a standard scriptPubKey with one or more destination addresses.
Definition: standard.cpp:251
std::string ToString() const
Definition: base58.cpp:194
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
uint256 GetBlockHash() const
Definition: chain.h:294
iterator end()
Definition: prevector.h:293
#define LOCK2(cs1, cs2)
Definition: sync.h:177
std::string name
Definition: server.h:135
bool push_back(const UniValue &val)
Definition: univalue.cpp:110
bool AreAssetsDeployed()
RVN START.
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid()) ...
Definition: pubkey.cpp:204
bool MineBlocksOnDemand() const
Make miner stop after a block is found.
Definition: chainparams.h:73
base58-encoded Raven addresses.
Definition: base58.h:103
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
Definition: validation.cpp:104
UniValue params
Definition: server.h:45
isminetype
IsMine() return codes.
Definition: ismine.h:18
#define LOCK(cs)
Definition: sync.h:176
UniValue getinfo(const JSONRPCRequest &request)
Definition: misc.cpp:49
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
Definition: pubkey.cpp:184
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
Definition: wallet.h:1114
An encapsulated public key.
Definition: pubkey.h:40
bool SetString(const char *pszSecret)
Definition: base58.cpp:316
bool IsHex(const std::string &str)
Unexpected type was passed as parameter.
Definition: protocol.h:51
const char * GetTxnOutputType(txnouttype t)
Get the name of a txnouttype as a C string, or nullptr if unknown.
Definition: standard.cpp:24
bool GetAssetInfoFromScript(const CScript &scriptPubKey, std::string &strName, CAmount &nAmount)
Definition: assets.cpp:3423
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:135
UniValue getaddressdeltas(const JSONRPCRequest &request)
Definition: misc.cpp:915
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:75
int get_int() const
Invalid address or key.
Definition: protocol.h:52
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Raven scriptPubKey for the given CTxDestination.
Definition: standard.cpp:347
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:522
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
UniValue getaddresstxids(const JSONRPCRequest &request)
Definition: misc.cpp:1169
bool isNull() const
Definition: univalue.h:79
UniValue setmocktime(const JSONRPCRequest &request)
Definition: misc.cpp:468
UniValue validateaddress(const JSONRPCRequest &request)
Definition: misc.cpp:170
UniValue getmemoryinfo(const JSONRPCRequest &request)
Definition: misc.cpp:527
UniValue getaddressutxos(const JSONRPCRequest &request)
Definition: misc.cpp:803
UniValue signmessagewithprivkey(const JSONRPCRequest &request)
Definition: misc.cpp:426
bool heightSort(std::pair< CAddressUnspentKey, CAddressUnspentValue > a, std::pair< CAddressUnspentKey, CAddressUnspentValue > b)
Definition: misc.cpp:702
CScript _createmultisig_redeemScript(CWallet *const pwallet, const UniValue &params)
Used by addmultisigaddress / createmultisig:
Definition: misc.cpp:262
uint256 GetHash()
Definition: hash.h:250
bool fHelp
Definition: server.h:46
txnouttype
Definition: standard.h:57
256-bit opaque blob.
Definition: uint256.h:123
CService proxy
Definition: netbase.h:37
uint32_t getCategoryMask(UniValue cats)
Definition: misc.cpp:574
bool IsValid() const
Definition: netbase.h:35
#define ARRAYLEN(array)
std::string EncodeDestination(const CTxDestination &dest)
Definition: base58.cpp:326
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:172
const CChainParams & Params()
Return the currently selected parameters.
A base58-encoded secret key.
Definition: base58.h:123
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:396
void RegisterMiscRPCCommands(CRPCTable &t)
Register miscellaneous RPC commands.
Definition: misc.cpp:1351
const UniValue & get_obj() const
std::string ToStringIPPort() const
Definition: netaddress.cpp:588
UniValue getaddressmempool(const JSONRPCRequest &request)
Definition: misc.cpp:712
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:30
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:448
UniValue logging(const JSONRPCRequest &request)
Definition: misc.cpp:588
std::string GetHex() const
Definition: uint256.cpp:22
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:673
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:81
160-bit opaque blob.
Definition: uint256.h:112
const UniValue NullUniValue
Definition: univalue.cpp:15
CWallet * GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
Definition: rpcwallet.cpp:40
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE)
Transaction fee set by the user.
iterator begin()
Definition: prevector.h:291
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:23
static const std::string TESTNET
A writer stream (for serialization) that computes a 256-bit hash.
Definition: hash.h:231
size_type size() const
Definition: prevector.h:283
bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address)
Definition: misc.cpp:654
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition: standard.cpp:368
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:552
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:55
size_t size() const
Definition: univalue.h:70
An encapsulated private key.
Definition: key.h:36
Stats stats() const
Get pool usage statistics.
Definition: lockedpool.cpp:305
UniValue getspentinfo(const JSONRPCRequest &request)
Definition: misc.cpp:1276
bool GetLogCategory(uint32_t *f, const std::string *str)
Return true if str parses as a log category and set the flags in f.
Definition: util.cpp:256
UniValue echo(const JSONRPCRequest &request)
Definition: misc.cpp:641
bool isArray() const
Definition: univalue.h:85
bool getAddressesFromParams(const UniValue &params, std::vector< std::pair< uint160, int > > &addresses)
Definition: misc.cpp:666
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:42
std::vector< CLogCategoryActive > ListActiveLogCategories()
Returns a vector of the active log categories.
Definition: util.cpp:294
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().
Definition: wallet.h:952
bool timestampSort(std::pair< CMempoolAddressDeltaKey, CMempoolAddressDelta > a, std::pair< CMempoolAddressDeltaKey, CMempoolAddressDelta > b)
Definition: misc.cpp:707
std::string EncodeBase64(const unsigned char *pch, size_t len)
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
Definition: httpserver.cpp:426
Memory statistics.
Definition: lockedpool.h:137
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:88
std::vector< unsigned char > ParseHex(const char *psz)
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:168