PRCYCoin  2.0.0.7rc1
P2P Digital Currency
rpcwallet.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2015-2018 The PIVX developers
5 // Copyright (c) 2018-2020 The DAPS Project developers
6 // Distributed under the MIT software license, see the accompanying
7 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 
9 #include "amount.h"
10 #include "base58.h"
11 #include "core_io.h"
12 #include "init.h"
13 #include "net.h"
14 #include "rpc/server.h"
15 #include "timedata.h"
16 #include "util.h"
17 #include "utilmoneystr.h"
18 #include "wallet/wallet.h"
19 #include "wallet/walletdb.h"
20 
21 #include <stdint.h>
22 #include <fstream>
23 #include <boost/algorithm/string.hpp>
24 
25 #include <boost/assign/list_of.hpp>
26 #include <univalue.h>
27 
28 
30 static RecursiveMutex cs_nWalletUnlockTime;
31 
33 {
34  return pwalletMain && pwalletMain->IsCrypted() ? "\nRequires wallet passphrase to be set with walletpassphrase call." : "";
35 }
36 
38 {
39  if (!pwalletMain) {
41  "Error: There is no privacy wallet, please use createprivacyaccount to create one.");
42  }
43 }
44 
45 void EnsureWalletIsUnlocked(bool fAllowAnonOnly)
46 {
47  if (pwalletMain->IsLocked() || (!fAllowAnonOnly && pwalletMain->fWalletUnlockStakingOnly))
48  throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with unlockwallet first.");
49 }
50 
51 void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
52 {
53  int confirms = wtx.GetDepthInMainChain(false);
54  int confirmsTotal = GetIXConfirmations(wtx.GetHash()) + confirms;
55  entry.push_back(Pair("confirmations", confirmsTotal));
56  entry.push_back(Pair("bcconfirmations", confirms));
57  if (wtx.IsCoinBase() || wtx.IsCoinStake())
58  entry.push_back(Pair("generated", true));
59  if (confirms > 0) {
60  entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
61  entry.push_back(Pair("blockindex", wtx.nIndex));
62  entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()));
63  }
64  uint256 hash = wtx.GetHash();
65  entry.push_back(Pair("txid", hash.GetHex()));
66  UniValue conflicts(UniValue::VARR);
67  for (const uint256& conflict : wtx.GetConflicts())
68  conflicts.push_back(conflict.GetHex());
69  entry.push_back(Pair("walletconflicts", conflicts));
70  entry.push_back(Pair("time", wtx.GetTxTime()));
71  entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
72 
73  if (wtx.hasPaymentID && pwalletMain->IsMine(wtx)) {
74  entry.push_back(Pair("paymentid", wtx.paymentID));
75  }
76 
77  for (const PAIRTYPE(std::string, std::string) & item : wtx.mapValue)
78  entry.push_back(Pair(item.first, item.second));
79 }
80 
81 std::string AccountFromValue(const UniValue& value)
82 {
83  std::string strAccount = value.get_str();
84  if (strAccount == "*")
85  throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name");
86  return strAccount;
87 }
88 
89 UniValue getnewaddress(const UniValue& params, bool fHelp)
90 {
91  if (fHelp || params.size() > 1)
92  throw std::runtime_error(
93  "getnewaddress ( \"account\" )\n"
94  "\nReturns a new PRCY address for receiving payments.\n"
95  "If 'account' is specified (recommended), it is added to the address book \n"
96  "so payments received with the address will be credited to 'account'.\n"
97  "\nArguments:\n"
98  "1. \"account\" (string, optional) The account name for the address to be linked to. if not provided, the default account \"\" is used. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created if there is no account by the given name.\n"
99  "\nResult:\n"
100  "\"prcycoinaddress\" (string) The new prcycoin address\n"
101  "\nExamples:\n" +
102  HelpExampleCli("getnewaddress", "") + HelpExampleCli("getnewaddress", "\"\"") + HelpExampleCli("getnewaddress", "\"myaccount\"") + HelpExampleRpc("getnewaddress", "\"myaccount\""));
103 
105 
106  // Parse the account first so we don't generate a key if there's an error
107  std::string strAccount;
108  if (params.size() > 0)
109  strAccount = AccountFromValue(params[0]);
110 
111  if (!pwalletMain->IsLocked())
113 
114  // Generate a new key that is added to wallet
115  CPubKey newKey;
116  if (!pwalletMain->GetKeyFromPool(newKey))
117  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
118  CKeyID keyID = newKey.GetID();
119 
120  pwalletMain->SetAddressBook(keyID, strAccount, "receive");
121 
122  return CBitcoinAddress(keyID).ToString();
123 }
124 
125 
126 CBitcoinAddress GetAccountAddress(std::string strAccount, bool bForceNew = false)
127 {
129 
130  CAccount account;
131  walletdb.ReadAccount(strAccount, account);
132 
133  bool bKeyUsed = false;
134 
135  // Check if the current key has been used
136  if (account.vchPubKey.IsValid()) {
137  CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID());
138  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
139  it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
140  ++it) {
141  const CWalletTx& wtx = (*it).second;
142  for (const CTxOut& txout : wtx.vout)
143  if (txout.scriptPubKey == scriptPubKey)
144  bKeyUsed = true;
145  }
146  }
147 
148  // Generate a new key
149  if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed) {
151  if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
152  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
153 
154  pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
155  walletdb.WriteAccount(strAccount, account);
156  }
157 
158  return CBitcoinAddress(account.vchPubKey.GetID());
159 }
160 
161 CBitcoinAddress GetHDAccountAddress(std::string strAccount, uint32_t nAccountIndex, bool bForceNew = false)
162 {
164 
165  CAccount account;
166  walletdb.ReadAccount(strAccount, account);
167 
168  bool bKeyUsed = false;
169 
170  // Check if the current key has been used
171  if (account.vchPubKey.IsValid()) {
172  CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID());
173  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
174  it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
175  ++it) {
176  const CWalletTx& wtx = (*it).second;
177  for (const CTxOut& txout : wtx.vout)
178  if (txout.scriptPubKey == scriptPubKey)
179  bKeyUsed = true;
180  }
181  }
182 
183  // Generate a new key
184  if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed) {
186  // if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
187  // throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
188 
189  CKey newKey;
190  pwalletMain->DeriveNewChildKey(nAccountIndex, newKey);
191  account.vchPubKey = newKey.GetPubKey();
192  account.nAccountIndex = nAccountIndex;
193 
194  pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
195  walletdb.WriteAccount(strAccount, account);
196  }
197 
198  return CBitcoinAddress(account.vchPubKey.GetID());
199 }
200 
201 UniValue getaccountaddress(const UniValue& params, bool fHelp)
202 {
203  if (fHelp || params.size() != 1)
204  throw std::runtime_error(
205  "getaccountaddress \"account\"\n"
206  "\nReturns the current PRCY address for receiving payments to this account.\n"
207  "\nArguments:\n"
208  "1. \"account\" (string, required) The account name for the address. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created and a new address created if there is no account by the given name.\n"
209  "\nResult:\n"
210  "\"prcycoinaddress\" (string) The account prcycoin address\n"
211  "\nExamples:\n" +
212  HelpExampleCli("getaccountaddress", "") + HelpExampleCli("getaccountaddress", "\"\"") + HelpExampleCli("getaccountaddress", "\"myaccount\"") + HelpExampleRpc("getaccountaddress", "\"myaccount\""));
214 
215  // Parse the account first so we don't generate a key if there's an error
216  std::string strAccount = AccountFromValue(params[0]);
217 
219 
220  ret = GetAccountAddress(strAccount).ToString();
221  return ret;
222 }
223 
224 UniValue getrawchangeaddress(const UniValue& params, bool fHelp)
225 {
226  if (fHelp || params.size() > 1)
227  throw std::runtime_error(
228  "getrawchangeaddress\n"
229  "\nReturns a new PRCY address, for receiving change.\n"
230  "This is for use with raw transactions, NOT normal use.\n"
231  "\nResult:\n"
232  "\"address\" (string) The address\n"
233  "\nExamples:\n" +
234  HelpExampleCli("getrawchangeaddress", "") + HelpExampleRpc("getrawchangeaddress", ""));
236 
237  if (!pwalletMain->IsLocked())
239 
240  CReserveKey reservekey(pwalletMain);
241  CPubKey vchPubKey;
242  if (!reservekey.GetReservedKey(vchPubKey))
243  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
244 
245  reservekey.KeepKey();
246 
247  CKeyID keyID = vchPubKey.GetID();
248 
249  return CBitcoinAddress(keyID).ToString();
250 }
251 
252 UniValue setaccount(const UniValue& params, bool fHelp)
253 {
254  if (fHelp || params.size() < 1 || params.size() > 2)
255  throw std::runtime_error(
256  "setaccount \"prcycoinaddress\" \"account\"\n"
257  "\nSets the account associated with the given address.\n"
258  "\nArguments:\n"
259  "1. \"prcycoinaddress\" (string, required) The prcycoin address to be associated with an account.\n"
260  "2. \"account\" (string, required) The account to assign the address to.\n"
261  "\nExamples:\n" +
262  HelpExampleCli("setaccount", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\" \"tabby\"") + HelpExampleRpc("setaccount", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\", \"tabby\""));
263 
265 
266  CBitcoinAddress address(params[0].get_str());
267  if (!address.IsValid())
268  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PRCY address");
269 
270  std::string strAccount;
271  if (params.size() > 1)
272  strAccount = AccountFromValue(params[1]);
273 
274  // Only add the account if the address is yours.
275  if (IsMine(*pwalletMain, address.Get())) {
276  // Detect when changing the account of an address that is the 'unused current key' of another account:
277  if (pwalletMain->mapAddressBook.count(address.Get())) {
278  std::string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
279  if (address == GetAccountAddress(strOldAccount))
280  GetAccountAddress(strOldAccount, true);
281  }
282  pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
283  } else
284  throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address");
285  return NullUniValue;
286 }
287 
288 
289 UniValue getaccount(const UniValue& params, bool fHelp)
290 {
291  if (fHelp || params.size() != 1)
292  throw std::runtime_error(
293  "getaccount \"prcycoinaddress\"\n"
294  "\nReturns the account associated with the given address.\n"
295  "\nArguments:\n"
296  "1. \"prcycoinaddress\" (string, required) The prcycoin address for account lookup.\n"
297  "\nResult:\n"
298  "\"accountname\" (string) the account address\n"
299  "\nExamples:\n" +
300  HelpExampleCli("getaccount", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\"") + HelpExampleRpc("getaccount", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\""));
301 
303 
304  CBitcoinAddress address(params[0].get_str());
305  if (!address.IsValid())
306  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PRCY address");
307 
308  std::string strAccount;
309  std::map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
310  if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty())
311  strAccount = (*mi).second.name;
312 
313  return strAccount;
314 }
315 
316 UniValue getaddressesbyaccount(const UniValue& params, bool fHelp)
317 {
318  if (fHelp || params.size() != 1)
319  throw std::runtime_error(
320  "getaddressesbyaccount \"account\"\n"
321  "\nReturns the list of addresses for the given account.\n"
322  "\nArguments:\n"
323  "1. \"account\" (string, required) The account name.\n"
324  "\nResult:\n"
325  "[ (json array of string)\n"
326  " \"prcycoinaddress\" (string) a prcycoin address associated with the given account\n"
327  " ,...\n"
328  "]\n"
329  "\nExamples:\n" +
330  HelpExampleCli("getaddressesbyaccount", "\"tabby\"") + HelpExampleRpc("getaddressesbyaccount", "\"tabby\""));
331 
333 
334  std::string strAccount = AccountFromValue(params[0]);
335 
336  // Find all addresses that have the given account
339  const CBitcoinAddress& address = item.first;
340  const std::string& strName = item.second.name;
341  if (strName == strAccount)
342  ret.push_back(address.ToString());
343  }
344  return ret;
345 }
346 
347 void SendMoney(const CTxDestination& address, CAmount nValue, CWalletTx& wtxNew, bool fUseIX = false)
348 {
349  // Check amount
350  if (nValue <= 0)
351  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
352 
353  std::string strError;
354  if (pwalletMain->IsLocked()) {
355  strError = "Error: Wallet locked, unable to create transaction!";
356  LogPrintf("SendMoney() : %s", strError);
357  throw JSONRPCError(RPC_WALLET_ERROR, strError);
358  }
359 
360  // Parse PRCY address
361  CScript scriptPubKey = GetScriptForDestination(address);
362 
363  // Create and send the transaction
364  CReserveKey reservekey(pwalletMain);
365  CAmount nFeeRequired;
366  if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError, NULL, ALL_COINS, fUseIX, (CAmount)0)) {
367  if (nValue + nFeeRequired > pwalletMain->GetBalance())
368  strError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
369  LogPrintf("SendMoney() : %s\n", strError);
370  throw JSONRPCError(RPC_WALLET_ERROR, strError);
371  }
372  if (!pwalletMain->CommitTransaction(wtxNew, reservekey, (!fUseIX ? NetMsgType::TX : NetMsgType::IX)))
373  throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
374 }
375 
376 UniValue listaddressgroupings(const UniValue& params, bool fHelp)
377 {
378  if (fHelp)
379  throw std::runtime_error(
380  "listaddressgroupings\n"
381  "\nLists groups of addresses which have had their common ownership\n"
382  "made public by common use as inputs or as the resulting change\n"
383  "in past transactions\n"
384  "\nResult:\n"
385  "[\n"
386  " [\n"
387  " [\n"
388  " \"prcycoinaddress\", (string) The prcycoin address\n"
389  " amount, (numeric) The amount in PRCY\n"
390  " \"account\" (string, optional) The account\n"
391  " ]\n"
392  " ,...\n"
393  " ]\n"
394  " ,...\n"
395  "]\n"
396  "\nExamples:\n" +
397  HelpExampleCli("listaddressgroupings", "") + HelpExampleRpc("listaddressgroupings", ""));
398 
400 
401  UniValue jsonGroupings(UniValue::VARR);
402  std::map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
403  for (std::set<CTxDestination> grouping : pwalletMain->GetAddressGroupings()) {
404  UniValue jsonGrouping(UniValue::VARR);
405  for (CTxDestination address : grouping) {
406  UniValue addressInfo(UniValue::VARR);
407  addressInfo.push_back(CBitcoinAddress(address).ToString());
408  addressInfo.push_back(ValueFromAmount(balances[address]));
409  {
410  if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
411  addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name);
412  }
413  jsonGrouping.push_back(addressInfo);
414  }
415  jsonGroupings.push_back(jsonGrouping);
416  }
417  return jsonGroupings;
418 }
419 
420 UniValue signmessage(const UniValue& params, bool fHelp)
421 {
422  if (fHelp || params.size() != 2)
423  throw std::runtime_error(
424  "signmessage \"prcycoinaddress\" \"message\"\n"
425  "\nSign a message with the private key of an address" +
426  HelpRequiringPassphrase() + "\n"
427  "\nArguments:\n"
428  "1. \"prcycoinaddress\" (string, required) The prcycoin address to use for the private key.\n"
429  "2. \"message\" (string, required) The message to create a signature of.\n"
430  "\nResult:\n"
431  "\"signature\" (string) The signature of the message encoded in base 64\n"
432  "\nExamples:\n"
433  "\nUnlock the wallet for 30 seconds\n" +
434  HelpExampleCli("unlockwallet", "\"mypassphrase\" 30") +
435  "\nCreate the signature\n" + HelpExampleCli("signmessage", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\" \"my message\"") +
436  "\nVerify the signature\n" + HelpExampleCli("verifymessage", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\" \"signature\" \"my message\"") +
437  "\nAs json rpc\n" + HelpExampleRpc("signmessage", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\", \"my message\""));
438 
440 
442 
443  std::string strAddress = params[0].get_str();
444  std::string strMessage = params[1].get_str();
445 
446  CBitcoinAddress addr(strAddress);
447  if (!addr.IsValid())
448  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
449 
450  CKeyID keyID;
451  if (!addr.GetKeyID(keyID))
452  throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
453 
454  CKey key;
455  if (!pwalletMain->GetKey(keyID, key))
456  throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
457 
458  CHashWriter ss(SER_GETHASH, 0);
459  ss << strMessageMagic;
460  ss << strMessage;
461 
462  std::vector<unsigned char> vchSig;
463  if (!key.SignCompact(ss.GetHash(), vchSig))
464  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
465 
466  return EncodeBase64(&vchSig[0], vchSig.size());
467 }
468 
469 UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
470 {
471  if (fHelp || params.size() < 1 || params.size() > 2)
472  throw std::runtime_error(
473  "getreceivedbyaddress \"prcycoinaddress\" ( minconf )\n"
474  "\nReturns the total amount received by the given prcycoinaddress in transactions with at least minconf confirmations.\n"
475  "\nArguments:\n"
476  "1. \"prcycoinaddress\" (string, required) The prcycoin address for transactions.\n"
477  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
478  "\nResult:\n"
479  "amount (numeric) The total amount in PRCY received at this address.\n"
480  "\nExamples:\n"
481  "\nThe amount from transactions with at least 1 confirmation\n" +
482  HelpExampleCli("getreceivedbyaddress", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\"") +
483  "\nThe amount including unconfirmed transactions, zero confirmations\n" + HelpExampleCli("getreceivedbyaddress", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\" 0") +
484  "\nThe amount with at least 6 confirmation, very safe\n" + HelpExampleCli("getreceivedbyaddress", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\" 6") +
485  "\nAs a json rpc call\n" + HelpExampleRpc("getreceivedbyaddress", "\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\", 6"));
486 
488 
489  // prcycoin address
490  CBitcoinAddress address = CBitcoinAddress(params[0].get_str());
491  if (!address.IsValid())
492  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PRCY address");
493  CScript scriptPubKey = GetScriptForDestination(address.Get());
494  if (!IsMine(*pwalletMain, scriptPubKey))
495  throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet");
496 
497  // Minimum confirmations
498  int nMinDepth = 1;
499  if (params.size() > 1)
500  nMinDepth = params[1].get_int();
501 
502  // Tally
503  CAmount nAmount = 0;
504  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
505  const CWalletTx& wtx = (*it).second;
506  if (wtx.IsCoinBase() || !IsFinalTx(wtx))
507  continue;
508 
509  for (const CTxOut& txout : wtx.vout)
510  if (txout.scriptPubKey == scriptPubKey)
511  if (wtx.GetDepthInMainChain() >= nMinDepth)
512  nAmount += txout.nValue;
513  }
514 
515  return ValueFromAmount(nAmount);
516 }
517 
518 
519 UniValue getreceivedbyaccount(const UniValue& params, bool fHelp)
520 {
521  if (fHelp || params.size() < 1 || params.size() > 2)
522  throw std::runtime_error(
523  "getreceivedbyaccount \"account\" ( minconf )\n"
524  "\nReturns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.\n"
525  "\nArguments:\n"
526  "1. \"account\" (string, required) The selected account, may be the default account using \"\".\n"
527  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
528  "\nResult:\n"
529  "amount (numeric) The total amount in PRCY received for this account.\n"
530  "\nExamples:\n"
531  "\nAmount received by the default account with at least 1 confirmation\n" +
532  HelpExampleCli("getreceivedbyaccount", "\"\"") +
533  "\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n" + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") +
534  "\nThe amount with at least 6 confirmation, very safe\n" + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") +
535  "\nAs a json rpc call\n" + HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6"));
536 
538 
539  // Minimum confirmations
540  int nMinDepth = 1;
541  if (params.size() > 1)
542  nMinDepth = params[1].get_int();
543 
544  // Get the set of pub keys assigned to accountValue getreceivedbyaccount(const Array& params, bool fHelp)
545  std::string strAccount = AccountFromValue(params[0]);
546  std::set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
547 
548  // Tally
549  CAmount nAmount = 0;
550  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
551  const CWalletTx& wtx = (*it).second;
552  if (wtx.IsCoinBase() || !IsFinalTx(wtx))
553  continue;
554 
555  for (const CTxOut& txout : wtx.vout) {
556  CTxDestination address;
557  if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address))
558  if (wtx.GetDepthInMainChain() >= nMinDepth)
559  nAmount += txout.nValue;
560  }
561  }
562 
563  return (double)nAmount / (double)COIN;
564 }
565 
566 
567 CAmount GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, int nMinDepth, const isminefilter& filter)
568 {
569  CAmount nBalance = 0;
570 
571  // Tally wallet transactions
572  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
573  const CWalletTx& wtx = (*it).second;
574  if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
575  continue;
576 
577  CAmount nReceived, nSent, nFee;
578  wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
579 
580  if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
581  nBalance += nReceived;
582  nBalance -= nSent + nFee;
583  }
584 
585  // Tally internal accounting entries
586  nBalance += walletdb.GetAccountCreditDebit(strAccount);
587 
588  return nBalance;
589 }
590 
591 CAmount GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter)
592 {
594  return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
595 }
596 
597 UniValue getbalance(const UniValue& params, bool fHelp)
598 {
599  if (fHelp || params.size() > 3)
600  throw std::runtime_error(
601  "getbalance ( \"account\" minconf includeWatchonly )\n"
602  "\nIf account is not specified, returns the server's total available balance.\n"
603  "If account is specified, returns the balance in the account.\n"
604  "Note that the account \"\" is not the same as leaving the parameter out.\n"
605  "The server total may be different to the balance in the default \"\" account.\n"
606  "\nArguments:\n"
607  "1. \"account\" (string, optional) The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n"
608  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
609  "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n"
610  "\nResult:\n"
611  "amount (numeric) The total amount in PRCY received for this account.\n"
612  "\nExamples:\n"
613  "\nThe total amount in the server across all accounts\n" +
614  HelpExampleCli("getbalance", "") +
615  "\nThe total amount in the server across all accounts, with at least 5 confirmations\n" + HelpExampleCli("getbalance", "\"*\" 6") +
616  "\nThe total amount in the default account with at least 1 confirmation\n" + HelpExampleCli("getbalance", "\"\"") +
617  "\nThe total amount in the account named tabby with at least 6 confirmations\n" + HelpExampleCli("getbalance", "\"tabby\" 6") +
618  "\nAs a json rpc call\n" + HelpExampleRpc("getbalance", "\"tabby\", 6"));
619 
621 
622  if (params.size() == 0)
624 
625  int nMinDepth = 1;
626  if (params.size() > 1)
627  nMinDepth = params[1].get_int();
629  if (params.size() > 2)
630  if (params[2].get_bool())
631  filter = filter | ISMINE_WATCH_ONLY;
632 
633  if (params[0].get_str() == "*") {
634  // Calculate total balance a different way from GetBalance()
635  // (GetBalance() sums up all unspent TxOuts)
636  // getbalance and "getbalance * 1 true" should return the same number
637  CAmount nBalance = 0;
638  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
639  const CWalletTx& wtx = (*it).second;
640  if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
641  continue;
642 
643  CAmount allFee;
644  std::string strSentAccount;
645  std::list<COutputEntry> listReceived;
646  std::list<COutputEntry> listSent;
647  wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
648  if (wtx.GetDepthInMainChain() >= nMinDepth) {
649  for (const COutputEntry& r : listReceived)
650  nBalance += r.amount;
651  }
652  for (const COutputEntry& s : listSent)
653  nBalance -= s.amount;
654  nBalance -= allFee;
655  }
656  return ValueFromAmount(nBalance);
657  }
658 
659  std::string strAccount = AccountFromValue(params[0]);
660 
661  CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
662 
663  return ValueFromAmount(nBalance);
664 }
665 
666 UniValue getbalances(const UniValue& params, bool fHelp)
667 {
668  if (fHelp)
669  throw std::runtime_error(
670  "getbalances"
671  "\nArguments:\n"
672  "\nResult:\n"
673  "total (numeric) The total amount of PRCY received for this wallet.\n"
674  "spendable (numeric) The total amount of PRCY spendable for this wallet.\n"
675  "pending (numeric) The total amount of PRCY pending for this wallet.\n"
676  "immature (numeric) The total amount of PRCY that are immature for this wallet.\n"
677  "locked (numeric) The total amount of PRCY that are locked for this wallet."
678  "\nExamples:\n"
679  "\nThe total amount in the server across all accounts\n" +
680  HelpExampleCli("getbalances", ""));
681 
683  obj.push_back(Pair("total", ValueFromAmount(pwalletMain->GetBalance())));
684  obj.push_back(Pair("spendable", ValueFromAmount(pwalletMain->GetSpendableBalance())));
686  obj.push_back(Pair("immature", ValueFromAmount(pwalletMain->GetImmatureBalance())));
687  obj.push_back(Pair("locked", ValueFromAmount(pwalletMain->GetLockedCoins())));
688 
689  return obj;
690 }
691 
692 UniValue getunconfirmedbalance(const UniValue& params, bool fHelp)
693 {
694  if (fHelp || params.size() > 0)
695  throw std::runtime_error(
696  "getunconfirmedbalance\n"
697  "Returns the server's total unconfirmed balance\n");
698 
700 
702 }
703 
704 UniValue movecmd(const UniValue& params, bool fHelp)
705 {
706  if (fHelp || params.size() < 3 || params.size() > 5)
707  throw std::runtime_error(
708  "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
709  "\nMove a specified amount from one account in your wallet to another.\n"
710  "\nArguments:\n"
711  "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
712  "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
713  "3. amount (numeric, required) Quantity of PIV to move between accounts.\n"
714  "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
715  "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
716  "\nResult:\n"
717  "true|false (boolean) true if successful.\n"
718  "\nExamples:\n"
719  "\nMove 0.01 PRCY from the default account to the account named tabby\n" +
720  HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
721  "\nMove 0.01 PRCY timotei to akiko with a comment\n" + HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 1 \"happy birthday!\"") +
722  "\nAs a json rpc call\n" + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 1, \"happy birthday!\""));
723 
725 
726  std::string strFrom = AccountFromValue(params[0]);
727  std::string strTo = AccountFromValue(params[1]);
728  CAmount nAmount = AmountFromValue(params[2]);
729  if (params.size() > 3)
730  // unused parameter, used to be nMinDepth, keep type-checking it though
731  (void)params[3].get_int();
732  std::string strComment;
733  if (params.size() > 4)
734  strComment = params[4].get_str();
735 
737  if (!walletdb.TxnBegin())
738  throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
739 
740  int64_t nNow = GetAdjustedTime();
741 
742  // Debit
743  CAccountingEntry debit;
744  debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
745  debit.strAccount = strFrom;
746  debit.nCreditDebit = -nAmount;
747  debit.nTime = nNow;
748  debit.strOtherAccount = strTo;
749  debit.strComment = strComment;
750  pwalletMain->AddAccountingEntry(debit, walletdb);
751 
752  // Credit
753  CAccountingEntry credit;
754  credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
755  credit.strAccount = strTo;
756  credit.nCreditDebit = nAmount;
757  credit.nTime = nNow;
758  credit.strOtherAccount = strFrom;
759  credit.strComment = strComment;
760  pwalletMain->AddAccountingEntry(credit, walletdb);
761 
762  if (!walletdb.TxnCommit())
763  throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
764 
765  return true;
766 }
767 
768 UniValue sendfrom(const UniValue& params, bool fHelp)
769 {
770  if (fHelp || params.size() < 3 || params.size() > 6)
771  throw std::runtime_error(
772  "sendfrom \"fromaccount\" \"toprcycoinaddress\" amount ( minconf \"comment\" \"comment-to\" )\n"
773  "\nSent an amount from an account to a prcycoin address.\n"
774  "The amount is a real and is rounded to the nearest 0.00000001." +
775  HelpRequiringPassphrase() + "\n"
776  "\nArguments:\n"
777  "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n"
778  "2. \"toprcycoinaddress\" (string, required) The prcycoin address to send funds to.\n"
779  "3. amount (numeric, required) The amount in PRCY. (transaction fee is added on top).\n"
780  "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
781  "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
782  " This is not part of the transaction, just kept in your wallet.\n"
783  "6. \"comment-to\" (string, optional) An optional comment to store the name of the person or organization \n"
784  " to which you're sending the transaction. This is not part of the transaction, \n"
785  " it is just kept in your wallet.\n"
786  "\nResult:\n"
787  "\"transactionid\" (string) The transaction id.\n"
788  "\nExamples:\n"
789  "\nSend 0.01 PRCY from the default account to the address, must have at least 1 confirmation\n" +
790  HelpExampleCli("sendfrom", "\"\" \"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\" 0.01") +
791  "\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n" + HelpExampleCli("sendfrom", "\"tabby\" \"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\" 0.01 6 \"donation\" \"seans outpost\"") +
792  "\nAs a json rpc call\n" + HelpExampleRpc("sendfrom", "\"tabby\", \"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\", 0.01, 6, \"donation\", \"seans outpost\""));
793 
795 
796  std::string strAccount = AccountFromValue(params[0]);
797  CBitcoinAddress address(params[1].get_str());
798  if (!address.IsValid())
799  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PRCY address");
800  CAmount nAmount = AmountFromValue(params[2]);
801  int nMinDepth = 1;
802  if (params.size() > 3)
803  nMinDepth = params[3].get_int();
804 
805  CWalletTx wtx;
806  wtx.strFromAccount = strAccount;
807  if (params.size() > 4 && !params[4].isNull() && !params[4].get_str().empty())
808  wtx.mapValue["comment"] = params[4].get_str();
809  if (params.size() > 5 && !params[5].isNull() && !params[5].get_str().empty())
810  wtx.mapValue["to"] = params[5].get_str();
811 
813 
814  // Check funds
815  CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
816  if (nAmount > nBalance)
817  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
818 
819  SendMoney(address.Get(), nAmount, wtx);
820 
821  return wtx.GetHash().GetHex();
822 }
823 
824 UniValue sendmany(const UniValue& params, bool fHelp)
825 {
826  if (fHelp || params.size() < 2 || params.size() > 4)
827  throw std::runtime_error(
828  "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" )\n"
829  "\nSend multiple times. Amounts are double-precision floating point numbers." +
830  HelpRequiringPassphrase() + "\n"
831  "\nArguments:\n"
832  "1. \"fromaccount\" (string, required) The account to send the funds from, can be \"\" for the default account\n"
833  "2. \"amounts\" (string, required) A json object with addresses and amounts\n"
834  " {\n"
835  " \"address\":amount (numeric) The prcycoin address is the key, the numeric amount in PRCY is the value\n"
836  " ,...\n"
837  " }\n"
838  "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
839  "4. \"comment\" (string, optional) A comment\n"
840  "\nResult:\n"
841  "\"transactionid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
842  " the number of addresses.\n"
843  "\nExamples:\n"
844  "\nSend two amounts to two different addresses:\n" +
845  HelpExampleCli("sendmany", "\"tabby\" \"{\\\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\\\":0.01,\\\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\\\":0.02}\"") +
846  "\nSend two amounts to two different addresses setting the confirmation and comment:\n" + HelpExampleCli("sendmany", "\"tabby\" \"{\\\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\\\":0.01,\\\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\\\":0.02}\" 6 \"testing\"") +
847  "\nAs a json rpc call\n" + HelpExampleRpc("sendmany", "\"tabby\", \"{\\\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\\\":0.01,\\\"DEQsu2RRB5iphm9tKXiP4iWSRMC17gseW5\\\":0.02}\", 6, \"testing\""));
848 
850 
851  std::string strAccount = AccountFromValue(params[0]);
852  UniValue sendTo = params[1].get_obj();
853  int nMinDepth = 1;
854  if (params.size() > 2)
855  nMinDepth = params[2].get_int();
856 
857  CWalletTx wtx;
858  wtx.strFromAccount = strAccount;
859  if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty())
860  wtx.mapValue["comment"] = params[3].get_str();
861 
862  std::set<CBitcoinAddress> setAddress;
863  std::vector<std::pair<CScript, CAmount> > vecSend;
864 
865  CAmount totalAmount = 0;
866  std::vector<std::string> keys = sendTo.getKeys();
867  for (const std::string& name_ : keys) {
868  CBitcoinAddress address(name_);
869  if (!address.IsValid())
870  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid PIVX address: ")+name_);
871 
872  if (setAddress.count(address))
873  throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+name_);
874  setAddress.insert(address);
875 
876  CScript scriptPubKey = GetScriptForDestination(address.Get());
877  CAmount nAmount = AmountFromValue(sendTo[name_]);
878  totalAmount += nAmount;
879 
880  vecSend.push_back(std::make_pair(scriptPubKey, nAmount));
881  }
882 
884 
885  // Check funds
886  CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
887  if (totalAmount > nBalance)
888  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
889 
890  // Send
891  CReserveKey keyChange(pwalletMain);
892  CAmount nFeeRequired = 0;
893  std::string strFailReason;
894  bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason);
895  if (!fCreated)
896  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
897  if (!pwalletMain->CommitTransaction(wtx, keyChange))
898  throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed");
899 
900  return wtx.GetHash().GetHex();
901 }
902 
903 // Defined in rpcmisc.cpp
904 extern CScript _createmultisig_redeemScript(const UniValue& params);
905 
906 UniValue addmultisigaddress(const UniValue& params, bool fHelp)
907 {
908  if (fHelp || params.size() < 2 || params.size() > 3) {
909  std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
910  "\nAdd a nrequired-to-sign multisignature address to the wallet.\n"
911  "Each key is a PRCY address or hex-encoded public key.\n"
912  "If 'account' is specified, assign address to that account.\n"
913 
914  "\nArguments:\n"
915  "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
916  "2. \"keysobject\" (string, required) A json array of prcycoin addresses or hex-encoded public keys\n"
917  " [\n"
918  " \"address\" (string) prcycoin address or hex-encoded public key\n"
919  " ...,\n"
920  " ]\n"
921  "3. \"account\" (string, optional) An account to assign the addresses to.\n"
922 
923  "\nResult:\n"
924  "\"prcycoinaddress\" (string) A prcycoin address associated with the keys.\n"
925 
926  "\nExamples:\n"
927  "\nAdd a multisig address from 2 addresses\n" +
928  HelpExampleCli("addmultisigaddress", "2 \"[\\\"Xt4qk9uKvQYAonVGSZNXqxeDmtjaEWgfrs\\\",\\\"XoSoWQkpgLpppPoyyzbUFh1fq2RBvW6UK1\\\"]\"") +
929  "\nAs json rpc call\n" + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"Xt4qk9uKvQYAonVGSZNXqxeDmtjaEWgfrs\\\",\\\"XoSoWQkpgLpppPoyyzbUFh1fq2RBvW6UK1\\\"]\"");
930  throw std::runtime_error(msg);
931  }
932 
934 
935  std::string strAccount;
936  if (params.size() > 2)
937  strAccount = AccountFromValue(params[2]);
938 
939  // Construct using pay-to-script-hash:
940  CScript inner = _createmultisig_redeemScript(params);
941  CScriptID innerID(inner);
942  pwalletMain->AddCScript(inner);
943 
944  pwalletMain->SetAddressBook(innerID, strAccount, "send");
945  return CBitcoinAddress(innerID).ToString();
946 }
947 
948 
949 struct tallyitem {
951  int nConf;
952  int nBCConf;
953  std::vector<uint256> txids;
956  {
957  nAmount = 0;
958  nConf = std::numeric_limits<int>::max();
959  nBCConf = std::numeric_limits<int>::max();
960  fIsWatchonly = false;
961  }
962 };
963 
964 UniValue ListReceived(const UniValue& params, bool fByAccounts)
965 {
966  // Minimum confirmations
967  int nMinDepth = 1;
968  if (params.size() > 0)
969  nMinDepth = params[0].get_int();
970 
971  // Whether to include empty accounts
972  bool fIncludeEmpty = false;
973  if (params.size() > 1)
974  fIncludeEmpty = params[1].get_bool();
975 
977  if (params.size() > 2)
978  if (params[2].get_bool())
979  filter = filter | ISMINE_WATCH_ONLY;
980 
981  // Tally
982  std::map<CBitcoinAddress, tallyitem> mapTally;
983  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
984  const CWalletTx& wtx = (*it).second;
985 
986  if (wtx.IsCoinBase() || !IsFinalTx(wtx))
987  continue;
988 
989  int nDepth = wtx.GetDepthInMainChain();
990  int nBCDepth = wtx.GetDepthInMainChain(false);
991  if (nDepth < nMinDepth)
992  continue;
993 
994  for (const CTxOut& txout : wtx.vout) {
995  CTxDestination address;
996  if (!ExtractDestination(txout.scriptPubKey, address))
997  continue;
998 
999  isminefilter mine = IsMine(*pwalletMain, address);
1000  if (!(mine & filter))
1001  continue;
1002 
1003  tallyitem& item = mapTally[address];
1004  item.nAmount += txout.nValue;
1005  item.nConf = std::min(item.nConf, nDepth);
1006  item.nBCConf = std::min(item.nBCConf, nBCDepth);
1007  item.txids.push_back(wtx.GetHash());
1008  if (mine & ISMINE_WATCH_ONLY)
1009  item.fIsWatchonly = true;
1010  }
1011  }
1012 
1013  // Reply
1014  UniValue ret(UniValue::VARR);
1015  std::map<std::string, tallyitem> mapAccountTally;
1017  const CBitcoinAddress& address = item.first;
1018  const std::string& strAccount = item.second.name;
1019  std::map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address);
1020  if (it == mapTally.end() && !fIncludeEmpty)
1021  continue;
1022 
1023  CAmount nAmount = 0;
1024  int nConf = std::numeric_limits<int>::max();
1025  int nBCConf = std::numeric_limits<int>::max();
1026  bool fIsWatchonly = false;
1027  if (it != mapTally.end()) {
1028  nAmount = (*it).second.nAmount;
1029  nConf = (*it).second.nConf;
1030  nBCConf = (*it).second.nBCConf;
1031  fIsWatchonly = (*it).second.fIsWatchonly;
1032  }
1033 
1034  if (fByAccounts) {
1035  tallyitem& item = mapAccountTally[strAccount];
1036  item.nAmount += nAmount;
1037  item.nConf = std::min(item.nConf, nConf);
1038  item.nBCConf = std::min(item.nBCConf, nBCConf);
1039  item.fIsWatchonly = fIsWatchonly;
1040  } else {
1041  UniValue obj(UniValue::VOBJ);
1042  if (fIsWatchonly)
1043  obj.push_back(Pair("involvesWatchonly", true));
1044  obj.push_back(Pair("address", address.ToString()));
1045  obj.push_back(Pair("account", strAccount));
1046  obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1047  obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1048  obj.push_back(Pair("bcconfirmations", (nBCConf == std::numeric_limits<int>::max() ? 0 : nBCConf)));
1049  UniValue transactions(UniValue::VARR);
1050  if (it != mapTally.end()) {
1051  for (const uint256& item : (*it).second.txids) {
1052  transactions.push_back(item.GetHex());
1053  }
1054  }
1055  obj.push_back(Pair("txids", transactions));
1056  ret.push_back(obj);
1057  }
1058  }
1059 
1060  if (fByAccounts) {
1061  for (std::map<std::string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it) {
1062  CAmount nAmount = (*it).second.nAmount;
1063  int nConf = (*it).second.nConf;
1064  int nBCConf = (*it).second.nBCConf;
1065  UniValue obj(UniValue::VOBJ);
1066  if ((*it).second.fIsWatchonly)
1067  obj.push_back(Pair("involvesWatchonly", true));
1068  obj.push_back(Pair("account", (*it).first));
1069  obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1070  obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1071  obj.push_back(Pair("bcconfirmations", (nBCConf == std::numeric_limits<int>::max() ? 0 : nBCConf)));
1072  ret.push_back(obj);
1073  }
1074  }
1075 
1076  return ret;
1077 }
1078 
1079 UniValue listreceivedbyaddress(const UniValue& params, bool fHelp)
1080 {
1081  if (fHelp || params.size() > 3)
1082  throw std::runtime_error(
1083  "listreceivedbyaddress ( minconf includeempty includeWatchonly)\n"
1084  "\nList balances by receiving address.\n"
1085  "\nArguments:\n"
1086  "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1087  "2. includeempty (numeric, optional, default=false) Whether to include addresses that haven't received any payments.\n"
1088  "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
1089 
1090  "\nResult:\n"
1091  "[\n"
1092  " {\n"
1093  " \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n"
1094  " \"address\" : \"receivingaddress\", (string) The receiving address\n"
1095  " \"account\" : \"accountname\", (string) The account of the receiving address. The default account is \"\".\n"
1096  " \"amount\" : x.xxx, (numeric) The total amount in PRCY received by the address\n"
1097  " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
1098  " \"bcconfirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n"
1099  " }\n"
1100  " ,...\n"
1101  "]\n"
1102 
1103  "\nExamples:\n" +
1104  HelpExampleCli("listreceivedbyaddress", "") + HelpExampleCli("listreceivedbyaddress", "6 true") + HelpExampleRpc("listreceivedbyaddress", "6, true, true"));
1105 
1107 
1108  return ListReceived(params, false);
1109 }
1110 
1111 UniValue listreceivedbyaccount(const UniValue& params, bool fHelp)
1112 {
1113  if (fHelp || params.size() > 3)
1114  throw std::runtime_error(
1115  "listreceivedbyaccount ( minconf includeempty includeWatchonly)\n"
1116  "\nList balances by account.\n"
1117  "\nArguments:\n"
1118  "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1119  "2. includeempty (boolean, optional, default=false) Whether to include accounts that haven't received any payments.\n"
1120  "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
1121 
1122  "\nResult:\n"
1123  "[\n"
1124  " {\n"
1125  " \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n"
1126  " \"account\" : \"accountname\", (string) The account name of the receiving account\n"
1127  " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
1128  " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
1129  " \"bcconfirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n"
1130  " }\n"
1131  " ,...\n"
1132  "]\n"
1133 
1134  "\nExamples:\n" +
1135  HelpExampleCli("listreceivedbyaccount", "") + HelpExampleCli("listreceivedbyaccount", "6 true") + HelpExampleRpc("listreceivedbyaccount", "6, true, true"));
1136 
1138 
1139  return ListReceived(params, true);
1140 }
1141 
1142 static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
1143 {
1144  CBitcoinAddress addr;
1145  if (addr.Set(dest))
1146  entry.push_back(Pair("address", addr.ToString()));
1147 }
1148 
1149 void ListTransactions(const CWalletTx& wtx, const std::string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter)
1150 {
1151  CAmount nFee;
1152  std::string strSentAccount;
1153  std::list<COutputEntry> listReceived;
1154  std::list<COutputEntry> listSent;
1155 
1156  wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
1157 
1158  bool fAllAccounts = (strAccount == std::string("*"));
1159  bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
1160 
1161  // Sent
1162  if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) {
1163  for (const COutputEntry& s : listSent) {
1164  UniValue entry(UniValue::VOBJ);
1165  if (involvesWatchonly || (::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY))
1166  entry.push_back(Pair("involvesWatchonly", true));
1167  entry.push_back(Pair("account", strSentAccount));
1168  MaybePushAddress(entry, s.destination);
1169  entry.push_back(Pair("category", "send"));
1170  entry.push_back(Pair("amount", ValueFromAmount(-s.amount)));
1171  entry.push_back(Pair("vout", s.vout));
1172  entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
1173  if (fLong)
1174  WalletTxToJSON(wtx, entry);
1175  ret.push_back(entry);
1176  }
1177  }
1178 
1179  // Received
1180  if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) {
1181  for (const COutputEntry& r : listReceived) {
1182  std::string account;
1183  if (pwalletMain->mapAddressBook.count(r.destination))
1184  account = pwalletMain->mapAddressBook[r.destination].name;
1185  if (fAllAccounts || (account == strAccount)) {
1186  UniValue entry(UniValue::VOBJ);
1187  if (involvesWatchonly || (::IsMine(*pwalletMain, r.destination) & ISMINE_WATCH_ONLY))
1188  entry.push_back(Pair("involvesWatchonly", true));
1189  entry.push_back(Pair("account", account));
1190  MaybePushAddress(entry, r.destination);
1191  if (wtx.IsCoinBase()) {
1192  if (wtx.GetDepthInMainChain() < 1)
1193  entry.push_back(Pair("category", "orphan"));
1194  else if (wtx.GetBlocksToMaturity() > 0)
1195  entry.push_back(Pair("category", "immature"));
1196  else
1197  entry.push_back(Pair("category", "generate"));
1198  } else {
1199  entry.push_back(Pair("category", "receive"));
1200  }
1201  entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
1202  entry.push_back(Pair("vout", r.vout));
1203  if (fLong)
1204  WalletTxToJSON(wtx, entry);
1205  ret.push_back(entry);
1206  }
1207  }
1208  }
1209 }
1210 
1211 void AcentryToJSON(const CAccountingEntry& acentry, const std::string& strAccount, UniValue& ret)
1212 {
1213  bool fAllAccounts = (strAccount == std::string("*"));
1214 
1215  if (fAllAccounts || acentry.strAccount == strAccount) {
1216  UniValue entry(UniValue::VOBJ);
1217  entry.push_back(Pair("account", acentry.strAccount));
1218  entry.push_back(Pair("category", "move"));
1219  entry.push_back(Pair("time", acentry.nTime));
1220  entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit)));
1221  entry.push_back(Pair("otheraccount", acentry.strOtherAccount));
1222  entry.push_back(Pair("comment", acentry.strComment));
1223  ret.push_back(entry);
1224  }
1225 }
1226 
1227 UniValue listtransactions(const UniValue& params, bool fHelp)
1228 {
1229  if (fHelp || params.size() > 4)
1230  throw std::runtime_error(
1231  "listtransactions ( \"account\" count from includeWatchonly)\n"
1232  "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
1233  "\nArguments:\n"
1234  "1. \"account\" (string, optional) The account name. If not included, it will list all transactions for all accounts.\n"
1235  " If \"\" is set, it will list transactions for the default account.\n"
1236  "2. count (numeric, optional, default=10) The number of transactions to return\n"
1237  "3. from (numeric, optional, default=0) The number of transactions to skip\n"
1238  "4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')\n"
1239  "\nResult:\n"
1240  "[\n"
1241  " {\n"
1242  " \"account\":\"accountname\", (string) The account name associated with the transaction. \n"
1243  " It will be \"\" for the default account.\n"
1244  " \"address\":\"prcycoinaddress\", (string) The prcycoin address of the transaction. Not present for \n"
1245  " move transactions (category = move).\n"
1246  " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
1247  " transaction between accounts, and not associated with an address,\n"
1248  " transaction id or block. 'send' and 'receive' transactions are \n"
1249  " associated with an address, transaction id and block details\n"
1250  " \"amount\": x.xxx, (numeric) The amount in PRCY. This is negative for the 'send' category, and for the\n"
1251  " 'move' category for moves outbound. It is positive for the 'receive' category,\n"
1252  " and for the 'move' category for inbound funds.\n"
1253  " \"vout\" : n, (numeric) the vout value\n"
1254  " \"fee\": x.xxx, (numeric) The amount of the fee in PRCY. This is negative and only available for the \n"
1255  " 'send' category of transactions.\n"
1256  " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n"
1257  " 'receive' category of transactions.\n"
1258  " \"bcconfirmations\": n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send'\n"
1259  " and 'receive' category of transactions.\n"
1260  " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
1261  " category of transactions.\n"
1262  " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n"
1263  " category of transactions.\n"
1264  " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1265  " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
1266  " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
1267  " for 'send' and 'receive' category of transactions.\n"
1268  " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1269  " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n"
1270  " from (for receiving funds, positive amounts), or went to (for sending funds,\n"
1271  " negative amounts).\n"
1272  " }\n"
1273  "]\n"
1274 
1275  "\nExamples:\n"
1276  "\nList the most recent 10 transactions in the systems\n" +
1277  HelpExampleCli("listtransactions", "") +
1278  "\nList the most recent 10 transactions for the tabby account\n" + HelpExampleCli("listtransactions", "\"tabby\"") +
1279  "\nList transactions 100 to 120 from the tabby account\n" + HelpExampleCli("listtransactions", "\"tabby\" 20 100") +
1280  "\nAs a json rpc call\n" + HelpExampleRpc("listtransactions", "\"tabby\", 20, 100"));
1281 
1283 
1284  std::string strAccount = "*";
1285  if (params.size() > 0)
1286  strAccount = params[0].get_str();
1287  int nCount = 10;
1288  if (params.size() > 1)
1289  nCount = params[1].get_int();
1290  int nFrom = 0;
1291  if (params.size() > 2)
1292  nFrom = params[2].get_int();
1293  isminefilter filter = ISMINE_SPENDABLE;
1294  if (params.size() > 3)
1295  if (params[3].get_bool())
1296  filter = filter | ISMINE_WATCH_ONLY;
1297 
1298  if (nCount < 0)
1299  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
1300  if (nFrom < 0)
1301  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
1302 
1303  UniValue ret(UniValue::VARR);
1304 
1305  const CWallet::TxItems & txOrdered = pwalletMain->wtxOrdered;
1306 
1307  // iterate backwards until we have nCount items to return:
1308  for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) {
1309  CWalletTx* const pwtx = (*it).second.first;
1310  if (pwtx != 0)
1311  ListTransactions(*pwtx, strAccount, 0, true, ret, filter);
1312  CAccountingEntry* const pacentry = (*it).second.second;
1313  if (pacentry != 0)
1314  AcentryToJSON(*pacentry, strAccount, ret);
1315 
1316  if ((int)ret.size() >= (nCount + nFrom)) break;
1317  }
1318  // ret is newest to oldest
1319 
1320  if (nFrom > (int)ret.size())
1321  nFrom = ret.size();
1322  if ((nFrom + nCount) > (int)ret.size())
1323  nCount = ret.size() - nFrom;
1324 
1325  std::vector<UniValue> arrTmp = ret.getValues();
1326 
1327  std::vector<UniValue>::iterator first = arrTmp.begin();
1328  std::advance(first, nFrom);
1329 
1330  std::vector<UniValue>::iterator last = arrTmp.begin();
1331  std::advance(last, nFrom + nCount);
1332 
1333  if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end());
1334  if (first != arrTmp.begin()) arrTmp.erase(arrTmp.begin(), first);
1335 
1336  std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
1337 
1338  ret.clear();
1339  ret.setArray();
1340  ret.push_backV(arrTmp);
1341 
1342  return ret;
1343 }
1344 
1346 {
1347  if (fHelp || params.size() > 3)
1348  throw std::runtime_error(
1349  "listtransactionsbypaymentid ( paymentid count from includeWatchonly)\n"
1350  "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for paymentid 'paymentid'.\n"
1351  "\nArguments:\n"
1352  "1. paymentid (numeric required) The paymentid to list all transactions for.\n"
1353  "2. count (numeric, optional, default=10) The number of transactions to return\n"
1354  "3. from (numeric, optional, default=0) The number of transactions to skip\n"
1355  "\nResult:\n"
1356  "[\n"
1357  " {\n"
1358  " \"account\":\"accountname\", (string) The account name associated with the transaction. \n"
1359  " It will be \"\" for the default account.\n"
1360  " \"address\":\"prcycoinaddress\", (string) The prcycoin address of the transaction. Not present for \n"
1361  " move transactions (category = move).\n"
1362  " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
1363  " transaction between accounts, and not associated with an address,\n"
1364  " transaction id or block. 'send' and 'receive' transactions are \n"
1365  " associated with an address, transaction id and block details\n"
1366  " \"amount\": x.xxx, (numeric) The amount in PRCY. This is negative for the 'send' category, and for the\n"
1367  " 'move' category for moves outbound. It is positive for the 'receive' category,\n"
1368  " and for the 'move' category for inbound funds.\n"
1369  " \"vout\" : n, (numeric) the vout value\n"
1370  " \"fee\": x.xxx, (numeric) The amount of the fee in PRCY. This is negative and only available for the \n"
1371  " 'send' category of transactions.\n"
1372  " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n"
1373  " 'receive' category of transactions.\n"
1374  " \"bcconfirmations\": n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send'\n"
1375  " and 'receive' category of transactions.\n"
1376  " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
1377  " category of transactions.\n"
1378  " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n"
1379  " category of transactions.\n"
1380  " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1381  " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
1382  " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
1383  " for 'send' and 'receive' category of transactions.\n"
1384  " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1385  " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n"
1386  " from (for receiving funds, positive amounts), or went to (for sending funds,\n"
1387  " negative amounts).\n"
1388  " }\n"
1389  "]\n"
1390 
1391  "\nExamples:\n"
1392  "\nList the most recent 10 transactions for the Payment ID\n" + HelpExampleCli("listtransactionsbypaymentid", "123456") +
1393  "\nList transactions 100 to 120 from the Payment ID\n" + HelpExampleCli("listtransactionsbypaymentid", "123456 20 100") +
1394  "\nAs a json rpc call\n" + HelpExampleRpc("listtransactionsbypaymentid", "123456, 20, 100"));
1395 
1397 
1398  std::string strAccount = "*";
1399  uint64_t paymentID = 0;
1400  if (params.size() > 0)
1401  paymentID = params[0].get_int64();
1402  int nCount = 10;
1403  if (params.size() > 1)
1404  nCount = params[1].get_int();
1405  int nFrom = 0;
1406  if (params.size() > 2)
1407  nFrom = params[2].get_int();
1408  isminefilter filter = ISMINE_SPENDABLE;
1409 
1410  if (nCount < 0)
1411  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
1412  if (nFrom < 0)
1413  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
1414 
1415  UniValue ret(UniValue::VARR);
1416 
1417  const CWallet::TxItems & txOrdered = pwalletMain->wtxOrdered;
1418 
1419  // iterate backwards until we have nCount items to return:
1420  for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) {
1421  CWalletTx* const pwtx = (*it).second.first;
1422  if (pwtx != 0 && (pwtx->hasPaymentID && pwtx->paymentID == paymentID))
1423  ListTransactions(*pwtx, strAccount, 0, true, ret, filter);
1424  CAccountingEntry* const pacentry = (*it).second.second;
1425  if (pacentry != 0)
1426  AcentryToJSON(*pacentry, strAccount, ret);
1427 
1428  if ((int)ret.size() >= (nCount + nFrom)) break;
1429  }
1430  // ret is newest to oldest
1431 
1432  if (nFrom > (int)ret.size())
1433  nFrom = ret.size();
1434  if ((nFrom + nCount) > (int)ret.size())
1435  nCount = ret.size() - nFrom;
1436 
1437  std::vector<UniValue> arrTmp = ret.getValues();
1438 
1439  std::vector<UniValue>::iterator first = arrTmp.begin();
1440  std::advance(first, nFrom);
1441 
1442  std::vector<UniValue>::iterator last = arrTmp.begin();
1443  std::advance(last, nFrom + nCount);
1444 
1445  if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end());
1446  if (first != arrTmp.begin()) arrTmp.erase(arrTmp.begin(), first);
1447 
1448  std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
1449 
1450  ret.clear();
1451  ret.setArray();
1452  ret.push_backV(arrTmp);
1453 
1454  return ret;
1455 }
1456 
1457 UniValue listaccounts(const UniValue& params, bool fHelp)
1458 {
1459  if (fHelp || params.size() > 2)
1460  throw std::runtime_error(
1461  "listaccounts ( minconf includeWatchonly)\n"
1462  "\nReturns Object that has account names as keys, account balances as values.\n"
1463  "\nArguments:\n"
1464  "1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n"
1465  "2. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n"
1466  "\nResult:\n"
1467  "{ (json object where keys are account names, and values are numeric balances\n"
1468  " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
1469  " ...\n"
1470  "}\n"
1471  "\nExamples:\n"
1472  "\nList account balances where there at least 1 confirmation\n" +
1473  HelpExampleCli("listaccounts", "") +
1474  "\nList account balances including zero confirmation transactions\n" + HelpExampleCli("listaccounts", "0") +
1475  "\nList account balances for 6 or more confirmations\n" + HelpExampleCli("listaccounts", "6") +
1476  "\nAs json rpc call\n" + HelpExampleRpc("listaccounts", "6"));
1477 
1479 
1480  int nMinDepth = 1;
1481  if (params.size() > 0)
1482  nMinDepth = params[0].get_int();
1483  isminefilter includeWatchonly = ISMINE_SPENDABLE;
1484  if (params.size() > 1)
1485  if (params[1].get_bool())
1486  includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
1487 
1488  std::map<std::string, CAmount> mapAccountBalances;
1490  if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
1491  mapAccountBalances[entry.second.name] = 0;
1492  }
1493 
1494  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
1495  const CWalletTx& wtx = (*it).second;
1496  CAmount nFee;
1497  std::string strSentAccount;
1498  std::list<COutputEntry> listReceived;
1499  std::list<COutputEntry> listSent;
1500  int nDepth = wtx.GetDepthInMainChain();
1501  if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
1502  continue;
1503  wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
1504  mapAccountBalances[strSentAccount] -= nFee;
1505  for (const COutputEntry& s : listSent)
1506  mapAccountBalances[strSentAccount] -= s.amount;
1507  if (nDepth >= nMinDepth) {
1508  for (const COutputEntry& r : listReceived)
1509  if (pwalletMain->mapAddressBook.count(r.destination))
1510  mapAccountBalances[pwalletMain->mapAddressBook[r.destination].name] += r.amount;
1511  else
1512  mapAccountBalances[""] += r.amount;
1513  }
1514  }
1515 
1516  const std::list<CAccountingEntry> & acentries = pwalletMain->laccentries;
1517  for (const CAccountingEntry& entry : acentries)
1518  mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
1519 
1520  UniValue ret(UniValue::VOBJ);
1521  for (const PAIRTYPE(std::string, CAmount) & accountBalance : mapAccountBalances) {
1522  ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
1523  }
1524  return ret;
1525 }
1526 
1527 UniValue listsinceblock(const UniValue& params, bool fHelp)
1528 {
1529  if (fHelp)
1530  throw std::runtime_error(
1531  "listsinceblock ( \"blockhash\" target-confirmations includeWatchonly)\n"
1532  "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
1533  "\nArguments:\n"
1534  "1. \"blockhash\" (string, optional) The block hash to list transactions since\n"
1535  "2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more\n"
1536  "3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')"
1537  "\nResult:\n"
1538  "{\n"
1539  " \"transactions\": [\n"
1540  " \"account\":\"accountname\", (string) The account name associated with the transaction. Will be \"\" for the default account.\n"
1541  " \"address\":\"prcycoinaddress\", (string) The prcycoin address of the transaction. Not present for move transactions (category = move).\n"
1542  " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
1543  " \"amount\": x.xxx, (numeric) The amount in PRCY. This is negative for the 'send' category, and for the 'move' category for moves \n"
1544  " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
1545  " \"vout\" : n, (numeric) the vout value\n"
1546  " \"fee\": x.xxx, (numeric) The amount of the fee in PRCY. This is negative and only available for the 'send' category of transactions.\n"
1547  " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
1548  " \"bcconfirmations\" : n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
1549  " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
1550  " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
1551  " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
1552  " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1553  " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n"
1554  " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n"
1555  " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1556  " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n"
1557  " ],\n"
1558  " \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n"
1559  "}\n"
1560  "\nExamples:\n" +
1561  HelpExampleCli("listsinceblock", "") + HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6") + HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6"));
1562 
1564 
1565  CBlockIndex* pindex = NULL;
1566  int target_confirms = 1;
1567  isminefilter filter = ISMINE_SPENDABLE;
1568 
1569  if (params.size() > 0) {
1570  uint256 blockId;
1571 
1572  blockId.SetHex(params[0].get_str());
1573  BlockMap::iterator it = mapBlockIndex.find(blockId);
1574  if (it != mapBlockIndex.end())
1575  pindex = it->second;
1576  }
1577 
1578  if (params.size() > 1) {
1579  target_confirms = params[1].get_int();
1580 
1581  if (target_confirms < 1)
1582  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
1583  }
1584 
1585  if (params.size() > 2)
1586  if (params[2].get_bool())
1587  filter = filter | ISMINE_WATCH_ONLY;
1588 
1589  int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
1590 
1591  UniValue transactions(UniValue::VARR);
1592 
1593  for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++) {
1594  CWalletTx tx = (*it).second;
1595 
1596  if (depth == -1 || tx.GetDepthInMainChain(false) < depth)
1597  ListTransactions(tx, "*", 0, true, transactions, filter);
1598  }
1599 
1600  CBlockIndex* pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
1601  uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : UINT256_ZERO;
1602 
1603  UniValue ret(UniValue::VOBJ);
1604  ret.push_back(Pair("transactions", transactions));
1605  ret.push_back(Pair("lastblock", lastblock.GetHex()));
1606 
1607  return ret;
1608 }
1609 
1610 UniValue gettransaction(const UniValue& params, bool fHelp)
1611 {
1612  if (fHelp || params.size() < 1 || params.size() > 2)
1613  throw std::runtime_error(
1614  "gettransaction \"txid\" ( includeWatchonly )\n"
1615  "\nGet detailed information about in-wallet transaction <txid>\n"
1616  "\nArguments:\n"
1617  "1. \"txid\" (string, required) The transaction id\n"
1618  "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n"
1619  "\nResult:\n"
1620  "{\n"
1621  " \"amount\" : x.xxx, (numeric) The transaction amount in PRCY\n"
1622  " \"confirmations\" : n, (numeric) The number of confirmations\n"
1623  " \"bcconfirmations\" : n, (numeric) The number of blockchain confirmations\n"
1624  " \"blockhash\" : \"hash\", (string) The block hash\n"
1625  " \"blockindex\" : xx, (numeric) The block index\n"
1626  " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n"
1627  " \"txid\" : \"transactionid\", (string) The transaction id.\n"
1628  " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n"
1629  " \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n"
1630  " \"details\" : [\n"
1631  " {\n"
1632  " \"account\" : \"accountname\", (string) The account name involved in the transaction, can be \"\" for the default account.\n"
1633  " \"address\" : \"prcycoinaddress\", (string) The prcycoin address involved in the transaction\n"
1634  " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
1635  " \"amount\" : x.xxx (numeric) The amount in PRCY\n"
1636  " \"vout\" : n, (numeric) the vout value\n"
1637  " }\n"
1638  " ,...\n"
1639  " ],\n"
1640  " \"hex\" : \"data\" (string) Raw data for transaction\n"
1641  "}\n"
1642 
1643  "\nExamples:\n" +
1644  HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true") + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\""));
1645 
1647 
1648  uint256 hash;
1649  hash.SetHex(params[0].get_str());
1650 
1651  isminefilter filter = ISMINE_SPENDABLE;
1652  if (params.size() > 1)
1653  if (params[1].get_bool())
1654  filter = filter | ISMINE_WATCH_ONLY;
1655 
1656  UniValue entry(UniValue::VOBJ);
1657  if (!pwalletMain->mapWallet.count(hash))
1658  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
1659  const CWalletTx& wtx = pwalletMain->mapWallet[hash];
1660 
1661  CAmount nCredit = wtx.GetCredit(filter);
1662  CAmount nDebit = wtx.GetDebit(filter);
1663  CAmount nNet = (nCredit > nDebit)? (nCredit - nDebit):(nDebit - nCredit);
1664  CAmount nFee = wtx.nTxFee;
1665  entry.push_back(Pair("amount", ValueFromAmount(nNet)));
1666  if (wtx.IsFromMe(filter))
1667  entry.push_back(Pair("fee", ValueFromAmount(nFee)));
1668 
1669  WalletTxToJSON(wtx, entry);
1670 
1671  UniValue details(UniValue::VARR);
1672  ListTransactions(wtx, "*", 0, false, details, filter);
1673  entry.push_back(Pair("details", details));
1674 
1675  std::string strHex = EncodeHexTx(static_cast<CTransaction>(wtx));
1676  entry.push_back(Pair("hex", strHex));
1677 
1678  return entry;
1679 }
1680 
1681 
1682 UniValue backupwallet(const UniValue& params, bool fHelp)
1683 {
1684  if (fHelp || params.size() != 1)
1685  throw std::runtime_error(
1686  "backupwallet \"destination\"\n"
1687  "\nSafely copies wallet.dat to destination, which can be a directory or a path with filename.\n"
1688  "\nArguments:\n"
1689  "1. \"destination\" (string) The destination directory or file\n"
1690  "\nExamples:\n" +
1691  HelpExampleCli("backupwallet", "\"backup.dat\"") + HelpExampleRpc("backupwallet", "\"backup.dat\""));
1692 
1694 
1695  std::string strDest = params[0].get_str();
1696  if (!BackupWallet(*pwalletMain, strDest))
1697  throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
1698 
1699  return "Done";
1700 }
1701 
1702 
1703 UniValue keypoolrefill(const UniValue& params, bool fHelp)
1704 {
1705  if (fHelp || params.size() > 1)
1706  throw std::runtime_error(
1707  "keypoolrefill ( newsize )\n"
1708  "\nFills the keypool." +
1709  HelpRequiringPassphrase() + "\n"
1710  "\nArguments\n"
1711  "1. newsize (numeric, optional, default=100) The new keypool size\n"
1712  "\nExamples:\n" +
1713  HelpExampleCli("keypoolrefill", "") + HelpExampleRpc("keypoolrefill", ""));
1714 
1716 
1717  // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
1718  unsigned int kpSize = 0;
1719  if (params.size() > 0) {
1720  if (params[0].get_int() < 0)
1721  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
1722  kpSize = (unsigned int)params[0].get_int();
1723  }
1724 
1726  pwalletMain->TopUpKeyPool(kpSize);
1727 
1728  if (pwalletMain->GetKeyPoolSize() < kpSize)
1729  throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
1730 
1731  return NullUniValue;
1732 }
1733 
1734 
1735 static void LockWallet(CWallet* pWallet)
1736 {
1737  LOCK(cs_nWalletUnlockTime);
1738  nWalletUnlockTime = 0;
1739  pWallet->fWalletUnlockStakingOnly = false;
1740  pWallet->Lock();
1741 }
1742 
1743 UniValue unlockwallet(const UniValue& params, bool fHelp)
1744 {
1745  if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3))
1746  throw std::runtime_error(
1747  "unlockwallet \"passphrase\" timeout ( stakingonly )\n"
1748  "\nStores the wallet decryption key in memory for 'timeout' seconds.\n"
1749  "This is needed prior to performing transactions related to private keys such as sending PRCYs\n"
1750  "\nArguments:\n"
1751  "1. \"passphrase\" (string, required) The wallet passphrase\n"
1752  "2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
1753  "3. stakingonly (boolean, optional, default=false) If is true sending functions are disabled."
1754  "\nNote:\n"
1755  "Issuing the unlockwallet command while the wallet is already unlocked will set a new unlock\n"
1756  "time that overrides the old one. A timeout of \"0\" unlocks until the wallet is closed.\n"
1757  "\nExamples:\n"
1758  "\nUnlock the wallet for 60 seconds\n" +
1759  HelpExampleCli("unlockwallet", "\"my pass phrase\" 60") +
1760  "\nUnlock the wallet for 60 seconds but allow Obfuscation only\n" + HelpExampleCli("unlockwallet", "\"my pass phrase\" 60 true") +
1761  "\nLock the wallet again (before 60 seconds)\n" + HelpExampleCli("walletlock", "") +
1762  "\nAs json rpc call\n" + HelpExampleRpc("unlockwallet", "\"my pass phrase\", 60"));
1763 
1765 
1766  if (fHelp)
1767  return true;
1768  if (!pwalletMain->IsCrypted())
1769  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but unlockwallet was called.");
1770 
1771  // Note that the walletpassphrase is stored in params[0] which is not mlock()ed
1772  SecureString strWalletPass;
1773  strWalletPass.reserve(100);
1774  // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
1775  // Alternately, find a way to make params[0] mlock()'d to begin with.
1776  strWalletPass = params[0].get_str().c_str();
1777 
1778  bool stakingOnly = false;
1779  if (params.size() == 3)
1780  stakingOnly = params[2].get_bool();
1781 
1782  if (!pwalletMain->IsLocked() && pwalletMain->fWalletUnlockStakingOnly && stakingOnly)
1783  throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked.");
1784 
1785  // Get the timeout
1786  int64_t nSleepTime = params[1].get_int64();
1787  // Timeout cannot be negative, otherwise it will relock immediately
1788  if (nSleepTime < 0) {
1789  throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative.");
1790  }
1791  // Clamp timeout
1792  constexpr int64_t MAX_SLEEP_TIME = 100000000; // larger values trigger a macos/libevent bug?
1793  if (nSleepTime > MAX_SLEEP_TIME) {
1794  nSleepTime = MAX_SLEEP_TIME;
1795  }
1796 
1797  if (!pwalletMain->Unlock(strWalletPass, stakingOnly))
1798  throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
1799 
1801 
1802 
1803  if (nSleepTime > 0) {
1804  nWalletUnlockTime = GetTime () + nSleepTime;
1805  RPCRunLater ("lockwallet", boost::bind (LockWallet, pwalletMain), nSleepTime);
1806  }
1807  return NullUniValue;
1808 }
1809 
1810 
1811 UniValue walletpassphrasechange(const UniValue& params, bool fHelp)
1812 {
1813  if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
1814  throw std::runtime_error(
1815  "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n"
1816  "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n"
1817  "\nArguments:\n"
1818  "1. \"oldpassphrase\" (string) The current passphrase\n"
1819  "2. \"newpassphrase\" (string) The new passphrase\n"
1820  "\nExamples:\n" +
1821  HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"") + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\""));
1822 
1824 
1825  if (fHelp)
1826  return true;
1827  if (!pwalletMain->IsCrypted())
1828  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
1829 
1830  // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
1831  // Alternately, find a way to make params[0] mlock()'d to begin with.
1832  SecureString strOldWalletPass;
1833  strOldWalletPass.reserve(100);
1834  strOldWalletPass = params[0].get_str().c_str();
1835 
1836  SecureString strNewWalletPass;
1837  strNewWalletPass.reserve(100);
1838  strNewWalletPass = params[1].get_str().c_str();
1839 
1840  if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
1841  throw std::runtime_error(
1842  "walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
1843  "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
1844 
1845  if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass))
1846  throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
1847 
1848  return NullUniValue;
1849 }
1850 
1851 
1852 UniValue walletlock(const UniValue& params, bool fHelp)
1853 {
1854  if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0))
1855  throw std::runtime_error(
1856  "walletlock\n"
1857  "\nRemoves the wallet encryption key from memory, locking the wallet.\n"
1858  "After calling this method, you will need to call unlockwallet again\n"
1859  "before being able to call any methods which require the wallet to be unlocked.\n"
1860  "\nExamples:\n"
1861  "\nSet the passphrase for 2 minutes to perform a transaction\n" +
1862  HelpExampleCli("unlockwallet", "\"my pass phrase\" 120") +
1863  "\nPerform a send (requires passphrase set)\n" + HelpExampleCli("sendtostealthaddress", "\"Pap5WCV4SjVMGLyYf98MEX82ErBEMVpg9ViQ1up3aBib6Fz4841SahrRXG6eSNSLBSNvEiGuQiWKXJC3RDfmotKv15oCrh6N2Ym\" 1.0") +
1864  "\nClear the passphrase since we are done before 2 minutes is up\n" + HelpExampleCli("walletlock", "") +
1865  "\nAs json rpc call\n" + HelpExampleRpc("walletlock", ""));
1866 
1868 
1869  if (fHelp)
1870  return true;
1871 
1872  if (!pwalletMain->IsCrypted())
1873  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
1874 
1875  pwalletMain->Lock();
1876  nWalletUnlockTime = 0;
1877 
1878  return NullUniValue;
1879 }
1880 
1881 
1882 UniValue encryptwallet(const UniValue& params, bool fHelp)
1883 {
1884  if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1))
1885  throw std::runtime_error(
1886  "encryptwallet \"passphrase\"\n"
1887  "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n"
1888  "After this, any calls that interact with private keys such as sending or signing \n"
1889  "will require the passphrase to be set prior the making these calls.\n"
1890  "Use the unlockwallet call for this, and then walletlock call.\n"
1891  "If the wallet is already encrypted, use the walletpassphrasechange call.\n"
1892  "Note that this will shutdown the server.\n"
1893  "\nArguments:\n"
1894  "1. \"passphrase\" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.\n"
1895  "\nExamples:\n"
1896  "\nEncrypt you wallet\n" +
1897  HelpExampleCli("encryptwallet", "\"my pass phrase\"") +
1898  "\nNow set the passphrase to use the wallet, such as for signing or sending PRCYs\n" + HelpExampleCli("unlockwallet", "\"my pass phrase\"") +
1899  "\nNow we can so something like sign\n" + HelpExampleCli("signmessage", "\"prcycoinaddress\" \"test message\"") +
1900  "\nNow lock the wallet again by removing the passphrase\n" + HelpExampleCli("walletlock", "") +
1901  "\nAs a json rpc call\n" + HelpExampleRpc("encryptwallet", "\"my pass phrase\""));
1902 
1904  if (fHelp)
1905  return true;
1906  if (pwalletMain->IsCrypted())
1907  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
1908 
1909  // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
1910  // Alternately, find a way to make params[0] mlock()'d to begin with.
1911  SecureString strWalletPass;
1912  strWalletPass.reserve(100);
1913  strWalletPass = params[0].get_str().c_str();
1914 
1915  if (strWalletPass.length() < 1)
1916  throw std::runtime_error(
1917  "encryptwallet <passphrase>\n"
1918  "Encrypts the wallet with <passphrase>.");
1919 
1920 
1921  if (!pwalletMain->EncryptWallet(strWalletPass))
1922  throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
1923 
1924  // BDB seems to have a bad habit of writing old data into
1925  // slack space in .dat files; that is bad if the old data is
1926  // unencrypted private keys. So:
1927  StartShutdown();
1928  return "wallet encrypted; prcycoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
1929 }
1930 
1931 UniValue lockunspent(const UniValue& params, bool fHelp)
1932 {
1933  if (fHelp || params.size() < 1 || params.size() > 2)
1934  throw std::runtime_error(
1935  "lockunspent unlock [{\"txid\":\"txid\",\"vout\":n},...]\n"
1936  "\nUpdates list of temporarily unspendable outputs.\n"
1937  "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
1938  "A locked transaction output will not be chosen by automatic coin selection, when spending PRCYs.\n"
1939  "Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n"
1940  "is always cleared (by virtue of process exit) when a node stops or fails.\n"
1941  "Also see the listunspent call\n"
1942  "\nArguments:\n"
1943  "1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions\n"
1944  "2. \"transactions\" (string, required) A json array of objects. Each object the txid (string) vout (numeric)\n"
1945  " [ (json array of json objects)\n"
1946  " {\n"
1947  " \"txid\":\"id\", (string) The transaction id\n"
1948  " \"vout\": n (numeric) The output number\n"
1949  " }\n"
1950  " ,...\n"
1951  " ]\n"
1952 
1953  "\nResult:\n"
1954  "true|false (boolean) Whether the command was successful or not\n"
1955 
1956  "\nExamples:\n"
1957  "\nList the unspent transactions\n" +
1958  HelpExampleCli("listunspent", "") +
1959  "\nLock an unspent transaction\n" + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"afbf98345239a27c35db94c03c33d87104ee9ce5c9790f3f756620e6f23d3816\\\",\\\"vout\\\":1}]\"") +
1960  "\nList the locked transactions\n" + HelpExampleCli("listlockunspent", "") +
1961  "\nUnlock the transaction again\n" + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"afbf98345239a27c35db94c03c33d87104ee9ce5c9790f3f756620e6f23d3816\\\",\\\"vout\\\":1}]\"") +
1962  "\nAs a json rpc call\n" + HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"afbf98345239a27c35db94c03c33d87104ee9ce5c9790f3f756620e6f23d3816\\\",\\\"vout\\\":1}]\""));
1963 
1965 
1966  if (params.size() == 1)
1967  RPCTypeCheck(params, boost::assign::list_of(UniValue::VBOOL));
1968  else
1969  RPCTypeCheck(params, boost::assign::list_of(UniValue::VBOOL)(UniValue::VARR));
1970 
1971  bool fUnlock = params[0].get_bool();
1972 
1973  if (params.size() == 1) {
1974  if (fUnlock)
1976  return true;
1977  }
1978 
1979  UniValue outputs = params[1].get_array();
1980  for (unsigned int idx = 0; idx < outputs.size(); idx++) {
1981  const UniValue& output = outputs[idx];
1982  if (!output.isObject())
1983  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
1984  const UniValue& o = output.get_obj();
1985  RPCTypeCheckObj(o, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM));
1986 
1987  std::string txid = find_value(o, "txid").get_str();
1988  if (!IsHex(txid))
1989  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid");
1990 
1991  int nOutput = find_value(o, "vout").get_int();
1992  if (nOutput < 0)
1993  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
1994 
1995  COutPoint outpt(uint256S(txid), nOutput);
1996 
1997  if (fUnlock)
1998  pwalletMain->UnlockCoin(outpt);
1999  else
2000  pwalletMain->LockCoin(outpt);
2001  }
2002 
2003  return true;
2004 }
2005 
2006 UniValue listlockunspent(const UniValue& params, bool fHelp)
2007 {
2008  if (fHelp || params.size() > 0)
2009  throw std::runtime_error(
2010  "listlockunspent\n"
2011  "\nReturns list of temporarily unspendable outputs.\n"
2012  "See the lockunspent call to lock and unlock transactions for spending.\n"
2013  "\nResult:\n"
2014  "[\n"
2015  " {\n"
2016  " \"txid\" : \"transactionid\", (string) The transaction id locked\n"
2017  " \"vout\" : n (numeric) The vout value\n"
2018  " }\n"
2019  " ,...\n"
2020  "]\n"
2021  "\nExamples:\n"
2022  "\nList the unspent transactions\n" +
2023  HelpExampleCli("listunspent", "") +
2024  "\nLock an unspent transaction\n" + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"afbf98345239a27c35db94c03c33d87104ee9ce5c9790f3f756620e6f23d3816\\\",\\\"vout\\\":1}]\"") +
2025  "\nList the locked transactions\n" + HelpExampleCli("listlockunspent", "") +
2026  "\nUnlock the transaction again\n" + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"afbf98345239a27c35db94c03c33d87104ee9ce5c9790f3f756620e6f23d3816\\\",\\\"vout\\\":1}]\"") +
2027  "\nAs a json rpc call\n" + HelpExampleRpc("listlockunspent", ""));
2028 
2030 
2031  std::vector<COutPoint> vOutpts;
2032  pwalletMain->ListLockedCoins(vOutpts);
2033 
2034  UniValue ret(UniValue::VARR);
2035 
2036  for (COutPoint& outpt : vOutpts) {
2038 
2039  o.push_back(Pair("txid", outpt.hash.GetHex()));
2040  o.push_back(Pair("vout", (int)outpt.n));
2041  ret.push_back(o);
2042  }
2043 
2044  return ret;
2045 }
2046 
2047 UniValue settxfee(const UniValue& params, bool fHelp)
2048 {
2049  if (fHelp || params.size() < 1 || params.size() > 1)
2050  throw std::runtime_error(
2051  "settxfee amount\n"
2052  "\nSet the transaction fee per kB.\n"
2053  "\nArguments:\n"
2054  "1. amount (numeric, required) The transaction fee in PRCY/kB rounded to the nearest 0.00000001\n"
2055  "\nResult\n"
2056  "true|false (boolean) Returns true if successful\n"
2057  "\nExamples:\n" +
2058  HelpExampleCli("settxfee", "0.00001") + HelpExampleRpc("settxfee", "0.00001"));
2059 
2061 
2062  // Amount
2063  CAmount nAmount = 0;
2064  if (params[0].get_real() != 0.0)
2065  nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts
2066 
2067  payTxFee = CFeeRate(nAmount, 1000);
2068  return true;
2069 }
2070 
2071 UniValue getwalletinfo(const UniValue& params, bool fHelp)
2072 {
2073  if (fHelp || params.size() != 0)
2074  throw std::runtime_error(
2075  "getwalletinfo\n"
2076  "Returns an object containing various wallet state info.\n"
2077  "\nResult:\n"
2078  "{\n"
2079  " \"walletversion\": xxxxx, (numeric) the wallet version\n"
2080  " \"balance\": xxxxxxx, (numeric) the total PRCY balance of the wallet\n"
2081  " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in PRCY\n"
2082  " \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in PRCY\n"
2083  " \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
2084  " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
2085  " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
2086  " \"walletunlocked\": true|false,(boolean) if the wallet is unlocked\n"
2087  " \"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"
2088  " \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in PRCY/kB\n"
2089  "}\n"
2090  "\nExamples:\n" +
2091  HelpExampleCli("getwalletinfo", "") + HelpExampleRpc("getwalletinfo", ""));
2092 
2094 
2095  UniValue obj(UniValue::VOBJ);
2096  obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
2097  obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
2098  obj.push_back(Pair("unconfirmed_balance", ValueFromAmount(pwalletMain->GetUnconfirmedBalance())));
2099  obj.push_back(Pair("immature_balance", ValueFromAmount(pwalletMain->GetImmatureBalance())));
2100  obj.push_back(Pair("txcount", (int)pwalletMain->mapWallet.size()));
2101  obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
2102  obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
2103  if (pwalletMain->IsCrypted())
2104  obj.push_back(Pair("walletunlocked", !pwalletMain->IsLocked()));
2105  obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
2106  obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
2107  return obj;
2108 }
2109 
2110 UniValue gettxcount(const UniValue& params, bool fHelp)
2111 {
2112  if (fHelp || params.size() != 0)
2113  throw std::runtime_error(
2114  "gettxcount\n"
2115  "Returns the total number of transactions in the wallet.\n"
2116  "\nResult:\n"
2117  "{\n"
2118  " \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
2119  "}\n"
2120  "\nExamples:\n" +
2121  HelpExampleCli("gettxcount", "") + HelpExampleRpc("gettxcount", ""));
2122 
2124 
2125  UniValue obj(UniValue::VOBJ);
2126  obj.push_back(Pair("txcount", (int)pwalletMain->mapWallet.size()));
2127  return obj;
2128 }
2129 
2130 // ppcoin: reserve balance from being staked for network protection
2131 UniValue reservebalance(const UniValue& params, bool fHelp)
2132 {
2133  if (fHelp || params.size() > 2)
2134  throw std::runtime_error(
2135  "reservebalance ( reserve amount )\n"
2136  "\nShow or set the reserve amount not participating in network protection\n"
2137  "If no parameters provided current setting is printed.\n"
2138 
2139  "\nArguments:\n"
2140  "1. reserve (boolean, optional) is true or false to turn balance reserve on or off.\n"
2141  "2. amount (numeric, optional) is a real and rounded to cent.\n"
2142 
2143  "\nResult:\n"
2144  "{\n"
2145  " \"reserve\": true|false, (boolean) Status of the reserve balance\n"
2146  " \"amount\": x.xxxx (numeric) Amount reserved\n"
2147  "\nExamples:\n" +
2148  HelpExampleCli("reservebalance", "true 5000") + HelpExampleRpc("reservebalance", "true 5000"));
2149 
2151 
2152  if (params.size() > 0) {
2153  bool fReserve = params[0].get_bool();
2154  if (fReserve) {
2155  if (params.size() == 1)
2156  throw std::runtime_error("must provide amount to reserve balance.\n");
2157  CAmount nAmount = AmountFromValue(params[1]);
2158  nAmount = (nAmount / CENT) * CENT; // round to cent
2159  if (nAmount < 0)
2160  throw std::runtime_error("amount cannot be negative.\n");
2161  nReserveBalance = nAmount;
2162 
2163  CWalletDB walletdb(pwalletMain->strWalletFile);
2164  walletdb.WriteReserveAmount(nReserveBalance / COIN);
2165 
2166  } else {
2167  if (params.size() > 1)
2168  throw std::runtime_error("cannot specify amount to turn off reserve.\n");
2169  nReserveBalance = 0;
2170  }
2171  }
2172 
2173  UniValue result(UniValue::VOBJ);
2174  result.push_back(Pair("reserve", (nReserveBalance > 0)));
2175  result.push_back(Pair("amount", ValueFromAmount(nReserveBalance)));
2176  return result;
2177 }
2178 
2179 // presstab HyperStake
2180 UniValue setstakesplitthreshold(const UniValue& params, bool fHelp)
2181 {
2182  if (fHelp || params.size() != 1)
2183  throw std::runtime_error(
2184  "setstakesplitthreshold value\n"
2185  "\nThis will set the output size of your stakes to never be below this number\n"
2186 
2187  "\nArguments:\n"
2188  "1. value (numeric, required) Threshold value between 1 and 999999\n"
2189  "\nResult:\n"
2190  "{\n"
2191  " \"threshold\": n, (numeric) Threshold value set\n"
2192  " \"saved\": true|false (boolean) 'true' if successfully saved to the wallet file\n"
2193  "}\n"
2194  "\nExamples:\n" +
2195  HelpExampleCli("setstakesplitthreshold", "5000") + HelpExampleRpc("setstakesplitthreshold", "5000"));
2196 
2197  uint64_t nStakeSplitThreshold = params[0].get_int();
2198  if (pwalletMain->IsLocked())
2199  throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Unlock wallet to use this feature");
2200  if (nStakeSplitThreshold > 999999)
2201  throw std::runtime_error("Value out of range, max allowed is 999999");
2202 
2203  CWalletDB walletdb(pwalletMain->strWalletFile);
2205  {
2206  bool fFileBacked = pwalletMain->fFileBacked;
2207 
2208  UniValue result(UniValue::VOBJ);
2209  pwalletMain->nStakeSplitThreshold = nStakeSplitThreshold;
2210  result.push_back(Pair("threshold", int(pwalletMain->nStakeSplitThreshold)));
2211  if (fFileBacked) {
2212  walletdb.WriteStakeSplitThreshold(nStakeSplitThreshold);
2213  result.push_back(Pair("saved", "true"));
2214  } else
2215  result.push_back(Pair("saved", "false"));
2216 
2217  return result;
2218  }
2219 }
2220 
2221 // presstab HyperStake
2222 UniValue getstakesplitthreshold(const UniValue& params, bool fHelp)
2223 {
2224  if (fHelp || params.size() != 0)
2225  throw std::runtime_error(
2226  "getstakesplitthreshold\n"
2227  "Returns the threshold for stake splitting\n"
2228  "\nResult:\n"
2229  "n (numeric) Threshold value\n"
2230  "\nExamples:\n" +
2231  HelpExampleCli("getstakesplitthreshold", "") + HelpExampleRpc("getstakesplitthreshold", ""));
2232 
2233  return int(pwalletMain->nStakeSplitThreshold);
2234 }
2235 
2236 UniValue autocombinedust(const UniValue& params, bool fHelp)
2237 {
2238  bool fEnable;
2239  if (params.size() >= 1)
2240  fEnable = params[0].get_bool();
2241 
2242  if (fHelp || params.size() < 1 || (fEnable && params.size() != 2) || params.size() > 2)
2243  throw std::runtime_error(
2244  "autocombinedust true|false ( threshold )\n"
2245  "\nWallet will automatically monitor for any coins with value below the threshold amount, and combine them if they reside with the same PRCY address\n"
2246  "When autocombinedust runs it will create a transaction, and therefore will be subject to transaction fees. Minimum of 25 dust transactions before activation.\n"
2247 
2248  "\nArguments:\n"
2249  "1. true|false (boolean, required) Enable auto combine (true) or disable (false)\n"
2250  "2. threshold (numeric, optional) Threshold amount (default: 0)\n"
2251  "\nExamples:\n" +
2252  HelpExampleCli("autocombinedust", "true 10") + HelpExampleRpc("autocombinedust", "true 150"));
2253 
2254  CWalletDB walletdb(pwalletMain->strWalletFile);
2255  CAmount nThreshold = 0;
2256 
2257  if (fEnable) {
2258  nThreshold = params[1].get_int();
2259  } else {
2260  nThreshold = 0;
2261  }
2262 
2263  pwalletMain->fCombineDust = fEnable;
2264  pwalletMain->nAutoCombineThreshold = nThreshold;
2265 
2266  if (!walletdb.WriteAutoCombineSettings(fEnable, nThreshold))
2267  throw std::runtime_error("Changed settings in wallet but failed to save to database\n");
2268 
2269  UniValue result(UniValue::VOBJ);
2270  result.push_back(Pair("autocombinedust", params[0].get_bool()));
2271  result.push_back(Pair("amount", int(pwalletMain->nAutoCombineThreshold)));
2272  return result;
2273 }
2274 
2276 {
2277  UniValue ret(UniValue::VARR);
2278  UniValue act(UniValue::VARR);
2279  act.push_back(Pair("MultiSendStake Activated?", pwalletMain->fMultiSendStake));
2280  act.push_back(Pair("MultiSendMasternode Activated?", pwalletMain->fMultiSendMasternodeReward));
2281  ret.push_back(act);
2282 
2283  if (pwalletMain->vDisabledAddresses.size() >= 1) {
2284  UniValue disAdd(UniValue::VOBJ);
2285  for (unsigned int i = 0; i < pwalletMain->vDisabledAddresses.size(); i++) {
2286  disAdd.push_back(Pair("Disabled From Sending", pwalletMain->vDisabledAddresses[i]));
2287  }
2288  ret.push_back(disAdd);
2289  }
2290 
2291  ret.push_back("MultiSend Addresses to Send To:");
2292 
2293  UniValue vMS(UniValue::VOBJ);
2294  for (unsigned int i = 0; i < pwalletMain->vMultiSend.size(); i++) {
2295  vMS.push_back(Pair("Address " + std::to_string(i), pwalletMain->vMultiSend[i].first));
2296  vMS.push_back(Pair("Percent", pwalletMain->vMultiSend[i].second));
2297  }
2298 
2299  ret.push_back(vMS);
2300  return ret;
2301 }
2302 
2304 {
2305  std::vector<COutput> vCoins;
2306  pwalletMain->AvailableCoins(vCoins);
2307  std::map<std::string, double> mapAddresses;
2308  for (const COutput& out : vCoins) {
2309  CTxDestination utxoAddress;
2310  ExtractDestination(out.tx->vout[out.i].scriptPubKey, utxoAddress);
2311  std::string strAdd = CBitcoinAddress(utxoAddress).ToString();
2312 
2313  if (mapAddresses.find(strAdd) == mapAddresses.end()) //if strAdd is not already part of the map
2314  mapAddresses[strAdd] = (double)out.tx->vout[out.i].nValue / (double)COIN;
2315  else
2316  mapAddresses[strAdd] += (double)out.tx->vout[out.i].nValue / (double)COIN;
2317  }
2318 
2319  UniValue ret(UniValue::VARR);
2320  for (std::map<std::string, double>::const_iterator it = mapAddresses.begin(); it != mapAddresses.end(); ++it) {
2321  UniValue obj(UniValue::VOBJ);
2322  const std::string* strAdd = &(*it).first;
2323  const double* nBalance = &(*it).second;
2324  obj.push_back(Pair("Address ", *strAdd));
2325  obj.push_back(Pair("Balance ", *nBalance));
2326  ret.push_back(obj);
2327  }
2328 
2329  return ret;
2330 }
2331 
2332 unsigned int sumMultiSend()
2333 {
2334  unsigned int sum = 0;
2335  for (unsigned int i = 0; i < pwalletMain->vMultiSend.size(); i++)
2336  sum += pwalletMain->vMultiSend[i].second;
2337  return sum;
2338 }
2339 
2340 UniValue multisend(const UniValue& params, bool fHelp)
2341 {
2342  CWalletDB walletdb(pwalletMain->strWalletFile);
2343  bool fFileBacked;
2344  //MultiSend Commands
2345  if (params.size() == 1) {
2346  std::string strCommand = params[0].get_str();
2347  UniValue ret(UniValue::VOBJ);
2348  if (strCommand == "print") {
2349  return printMultiSend();
2350  } else if (strCommand == "printaddress" || strCommand == "printaddresses") {
2351  return printAddresses();
2352  } else if (strCommand == "clear") {
2354  {
2355  bool erased = false;
2356  if (pwalletMain->fFileBacked) {
2357  if (walletdb.EraseMultiSend(pwalletMain->vMultiSend))
2358  erased = true;
2359  }
2360 
2361  pwalletMain->vMultiSend.clear();
2363 
2364  UniValue obj(UniValue::VOBJ);
2365  obj.push_back(Pair("Erased from database", erased));
2366  obj.push_back(Pair("Erased from RAM", true));
2367 
2368  return obj;
2369  }
2370  } else if (strCommand == "enablestake" || strCommand == "activatestake") {
2371  if (pwalletMain->vMultiSend.size() < 1)
2372  throw JSONRPCError(RPC_INVALID_REQUEST, "Unable to activate MultiSend, check MultiSend vector");
2373 
2374  if (CBitcoinAddress(pwalletMain->vMultiSend[0].first).IsValid()) {
2375  pwalletMain->fMultiSendStake = true;
2377  UniValue obj(UniValue::VOBJ);
2378  obj.push_back(Pair("error", "MultiSend activated but writing settings to DB failed"));
2379  UniValue arr(UniValue::VARR);
2380  arr.push_back(obj);
2381  arr.push_back(printMultiSend());
2382  return arr;
2383  } else
2384  return printMultiSend();
2385  }
2386 
2387  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to activate MultiSend, check MultiSend vector");
2388  } else if (strCommand == "enablemasternode" || strCommand == "activatemasternode") {
2389  if (pwalletMain->vMultiSend.size() < 1)
2390  throw JSONRPCError(RPC_INVALID_REQUEST, "Unable to activate MultiSend, check MultiSend vector");
2391 
2392  if (CBitcoinAddress(pwalletMain->vMultiSend[0].first).IsValid()) {
2394 
2396  UniValue obj(UniValue::VOBJ);
2397  obj.push_back(Pair("error", "MultiSend activated but writing settings to DB failed"));
2398  UniValue arr(UniValue::VARR);
2399  arr.push_back(obj);
2400  arr.push_back(printMultiSend());
2401  return arr;
2402  } else
2403  return printMultiSend();
2404  }
2405 
2406  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to activate MultiSend, check MultiSend vector");
2407  } else if (strCommand == "disable" || strCommand == "deactivate") {
2409  if (!walletdb.WriteMSettings(false, false, pwalletMain->nLastMultiSendHeight))
2410  throw JSONRPCError(RPC_DATABASE_ERROR, "MultiSend deactivated but writing settings to DB failed");
2411 
2412  return printMultiSend();
2413  } else if (strCommand == "enableall") {
2415  return "failed to clear old vector from walletDB";
2416  else {
2418  return printMultiSend();
2419  }
2420  }
2421  }
2422  if (params.size() == 2 && params[0].get_str() == "delete") {
2423  int del = std::stoi(params[1].get_str().c_str());
2424  if (!walletdb.EraseMultiSend(pwalletMain->vMultiSend))
2425  throw JSONRPCError(RPC_DATABASE_ERROR, "failed to delete old MultiSend vector from database");
2426 
2427  pwalletMain->vMultiSend.erase(pwalletMain->vMultiSend.begin() + del);
2428  if (!walletdb.WriteMultiSend(pwalletMain->vMultiSend))
2429  throw JSONRPCError(RPC_DATABASE_ERROR, "walletdb WriteMultiSend failed!");
2430 
2431  return printMultiSend();
2432  }
2433  if (params.size() == 2 && params[0].get_str() == "disable") {
2434  std::string disAddress = params[1].get_str();
2435  if (!CBitcoinAddress(disAddress).IsValid())
2436  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "address you want to disable is not valid");
2437  else {
2438  pwalletMain->vDisabledAddresses.push_back(disAddress);
2440  throw JSONRPCError(RPC_DATABASE_ERROR, "disabled address from sending, but failed to clear old vector from walletDB");
2441 
2443  throw JSONRPCError(RPC_DATABASE_ERROR, "disabled address from sending, but failed to store it to walletDB");
2444  else
2445  return printMultiSend();
2446  }
2447  }
2448 
2449  //if no commands are used
2450  if (fHelp || params.size() != 2)
2451  throw std::runtime_error(
2452  "multisend <command>\n"
2453  "****************************************************************\n"
2454  "WHAT IS MULTISEND?\n"
2455  "MultiSend allows a user to automatically send a percent of their stake reward to as many addresses as you would like\n"
2456  "The MultiSend transaction is sent when the staked coins mature (100 confirmations)\n"
2457  "****************************************************************\n"
2458  "TO CREATE OR ADD TO THE MULTISEND VECTOR:\n"
2459  "multisend <PRCY Address> <percent>\n"
2460  "This will add a new address to the MultiSend vector\n"
2461  "Percent is a whole number 1 to 100.\n"
2462  "****************************************************************\n"
2463  "MULTISEND COMMANDS (usage: multisend <command>)\n"
2464  " print - displays the current MultiSend vector \n"
2465  " clear - deletes the current MultiSend vector \n"
2466  " enablestake/activatestake - activates the current MultiSend vector to be activated on stake rewards\n"
2467  " enablemasternode/activatemasternode - activates the current MultiSend vector to be activated on masternode rewards\n"
2468  " disable/deactivate - disables the current MultiSend vector \n"
2469  " delete <Address #> - deletes an address from the MultiSend vector \n"
2470  " disable <address> - prevents a specific address from sending MultiSend transactions\n"
2471  " enableall - enables all addresses to be eligible to send MultiSend transactions\n"
2472  "****************************************************************\n");
2473 
2474  //if the user is entering a new MultiSend item
2475  std::string strAddress = params[0].get_str();
2476  CBitcoinAddress address(strAddress);
2477  if (!address.IsValid())
2478  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PRCY address");
2479  if (std::stoi(params[1].get_str().c_str()) < 0)
2480  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid percentage");
2481 
2483 
2484  unsigned int nPercent = (unsigned int) std::stoul(params[1].get_str().c_str());
2485 
2487  {
2488  fFileBacked = pwalletMain->fFileBacked;
2489  //Error if 0 is entered
2490  if (nPercent == 0) {
2491  throw JSONRPCError(RPC_INVALID_PARAMETER, "Sending 0% of stake is not valid");
2492  }
2493 
2494  //MultiSend can only send 100% of your stake
2495  if (nPercent + sumMultiSend() > 100)
2496  throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to add to MultiSend vector, the sum of your MultiSend is greater than 100%");
2497 
2498  for (unsigned int i = 0; i < pwalletMain->vMultiSend.size(); i++) {
2499  if (pwalletMain->vMultiSend[i].first == strAddress)
2500  throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to add to MultiSend vector, cannot use the same address twice");
2501  }
2502 
2503  if (fFileBacked)
2505 
2506  std::pair<std::string, int> newMultiSend;
2507  newMultiSend.first = strAddress;
2508  newMultiSend.second = nPercent;
2509  pwalletMain->vMultiSend.push_back(newMultiSend);
2510  if (fFileBacked) {
2511  if (!walletdb.WriteMultiSend(pwalletMain->vMultiSend))
2512  throw JSONRPCError(RPC_DATABASE_ERROR, "walletdb WriteMultiSend failed!");
2513  }
2514  }
2515  return printMultiSend();
2516 }
2517 
2518 UniValue createprivacywallet(const UniValue& params, bool fHelp)
2519 {
2520  if (fHelp || params.size() >2 || params.size() < 1)
2521  throw std::runtime_error(
2522  "createprivacywallet \"password\" (\"language\") \n"
2523  "\nCreate a new wallet for privacy with dual-key stealth address.\n"
2524  "If 'language' is specified, it is used, otherwise english \n"
2525  "\nArguments:\n"
2526  "1. \"account\" (string, required) password for the wallet \n"
2527  "2. \"language\" (string, optional) language for the wallet's mnemmonics \n"
2528  "\nResult:\n"
2529  "\"privacy wallet created\" (string) the base address of the wallet\n"
2530  "\nExamples:\n" +
2531  HelpExampleCli("createprivacywallet", "") + HelpExampleCli("createprivacywallet", "\"\"") + HelpExampleCli("createprivacywallet", "\"1234567890\"") + HelpExampleRpc("createprivacywallet", "\"1234567890\""));
2532 
2534 
2535  //privacy wallet is already created
2537  "Error: RPC unimplemented.");
2538 }
2539 
2540 UniValue createprivacyaccount(const UniValue& params, bool fHelp)
2541 {
2542  if (fHelp || params.size() != 0)
2543  throw std::runtime_error(
2544  "createprivacyaccount \n"
2545  "\nCreate a new wallet account for privacy.\n"
2546  "\nArguments:\n"
2547  "\nResult:\n"
2548  "\"account address\" (string) the address of the created account\n"
2549  "\nExamples:\n" +
2550  HelpExampleCli("createprivacyaccount", "") + HelpExampleCli("createprivacyaccount", "\"\"") + HelpExampleCli("createprivacyaccount", "") + HelpExampleRpc("createprivacyaccount", ""));
2551 
2552  EnsureWallet();
2553 
2554  CWalletDB walletdb(pwalletMain->strWalletFile);
2555  UniValue ret(UniValue::VOBJ);
2556  int i = 0;
2557  while (i < 10) {
2558  std::string viewAccountLabel = "viewaccount";
2559  std::string spendAccountLabel = "spendaccount";
2560 
2561  CAccount viewAccount;
2562  walletdb.ReadAccount(viewAccountLabel, viewAccount);
2563  if (!viewAccount.vchPubKey.IsValid()) {
2564  std::string viewAccountAddress = GetHDAccountAddress(viewAccountLabel, 0).ToString();
2565  }
2566 
2567  CAccount spendAccount;
2568  walletdb.ReadAccount(spendAccountLabel, spendAccount);
2569  if (!spendAccount.vchPubKey.IsValid()) {
2570  std::string spendAccountAddress = GetHDAccountAddress(spendAccountLabel, 1).ToString();
2571  }
2572  if (viewAccount.vchPubKey.GetHex() == "" || spendAccount.vchPubKey.GetHex() == "") {
2573  i++;
2574  continue;
2575  }
2576  ret.push_back(Pair("viewpublickey", viewAccount.vchPubKey.GetHex()));
2577 
2578  ret.push_back(Pair("spendpublickey", spendAccount.vchPubKey.GetHex()));
2579 
2580  std::string stealthAddr;
2581  if (pwalletMain->EncodeStealthPublicAddress(viewAccount.vchPubKey, spendAccount.vchPubKey, stealthAddr)) {
2582  ret.push_back(Pair("stealthaddress", stealthAddr));
2583  }
2584  break;
2585  }
2586  return ret;
2587 }
2588 
2589 UniValue showstealthaddress(const UniValue& params, bool fHelp)
2590 {
2591  if (fHelp || params.size() != 0)
2592  throw std::runtime_error(
2593  "showstealthaddress \n"
2594  "\nShow stealth address.\n"
2595  "\nArguments:\n"
2596  "\nResult:\n"
2597  "\"account address\" (string) the address of the created account\n"
2598  "\nExamples:\n" +
2599  HelpExampleCli("showstealthaddress", "") + HelpExampleCli("showstealthaddress", "\"\"") + HelpExampleCli("showstealthaddress", "") + HelpExampleRpc("showstealthaddress", ""));
2600 
2601  EnsureWallet();
2602 
2603  std::string address;
2604  pwalletMain->ComputeStealthPublicAddress("masteraccount", address);
2605  return address;
2606 }
2607 
2608 UniValue generateintegratedaddress(const UniValue& params, bool fHelp)
2609 {
2610  if (fHelp || params.size() > 1)
2611  throw std::runtime_error(
2612  "generateintegratedaddress <paymentID>\n"
2613  "\nGenerate integrated addresses for this wallet with a random payment ID.\n"
2614  "\nArguments:\n"
2615  "optional: paymentID"
2616  "\nResult:\n"
2617  "\nExamples:\n" +
2618  HelpExampleCli("generateintegratedaddress", "1234") + HelpExampleCli("generateintegratedaddress", "\"\"") + HelpExampleCli("generateintegratedaddress", "") + HelpExampleRpc("generateintegratedaddress", ""));
2619 
2620  EnsureWallet();
2621 
2622  UniValue ret(UniValue::VOBJ);
2623  uint64_t paymentID = 0;
2624  std::string address;
2625  if (params.size() == 1) {
2626  paymentID = params[0].get_int64();
2627  address = pwalletMain->GenerateIntegratedAddressWithProvidedPaymentID("masteraccount", paymentID);
2628  } else {
2629  address = pwalletMain->GenerateIntegratedAddressWithRandomPaymentID("masteraccount", paymentID);
2630  }
2631  ret.push_back(Pair("integratedaddress", address));
2632  ret.push_back(Pair("paymentid", paymentID));
2633  return ret;
2634 }
2635 
2636 UniValue importkeys(const UniValue& params, bool fHelp)
2637 {
2638  if (fHelp || params.size() != 2)
2639  throw std::runtime_error(
2640  "importkeys \n"
2641  "\nCreate a new wallet account for privacy.\n"
2642  "\nArguments:\n"
2643  "\nResult:\n"
2644  "\"account address\" (string) the address of the created account\n"
2645  "\nExamples:\n" +
2646  HelpExampleCli("importkeys", "") + HelpExampleCli("importkeys", "\"\"") + HelpExampleCli("importkeys", "") + HelpExampleRpc("importkeys", ""));
2647 
2648  EnsureWallet();
2649 
2650  CWalletDB walletdb(pwalletMain->strWalletFile);
2651 
2652  std::string viewStr = params[0].get_str();
2653  std::string spendStr = params[1].get_str();
2654 
2655  CAccount viewAc, spendAc;
2656 
2657  std::vector<unsigned char> view, spend;
2658  DecodeBase58(viewStr, view);
2659  DecodeBase58(spendStr, spend);
2660  std::string viewAccountLabel = "viewaccount";
2661  std::string spendAccountLabel = "spendaccount";
2662 
2663  CKey viewPk, spendPk;
2664  viewPk.Set(view.begin(), view.end(), true);
2665  spendPk.Set(spend.begin(), spend.end(), true);
2666 
2667  pwalletMain->AddKey(viewPk);
2668  pwalletMain->AddKey(spendPk);
2669  viewAc.vchPubKey = viewPk.GetPubKey();
2670  spendAc.vchPubKey = spendPk.GetPubKey();
2671 
2672  pwalletMain->SetAddressBook(viewAc.vchPubKey.GetID(), viewAccountLabel, "receive");
2673  walletdb.WriteAccount(viewAccountLabel, viewAc);
2674 
2675  pwalletMain->SetAddressBook(spendAc.vchPubKey.GetID(), spendAccountLabel, "receive");
2676  walletdb.WriteAccount(spendAccountLabel, spendAc);
2677 
2678  return true;
2679 }
2680 
2681 UniValue createprivacysubaddress(const UniValue& params, bool fHelp)
2682 {
2683  if (fHelp || params.size() != 1)
2684  throw std::runtime_error(
2685  "createprivacysubaddress \"label\" \n"
2686  "\nCreate a new wallet account subaddress for privacy transaction.\n"
2687  "\nArguments:\n"
2688  "1. \"label\" (string, required) label for the wallet account address\n"
2689  "\nResult:\n"
2690  "\"account address\" (string) the created address for the corresponding account\n"
2691  "\"address index\" (string) the index of the created address for the account\n"
2692  "\nExamples:\n" +
2693  HelpExampleCli("createprivacysubaddress", "") + HelpExampleCli("createprivacysubaddress", "\"\"") + HelpExampleCli("createprivacysubaddress", "\"address1\"") + HelpExampleRpc("createprivacysubaddress", "\"address1\""));
2694 
2695  EnsureWallet();
2697 
2698  std::string label = params[0].get_str();
2699 
2700  CWalletDB walletdb(pwalletMain->strWalletFile);
2701  std::string viewAccountLabel = label + "view";
2702  std::string spendAccountLabel = label + "spend";
2703  CStealthAccount account;
2704  if (!walletdb.ReadStealthAccount(label, account)) {
2705  int i = 0;
2706  while (i < 10) {
2707  CAccount viewAccount;
2708  walletdb.ReadAccount(label + "view", viewAccount);
2709  if (!viewAccount.vchPubKey.IsValid()) {
2710  GetAccountAddress(viewAccountLabel).ToString();
2711  }
2712 
2713  CAccount spendAccount;
2714  walletdb.ReadAccount(spendAccountLabel, spendAccount);
2715  if (!spendAccount.vchPubKey.IsValid()) {
2716  GetAccountAddress(spendAccountLabel).ToString();
2717  }
2718  if (viewAccount.vchPubKey.GetHex() == "" || spendAccount.vchPubKey.GetHex() == "") {
2719  i++;
2720  continue;
2721  }
2722  account.viewAccount = viewAccount;
2723  account.spendAccount = spendAccount;
2724  walletdb.AppendStealthAccountList(label);
2725  break;
2726  }
2727  }
2728 
2729  UniValue ret(UniValue::VOBJ);
2730 
2731  ret.push_back(Pair("viewpublickey", account.viewAccount.vchPubKey.GetHex()));
2732 
2733  ret.push_back(Pair("spendpublickey", account.spendAccount.vchPubKey.GetHex()));
2734 
2735  std::string stealthAddr;
2736  if (pwalletMain->EncodeStealthPublicAddress(account.viewAccount.vchPubKey, account.spendAccount.vchPubKey, stealthAddr)) {
2737  ret.push_back(Pair("stealthaddress", stealthAddr));
2738  }
2739  return ret;
2740 }
2741 
2742 UniValue readmasteraccount(const UniValue& params, bool fHelp)
2743 {
2744  if (fHelp || params.size() != 0)
2745  throw std::runtime_error(
2746  "readmasteraccount \n"
2747  "\nRead stealth master account address.\n"
2748  "\nArguments:\n"
2749  "\nResult:\n"
2750  "\"public address\" (string) the public address"
2751  "\nExamples:\n" +
2752  HelpExampleCli("readmasteraccount", "") + HelpExampleCli("readmasteraccount", "\"\"") + HelpExampleCli("readmasteraccount", "") + HelpExampleRpc("readmasteraccount", ""));
2753 
2754  EnsureWallet();
2755 
2756  std::string address;
2757  pwalletMain->ComputeStealthPublicAddress("masteraccount", address);
2758  return address;
2759 }
2760 
2761 UniValue decodestealthaddress(const UniValue& params, bool fHelp)
2762 {
2763  if (fHelp || params.size() != 1)
2764  throw std::runtime_error(
2765  "decodestealthaddress \n"
2766  "\nDecode a stealth address into spend and view public keys.\n"
2767  "\nArguments:\n"
2768  "1. \"stealth_address\" (string, required) The Base58 stealth address\n"
2769  "\nResult:\n"
2770  "\"public view key\" (string) the view public key\n"
2771  "\"public spend key\" (string) the spend public key"
2772  "\nExamples:\n" +
2773  HelpExampleCli("decodestealthaddress", "") + HelpExampleCli("decodestealthaddress", "\"\"") + HelpExampleCli("decodestealthaddress", "") + HelpExampleRpc("decodestealthaddress", ""));
2774 
2775  EnsureWallet();
2776 
2777  std::string addr = params[0].get_str();
2778 
2779  UniValue ret(UniValue::VOBJ);
2780  CPubKey viewKey, spendKey;
2781  bool hasPaymentID;
2782  uint64_t paymentID;
2783 
2784  if (!CWallet::DecodeStealthAddress(addr, viewKey, spendKey, hasPaymentID, paymentID)) {
2786  "Error: Stealth address is not correctly formatted.");
2787  }
2788  ret.push_back(Pair("spendpublickey", spendKey.GetHex()));
2789  ret.push_back(Pair("viewpublickey", viewKey.GetHex()));
2790  if (hasPaymentID) {
2791  ret.push_back(Pair("paymentid", paymentID));
2792  }
2793 
2794  return ret;
2795 }
2796 
2797 UniValue sendtostealthaddress(const UniValue& params, bool fHelp)
2798 {
2799  if (fHelp || params.size() < 2 || params.size() > 3)
2800  throw std::runtime_error(
2801  "sendtostealthaddress \"prcystealthaddress\" amount\n"
2802  "\nSend an amount to a given prcy stealth address address. The amount is a real and is rounded to the nearest 0.00000001\n" +
2804  "\nArguments:\n"
2805  "1. \"prcystealthaddress\" (string, required) The prcycoin stealth address to send to.\n"
2806  "2. \"amount\" (numeric, required) The amount in PRCY to send. eg 0.1\n"
2807  "3. \"lock_output\" (bool, optional, default=false) Whether to lock the output or not.\n"
2808  "\nResult:\n"
2809  "\"transactionid\" (string) The transaction id.\n"
2810  "\nExamples:\n" +
2811  HelpExampleCli("sendtostealthaddress", "\"Pap5WCV4SjVMGLyYf98MEX82ErBEMVpg9ViQ1up3aBib6Fz4841SahrRXG6eSNSLBSNvEiGuQiWKXJC3RDfmotKv15oCrh6N2Ym\" 0.1") + HelpExampleCli("sendtostealthaddress", "\"Pap5WCV4SjVMGLyYf98MEX82ErBEMVpg9ViQ1up3aBib6Fz4841SahrRXG6eSNSLBSNvEiGuQiWKXJC3RDfmotKv15oCrh6N2Ym\" 0.1 \"donation\" \"seans outpost\"") + HelpExampleRpc("sendtostealthaddress", "\"Pap5WCV4SjVMGLyYf98MEX82ErBEMVpg9ViQ1up3aBib6Fz4841SahrRXG6eSNSLBSNvEiGuQiWKXJC3RDfmotKv15oCrh6N2Ym\", 0.1, \"donation\", \"seans outpost\""));
2812 
2814 
2815  // Stealth Address
2816  std::string stealthAddr = params[0].get_str();
2817 
2818  // Amount
2819  CAmount nAmount = AmountFromValue(params[1]);
2820 
2821  // Wallet comments
2822  CWalletTx wtx;
2823 
2824  // Lock the output, ignored if not to ourself
2825  bool lockOutput = false;
2826  if (params.size() > 2)
2827  lockOutput = params[2].get_bool();
2828 
2829  if (!pwalletMain->SendToStealthAddress(stealthAddr, nAmount, wtx)) {
2831  "Cannot create transaction.");
2832  }
2833 
2834  std::string myAddress;
2835  pwalletMain->ComputeStealthPublicAddress("masteraccount", myAddress);
2836  int indexOut = -1;
2837  if (stealthAddr == myAddress) {
2838  if (lockOutput) {
2839  for (int i=0; i < (int)wtx.vout.size(); i++) {
2840  UniValue obj(UniValue::VOBJ);
2841  CTxOut& out = wtx.vout[i];
2842  CAmount value = pwalletMain->getCTxOutValue(wtx, out);
2843  if (value == nAmount) {
2844  indexOut = i;
2845 
2846  // Lock output
2847  COutPoint collateralOut(wtx.GetHash(), indexOut);
2848  pwalletMain->LockCoin(collateralOut);
2849  LogPrintf("Output transaction: %s:%i has been locked\n", wtx.GetHash().GetHex().c_str(), indexOut);
2850  }
2851  }
2852  }
2853  }
2854  return wtx.GetHash().GetHex();
2855 }
2856 
2857 UniValue sendalltostealthaddress(const UniValue& params, bool fHelp)
2858 {
2859  if (fHelp || params.size() < 1 || params.size() > 2)
2860  throw std::runtime_error(
2861  "sendalltostealthaddress \"prcystealthaddress\" ( includeLocked )\n"
2862  "\nSend all PRCY to stealth address\n" +
2864  "\nArguments:\n"
2865  "1. \"prcystealthaddress\" (string, required) The prcycoin stealth address to send to.\n"
2866  "2. \"include_locked\" (bool, optional, default=false) Whether to include locked coins or not.\n"
2867  "\nResult:\n"
2868  "\"transactionid\" (string) The transaction id.\n"
2869  "\nExamples:\n" +
2870  HelpExampleCli("sendalltostealthaddress", "\"Pap5WCV4SjVMGLyYf98MEX82ErBEMVpg9ViQ1up3aBib6Fz4841SahrRXG6eSNSLBSNvEiGuQiWKXJC3RDfmotKv15oCrh6N2Ym\""));
2871 
2873 
2874  // Stealth Address
2875  std::string stealthAddr = params[0].get_str();
2876 
2877  // Wallet comments
2878  CWalletTx wtx;
2879 
2880  // Include Locked Coins
2881  bool inclLocked = false;
2882  if (params.size() > 1)
2883  inclLocked = params[1].get_bool();
2884 
2885  if (!pwalletMain->SendAll(stealthAddr, wtx, inclLocked)) {
2887  "Cannot create transaction.");
2888  }
2889  return wtx.GetHash().GetHex();
2890 }
2891 
2892 UniValue setdecoyconfirmation(const UniValue& params, bool fHelp)
2893 {
2894  if (fHelp || params.size() != 1)
2895  throw std::runtime_error(
2896  "setdecoyconfirmation\n"
2897  "\nSend the minimum confirmation for decoys in RingCT\n" +
2899  "\nArguments:\n"
2900  "2. \"confirm\" (numeric, required) The required minim confirmation for decoys\n"
2901  "\nResult:\n"
2902  "\"decoy_confirmation\" (numeric) The minimum decoy confirmation.\n"
2903  "\nExamples:\n" +
2904  HelpExampleCli("setdecoyconfirmation", "\"20\"") + HelpExampleCli("setdecoyconfirmation", "\"20\"") + HelpExampleRpc("setdecoyconfirmation", "\"20\""));
2905 
2906  EnsureWallet();
2907 
2908  int confirmation = params[0].get_int();
2909 
2910  if (confirmation <= 0) {
2912  "Error: Min decoy confirmation must be positive.");
2913  }
2914  pwalletMain->DecoyConfirmationMinimum = confirmation;
2915  UniValue ret(UniValue::VOBJ);
2916  ret.push_back(Pair("decoy_confirmation", confirmation));
2917  return ret;
2918 }
2919 
2920 UniValue getdecoyconfirmation(const UniValue& params, bool fHelp)
2921 {
2922  if (fHelp || params.size() != 0)
2923  throw std::runtime_error(
2924  "getdecoyconfirmation\n"
2925  "\nShow the current decoy confirmation\n" +
2927  "\nArguments:\n"
2928  "\nResult:\n"
2929  "\"decoy_confirmation\" (numeric) The minimum decoy confirmation.\n"
2930  "\nExamples:\n" +
2931  HelpExampleCli("getdecoyconfirmation", "") + HelpExampleCli("getdecoyconfirmation", "") + HelpExampleRpc("getdecoyconfirmation", ""));
2932 
2933  EnsureWallet();
2934 
2935  UniValue ret(UniValue::VOBJ);
2936  ret.push_back(Pair("decoy_confirmation", pwalletMain->DecoyConfirmationMinimum));
2937  return ret;
2938 }
2939 
2940 std::string GetHex(const unsigned char* vch, int sz) {
2941  char psz[sz * 2 + 1];
2942  for (int i = 0; i < sz; i++)
2943  sprintf(psz + i * 2, "%02x", vch[sz - i - 1]);
2944  return std::string(psz, psz + sz * 2);
2945 }
2946 
2947 UniValue revealviewprivatekey(const UniValue& params, bool fHelp) {
2948  if (fHelp || params.size() != 0)
2949  throw std::runtime_error(
2950  "revealviewprivatekey \n"
2951  "\nReveal view private key.\n"
2952  "\nArguments:\n"
2953  "\nResult:\n"
2954  "\"Private view key\" (string) the private view key\n"
2955  "\nExamples:\n" +
2956  HelpExampleCli("revealviewprivatekey", "") + HelpExampleCli("revealviewprivatekey", "\"\"") +
2957  HelpExampleCli("revealviewprivatekey", "") + HelpExampleRpc("revealviewprivatekey", ""));
2958 
2959  EnsureWallet();
2961 
2962  CKey view;
2964  return CBitcoinSecret(view).ToString();
2965 }
2966 
2967 UniValue revealspendprivatekey(const UniValue& params, bool fHelp) {
2968  if (fHelp || params.size() != 0)
2969  throw std::runtime_error(
2970  "revealspendprivatekey \n"
2971  "\nReveal view private key.\n"
2972  "\nArguments:\n"
2973  "\nResult:\n"
2974  "\"Private spend key\" (string) the private spend key\n"
2975  "\nExamples:\n" +
2976  HelpExampleCli("revealspendprivatekey", "") + HelpExampleCli("revealspendprivatekey", "\"\"") +
2977  HelpExampleCli("revealspendprivatekey", "") + HelpExampleRpc("revealspendprivatekey", ""));
2978 
2979  EnsureWallet();
2981 
2982  CKey spend;
2984  return CBitcoinSecret(spend).ToString();
2985 }
2986 
2987 UniValue showtxprivatekeys(const UniValue& params, bool fHelp) {
2988  if (fHelp || params.size() != 1)
2989  throw std::runtime_error(
2990  "showtxprivatekeys <txhash>\n"
2991  "\nShow transaction private keys for each UTXO of a transaction.\n"
2992  "\nArguments:\n"
2993  "\nResult:\n"
2994  "\"Private spend key\" (string) the private spend key\n"
2995  "\nExamples:\n" +
2996  HelpExampleCli("showtxprivatekeys", "") + HelpExampleCli("showtxprivatekeys", "\"\"") +
2997  HelpExampleCli("showtxprivatekeys", "") + HelpExampleRpc("showtxprivatekeys", ""));
2998 
2999  EnsureWallet();
3001 
3002  UniValue ret(UniValue::VOBJ);
3004  for(int i = 0; i < 10; i++) {
3005  std::string key = params[0].get_str() + std::to_string(i);
3006  std::string secret;
3007  if (db.ReadTxPrivateKey(key, secret)) {
3008  ret.push_back(Pair(std::to_string(i), secret));
3009  } else break;
3010  }
3011  return ret;
3012 }
3013 
3014 UniValue rescan(const UniValue& params, bool fHelp) {
3015  if (fHelp || params.size() != 0)
3016  throw std::runtime_error(
3017  "rescan\n"
3018  "\nRescan wallet transactions from the first block.\n"
3019  "\nArguments:\n"
3020  "\nResult:\n"
3021  "\"scanned wallet transactions\" \n"
3022  "\nExamples:\n" +
3023  HelpExampleCli("rescan", "") + HelpExampleCli("rescan", "\"\"") +
3024  HelpExampleRpc("rescan", ""));
3025 
3026  EnsureWallet();
3028 
3029  int nHeight = 1;
3030  if (!pwalletMain->RescanAfterUnlock(nHeight)) {
3031  return "Failed to rescan";
3032  }
3033  return "Done";
3034 }
3035 
3036 UniValue rescanwallettransactions(const UniValue& params, bool fHelp) {
3037  if (fHelp || params.size() != 1)
3038  throw std::runtime_error(
3039  "rescanwallettransactions \"block height\"\n"
3040  "\nRescan wallet transactions from a certain block height.\n"
3041  "\nArguments:\n"
3042  "\nblock height: block height from which the chain will be rescanned\n"
3043  "\nResult:\n"
3044  "\"scanned wallet transactions\" \n"
3045  "\nExamples:\n" +
3046  HelpExampleCli("rescanwallettransactions", "") + HelpExampleCli("rescanwallettransactions", "\"\"") +
3047  HelpExampleRpc("rescanwallettransactions", ""));
3048 
3049  EnsureWallet();
3051 
3052  int nHeight = 0;
3053  if (params.size() == 1) {
3054  nHeight = params[0].get_int();
3055  }
3056  if (!pwalletMain->RescanAfterUnlock(nHeight)) {
3057  return "Failed to rescan";
3058  }
3059  return "Done";
3060 }
3061 
3062 UniValue erasewallettransactions(const UniValue& params, bool fHelp) {
3063  if (fHelp || params.size() != 0)
3064  throw std::runtime_error(
3065  "erasewallettransactions \n"
3066  "\nErase wallet transactions based on prcycoin.conf parameters\n"
3067  "\nResult:\n"
3068  "\"erased wallet transactions\" \n"
3069  "\nExamples:\n" +
3070  HelpExampleCli("erasewallettransactions", "") + HelpExampleCli("erasewallettransactions", "\"\"") +
3071  HelpExampleRpc("erasewallettransactions", ""));
3072 
3073  EnsureWallet();
3075 
3077 
3078  CBlockIndex* pindex = chainActive.Tip();
3079  int initialCount = (int)pwalletMain->mapWallet.size();
3080  int newCount, removedTxes = 0;
3081 
3082 <<<<<<< HEAD
3083  UniValue ret(UniValue::VOBJ);
3084  ret.push_back(Pair("initial_utxo_count", pwalletMain->mapWallet.size()));
3085  pwalletMain->DeleteWalletTransactions(pindex, false);
3086  ret.push_back(Pair("new_utxo_count", pwalletMain->mapWallet.size()));
3087  ret.push_back(Pair("deleted_utxo_count", ret["initial_utxo_count"].get_int() - ret["new_utxo_count"].get_int()));
3088 
3089 =======
3090  pwalletMain->DeleteWalletTransactions(pindex, false);
3091 
3092  newCount = (int)pwalletMain->mapWallet.size();
3093  removedTxes = initialCount - newCount;
3094 
3095  UniValue ret(UniValue::VOBJ);
3096  ret.push_back(Pair("initial_utxo_count", initialCount));
3097  ret.push_back(Pair("new_utxo_count", newCount));
3098  ret.push_back(Pair("deleted_utxo_count", removedTxes));
3099 
3100 >>>>>>> 8b6832858a1ed35a91aa239a94722b31d6e659f1
3101  return ret;
3102 }
3103 
3104 UniValue revealmnemonicphrase(const UniValue& params, bool fHelp)
3105 {
3106  if (fHelp || params.size() != 0)
3107  throw std::runtime_error(
3108  "revealmnemonicphrase \n"
3109  "\nReveal Mnemonic Phrase.\n"
3110  "\nArguments:\n"
3111  "\nResult:\n"
3112  "\"Mnemonic Phrase\" (string) mnemonic phrase\n"
3113  "\nExamples:\n" +
3114  HelpExampleCli("revealmnemonicphrase", "") + HelpExampleCli("revealmnemonicphrase", "\"\"") +
3115  HelpExampleCli("revealmnemonicphrase", "") + HelpExampleRpc("revealmnemonicphrase", ""));
3116 
3118 
3120 
3121  std::string phrase;
3122  if (!pwalletMain->GetSeedPhrase(phrase))
3123  throw JSONRPCError(RPC_WALLET_ERROR, "Error: There was an error retrieving mnemonic phrase.");
3124 
3125  return phrase;
3126 }
3127 
3128 UniValue erasefromwallet(const UniValue& params, bool fHelp)
3129 {
3130  if (fHelp || params.size() != 1)
3131  throw std::runtime_error(
3132  "erasefromwallet\n"
3133  "\nErase a transaction from the wallet.\n"
3134  "\nResult:\n"
3135  "n (result) Done\n"
3136  "\nExamples:\n" +
3137  HelpExampleCli("erasefromwallet", "") + HelpExampleRpc("erasefromwallet", ""));
3138 
3140 
3141  uint256 hash;
3142  hash.SetHex(params[0].get_str());
3143 
3144  if (!pwalletMain->mapWallet.count(hash))
3145  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
3146 
3147  if (!pwalletMain->mapWallet.count(hash))
3148  return "Failed to delete transaction";
3149 
3150  return "Done";
3151 }
3152 
RPC_INVALID_REQUEST
@ RPC_INVALID_REQUEST
Standard JSON-RPC 2.0 errors.
Definition: protocol.h:33
CWallet::LockCoin
void LockCoin(COutPoint &output)
Definition: wallet.cpp:5057
RPC_MISC_ERROR
@ RPC_MISC_ERROR
General application defined errors.
Definition: protocol.h:40
LOCK2
#define LOCK2(cs1, cs2)
Definition: sync.h:183
gettransaction
UniValue gettransaction(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1610
sendalltostealthaddress
UniValue sendalltostealthaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2857
isminefilter
uint8_t isminefilter
used for bitflags of isminetype
Definition: wallet_ismine.h:24
UINT256_ZERO
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:129
multisend
UniValue multisend(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2340
tallyitem::txids
std::vector< uint256 > txids
Definition: rpcwallet.cpp:953
CAccountingEntry
Internal transfers.
Definition: wallet.h:982
IsMine
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
Definition: wallet_ismine.cpp:30
CWallet::IncOrderPosNext
int64_t IncOrderPosNext(CWalletDB *pwalletdb=NULL)
Increment the next transaction order id.
Definition: wallet.cpp:1150
CWallet::EncodeStealthPublicAddress
bool EncodeStealthPublicAddress(const std::vector< unsigned char > &pubViewKey, const std::vector< unsigned char > &pubSpendKey, std::string &pubAddr)
Definition: wallet.cpp:6437
CWallet::GetAddressGroupings
std::set< std::set< CTxDestination > > GetAddressGroupings()
Definition: wallet.cpp:4896
addmultisigaddress
UniValue addmultisigaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:906
UniValue::VOBJ
@ VOBJ
Definition: univalue.h:21
showtxprivatekeys
UniValue showtxprivatekeys(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2987
CWallet::fWalletUnlockStakingOnly
bool fWalletUnlockStakingOnly
Definition: wallet.h:304
UniValue::get_bool
bool get_bool() const
Definition: univalue.cpp:302
listreceivedbyaddress
UniValue listreceivedbyaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1079
GetTime
int64_t GetTime()
For unit testing.
Definition: utiltime.cpp:19
CWallet::mapWallet
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:344
erasewallettransactions
UniValue erasewallettransactions(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:3062
CDB::TxnCommit
bool TxnCommit()
Definition: db.h:296
CWallet::SendAll
bool SendAll(std::string des, CWalletTx &wtxNew, bool inclLocked)
Definition: wallet.cpp:5252
SER_GETHASH
@ SER_GETHASH
Definition: serialize.h:161
RPC_WALLET_ALREADY_UNLOCKED
@ RPC_WALLET_ALREADY_UNLOCKED
Failed to encrypt the wallet.
Definition: protocol.h:76
CWallet::fFileBacked
bool fFileBacked
Definition: wallet.h:303
RPC_WALLET_WRONG_ENC_STATE
@ RPC_WALLET_WRONG_ENC_STATE
The wallet passphrase entered was incorrect.
Definition: protocol.h:74
CWallet::GetImmatureBalance
CAmount GetImmatureBalance() const
Definition: wallet.cpp:2333
CWallet::DeriveNewChildKey
void DeriveNewChildKey(uint32_t nAccountIndex, CKey &secretRet)
Definition: wallet.cpp:6860
UniValue::clear
void clear()
Definition: univalue.cpp:80
CWallet::CommitTransaction
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, std::string strCommand=NetMsgType::TX)
Call after CreateTransaction unless you want to abort.
Definition: wallet.cpp:4458
StartShutdown
void StartShutdown()
Definition: init.cpp:131
CWallet::GetOldestKeyPoolTime
int64_t GetOldestKeyPoolTime()
Definition: wallet.cpp:4847
RPC_PRIVACY_DECOY_MIN
@ RPC_PRIVACY_DECOY_MIN
Privacy wallet is existed.
Definition: protocol.h:78
CWallet::nStakeSplitThreshold
uint64_t nStakeSplitThreshold
Definition: wallet.h:317
CBitcoinAddress::GetKeyID
bool GetKeyID(CKeyID &keyID) const
Definition: base58.cpp:281
CWallet::IsMine
isminetype IsMine(const CTxIn &txin) const
Definition: wallet.cpp:1333
listaddressgroupings
UniValue listaddressgroupings(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:376
CWallet::TxItems
std::multimap< int64_t, TxPair > TxItems
Definition: wallet.h:348
base_uint::GetHex
std::string GetHex() const
Definition: arith_uint256.cpp:155
backupwallet
UniValue backupwallet(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1682
listtransactions
UniValue listtransactions(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1227
ValueFromAmount
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:118
createprivacywallet
UniValue createprivacywallet(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2518
ALL_COINS
@ ALL_COINS
Definition: wallet.h:110
SendMoney
void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx &wtxNew, bool fUseIX=false)
Definition: rpcwallet.cpp:347
chainActive
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:70
lockunspent
UniValue lockunspent(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1931
timedata.h
NullUniValue
const UniValue NullUniValue
Definition: univalue.cpp:78
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:285
CWallet::GetKeyFromPool
bool GetKeyFromPool(CPubKey &key)
Definition: wallet.cpp:4829
CWalletDB::WriteMSDisabledAddresses
bool WriteMSDisabledAddresses(std::vector< std::string > vDisabledAddresses)
Definition: walletdb.cpp:234
CWalletTx::mapValue
mapValue_t mapValue
Definition: wallet.h:798
tallyitem::nConf
int nConf
Definition: rpcwallet.cpp:951
EnsureWallet
void EnsureWallet()
Definition: rpcwallet.cpp:37
CBitcoinAddress
base58-encoded PRCY addresses.
Definition: base58.h:109
nWalletUnlockTime
int64_t nWalletUnlockTime
Definition: rpcwallet.cpp:29
RPC_INVALID_PARAMETER
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
Definition: protocol.h:45
CKey::Set
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
Definition: key.h:83
CWalletDB::ReadAccount
bool ReadAccount(const std::string &strAccount, CAccount &account)
Definition: walletdb.cpp:362
reservebalance
UniValue reservebalance(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2131
CWallet::Unlock
bool Unlock(const SecureString &strWalletPassphrase, bool anonimizeOnly=false)
Definition: wallet.cpp:552
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:181
CReserveKey
A key allocated from the key pool.
Definition: wallet.h:679
listsinceblock
UniValue listsinceblock(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1527
listlockunspent
UniValue listlockunspent(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2006
CWallet::AddAccountingEntry
bool AddAccountingEntry(const CAccountingEntry &, CWalletDB &pwalletdb)
Definition: wallet.cpp:4510
importkeys
UniValue importkeys(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2636
wallet.h
NetMsgType::IX
const char * IX
The ix message transmits a single SwiftX transaction.
Definition: protocol.cpp:48
CWallet::GetSpendableBalance
CAmount GetSpendableBalance()
Definition: wallet.cpp:2260
CWallet::nAutoCombineThreshold
CAmount nAutoCombineThreshold
Definition: wallet.h:332
printMultiSend
UniValue printMultiSend()
Definition: rpcwallet.cpp:2275
decodestealthaddress
UniValue decodestealthaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2761
walletpassphrasechange
UniValue walletpassphrasechange(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1811
HelpRequiringPassphrase
std::string HelpRequiringPassphrase()
Definition: rpcwallet.cpp:32
AnnotatedMixin< std::recursive_mutex >
AcentryToJSON
void AcentryToJSON(const CAccountingEntry &acentry, const std::string &strAccount, UniValue &ret)
Definition: rpcwallet.cpp:1211
RPC_WALLET_KEYPOOL_RAN_OUT
@ RPC_WALLET_KEYPOOL_RAN_OUT
Invalid account name.
Definition: protocol.h:71
CWalletDB::EraseMultiSend
bool EraseMultiSend(std::vector< std::pair< std::string, int > > vMultiSend)
Definition: walletdb.cpp:212
CWallet::CreateTransaction
bool CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx &wtxNew, CReserveKey &reservekey, int64_t &nFeeRet, std::string &strFailReason, const CCoinControl *coinControl)
CWallet::GetAccountAddresses
std::set< CTxDestination > GetAccountAddresses(std::string strAccount) const
Definition: wallet.cpp:4979
UniValue::isNull
bool isNull() const
Definition: univalue.h:77
CKeyID
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:29
tallyitem::nBCConf
int nBCConf
Definition: rpcwallet.cpp:952
RPCTypeCheck
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:70
RPC_WALLET_INVALID_ACCOUNT_NAME
@ RPC_WALLET_INVALID_ACCOUNT_NAME
Not enough funds in wallet or account.
Definition: protocol.h:70
CBitcoinAddress::Set
bool Set(const CKeyID &id)
Definition: base58.cpp:237
CWallet::ComputeStealthPublicAddress
bool ComputeStealthPublicAddress(const std::string &accountName, std::string &pubAddress)
Definition: wallet.cpp:6379
EnsureWalletIsUnlocked
void EnsureWalletIsUnlocked(bool fAllowAnonOnly)
Definition: rpcwallet.cpp:45
CReserveKey::GetReservedKey
bool GetReservedKey(CPubKey &pubkey)
Definition: wallet.cpp:4992
DecodeBase58
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vch)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
Definition: base58.cpp:22
FormatMoney
std::string FormatMoney(const CAmount &n, bool fPlus)
Money parsing/formatting utilities.
Definition: utilmoneystr.cpp:13
IsFinalTx
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Check if transaction is final and can be included in a block with the specified height and time.
Definition: tx_verify.cpp:12
listtransactionsbypaymentid
UniValue listtransactionsbypaymentid(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1345
movecmd
UniValue movecmd(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:704
CBase58Data::ToString
std::string ToString() const
Definition: base58.cpp:200
CStealthAccount
Definition: wallet.h:195
CWallet::GetAddressBalances
std::map< CTxDestination, CAmount > GetAddressBalances()
Definition: wallet.cpp:4858
listaccounts
UniValue listaccounts(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1457
payTxFee
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE)
Transaction fee set by the user.
gettxcount
UniValue gettxcount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2110
core_io.h
CFeeRate
Fee rate in PRCY per kilobyte: CAmount / kB.
Definition: amount.h:39
CWallet::UnlockCoin
void UnlockCoin(COutPoint &output)
Definition: wallet.cpp:5063
CWallet::DecoyConfirmationMinimum
int64_t DecoyConfirmationMinimum
Definition: wallet.h:366
UniValue
Definition: univalue.h:19
CPubKey::GetHex
std::string GetHex() const
Definition: pubkey.h:193
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:269
CAccountingEntry::strAccount
std::string strAccount
Definition: wallet.h:985
CBitcoinSecret
A base58-encoded secret key.
Definition: base58.h:131
GetHDAccountAddress
CBitcoinAddress GetHDAccountAddress(std::string strAccount, uint32_t nAccountIndex, bool bForceNew=false)
Definition: rpcwallet.cpp:161
CWallet::AddCScript
bool AddCScript(const CScript &redeemScript)
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
Definition: wallet.cpp:445
getrawchangeaddress
UniValue getrawchangeaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:224
CWallet::vDisabledAddresses
std::vector< std::string > vDisabledAddresses
Definition: wallet.h:328
r
void const uint64_t uint64_t * r
Definition: field_5x52_asm_impl.h:10
CWallet::SetAddressBook
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:4589
getreceivedbyaddress
UniValue getreceivedbyaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:469
CTxOut::nValue
CAmount nValue
Definition: transaction.h:167
UniValue::get_str
const std::string & get_str() const
Definition: univalue.cpp:309
readmasteraccount
UniValue readmasteraccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2742
rescanwallettransactions
UniValue rescanwallettransactions(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:3036
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
CAccountingEntry::nCreditDebit
CAmount nCreditDebit
Definition: wallet.h:986
CTransaction::IsCoinBase
bool IsCoinBase() const
Definition: transaction.h:359
setaccount
UniValue setaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:252
CMerkleTx::nIndex
int nIndex
Definition: wallet.h:738
CWalletTx::nTimeReceived
unsigned int nTimeReceived
Definition: wallet.h:801
UniValue::get_int64
int64_t get_int64() const
Definition: univalue.cpp:326
sendfrom
UniValue sendfrom(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:768
UniValue::get_obj
const UniValue & get_obj() const
Definition: univalue.cpp:346
IsHex
bool IsHex(const std::string &str)
Definition: utilstrencodings.cpp:68
autocombinedust
UniValue autocombinedust(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2236
walletlock
UniValue walletlock(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1852
RPCTypeCheckObj
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValue::VType > &typesExpected, bool fAllowNull)
Check for expected keys/value types in an Object.
Definition: server.cpp:86
CWalletTx::GetCredit
CAmount GetCredit(const isminefilter &filter) const
Definition: wallet.cpp:1505
CTxOut
An output of a transaction.
Definition: transaction.h:164
WalletTxToJSON
void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry)
Definition: rpcwallet.cpp:51
GetAccountBalance
CAmount GetAccountBalance(CWalletDB &walletdb, const std::string &strAccount, int nMinDepth, const isminefilter &filter)
Definition: rpcwallet.cpp:567
settxfee
UniValue settxfee(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2047
nReserveBalance
int64_t nReserveBalance
Definition: wallet.cpp:59
CWallet::GenerateIntegratedAddressWithProvidedPaymentID
std::string GenerateIntegratedAddressWithProvidedPaymentID(std::string accountName, uint64_t paymentID)
Definition: wallet.cpp:6512
unlockwallet
UniValue unlockwallet(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1743
getbalance
UniValue getbalance(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:597
init.h
CTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:286
CWallet::vMultiSend
std::vector< std::pair< std::string, int > > vMultiSend
Definition: wallet.h:322
revealviewprivatekey
UniValue revealviewprivatekey(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2947
CTxOut::scriptPubKey
CScript scriptPubKey
Definition: transaction.h:168
RPC_WALLET_PASSPHRASE_INCORRECT
@ RPC_WALLET_PASSPHRASE_INCORRECT
Enter the wallet passphrase with unlockwallet first.
Definition: protocol.h:73
CWallet::nLastMultiSendHeight
int nLastMultiSendHeight
Definition: wallet.h:327
CWallet::mySpendPrivateKey
bool mySpendPrivateKey(CKey &spend) const
Definition: wallet.cpp:7004
tallyitem::nAmount
CAmount nAmount
Definition: rpcwallet.cpp:950
encryptwallet
UniValue encryptwallet(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1882
UniValue::VBOOL
@ VBOOL
Definition: univalue.h:21
CWalletTx::GetDebit
CAmount GetDebit(const isminefilter &filter) const
Definition: wallet.cpp:1478
tallyitem::fIsWatchonly
bool fIsWatchonly
Definition: rpcwallet.cpp:954
getunconfirmedbalance
UniValue getunconfirmedbalance(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:692
univalue.h
CAddressBookData
Address book data.
Definition: wallet.h:148
CKey::SignCompact
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:126
RPC_DATABASE_ERROR
@ RPC_DATABASE_ERROR
Invalid, missing or duplicate parameter.
Definition: protocol.h:46
CWallet::GetLockedCoins
CAmount GetLockedCoins() const
Definition: wallet.cpp:2300
CWallet::wtxOrdered
TxItems wtxOrdered
Definition: wallet.h:349
SecureString
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: allocators.h:262
RPCRunLater
void RPCRunLater(const std::string &name, boost::function< void(void)> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:627
UniValue::push_backV
bool push_backV(const std::vector< UniValue > &vec)
Definition: univalue.cpp:182
getaccount
UniValue getaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:289
PAIRTYPE
#define PAIRTYPE(t1, t2)
This is needed because the foreach macro can't get over the comma in pair<t1, t2>
Definition: utilstrencodings.h:24
CWalletDB
Access to the wallet database (wallet.dat)
Definition: walletdb.h:80
sendmany
UniValue sendmany(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:824
COutputEntry
Definition: wallet.h:724
CWallet::GetVersion
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.cpp:6238
RPC_WALLET_UNLOCK_NEEDED
@ RPC_WALLET_UNLOCK_NEEDED
Keypool ran out, call keypoolrefill first.
Definition: protocol.h:72
tallyitem
Definition: rpcwallet.cpp:949
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:60
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
RPC_WALLET_ENCRYPTION_FAILED
@ RPC_WALLET_ENCRYPTION_FAILED
Command given in wrong wallet encryption state (encrypting an encrypted wallet etc....
Definition: protocol.h:75
CTransaction::nTxFee
CAmount nTxFee
Definition: transaction.h:298
CWalletDB::WriteAutoCombineSettings
bool WriteAutoCombineSettings(bool fEnable, CAmount nCombineThreshold)
Definition: walletdb.cpp:255
CAccountingEntry::strOtherAccount
std::string strOtherAccount
Definition: wallet.h:988
CStealthAccount::spendAccount
CAccount spendAccount
Definition: wallet.h:198
RPC_WALLET_ERROR
@ RPC_WALLET_ERROR
Invalid IP/Subnet.
Definition: protocol.h:68
ISMINE_SPENDABLE
@ ISMINE_SPENDABLE
Definition: wallet_ismine.h:20
UniValue::getKeys
const std::vector< std::string > & getKeys() const
Definition: univalue.cpp:288
HelpExampleRpc
std::string HelpExampleRpc(std::string methodname, std::string args)
Definition: server.cpp:607
CAccount
Account information.
Definition: wallet.h:167
UniValue::VNUM
@ VNUM
Definition: univalue.h:21
CWallet::GetBalance
CAmount GetBalance()
Definition: wallet.cpp:2243
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
uint256S
uint256 uint256S(const char *str)
Definition: uint256.h:99
signmessage
UniValue signmessage(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:420
GetAccountAddress
CBitcoinAddress GetAccountAddress(std::string strAccount, bool bForceNew=false)
Definition: rpcwallet.cpp:126
base_uint::SetHex
void SetHex(const char *psz)
Definition: arith_uint256.cpp:164
CWallet::GetUnconfirmedBalance
CAmount GetUnconfirmedBalance() const
Definition: wallet.cpp:2319
AmountFromValue
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:107
CKey::GetPubKey
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:79
CWalletTx::GetTxTime
int64_t GetTxTime() const
Definition: wallet.cpp:1433
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
CWallet::DeleteWalletTransactions
bool DeleteWalletTransactions(const CBlockIndex *pindex, bool fRescan=false)
Definition: wallet.cpp:1909
CWalletTx::strFromAccount
std::string strFromAccount
Definition: wallet.h:804
ExtractDestination
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: standard.cpp:199
CWallet::SendToStealthAddress
bool SendToStealthAddress(const std::string &stealthAddr, CAmount nValue, CWalletTx &wtxNew, bool fUseIX=false, int ringSize=5)
Definition: wallet.cpp:6640
ISMINE_WATCH_ONLY
@ ISMINE_WATCH_ONLY
Indicates that we dont know how to create a scriptSig that would solve this if we were given the appr...
Definition: wallet_ismine.h:19
ListTransactions
void ListTransactions(const CWalletTx &wtx, const std::string &strAccount, int nMinDepth, bool fLong, UniValue &ret, const isminefilter &filter)
Definition: rpcwallet.cpp:1149
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:359
EncodeBase64
std::string EncodeBase64(const unsigned char *pch, size_t len)
Definition: utilstrencodings.cpp:102
getdecoyconfirmation
UniValue getdecoyconfirmation(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2920
CWalletDB::GetAccountCreditDebit
CAmount GetAccountCreditDebit(const std::string &strAccount)
Definition: walletdb.cpp:413
createprivacyaccount
UniValue createprivacyaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2540
CTxDestination
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:81
setdecoyconfirmation
UniValue setdecoyconfirmation(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2892
CMerkleTx::GetDepthInMainChain
int GetDepthInMainChain(const CBlockIndex *&pindexRet, bool enableIX=true) const
Return depth of transaction in blockchain: -1 : not in blockchain, and not in memory pool (conflicted...
Definition: wallet.cpp:6006
keypoolrefill
UniValue keypoolrefill(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1703
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:641
GetHex
std::string GetHex(const unsigned char *vch, int sz)
Definition: rpcwallet.cpp:2940
getaddressesbyaccount
UniValue getaddressesbyaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:316
rescan
UniValue rescan(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:3014
CWallet::Lock
bool Lock()
Lock Wallet.
Definition: wallet.cpp:582
CWallet::laccentries
std::list< CAccountingEntry > laccentries
Definition: wallet.h:345
CWallet::setMultiSendDisabled
void setMultiSendDisabled()
Definition: wallet.cpp:6147
HelpExampleCli
std::string HelpExampleCli(std::string methodname, std::string args)
Definition: server.cpp:603
CAccountingEntry::nTime
int64_t nTime
Definition: wallet.h:987
RPC_INVALID_ADDRESS_OR_KEY
@ RPC_INVALID_ADDRESS_OR_KEY
Unexpected type was passed as parameter.
Definition: protocol.h:43
CWallet::EncryptWallet
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:1049
getbalances
UniValue getbalances(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:666
CWallet::DecodeStealthAddress
static bool DecodeStealthAddress(const std::string &stealth, CPubKey &pubViewKey, CPubKey &pubSpendKey, bool &hasPaymentID, uint64_t &paymentID)
Definition: wallet.cpp:6522
strprintf
#define strprintf
Definition: tinyformat.h:1056
CWallet::fCombineDust
bool fCombineDust
Definition: wallet.h:331
CWalletDB::WriteAccount
bool WriteAccount(const std::string &strAccount, const CAccount &account)
Definition: walletdb.cpp:383
createprivacysubaddress
UniValue createprivacysubaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2681
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
GetAdjustedTime
int64_t GetAdjustedTime()
Definition: timedata.cpp:30
CWallet::AvailableCoins
bool AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool fIncludeZeroValue=false, AvailableCoinsType nCoinType=ALL_COINS, bool fUseIX=false)
populate vCoins with vector of available COutputs.
Definition: wallet.cpp:2490
revealmnemonicphrase
UniValue revealmnemonicphrase(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:3104
CAccount::vchPubKey
CPubKey vchPubKey
Definition: wallet.h:170
CWalletTx::GetAmounts
void GetAmounts(std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, std::string &strSentAccount, const isminefilter &filter) const
Definition: wallet.cpp:1681
CMerkleTx::GetBlocksToMaturity
int GetBlocksToMaturity() const
Definition: wallet.cpp:6025
NetMsgType::TX
const char * TX
The tx message transmits a single transaction.
Definition: protocol.cpp:25
getaccountaddress
UniValue getaccountaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:201
UniValue::get_int
int get_int() const
Definition: univalue.cpp:316
CKey
An encapsulated private key.
Definition: key.h:39
CReserveKey::KeepKey
void KeepKey()
Definition: wallet.cpp:5008
CWallet::TopUpKeyPool
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:4706
RPC_WALLET_INSUFFICIENT_FUNDS
@ RPC_WALLET_INSUFFICIENT_FUNDS
Unspecified problem with wallet (key not found etc.)
Definition: protocol.h:69
AccountFromValue
std::string AccountFromValue(const UniValue &value)
Definition: rpcwallet.cpp:81
CKeyStore::AddKey
virtual bool AddKey(const CKey &key)
Definition: keystore.cpp:22
utilmoneystr.h
CAccountingEntry::nOrderPos
int64_t nOrderPos
Definition: wallet.h:991
CStealthAccount::viewAccount
CAccount viewAccount
Definition: wallet.h:199
LOCK
#define LOCK(cs)
Definition: sync.h:182
CWalletDB::WriteMSettings
bool WriteMSettings(bool fMultiSendStake, bool fMultiSendMasternode, int nLastMultiSendHeight)
Definition: walletdb.cpp:225
key
CKey key
Definition: bip38tooldialog.cpp:173
printAddresses
UniValue printAddresses()
Definition: rpcwallet.cpp:2303
CWallet
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:243
CWalletTx
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:792
CTransaction::paymentID
uint64_t paymentID
Definition: transaction.h:292
CWallet::RescanAfterUnlock
bool RescanAfterUnlock(int fromHeight)
Definition: wallet.cpp:499
CHashWriter
A writer stream (for serialization) that computes a 256-bit hash.
Definition: hash.h:259
UniValue::push_back
bool push_back(const UniValue &val)
Definition: univalue.cpp:173
strMessageMagic
const std::string strMessageMagic
Definition: main.cpp:119
sendtostealthaddress
UniValue sendtostealthaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2797
revealspendprivatekey
UniValue revealspendprivatekey(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2967
_createmultisig_redeemScript
CScript _createmultisig_redeemScript(const UniValue &params)
Used by addmultisigaddress / createmultisig:
Definition: misc.cpp:362
CWallet::GetSeedPhrase
bool GetSeedPhrase(std::string &phrase)
Definition: wallet.cpp:351
listreceivedbyaccount
UniValue listreceivedbyaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1111
CWalletDB::WriteStakeSplitThreshold
bool WriteStakeSplitThreshold(uint64_t nStakeSplitThreshold)
Definition: walletdb.cpp:192
getreceivedbyaccount
UniValue getreceivedbyaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:519
CWalletDB::ReadTxPrivateKey
bool ReadTxPrivateKey(const std::string &outpointKey, std::string &k)
Definition: walletdb.cpp:1276
CWallet::cs_wallet
RecursiveMutex cs_wallet
Definition: wallet.h:301
setstakesplitthreshold
UniValue setstakesplitthreshold(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2180
UniValue::getValues
const std::vector< UniValue > & getValues() const
Definition: univalue.cpp:295
base58.h
CWalletDB::EraseMSDisabledAddresses
bool EraseMSDisabledAddresses(std::vector< std::string > vDisabledAddresses)
Definition: walletdb.cpp:245
CDB::TxnBegin
bool TxnBegin()
Definition: db.h:285
UniValue::size
size_t size() const
Definition: univalue.h:69
CCryptoKeyStore::IsCrypted
bool IsCrypted() const
Definition: crypter.h:154
getwalletinfo
UniValue getwalletinfo(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2071
CTransaction::GetHash
const uint256 & GetHash() const
Definition: transaction.h:342
BackupWallet
bool BackupWallet(const CWallet &wallet, const fs::path &strDest, bool fEnableCustom)
Definition: walletdb.cpp:1045
CMerkleTx::hashBlock
uint256 hashBlock
Definition: wallet.h:737
CWallet::GetKeyPoolSize
unsigned int GetKeyPoolSize()
Definition: wallet.cpp:6232
CAccount::nAccountIndex
uint32_t nAccountIndex
Definition: wallet.h:171
EncodeHexTx
std::string EncodeHexTx(const CTransaction &tx)
Definition: core_write.cpp:55
walletdb.h
showstealthaddress
UniValue showstealthaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2589
ListReceived
UniValue ListReceived(const UniValue &params, bool fByAccounts)
Definition: rpcwallet.cpp:964
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
CChain::Tip
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
Definition: chain.h:596
find_value
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:279
generateintegratedaddress
UniValue generateintegratedaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2608
CPubKey::IsValid
bool IsValid() const
Definition: pubkey.h:159
RPC_TYPE_ERROR
@ RPC_TYPE_ERROR
Server is in safe mode, and command is not allowed in safe mode.
Definition: protocol.h:42
RPC_PRIVACY_WALLET_EXISTED
@ RPC_PRIVACY_WALLET_EXISTED
Wallet is already unlocked.
Definition: protocol.h:77
CTransaction::hasPaymentID
char hasPaymentID
Definition: transaction.h:291
CWalletDB::WriteReserveAmount
bool WriteReserveAmount(const double &amount)
Definition: walletdb.cpp:161
getnewaddress
UniValue getnewaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:89
CWallet::ChangeWalletPassphrase
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:656
UniValue::get_array
const UniValue & get_array() const
Definition: univalue.cpp:353
UniValue::VARR
@ VARR
Definition: univalue.h:21
tallyitem::tallyitem
tallyitem()
Definition: rpcwallet.cpp:955
CHashWriter::GetHash
uint256 GetHash()
Definition: hash.h:277
CBitcoinAddress::IsValid
bool IsValid() const
Definition: base58.cpp:254
CWalletTx::GetAccountAmounts
void GetAccountAmounts(const std::string &strAccount, CAmount &nReceived, CAmount &nSent, CAmount &nFee, const isminefilter &filter) const
Definition: wallet.cpp:1731
server.h
CWallet::fMultiSendStake
bool fMultiSendStake
Definition: wallet.h:323
net.h
CAddressBookData::name
std::string name
Definition: wallet.h:151
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
CWalletTx::GetConflicts
std::set< uint256 > GetConflicts() const
Definition: wallet.cpp:2188
CScriptID
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:20
CFeeRate::GetFeePerK
CAmount GetFeePerK() const
Definition: amount.h:50
CBitcoinAddress::Get
CTxDestination Get() const
Definition: base58.cpp:267
CWalletDB::ReadStealthAccount
bool ReadStealthAccount(const std::string &strAccount, CStealthAccount &account)
Definition: walletdb.cpp:388
CWallet::ListLockedCoins
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
Definition: wallet.cpp:5083
CWallet::strWalletFile
std::string strWalletFile
Definition: wallet.h:305
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
COutput
Definition: wallet.h:922
sumMultiSend
unsigned int sumMultiSend()
Definition: rpcwallet.cpp:2332
CWallet::GetKey
bool GetKey(const CKeyID &address, CKey &keyOut) const
GetKey implementation that can derive a HD private key on the fly.
Definition: wallet.cpp:6906
UniValue::VSTR
@ VSTR
Definition: univalue.h:21
amount.h
GetIXConfirmations
int GetIXConfirmations(uint256 nTXHash)
Definition: main.cpp:1392
CWallet::getCTxOutValue
CAmount getCTxOutValue(const CTransaction &tx, const CTxOut &out) const
Definition: wallet.cpp:7202
CWallet::mapAddressBook
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:354
CWalletDB::AppendStealthAccountList
bool AppendStealthAccountList(const std::string &accountName)
Definition: walletdb.cpp:33
getstakesplitthreshold
UniValue getstakesplitthreshold(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2222
CWallet::GenerateIntegratedAddressWithRandomPaymentID
std::string GenerateIntegratedAddressWithRandomPaymentID(std::string accountName, uint64_t &paymentID)
Definition: wallet.cpp:6501
CCryptoKeyStore::IsLocked
bool IsLocked() const
Definition: crypter.h:159
erasefromwallet
UniValue erasefromwallet(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:3128
CPubKey::GetID
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:143
CWallet::myViewPrivateKey
bool myViewPrivateKey(CKey &view) const
Definition: wallet.cpp:7025
UniValue::setArray
bool setArray()
Definition: univalue.cpp:159
mapBlockIndex
BlockMap mapBlockIndex
Definition: main.cpp:67
CWallet::fMultiSendMasternodeReward
bool fMultiSendMasternodeReward
Definition: wallet.h:324
CWalletTx::IsFromMe
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.cpp:6355
CWalletDB::WriteMultiSend
bool WriteMultiSend(std::vector< std::pair< std::string, int > > vMultiSend)
Definition: walletdb.cpp:199
UniValue::isObject
bool isObject() const
Definition: univalue.h:84
CTransaction::IsCoinStake
bool IsCoinStake() const
Definition: transaction.cpp:143
CWallet::UnlockAllCoins
void UnlockAllCoins()
Definition: wallet.cpp:5069
CAccountingEntry::strComment
std::string strComment
Definition: wallet.h:989