Dash Core  0.12.2.1
P2P Digital Currency
rpcwallet.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2014-2017 The Dash Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "amount.h"
8 #include "base58.h"
9 #include "chain.h"
10 #include "core_io.h"
11 #include "init.h"
12 #include "instantx.h"
13 #include "net.h"
14 #include "policy/rbf.h"
15 #include "rpc/server.h"
16 #include "timedata.h"
17 #include "util.h"
18 #include "utilmoneystr.h"
19 #include "validation.h"
20 #include "wallet.h"
21 #include "walletdb.h"
22 #include "keepass.h"
23 
24 #include <stdint.h>
25 
26 #include <boost/assign/list_of.hpp>
27 
28 #include <univalue.h>
29 
30 using namespace std;
31 
34 
36 {
37  return pwalletMain && pwalletMain->IsCrypted()
38  ? "\nRequires wallet passphrase to be set with walletpassphrase call."
39  : "";
40 }
41 
42 bool EnsureWalletIsAvailable(bool avoidException)
43 {
44  if (!pwalletMain)
45  {
46  if (!avoidException)
47  throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
48  else
49  return false;
50  }
51  return true;
52 }
53 
55 {
56  if (pwalletMain->IsLocked())
57  throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
58 }
59 
60 void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
61 {
62  int confirms = wtx.GetDepthInMainChain(false);
64  entry.push_back(Pair("confirmations", confirms));
65  entry.push_back(Pair("instantlock", fLocked));
66  if (wtx.IsCoinBase())
67  entry.push_back(Pair("generated", true));
68  if (confirms > 0)
69  {
70  entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
71  entry.push_back(Pair("blockindex", wtx.nIndex));
72  entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()));
73  } else {
74  entry.push_back(Pair("trusted", wtx.IsTrusted()));
75  }
76  uint256 hash = wtx.GetHash();
77  entry.push_back(Pair("txid", hash.GetHex()));
78  UniValue conflicts(UniValue::VARR);
79  BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts())
80  conflicts.push_back(conflict.GetHex());
81  entry.push_back(Pair("walletconflicts", conflicts));
82  entry.push_back(Pair("time", wtx.GetTxTime()));
83  entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
84 
85  // Add opt-in RBF status
86  std::string rbfStatus = "no";
87  if (confirms <= 0) {
88  LOCK(mempool.cs);
89  if (!mempool.exists(hash)) {
90  if (SignalsOptInRBF(wtx)) {
91  rbfStatus = "yes";
92  } else {
93  rbfStatus = "unknown";
94  }
95  } else if (IsRBFOptIn(*mempool.mapTx.find(hash), mempool)) {
96  rbfStatus = "yes";
97  }
98  }
99  entry.push_back(Pair("bip125-replaceable", rbfStatus));
100 
101  BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue)
102  entry.push_back(Pair(item.first, item.second));
103 }
104 
105 string AccountFromValue(const UniValue& value)
106 {
107  string strAccount = value.get_str();
108  if (strAccount == "*")
109  throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name");
110  return strAccount;
111 }
112 
113 UniValue getnewaddress(const UniValue& params, bool fHelp)
114 {
115  if (!EnsureWalletIsAvailable(fHelp))
116  return NullUniValue;
117 
118  if (fHelp || params.size() > 1)
119  throw runtime_error(
120  "getnewaddress ( \"account\" )\n"
121  "\nReturns a new Dash address for receiving payments.\n"
122  "If 'account' is specified (DEPRECATED), it is added to the address book \n"
123  "so payments received with the address will be credited to 'account'.\n"
124  "\nArguments:\n"
125  "1. \"account\" (string, optional) DEPRECATED. 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"
126  "\nResult:\n"
127  "\"dashaddress\" (string) The new dash address\n"
128  "\nExamples:\n"
129  + HelpExampleCli("getnewaddress", "")
130  + HelpExampleRpc("getnewaddress", "")
131  );
132 
134 
135  // Parse the account first so we don't generate a key if there's an error
136  string strAccount;
137  if (params.size() > 0)
138  strAccount = AccountFromValue(params[0]);
139 
140  if (!pwalletMain->IsLocked(true))
142 
143  // Generate a new key that is added to wallet
144  CPubKey newKey;
145  if (!pwalletMain->GetKeyFromPool(newKey, false))
146  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
147  CKeyID keyID = newKey.GetID();
148 
149  pwalletMain->SetAddressBook(keyID, strAccount, "receive");
150 
151  return CBitcoinAddress(keyID).ToString();
152 }
153 
154 
155 CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
156 {
158 
159  CAccount account;
160  walletdb.ReadAccount(strAccount, account);
161 
162  bool bKeyUsed = false;
163 
164  // Check if the current key has been used
165  if (account.vchPubKey.IsValid())
166  {
167  CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID());
168  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
169  it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
170  ++it)
171  {
172  const CWalletTx& wtx = (*it).second;
173  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
174  if (txout.scriptPubKey == scriptPubKey)
175  bKeyUsed = true;
176  }
177  }
178 
179  // Generate a new key
180  if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed)
181  {
182  if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false))
183  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
184 
185  pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
186  walletdb.WriteAccount(strAccount, account);
187  }
188 
189  return CBitcoinAddress(account.vchPubKey.GetID());
190 }
191 
192 UniValue getaccountaddress(const UniValue& params, bool fHelp)
193 {
194  if (!EnsureWalletIsAvailable(fHelp))
195  return NullUniValue;
196 
197  if (fHelp || params.size() != 1)
198  throw runtime_error(
199  "getaccountaddress \"account\"\n"
200  "\nDEPRECATED. Returns the current Dash address for receiving payments to this account.\n"
201  "\nArguments:\n"
202  "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"
203  "\nResult:\n"
204  "\"dashaddress\" (string) The account dash address\n"
205  "\nExamples:\n"
206  + HelpExampleCli("getaccountaddress", "")
207  + HelpExampleCli("getaccountaddress", "\"\"")
208  + HelpExampleCli("getaccountaddress", "\"myaccount\"")
209  + HelpExampleRpc("getaccountaddress", "\"myaccount\"")
210  );
211 
213 
214  // Parse the account first so we don't generate a key if there's an error
215  string strAccount = AccountFromValue(params[0]);
216 
218 
219  ret = GetAccountAddress(strAccount).ToString();
220  return ret;
221 }
222 
223 
224 UniValue getrawchangeaddress(const UniValue& params, bool fHelp)
225 {
226  if (!EnsureWalletIsAvailable(fHelp))
227  return NullUniValue;
228 
229  if (fHelp || params.size() > 1)
230  throw runtime_error(
231  "getrawchangeaddress\n"
232  "\nReturns a new Dash address, for receiving change.\n"
233  "This is for use with raw transactions, NOT normal use.\n"
234  "\nResult:\n"
235  "\"address\" (string) The address\n"
236  "\nExamples:\n"
237  + HelpExampleCli("getrawchangeaddress", "")
238  + HelpExampleRpc("getrawchangeaddress", "")
239  );
240 
242 
243  if (!pwalletMain->IsLocked(true))
245 
246  CReserveKey reservekey(pwalletMain);
247  CPubKey vchPubKey;
248  if (!reservekey.GetReservedKey(vchPubKey, true))
249  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
250 
251  reservekey.KeepKey();
252 
253  CKeyID keyID = vchPubKey.GetID();
254 
255  return CBitcoinAddress(keyID).ToString();
256 }
257 
258 
259 UniValue setaccount(const UniValue& params, bool fHelp)
260 {
261  if (!EnsureWalletIsAvailable(fHelp))
262  return NullUniValue;
263 
264  if (fHelp || params.size() < 1 || params.size() > 2)
265  throw runtime_error(
266  "setaccount \"dashaddress\" \"account\"\n"
267  "\nDEPRECATED. Sets the account associated with the given address.\n"
268  "\nArguments:\n"
269  "1. \"dashaddress\" (string, required) The dash address to be associated with an account.\n"
270  "2. \"account\" (string, required) The account to assign the address to.\n"
271  "\nExamples:\n"
272  + HelpExampleCli("setaccount", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" \"tabby\"")
273  + HelpExampleRpc("setaccount", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", \"tabby\"")
274  );
275 
277 
278  CBitcoinAddress address(params[0].get_str());
279  if (!address.IsValid())
280  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
281 
282  string strAccount;
283  if (params.size() > 1)
284  strAccount = AccountFromValue(params[1]);
285 
286  // Only add the account if the address is yours.
287  if (IsMine(*pwalletMain, address.Get()))
288  {
289  // Detect when changing the account of an address that is the 'unused current key' of another account:
290  if (pwalletMain->mapAddressBook.count(address.Get()))
291  {
292  string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
293  if (address == GetAccountAddress(strOldAccount))
294  GetAccountAddress(strOldAccount, true);
295  }
296  pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
297  }
298  else
299  throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address");
300 
301  return NullUniValue;
302 }
303 
304 
305 UniValue getaccount(const UniValue& params, bool fHelp)
306 {
307  if (!EnsureWalletIsAvailable(fHelp))
308  return NullUniValue;
309 
310  if (fHelp || params.size() != 1)
311  throw runtime_error(
312  "getaccount \"dashaddress\"\n"
313  "\nDEPRECATED. Returns the account associated with the given address.\n"
314  "\nArguments:\n"
315  "1. \"dashaddress\" (string, required) The dash address for account lookup.\n"
316  "\nResult:\n"
317  "\"accountname\" (string) the account address\n"
318  "\nExamples:\n"
319  + HelpExampleCli("getaccount", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"")
320  + HelpExampleRpc("getaccount", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"")
321  );
322 
324 
325  CBitcoinAddress address(params[0].get_str());
326  if (!address.IsValid())
327  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
328 
329  string strAccount;
330  map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
331  if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty())
332  strAccount = (*mi).second.name;
333  return strAccount;
334 }
335 
336 
337 UniValue getaddressesbyaccount(const UniValue& params, bool fHelp)
338 {
339  if (!EnsureWalletIsAvailable(fHelp))
340  return NullUniValue;
341 
342  if (fHelp || params.size() != 1)
343  throw runtime_error(
344  "getaddressesbyaccount \"account\"\n"
345  "\nDEPRECATED. Returns the list of addresses for the given account.\n"
346  "\nArguments:\n"
347  "1. \"account\" (string, required) The account name.\n"
348  "\nResult:\n"
349  "[ (json array of string)\n"
350  " \"dashaddress\" (string) a dash address associated with the given account\n"
351  " ,...\n"
352  "]\n"
353  "\nExamples:\n"
354  + HelpExampleCli("getaddressesbyaccount", "\"tabby\"")
355  + HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")
356  );
357 
359 
360  string strAccount = AccountFromValue(params[0]);
361 
362  // Find all addresses that have the given account
365  {
366  const CBitcoinAddress& address = item.first;
367  const string& strName = item.second.name;
368  if (strName == strAccount)
369  ret.push_back(address.ToString());
370  }
371  return ret;
372 }
373 
374 static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, bool fUseInstantSend=false, bool fUsePrivateSend=false)
375 {
376  CAmount curBalance = pwalletMain->GetBalance();
377 
378  // Check amount
379  if (nValue <= 0)
380  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
381 
382  if (nValue > curBalance)
383  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
384 
386  throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
387 
388  // Parse Dash address
389  CScript scriptPubKey = GetScriptForDestination(address);
390 
391  // Create and send the transaction
392  CReserveKey reservekey(pwalletMain);
393  CAmount nFeeRequired;
394  std::string strError;
395  vector<CRecipient> vecSend;
396  int nChangePosRet = -1;
397  CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount};
398  vecSend.push_back(recipient);
399  if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet,
400  strError, NULL, true, fUsePrivateSend ? ONLY_DENOMINATED : ALL_COINS, fUseInstantSend)) {
401  if (!fSubtractFeeFromAmount && nValue + nFeeRequired > pwalletMain->GetBalance())
402  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));
403  throw JSONRPCError(RPC_WALLET_ERROR, strError);
404  }
405  if (!pwalletMain->CommitTransaction(wtxNew, reservekey, g_connman.get(), fUseInstantSend ? NetMsgType::TXLOCKREQUEST : NetMsgType::TX))
406  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.");
407 }
408 
409 UniValue sendtoaddress(const UniValue& params, bool fHelp)
410 {
411  if (!EnsureWalletIsAvailable(fHelp))
412  return NullUniValue;
413 
414  if (fHelp || params.size() < 2 || params.size() > 7)
415  throw runtime_error(
416  "sendtoaddress \"dashaddress\" amount ( \"comment\" \"comment-to\" subtractfeefromamount use_is use_ps )\n"
417  "\nSend an amount to a given address.\n"
419  "\nArguments:\n"
420  "1. \"dashaddress\" (string, required) The dash address to send to.\n"
421  "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n"
422  "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
423  " This is not part of the transaction, just kept in your wallet.\n"
424  "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n"
425  " to which you're sending the transaction. This is not part of the \n"
426  " transaction, just kept in your wallet.\n"
427  "5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
428  " The recipient will receive less amount of Dash than you enter in the amount field.\n"
429  "6. \"use_is\" (bool, optional) Send this transaction as InstantSend (default: false)\n"
430  "7. \"use_ps\" (bool, optional) Use anonymized funds only (default: false)\n"
431  "\nResult:\n"
432  "\"transactionid\" (string) The transaction id.\n"
433  "\nExamples:\n"
434  + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1")
435  + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"donation\" \"seans outpost\"")
436  + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"\" \"\" true")
437  + HelpExampleRpc("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", 0.1, \"donation\", \"seans outpost\"")
438  );
439 
441 
442  CBitcoinAddress address(params[0].get_str());
443  if (!address.IsValid())
444  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
445 
446  // Amount
447  CAmount nAmount = AmountFromValue(params[1]);
448  if (nAmount <= 0)
449  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
450 
451  // Wallet comments
452  CWalletTx wtx;
453  if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty())
454  wtx.mapValue["comment"] = params[2].get_str();
455  if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty())
456  wtx.mapValue["to"] = params[3].get_str();
457 
458  bool fSubtractFeeFromAmount = false;
459  if (params.size() > 4)
460  fSubtractFeeFromAmount = params[4].get_bool();
461 
462  bool fUseInstantSend = false;
463  bool fUsePrivateSend = false;
464  if (params.size() > 5)
465  fUseInstantSend = params[5].get_bool();
466  if (params.size() > 6)
467  fUsePrivateSend = params[6].get_bool();
468 
470 
471  SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx, fUseInstantSend, fUsePrivateSend);
472 
473  return wtx.GetHash().GetHex();
474 }
475 
476 UniValue instantsendtoaddress(const UniValue& params, bool fHelp)
477 {
478  if (!EnsureWalletIsAvailable(fHelp))
479  return NullUniValue;
480 
481  if (fHelp || params.size() < 2 || params.size() > 5)
482  throw runtime_error(
483  "instantsendtoaddress \"dashaddress\" amount ( \"comment\" \"comment-to\" subtractfeefromamount )\n"
484  "\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n"
486  "\nArguments:\n"
487  "1. \"dashaddress\" (string, required) The dash address to send to.\n"
488  "2. \"amount\" (numeric, required) The amount in btc to send. eg 0.1\n"
489  "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
490  " This is not part of the transaction, just kept in your wallet.\n"
491  "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n"
492  " to which you're sending the transaction. This is not part of the \n"
493  " transaction, just kept in your wallet.\n"
494  "5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
495  " The recipient will receive less amount of Dash than you enter in the amount field.\n"
496  "\nResult:\n"
497  "\"transactionid\" (string) The transaction id.\n"
498  "\nExamples:\n"
499  + HelpExampleCli("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1")
500  + HelpExampleCli("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"donation\" \"seans outpost\"")
501  + HelpExampleCli("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"\" \"\" true")
502  + HelpExampleRpc("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", 0.1, \"donation\", \"seans outpost\"")
503  );
504 
506 
507  CBitcoinAddress address(params[0].get_str());
508  if (!address.IsValid())
509  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
510 
511  // Amount
512  CAmount nAmount = AmountFromValue(params[1]);
513  if (nAmount <= 0)
514  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
515 
516  // Wallet comments
517  CWalletTx wtx;
518  if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty())
519  wtx.mapValue["comment"] = params[2].get_str();
520  if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty())
521  wtx.mapValue["to"] = params[3].get_str();
522 
523  bool fSubtractFeeFromAmount = false;
524  if (params.size() > 4)
525  fSubtractFeeFromAmount = params[4].get_bool();
526 
528 
529  SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx, true);
530 
531  return wtx.GetHash().GetHex();
532 }
533 
534 UniValue listaddressgroupings(const UniValue& params, bool fHelp)
535 {
536  if (!EnsureWalletIsAvailable(fHelp))
537  return NullUniValue;
538 
539  if (fHelp)
540  throw runtime_error(
541  "listaddressgroupings\n"
542  "\nLists groups of addresses which have had their common ownership\n"
543  "made public by common use as inputs or as the resulting change\n"
544  "in past transactions\n"
545  "\nResult:\n"
546  "[\n"
547  " [\n"
548  " [\n"
549  " \"dashaddress\", (string) The dash address\n"
550  " amount, (numeric) The amount in " + CURRENCY_UNIT + "\n"
551  " \"account\" (string, optional) The account (DEPRECATED)\n"
552  " ]\n"
553  " ,...\n"
554  " ]\n"
555  " ,...\n"
556  "]\n"
557  "\nExamples:\n"
558  + HelpExampleCli("listaddressgroupings", "")
559  + HelpExampleRpc("listaddressgroupings", "")
560  );
561 
563 
564  UniValue jsonGroupings(UniValue::VARR);
565  map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
566  BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
567  {
568  UniValue jsonGrouping(UniValue::VARR);
569  BOOST_FOREACH(CTxDestination address, grouping)
570  {
571  UniValue addressInfo(UniValue::VARR);
572  addressInfo.push_back(CBitcoinAddress(address).ToString());
573  addressInfo.push_back(ValueFromAmount(balances[address]));
574  {
575  if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
576  addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name);
577  }
578  jsonGrouping.push_back(addressInfo);
579  }
580  jsonGroupings.push_back(jsonGrouping);
581  }
582  return jsonGroupings;
583 }
584 
585 UniValue signmessage(const UniValue& params, bool fHelp)
586 {
587  if (!EnsureWalletIsAvailable(fHelp))
588  return NullUniValue;
589 
590  if (fHelp || params.size() != 2)
591  throw runtime_error(
592  "signmessage \"dashaddress\" \"message\"\n"
593  "\nSign a message with the private key of an address"
594  + HelpRequiringPassphrase() + "\n"
595  "\nArguments:\n"
596  "1. \"dashaddress\" (string, required) The dash address to use for the private key.\n"
597  "2. \"message\" (string, required) The message to create a signature of.\n"
598  "\nResult:\n"
599  "\"signature\" (string) The signature of the message encoded in base 64\n"
600  "\nExamples:\n"
601  "\nUnlock the wallet for 30 seconds\n"
602  + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
603  "\nCreate the signature\n"
604  + HelpExampleCli("signmessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" \"my message\"") +
605  "\nVerify the signature\n"
606  + HelpExampleCli("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" \"signature\" \"my message\"") +
607  "\nAs json rpc\n"
608  + HelpExampleRpc("signmessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", \"my message\"")
609  );
610 
612 
614 
615  string strAddress = params[0].get_str();
616  string strMessage = params[1].get_str();
617 
618  CBitcoinAddress addr(strAddress);
619  if (!addr.IsValid())
620  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
621 
622  CKeyID keyID;
623  if (!addr.GetKeyID(keyID))
624  throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
625 
626  CKey key;
627  if (!pwalletMain->GetKey(keyID, key))
628  throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
629 
630  CHashWriter ss(SER_GETHASH, 0);
631  ss << strMessageMagic;
632  ss << strMessage;
633 
634  vector<unsigned char> vchSig;
635  if (!key.SignCompact(ss.GetHash(), vchSig))
636  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
637 
638  return EncodeBase64(&vchSig[0], vchSig.size());
639 }
640 
641 UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
642 {
643  if (!EnsureWalletIsAvailable(fHelp))
644  return NullUniValue;
645 
646  if (fHelp || params.size() < 1 || params.size() > 3)
647  throw runtime_error(
648  "getreceivedbyaddress \"dashaddress\" ( minconf addlockconf )\n"
649  "\nReturns the total amount received by the given dashaddress in transactions with specified minimum number of confirmations.\n"
650  "\nArguments:\n"
651  "1. \"dashaddress\" (string, required) The dash address for transactions.\n"
652  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
653  "3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
654  "\nResult:\n"
655  "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n"
656  "\nExamples:\n"
657  "\nThe amount from transactions with at least 1 confirmation\n"
658  + HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") +
659  "\nThe amount including unconfirmed transactions, zero confirmations\n"
660  + HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0") +
661  "\nThe amount with at least 6 confirmation, very safe\n"
662  + HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 6") +
663  "\nAs a json rpc call\n"
664  + HelpExampleRpc("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", 6")
665  );
666 
668 
669  // Dash address
670  CBitcoinAddress address = CBitcoinAddress(params[0].get_str());
671  if (!address.IsValid())
672  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
673  CScript scriptPubKey = GetScriptForDestination(address.Get());
674  if (!IsMine(*pwalletMain, scriptPubKey))
675  return ValueFromAmount(0);
676 
677  // Minimum confirmations
678  int nMinDepth = 1;
679  if (params.size() > 1)
680  nMinDepth = params[1].get_int();
681  bool fAddLockConf = (params.size() > 2 && params[2].get_bool());
682 
683  // Tally
684  CAmount nAmount = 0;
685  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
686  {
687  const CWalletTx& wtx = (*it).second;
688  if (wtx.IsCoinBase() || !CheckFinalTx(wtx))
689  continue;
690 
691  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
692  if (txout.scriptPubKey == scriptPubKey)
693  if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth)
694  nAmount += txout.nValue;
695  }
696 
697  return ValueFromAmount(nAmount);
698 }
699 
700 
701 UniValue getreceivedbyaccount(const UniValue& params, bool fHelp)
702 {
703  if (!EnsureWalletIsAvailable(fHelp))
704  return NullUniValue;
705 
706  if (fHelp || params.size() < 1 || params.size() > 3)
707  throw runtime_error(
708  "getreceivedbyaccount \"account\" ( minconf addlockconf )\n"
709  "\nDEPRECATED. Returns the total amount received by addresses with <account> in transactions with specified minimum number of confirmations.\n"
710  "\nArguments:\n"
711  "1. \"account\" (string, required) The selected account, may be the default account using \"\".\n"
712  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
713  "3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
714  "\nResult:\n"
715  "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
716  "\nExamples:\n"
717  "\nAmount received by the default account with at least 1 confirmation\n"
718  + HelpExampleCli("getreceivedbyaccount", "\"\"") +
719  "\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n"
720  + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") +
721  "\nThe amount with at least 6 confirmation, very safe\n"
722  + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") +
723  "\nAs a json rpc call\n"
724  + HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6")
725  );
726 
728 
729  // Minimum confirmations
730  int nMinDepth = 1;
731  if (params.size() > 1)
732  nMinDepth = params[1].get_int();
733  bool fAddLockConf = (params.size() > 2 && params[2].get_bool());
734 
735  // Get the set of pub keys assigned to account
736  string strAccount = AccountFromValue(params[0]);
737  set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
738 
739  // Tally
740  CAmount nAmount = 0;
741  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
742  {
743  const CWalletTx& wtx = (*it).second;
744  if (wtx.IsCoinBase() || !CheckFinalTx(wtx))
745  continue;
746 
747  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
748  {
749  CTxDestination address;
750  if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address))
751  if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth)
752  nAmount += txout.nValue;
753  }
754  }
755 
756  return ValueFromAmount(nAmount);
757 }
758 
759 
760 CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter, bool fAddLockConf)
761 {
762  CAmount nBalance = 0;
763 
764  // Tally wallet transactions
765  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
766  {
767  const CWalletTx& wtx = (*it).second;
768  if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain(fAddLockConf) < 0)
769  continue;
770 
771  CAmount nReceived, nSent, nFee;
772  wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
773 
774  if (nReceived != 0 && wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth)
775  nBalance += nReceived;
776  nBalance -= nSent + nFee;
777  }
778 
779  // Tally internal accounting entries
780  nBalance += walletdb.GetAccountCreditDebit(strAccount);
781 
782  return nBalance;
783 }
784 
785 CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter, bool fAddLockConf)
786 {
788  return GetAccountBalance(walletdb, strAccount, nMinDepth, filter, fAddLockConf);
789 }
790 
791 
792 UniValue getbalance(const UniValue& params, bool fHelp)
793 {
794  if (!EnsureWalletIsAvailable(fHelp))
795  return NullUniValue;
796 
797  if (fHelp || params.size() > 4)
798  throw runtime_error(
799  "getbalance ( \"account\" minconf addlockconf includeWatchonly )\n"
800  "\nIf account is not specified, returns the server's total available balance.\n"
801  "If account is specified (DEPRECATED), returns the balance in the account.\n"
802  "Note that the account \"\" is not the same as leaving the parameter out.\n"
803  "The server total may be different to the balance in the default \"\" account.\n"
804  "\nArguments:\n"
805  "1. \"account\" (string, optional) DEPRECATED. The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n"
806  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
807  "3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
808  "4. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n"
809  "\nResult:\n"
810  "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
811  "\nExamples:\n"
812  "\nThe total amount in the wallet\n"
813  + HelpExampleCli("getbalance", "") +
814  "\nThe total amount in the wallet at least 5 blocks confirmed\n"
815  + HelpExampleCli("getbalance", "\"*\" 6") +
816  "\nAs a json rpc call\n"
817  + HelpExampleRpc("getbalance", "\"*\", 6")
818  );
819 
821 
822  if (params.size() == 0)
824 
825  int nMinDepth = 1;
826  if (params.size() > 1)
827  nMinDepth = params[1].get_int();
828  bool fAddLockConf = (params.size() > 2 && params[2].get_bool());
830  if(params.size() > 3)
831  if(params[3].get_bool())
832  filter = filter | ISMINE_WATCH_ONLY;
833 
834  if (params[0].get_str() == "*") {
835  // Calculate total balance a different way from GetBalance()
836  // (GetBalance() sums up all unspent TxOuts)
837  // getbalance and "getbalance * 1 true" should return the same number
838  CAmount nBalance = 0;
839  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
840  {
841  const CWalletTx& wtx = (*it).second;
842  if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
843  continue;
844 
845  CAmount allFee;
846  string strSentAccount;
847  list<COutputEntry> listReceived;
848  list<COutputEntry> listSent;
849  wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
850  if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth)
851  {
852  BOOST_FOREACH(const COutputEntry& r, listReceived)
853  nBalance += r.amount;
854  }
855  BOOST_FOREACH(const COutputEntry& s, listSent)
856  nBalance -= s.amount;
857  nBalance -= allFee;
858  }
859  return ValueFromAmount(nBalance);
860  }
861 
862  string strAccount = AccountFromValue(params[0]);
863 
864  CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter, fAddLockConf);
865 
866  return ValueFromAmount(nBalance);
867 }
868 
869 UniValue getunconfirmedbalance(const UniValue &params, bool fHelp)
870 {
871  if (!EnsureWalletIsAvailable(fHelp))
872  return NullUniValue;
873 
874  if (fHelp || params.size() > 0)
875  throw runtime_error(
876  "getunconfirmedbalance\n"
877  "Returns the server's total unconfirmed balance\n");
878 
880 
882 }
883 
884 
885 UniValue movecmd(const UniValue& params, bool fHelp)
886 {
887  if (!EnsureWalletIsAvailable(fHelp))
888  return NullUniValue;
889 
890  if (fHelp || params.size() < 3 || params.size() > 5)
891  throw runtime_error(
892  "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
893  "\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n"
894  "\nArguments:\n"
895  "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
896  "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
897  "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n"
898  "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
899  "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
900  "\nResult:\n"
901  "true|false (boolean) true if successful.\n"
902  "\nExamples:\n"
903  "\nMove 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby\n"
904  + HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
905  "\nMove 0.01 " + CURRENCY_UNIT + " timotei to akiko with a comment and funds have 6 confirmations\n"
906  + HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") +
907  "\nAs a json rpc call\n"
908  + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")
909  );
910 
912 
913  string strFrom = AccountFromValue(params[0]);
914  string strTo = AccountFromValue(params[1]);
915  CAmount nAmount = AmountFromValue(params[2]);
916  if (nAmount <= 0)
917  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
918  if (params.size() > 3)
919  // unused parameter, used to be nMinDepth, keep type-checking it though
920  (void)params[3].get_int();
921  string strComment;
922  if (params.size() > 4)
923  strComment = params[4].get_str();
924 
926  if (!walletdb.TxnBegin())
927  throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
928 
929  int64_t nNow = GetAdjustedTime();
930 
931  // Debit
932  CAccountingEntry debit;
933  debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
934  debit.strAccount = strFrom;
935  debit.nCreditDebit = -nAmount;
936  debit.nTime = nNow;
937  debit.strOtherAccount = strTo;
938  debit.strComment = strComment;
939  pwalletMain->AddAccountingEntry(debit, walletdb);
940 
941  // Credit
942  CAccountingEntry credit;
943  credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
944  credit.strAccount = strTo;
945  credit.nCreditDebit = nAmount;
946  credit.nTime = nNow;
947  credit.strOtherAccount = strFrom;
948  credit.strComment = strComment;
949  pwalletMain->AddAccountingEntry(credit, walletdb);
950 
951  if (!walletdb.TxnCommit())
952  throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
953 
954  return true;
955 }
956 
957 
958 UniValue sendfrom(const UniValue& params, bool fHelp)
959 {
960  if (!EnsureWalletIsAvailable(fHelp))
961  return NullUniValue;
962 
963  if (fHelp || params.size() < 3 || params.size() > 7)
964  throw runtime_error(
965  "sendfrom \"fromaccount\" \"todashaddress\" amount ( minconf addlockconf \"comment\" \"comment-to\" )\n"
966  "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a dash address."
967  + HelpRequiringPassphrase() + "\n"
968  "\nArguments:\n"
969  "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n"
970  "2. \"todashaddress\" (string, required) The dash address to send funds to.\n"
971  "3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n"
972  "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
973  "5. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
974  "6. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
975  " This is not part of the transaction, just kept in your wallet.\n"
976  "7. \"comment-to\" (string, optional) An optional comment to store the name of the person or organization \n"
977  " to which you're sending the transaction. This is not part of the transaction, \n"
978  " it is just kept in your wallet.\n"
979  "\nResult:\n"
980  "\"transactionid\" (string) The transaction id.\n"
981  "\nExamples:\n"
982  "\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n"
983  + HelpExampleCli("sendfrom", "\"\" \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.01") +
984  "\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n"
985  + HelpExampleCli("sendfrom", "\"tabby\" \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.01 6 false \"donation\" \"seans outpost\"") +
986  "\nAs a json rpc call\n"
987  + HelpExampleRpc("sendfrom", "\"tabby\", \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", 0.01, 6, false, \"donation\", \"seans outpost\"")
988  );
989 
991 
992  string strAccount = AccountFromValue(params[0]);
993  CBitcoinAddress address(params[1].get_str());
994  if (!address.IsValid())
995  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
996  CAmount nAmount = AmountFromValue(params[2]);
997  if (nAmount <= 0)
998  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
999  int nMinDepth = 1;
1000  if (params.size() > 3)
1001  nMinDepth = params[3].get_int();
1002  bool fAddLockConf = (params.size() > 4 && params[4].get_bool());
1003 
1004  CWalletTx wtx;
1005  wtx.strFromAccount = strAccount;
1006  if (params.size() > 5 && !params[5].isNull() && !params[5].get_str().empty())
1007  wtx.mapValue["comment"] = params[5].get_str();
1008  if (params.size() > 6 && !params[6].isNull() && !params[6].get_str().empty())
1009  wtx.mapValue["to"] = params[6].get_str();
1010 
1012 
1013  // Check funds
1014  CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLockConf);
1015  if (nAmount > nBalance)
1016  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
1017 
1018  SendMoney(address.Get(), nAmount, false, wtx);
1019 
1020  return wtx.GetHash().GetHex();
1021 }
1022 
1023 
1024 UniValue sendmany(const UniValue& params, bool fHelp)
1025 {
1026  if (!EnsureWalletIsAvailable(fHelp))
1027  return NullUniValue;
1028 
1029  if (fHelp || params.size() < 2 || params.size() > 8)
1030  throw runtime_error(
1031  "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf addlockconf \"comment\" [\"address\",...] subtractfeefromamount use_is use_ps )\n"
1032  "\nSend multiple times. Amounts are double-precision floating point numbers."
1033  + HelpRequiringPassphrase() + "\n"
1034  "\nArguments:\n"
1035  "1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n"
1036  "2. \"amounts\" (string, required) A json object with addresses and amounts\n"
1037  " {\n"
1038  " \"address\":amount (numeric or string) The dash address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value\n"
1039  " ,...\n"
1040  " }\n"
1041  "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
1042  "4. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
1043  "5. \"comment\" (string, optional) A comment\n"
1044  "6. subtractfeefromamount (string, optional) A json array with addresses.\n"
1045  " The fee will be equally deducted from the amount of each selected address.\n"
1046  " Those recipients will receive less dashs than you enter in their corresponding amount field.\n"
1047  " If no addresses are specified here, the sender pays the fee.\n"
1048  " [\n"
1049  " \"address\" (string) Subtract fee from this address\n"
1050  " ,...\n"
1051  " ]\n"
1052  "7. \"use_is\" (bool, optional) Send this transaction as InstantSend (default: false)\n"
1053  "8. \"use_ps\" (bool, optional) Use anonymized funds only (default: false)\n"
1054  "\nResult:\n"
1055  "\"transactionid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
1056  " the number of addresses.\n"
1057  "\nExamples:\n"
1058  "\nSend two amounts to two different addresses:\n"
1059  + HelpExampleCli("sendmany", "\"tabby\" \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\":0.02}\"") +
1060  "\nSend two amounts to two different addresses setting the confirmation and comment:\n"
1061  + HelpExampleCli("sendmany", "\"tabby\" \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\":0.02}\" 6 false \"testing\"") +
1062  "\nAs a json rpc call\n"
1063  + HelpExampleRpc("sendmany", "\"tabby\", \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\":0.02}\", 6, false, \"testing\"")
1064  );
1065 
1067 
1069  throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
1070 
1071  string strAccount = AccountFromValue(params[0]);
1072  UniValue sendTo = params[1].get_obj();
1073  int nMinDepth = 1;
1074  if (params.size() > 2)
1075  nMinDepth = params[2].get_int();
1076  bool fAddLockConf = (params.size() > 3 && params[3].get_bool());
1077 
1078  CWalletTx wtx;
1079  wtx.strFromAccount = strAccount;
1080  if (params.size() > 4 && !params[4].isNull() && !params[4].get_str().empty())
1081  wtx.mapValue["comment"] = params[4].get_str();
1082 
1083  UniValue subtractFeeFromAmount(UniValue::VARR);
1084  if (params.size() > 5)
1085  subtractFeeFromAmount = params[5].get_array();
1086 
1087  set<CBitcoinAddress> setAddress;
1088  vector<CRecipient> vecSend;
1089 
1090  CAmount totalAmount = 0;
1091  vector<string> keys = sendTo.getKeys();
1092  BOOST_FOREACH(const string& name_, keys)
1093  {
1094  CBitcoinAddress address(name_);
1095  if (!address.IsValid())
1096  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Dash address: ")+name_);
1097 
1098  if (setAddress.count(address))
1099  throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_);
1100  setAddress.insert(address);
1101 
1102  CScript scriptPubKey = GetScriptForDestination(address.Get());
1103  CAmount nAmount = AmountFromValue(sendTo[name_]);
1104  if (nAmount <= 0)
1105  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
1106  totalAmount += nAmount;
1107 
1108  bool fSubtractFeeFromAmount = false;
1109  for (unsigned int idx = 0; idx < subtractFeeFromAmount.size(); idx++) {
1110  const UniValue& addr = subtractFeeFromAmount[idx];
1111  if (addr.get_str() == name_)
1112  fSubtractFeeFromAmount = true;
1113  }
1114 
1115  CRecipient recipient = {scriptPubKey, nAmount, fSubtractFeeFromAmount};
1116  vecSend.push_back(recipient);
1117  }
1118 
1120 
1121  // Check funds
1122  CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLockConf);
1123  if (totalAmount > nBalance)
1124  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
1125 
1126  // Send
1127  CReserveKey keyChange(pwalletMain);
1128  CAmount nFeeRequired = 0;
1129  int nChangePosRet = -1;
1130  string strFailReason;
1131  bool fUseInstantSend = false;
1132  bool fUsePrivateSend = false;
1133  if (params.size() > 6)
1134  fUseInstantSend = params[6].get_bool();
1135  if (params.size() > 7)
1136  fUsePrivateSend = params[7].get_bool();
1137 
1138  bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason,
1139  NULL, true, fUsePrivateSend ? ONLY_DENOMINATED : ALL_COINS, fUseInstantSend);
1140  if (!fCreated)
1141  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
1142  if (!pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get(), fUseInstantSend ? NetMsgType::TXLOCKREQUEST : NetMsgType::TX))
1143  throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed");
1144 
1145  return wtx.GetHash().GetHex();
1146 }
1147 
1148 // Defined in rpc/misc.cpp
1149 extern CScript _createmultisig_redeemScript(const UniValue& params);
1150 
1151 UniValue addmultisigaddress(const UniValue& params, bool fHelp)
1152 {
1153  if (!EnsureWalletIsAvailable(fHelp))
1154  return NullUniValue;
1155 
1156  if (fHelp || params.size() < 2 || params.size() > 3)
1157  {
1158  string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
1159  "\nAdd a nrequired-to-sign multisignature address to the wallet.\n"
1160  "Each key is a Dash address or hex-encoded public key.\n"
1161  "If 'account' is specified (DEPRECATED), assign address to that account.\n"
1162 
1163  "\nArguments:\n"
1164  "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
1165  "2. \"keysobject\" (string, required) A json array of dash addresses or hex-encoded public keys\n"
1166  " [\n"
1167  " \"address\" (string) dash address or hex-encoded public key\n"
1168  " ...,\n"
1169  " ]\n"
1170  "3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n"
1171 
1172  "\nResult:\n"
1173  "\"dashaddress\" (string) A dash address associated with the keys.\n"
1174 
1175  "\nExamples:\n"
1176  "\nAdd a multisig address from 2 addresses\n"
1177  + HelpExampleCli("addmultisigaddress", "2 \"[\\\"Xt4qk9uKvQYAonVGSZNXqxeDmtjaEWgfrs\\\",\\\"XoSoWQkpgLpppPoyyzbUFh1fq2RBvW6UK1\\\"]\"") +
1178  "\nAs json rpc call\n"
1179  + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"Xt4qk9uKvQYAonVGSZNXqxeDmtjaEWgfrs\\\",\\\"XoSoWQkpgLpppPoyyzbUFh1fq2RBvW6UK1\\\"]\"")
1180  ;
1181  throw runtime_error(msg);
1182  }
1183 
1185 
1186  string strAccount;
1187  if (params.size() > 2)
1188  strAccount = AccountFromValue(params[2]);
1189 
1190  // Construct using pay-to-script-hash:
1191  CScript inner = _createmultisig_redeemScript(params);
1192  CScriptID innerID(inner);
1193  pwalletMain->AddCScript(inner);
1194 
1195  pwalletMain->SetAddressBook(innerID, strAccount, "send");
1196  return CBitcoinAddress(innerID).ToString();
1197 }
1198 
1199 
1201 {
1203  int nConf;
1204  vector<uint256> txids;
1207  {
1208  nAmount = 0;
1209  nConf = std::numeric_limits<int>::max();
1210  fIsWatchonly = false;
1211  }
1212 };
1213 
1214 UniValue ListReceived(const UniValue& params, bool fByAccounts)
1215 {
1216  // Minimum confirmations
1217  int nMinDepth = 1;
1218  if (params.size() > 0)
1219  nMinDepth = params[0].get_int();
1220  bool fAddLockConf = (params.size() > 1 && params[1].get_bool());
1221 
1222  // Whether to include empty accounts
1223  bool fIncludeEmpty = false;
1224  if (params.size() > 2)
1225  fIncludeEmpty = params[2].get_bool();
1226 
1227  isminefilter filter = ISMINE_SPENDABLE;
1228  if(params.size() > 3)
1229  if(params[3].get_bool())
1230  filter = filter | ISMINE_WATCH_ONLY;
1231 
1232  // Tally
1233  map<CBitcoinAddress, tallyitem> mapTally;
1234  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
1235  {
1236  const CWalletTx& wtx = (*it).second;
1237 
1238  if (wtx.IsCoinBase() || !CheckFinalTx(wtx))
1239  continue;
1240 
1241  int nDepth = wtx.GetDepthInMainChain(fAddLockConf);
1242  if (nDepth < nMinDepth)
1243  continue;
1244 
1245  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
1246  {
1247  CTxDestination address;
1248  if (!ExtractDestination(txout.scriptPubKey, address))
1249  continue;
1250 
1251  isminefilter mine = IsMine(*pwalletMain, address);
1252  if(!(mine & filter))
1253  continue;
1254 
1255  tallyitem& item = mapTally[address];
1256  item.nAmount += txout.nValue;
1257  item.nConf = min(item.nConf, nDepth);
1258  item.txids.push_back(wtx.GetHash());
1259  if (mine & ISMINE_WATCH_ONLY)
1260  item.fIsWatchonly = true;
1261  }
1262  }
1263 
1264  // Reply
1265  UniValue ret(UniValue::VARR);
1266  map<string, tallyitem> mapAccountTally;
1267  BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
1268  {
1269  const CBitcoinAddress& address = item.first;
1270  const string& strAccount = item.second.name;
1271  map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address);
1272  if (it == mapTally.end() && !fIncludeEmpty)
1273  continue;
1274 
1275  isminefilter mine = IsMine(*pwalletMain, address.Get());
1276  if(!(mine & filter))
1277  continue;
1278 
1279  CAmount nAmount = 0;
1280  int nConf = std::numeric_limits<int>::max();
1281  bool fIsWatchonly = false;
1282  if (it != mapTally.end())
1283  {
1284  nAmount = (*it).second.nAmount;
1285  nConf = (*it).second.nConf;
1286  fIsWatchonly = (*it).second.fIsWatchonly;
1287  }
1288 
1289  if (fByAccounts)
1290  {
1291  tallyitem& item = mapAccountTally[strAccount];
1292  item.nAmount += nAmount;
1293  item.nConf = min(item.nConf, nConf);
1294  item.fIsWatchonly = fIsWatchonly;
1295  }
1296  else
1297  {
1298  UniValue obj(UniValue::VOBJ);
1299  if(fIsWatchonly)
1300  obj.push_back(Pair("involvesWatchonly", true));
1301  obj.push_back(Pair("address", address.ToString()));
1302  obj.push_back(Pair("account", strAccount));
1303  obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1304  obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1305  if (!fByAccounts)
1306  obj.push_back(Pair("label", strAccount));
1307  UniValue transactions(UniValue::VARR);
1308  if (it != mapTally.end())
1309  {
1310  BOOST_FOREACH(const uint256& item, (*it).second.txids)
1311  {
1312  transactions.push_back(item.GetHex());
1313  }
1314  }
1315  obj.push_back(Pair("txids", transactions));
1316  ret.push_back(obj);
1317  }
1318  }
1319 
1320  if (fByAccounts)
1321  {
1322  for (map<string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
1323  {
1324  CAmount nAmount = (*it).second.nAmount;
1325  int nConf = (*it).second.nConf;
1326  UniValue obj(UniValue::VOBJ);
1327  if((*it).second.fIsWatchonly)
1328  obj.push_back(Pair("involvesWatchonly", true));
1329  obj.push_back(Pair("account", (*it).first));
1330  obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1331  obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1332  ret.push_back(obj);
1333  }
1334  }
1335 
1336  return ret;
1337 }
1338 
1339 UniValue listreceivedbyaddress(const UniValue& params, bool fHelp)
1340 {
1341  if (!EnsureWalletIsAvailable(fHelp))
1342  return NullUniValue;
1343 
1344  if (fHelp || params.size() > 4)
1345  throw runtime_error(
1346  "listreceivedbyaddress ( minconf addlockconf includeempty includeWatchonly)\n"
1347  "\nList balances by receiving address.\n"
1348  "\nArguments:\n"
1349  "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1350  "2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
1351  "3. includeempty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n"
1352  "4. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
1353 
1354  "\nResult:\n"
1355  "[\n"
1356  " {\n"
1357  " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
1358  " \"address\" : \"receivingaddress\", (string) The receiving address\n"
1359  " \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n"
1360  " \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address\n"
1361  " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included.\n"
1362  " If 'addlockconf' is true, the minimum number of confirmations is calculated\n"
1363  " including additional " + std::to_string(nInstantSendDepth) + " confirmations for transactions locked via InstantSend\n"
1364  " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
1365  " }\n"
1366  " ,...\n"
1367  "]\n"
1368 
1369  "\nExamples:\n"
1370  + HelpExampleCli("listreceivedbyaddress", "")
1371  + HelpExampleCli("listreceivedbyaddress", "6 false true")
1372  + HelpExampleRpc("listreceivedbyaddress", "6, false, true, true")
1373  );
1374 
1376 
1377  return ListReceived(params, false);
1378 }
1379 
1380 UniValue listreceivedbyaccount(const UniValue& params, bool fHelp)
1381 {
1382  if (!EnsureWalletIsAvailable(fHelp))
1383  return NullUniValue;
1384 
1385  if (fHelp || params.size() > 4)
1386  throw runtime_error(
1387  "listreceivedbyaccount ( minconf addlockconf includeempty includeWatchonly)\n"
1388  "\nDEPRECATED. List balances by account.\n"
1389  "\nArguments:\n"
1390  "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1391  "2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
1392  "3. includeempty (bool, optional, default=false) Whether to include accounts that haven't received any payments.\n"
1393  "4. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
1394 
1395  "\nResult:\n"
1396  "[\n"
1397  " {\n"
1398  " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
1399  " \"account\" : \"accountname\", (string) The account name of the receiving account\n"
1400  " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
1401  " \"confirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n"
1402  " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
1403  " }\n"
1404  " ,...\n"
1405  "]\n"
1406 
1407  "\nExamples:\n"
1408  + HelpExampleCli("listreceivedbyaccount", "")
1409  + HelpExampleCli("listreceivedbyaccount", "6 false true")
1410  + HelpExampleRpc("listreceivedbyaccount", "6, false, true, true")
1411  );
1412 
1414 
1415  return ListReceived(params, true);
1416 }
1417 
1418 static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
1419 {
1420  CBitcoinAddress addr;
1421  if (addr.Set(dest))
1422  entry.push_back(Pair("address", addr.ToString()));
1423 }
1424 
1425 void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter)
1426 {
1427  CAmount nFee;
1428  string strSentAccount;
1429  list<COutputEntry> listReceived;
1430  list<COutputEntry> listSent;
1431 
1432  wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
1433 
1434  bool fAllAccounts = (strAccount == string("*"));
1435  bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
1436 
1437  // Sent
1438  if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
1439  {
1440  BOOST_FOREACH(const COutputEntry& s, listSent)
1441  {
1442  UniValue entry(UniValue::VOBJ);
1443  if(involvesWatchonly || (::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY))
1444  entry.push_back(Pair("involvesWatchonly", true));
1445  entry.push_back(Pair("account", strSentAccount));
1446  MaybePushAddress(entry, s.destination);
1447  std::map<std::string, std::string>::const_iterator it = wtx.mapValue.find("DS");
1448  entry.push_back(Pair("category", (it != wtx.mapValue.end() && it->second == "1") ? "privatesend" : "send"));
1449  entry.push_back(Pair("amount", ValueFromAmount(-s.amount)));
1450  if (pwalletMain->mapAddressBook.count(s.destination))
1451  entry.push_back(Pair("label", pwalletMain->mapAddressBook[s.destination].name));
1452  entry.push_back(Pair("vout", s.vout));
1453  entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
1454  if (fLong)
1455  WalletTxToJSON(wtx, entry);
1456  entry.push_back(Pair("abandoned", wtx.isAbandoned()));
1457  ret.push_back(entry);
1458  }
1459  }
1460 
1461  // Received
1462  if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
1463  {
1464  BOOST_FOREACH(const COutputEntry& r, listReceived)
1465  {
1466  string account;
1467  if (pwalletMain->mapAddressBook.count(r.destination))
1468  account = pwalletMain->mapAddressBook[r.destination].name;
1469  if (fAllAccounts || (account == strAccount))
1470  {
1471  UniValue entry(UniValue::VOBJ);
1472  if(involvesWatchonly || (::IsMine(*pwalletMain, r.destination) & ISMINE_WATCH_ONLY))
1473  entry.push_back(Pair("involvesWatchonly", true));
1474  entry.push_back(Pair("account", account));
1475  MaybePushAddress(entry, r.destination);
1476  if (wtx.IsCoinBase())
1477  {
1478  if (wtx.GetDepthInMainChain() < 1)
1479  entry.push_back(Pair("category", "orphan"));
1480  else if (wtx.GetBlocksToMaturity() > 0)
1481  entry.push_back(Pair("category", "immature"));
1482  else
1483  entry.push_back(Pair("category", "generate"));
1484  }
1485  else
1486  {
1487  entry.push_back(Pair("category", "receive"));
1488  }
1489  entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
1490  if (pwalletMain->mapAddressBook.count(r.destination))
1491  entry.push_back(Pair("label", account));
1492  entry.push_back(Pair("vout", r.vout));
1493  if (fLong)
1494  WalletTxToJSON(wtx, entry);
1495  ret.push_back(entry);
1496  }
1497  }
1498  }
1499 }
1500 
1501 void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, UniValue& ret)
1502 {
1503  bool fAllAccounts = (strAccount == string("*"));
1504 
1505  if (fAllAccounts || acentry.strAccount == strAccount)
1506  {
1507  UniValue entry(UniValue::VOBJ);
1508  entry.push_back(Pair("account", acentry.strAccount));
1509  entry.push_back(Pair("category", "move"));
1510  entry.push_back(Pair("time", acentry.nTime));
1511  entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit)));
1512  entry.push_back(Pair("otheraccount", acentry.strOtherAccount));
1513  entry.push_back(Pair("comment", acentry.strComment));
1514  ret.push_back(entry);
1515  }
1516 }
1517 
1518 UniValue listtransactions(const UniValue& params, bool fHelp)
1519 {
1520  if (!EnsureWalletIsAvailable(fHelp))
1521  return NullUniValue;
1522 
1523  if (fHelp || params.size() > 4)
1524  throw runtime_error(
1525  "listtransactions ( \"account\" count from includeWatchonly)\n"
1526  "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
1527  "\nArguments:\n"
1528  "1. \"account\" (string, optional) DEPRECATED. The account name. Should be \"*\".\n"
1529  "2. count (numeric, optional, default=10) The number of transactions to return\n"
1530  "3. from (numeric, optional, default=0) The number of transactions to skip\n"
1531  "4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')\n"
1532  "\nResult:\n"
1533  "[\n"
1534  " {\n"
1535  " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. \n"
1536  " It will be \"\" for the default account.\n"
1537  " \"address\":\"dashaddress\", (string) The dash address of the transaction. Not present for \n"
1538  " move transactions (category = move).\n"
1539  " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
1540  " transaction between accounts, and not associated with an address,\n"
1541  " transaction id or block. 'send' and 'receive' transactions are \n"
1542  " associated with an address, transaction id and block details\n"
1543  " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the\n"
1544  " 'move' category for moves outbound. It is positive for the 'receive' category,\n"
1545  " and for the 'move' category for inbound funds.\n"
1546  " \"vout\": n, (numeric) the vout value\n"
1547  " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
1548  " 'send' category of transactions.\n"
1549  " \"instantlock\" : true|false, (bool) Current transaction lock state. Available for 'send' and 'receive' category of transactions.\n"
1550  " \"confirmations\": n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and \n"
1551  " 'receive' category of transactions. Negative confirmations indicate the\n"
1552  " transation conflicts with the block chain\n"
1553  " \"trusted\": xxx (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n"
1554  " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
1555  " category of transactions.\n"
1556  " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n"
1557  " category of transactions.\n"
1558  " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
1559  " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1560  " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
1561  " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
1562  " for 'send' and 'receive' category of transactions.\n"
1563  " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1564  " \"label\": \"label\" (string) A comment for the address/transaction, if any\n"
1565  " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n"
1566  " from (for receiving funds, positive amounts), or went to (for sending funds,\n"
1567  " negative amounts).\n"
1568  " \"bip125-replaceable\": \"yes|no|unknown\" (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1569  " may be unknown for unconfirmed transactions not in the mempool\n"
1570  " }\n"
1571  "]\n"
1572 
1573  "\nExamples:\n"
1574  "\nList the most recent 10 transactions in the systems\n"
1575  + HelpExampleCli("listtransactions", "") +
1576  "\nList transactions 100 to 120\n"
1577  + HelpExampleCli("listtransactions", "\"*\" 20 100") +
1578  "\nAs a json rpc call\n"
1579  + HelpExampleRpc("listtransactions", "\"*\", 20, 100")
1580  );
1581 
1583 
1584  string strAccount = "*";
1585  if (params.size() > 0)
1586  strAccount = params[0].get_str();
1587  int nCount = 10;
1588  if (params.size() > 1)
1589  nCount = params[1].get_int();
1590  int nFrom = 0;
1591  if (params.size() > 2)
1592  nFrom = params[2].get_int();
1593  isminefilter filter = ISMINE_SPENDABLE;
1594  if(params.size() > 3)
1595  if(params[3].get_bool())
1596  filter = filter | ISMINE_WATCH_ONLY;
1597 
1598  if (nCount < 0)
1599  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
1600  if (nFrom < 0)
1601  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
1602 
1603  UniValue ret(UniValue::VARR);
1604 
1605  const CWallet::TxItems & txOrdered = pwalletMain->wtxOrdered;
1606 
1607  // iterate backwards until we have nCount items to return:
1608  for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
1609  {
1610  CWalletTx *const pwtx = (*it).second.first;
1611  if (pwtx != 0)
1612  ListTransactions(*pwtx, strAccount, 0, true, ret, filter);
1613  CAccountingEntry *const pacentry = (*it).second.second;
1614  if (pacentry != 0)
1615  AcentryToJSON(*pacentry, strAccount, ret);
1616 
1617  if ((int)ret.size() >= (nCount+nFrom)) break;
1618  }
1619  // ret is newest to oldest
1620 
1621  if (nFrom > (int)ret.size())
1622  nFrom = ret.size();
1623  if ((nFrom + nCount) > (int)ret.size())
1624  nCount = ret.size() - nFrom;
1625 
1626  vector<UniValue> arrTmp = ret.getValues();
1627 
1628  vector<UniValue>::iterator first = arrTmp.begin();
1629  std::advance(first, nFrom);
1630  vector<UniValue>::iterator last = arrTmp.begin();
1631  std::advance(last, nFrom+nCount);
1632 
1633  if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end());
1634  if (first != arrTmp.begin()) arrTmp.erase(arrTmp.begin(), first);
1635 
1636  std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
1637 
1638  ret.clear();
1639  ret.setArray();
1640  ret.push_backV(arrTmp);
1641 
1642  return ret;
1643 }
1644 
1645 UniValue listaccounts(const UniValue& params, bool fHelp)
1646 {
1647  if (!EnsureWalletIsAvailable(fHelp))
1648  return NullUniValue;
1649 
1650  if (fHelp || params.size() > 3)
1651  throw runtime_error(
1652  "listaccounts ( minconf addlockconf includeWatchonly)\n"
1653  "\nDEPRECATED. Returns Object that has account names as keys, account balances as values.\n"
1654  "\nArguments:\n"
1655  "1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n"
1656  "2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
1657  "3. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n"
1658  "\nResult:\n"
1659  "{ (json object where keys are account names, and values are numeric balances\n"
1660  " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
1661  " ...\n"
1662  "}\n"
1663  "\nExamples:\n"
1664  "\nList account balances where there at least 1 confirmation\n"
1665  + HelpExampleCli("listaccounts", "") +
1666  "\nList account balances including zero confirmation transactions\n"
1667  + HelpExampleCli("listaccounts", "0") +
1668  "\nList account balances for 6 or more confirmations\n"
1669  + HelpExampleCli("listaccounts", "6") +
1670  "\nAs json rpc call\n"
1671  + HelpExampleRpc("listaccounts", "6")
1672  );
1673 
1675 
1676  int nMinDepth = 1;
1677  if (params.size() > 0)
1678  nMinDepth = params[0].get_int();
1679  bool fAddLockConf = (params.size() > 1 && params[1].get_bool());
1680  isminefilter includeWatchonly = ISMINE_SPENDABLE;
1681  if(params.size() > 2)
1682  if(params[2].get_bool())
1683  includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
1684 
1685  map<string, CAmount> mapAccountBalances;
1686  BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
1687  if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
1688  mapAccountBalances[entry.second.name] = 0;
1689  }
1690 
1691  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
1692  {
1693  const CWalletTx& wtx = (*it).second;
1694  CAmount nFee;
1695  string strSentAccount;
1696  list<COutputEntry> listReceived;
1697  list<COutputEntry> listSent;
1698  int nDepth = wtx.GetDepthInMainChain(fAddLockConf);
1699  if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
1700  continue;
1701  wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
1702  mapAccountBalances[strSentAccount] -= nFee;
1703  BOOST_FOREACH(const COutputEntry& s, listSent)
1704  mapAccountBalances[strSentAccount] -= s.amount;
1705  if (nDepth >= nMinDepth)
1706  {
1707  BOOST_FOREACH(const COutputEntry& r, listReceived)
1708  if (pwalletMain->mapAddressBook.count(r.destination))
1709  mapAccountBalances[pwalletMain->mapAddressBook[r.destination].name] += r.amount;
1710  else
1711  mapAccountBalances[""] += r.amount;
1712  }
1713  }
1714 
1715  const list<CAccountingEntry> & acentries = pwalletMain->laccentries;
1716  BOOST_FOREACH(const CAccountingEntry& entry, acentries)
1717  mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
1718 
1719  UniValue ret(UniValue::VOBJ);
1720  BOOST_FOREACH(const PAIRTYPE(string, CAmount)& accountBalance, mapAccountBalances) {
1721  ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
1722  }
1723  return ret;
1724 }
1725 
1726 UniValue listsinceblock(const UniValue& params, bool fHelp)
1727 {
1728  if (!EnsureWalletIsAvailable(fHelp))
1729  return NullUniValue;
1730 
1731  if (fHelp)
1732  throw runtime_error(
1733  "listsinceblock ( \"blockhash\" target-confirmations includeWatchonly)\n"
1734  "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
1735  "\nArguments:\n"
1736  "1. \"blockhash\" (string, optional) The block hash to list transactions since\n"
1737  "2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more\n"
1738  "3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')"
1739  "\nResult:\n"
1740  "{\n"
1741  " \"transactions\": [\n"
1742  " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. Will be \"\" for the default account.\n"
1743  " \"address\":\"dashaddress\", (string) The dash address of the transaction. Not present for move transactions (category = move).\n"
1744  " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
1745  " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n"
1746  " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
1747  " \"vout\" : n, (numeric) the vout value\n"
1748  " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n"
1749  " \"instantlock\" : true|false, (bool) Current transaction lock state. Available for 'send' and 'receive' category of transactions.\n"
1750  " \"confirmations\" : n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
1751  " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
1752  " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions.\n"
1753  " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
1754  " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1755  " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n"
1756  " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n"
1757  " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1758  " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
1759  " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n"
1760  " ],\n"
1761  " \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n"
1762  "}\n"
1763  "\nExamples:\n"
1764  + HelpExampleCli("listsinceblock", "")
1765  + HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6")
1766  + HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6")
1767  );
1768 
1770 
1771  CBlockIndex *pindex = NULL;
1772  int target_confirms = 1;
1773  isminefilter filter = ISMINE_SPENDABLE;
1774 
1775  if (params.size() > 0)
1776  {
1777  uint256 blockId;
1778 
1779  blockId.SetHex(params[0].get_str());
1780  BlockMap::iterator it = mapBlockIndex.find(blockId);
1781  if (it != mapBlockIndex.end())
1782  pindex = it->second;
1783  else
1784  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid blockhash");
1785  }
1786 
1787  if (params.size() > 1)
1788  {
1789  target_confirms = params[1].get_int();
1790 
1791  if (target_confirms < 1)
1792  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
1793  }
1794 
1795  if(params.size() > 2)
1796  if(params[2].get_bool())
1797  filter = filter | ISMINE_WATCH_ONLY;
1798 
1799  int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
1800 
1801  UniValue transactions(UniValue::VARR);
1802 
1803  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++)
1804  {
1805  CWalletTx tx = (*it).second;
1806 
1807  if (depth == -1 || tx.GetDepthInMainChain(false) < depth)
1808  ListTransactions(tx, "*", 0, true, transactions, filter);
1809  }
1810 
1811  CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
1812  uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : uint256();
1813 
1814  UniValue ret(UniValue::VOBJ);
1815  ret.push_back(Pair("transactions", transactions));
1816  ret.push_back(Pair("lastblock", lastblock.GetHex()));
1817 
1818  return ret;
1819 }
1820 
1821 UniValue gettransaction(const UniValue& params, bool fHelp)
1822 {
1823  if (!EnsureWalletIsAvailable(fHelp))
1824  return NullUniValue;
1825 
1826  if (fHelp || params.size() < 1 || params.size() > 2)
1827  throw runtime_error(
1828  "gettransaction \"txid\" ( includeWatchonly )\n"
1829  "\nGet detailed information about in-wallet transaction <txid>\n"
1830  "\nArguments:\n"
1831  "1. \"txid\" (string, required) The transaction id\n"
1832  "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n"
1833  "\nResult:\n"
1834  "{\n"
1835  " \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n"
1836  " \"instantlock\" : true|false, (bool) Current transaction lock state\n"
1837  " \"confirmations\" : n, (numeric) The number of blockchain confirmations\n"
1838  " \"blockhash\" : \"hash\", (string) The block hash\n"
1839  " \"blockindex\" : xx, (numeric) The index of the transaction in the block that includes it\n"
1840  " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n"
1841  " \"txid\" : \"transactionid\", (string) The transaction id.\n"
1842  " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n"
1843  " \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n"
1844  " \"bip125-replaceable\": \"yes|no|unknown\" (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1845  " may be unknown for unconfirmed transactions not in the mempool\n"
1846  " \"details\" : [\n"
1847  " {\n"
1848  " \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n"
1849  " \"address\" : \"dashaddress\", (string) The dash address involved in the transaction\n"
1850  " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
1851  " \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + "\n"
1852  " \"label\" : \"label\", (string) A comment for the address/transaction, if any\n"
1853  " \"vout\" : n, (numeric) the vout value\n"
1854  " }\n"
1855  " ,...\n"
1856  " ],\n"
1857  " \"hex\" : \"data\" (string) Raw data for transaction\n"
1858  "}\n"
1859 
1860  "\nExamples:\n"
1861  + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1862  + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
1863  + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1864  );
1865 
1867 
1868  uint256 hash;
1869  hash.SetHex(params[0].get_str());
1870 
1871  isminefilter filter = ISMINE_SPENDABLE;
1872  if(params.size() > 1)
1873  if(params[1].get_bool())
1874  filter = filter | ISMINE_WATCH_ONLY;
1875 
1876  UniValue entry(UniValue::VOBJ);
1877  if (!pwalletMain->mapWallet.count(hash))
1878  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
1879  const CWalletTx& wtx = pwalletMain->mapWallet[hash];
1880 
1881  CAmount nCredit = wtx.GetCredit(filter);
1882  CAmount nDebit = wtx.GetDebit(filter);
1883  CAmount nNet = nCredit - nDebit;
1884  CAmount nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
1885 
1886  entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
1887  if (wtx.IsFromMe(filter))
1888  entry.push_back(Pair("fee", ValueFromAmount(nFee)));
1889 
1890  WalletTxToJSON(wtx, entry);
1891 
1892  UniValue details(UniValue::VARR);
1893  ListTransactions(wtx, "*", 0, false, details, filter);
1894  entry.push_back(Pair("details", details));
1895 
1896  string strHex = EncodeHexTx(static_cast<CTransaction>(wtx));
1897  entry.push_back(Pair("hex", strHex));
1898 
1899  return entry;
1900 }
1901 
1902 UniValue abandontransaction(const UniValue& params, bool fHelp)
1903 {
1904  if (!EnsureWalletIsAvailable(fHelp))
1905  return NullUniValue;
1906 
1907  if (fHelp || params.size() != 1)
1908  throw runtime_error(
1909  "abandontransaction \"txid\"\n"
1910  "\nMark in-wallet transaction <txid> as abandoned\n"
1911  "This will mark this transaction and all its in-wallet descendants as abandoned which will allow\n"
1912  "for their inputs to be respent. It can be used to replace \"stuck\" or evicted transactions.\n"
1913  "It only works on transactions which are not included in a block and are not currently in the mempool.\n"
1914  "It has no effect on transactions which are already conflicted or abandoned.\n"
1915  "\nArguments:\n"
1916  "1. \"txid\" (string, required) The transaction id\n"
1917  "\nResult:\n"
1918  "\nExamples:\n"
1919  + HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1920  + HelpExampleRpc("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1921  );
1922 
1924 
1925  uint256 hash;
1926  hash.SetHex(params[0].get_str());
1927 
1928  if (!pwalletMain->mapWallet.count(hash))
1929  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
1930  if (!pwalletMain->AbandonTransaction(hash))
1931  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not eligible for abandonment");
1932 
1933  return NullUniValue;
1934 }
1935 
1936 
1937 UniValue backupwallet(const UniValue& params, bool fHelp)
1938 {
1939  if (!EnsureWalletIsAvailable(fHelp))
1940  return NullUniValue;
1941 
1942  if (fHelp || params.size() != 1)
1943  throw runtime_error(
1944  "backupwallet \"destination\"\n"
1945  "\nSafely copies wallet.dat to destination, which can be a directory or a path with filename.\n"
1946  "\nArguments:\n"
1947  "1. \"destination\" (string) The destination directory or file\n"
1948  "\nExamples:\n"
1949  + HelpExampleCli("backupwallet", "\"backup.dat\"")
1950  + HelpExampleRpc("backupwallet", "\"backup.dat\"")
1951  );
1952 
1954 
1955  string strDest = params[0].get_str();
1956  if (!BackupWallet(*pwalletMain, strDest))
1957  throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
1958 
1959  return NullUniValue;
1960 }
1961 
1962 
1963 UniValue keypoolrefill(const UniValue& params, bool fHelp)
1964 {
1965  if (!EnsureWalletIsAvailable(fHelp))
1966  return NullUniValue;
1967 
1968  if (fHelp || params.size() > 1)
1969  throw runtime_error(
1970  "keypoolrefill ( newsize )\n"
1971  "\nFills the keypool."
1972  + HelpRequiringPassphrase() + "\n"
1973  "\nArguments\n"
1974  "1. newsize (numeric, optional, default=" + itostr(DEFAULT_KEYPOOL_SIZE) + ") The new keypool size\n"
1975  "\nExamples:\n"
1976  + HelpExampleCli("keypoolrefill", "")
1977  + HelpExampleRpc("keypoolrefill", "")
1978  );
1979 
1981 
1982  // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
1983  unsigned int kpSize = 0;
1984  if (params.size() > 0) {
1985  if (params[0].get_int() < 0)
1986  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
1987  kpSize = (unsigned int)params[0].get_int();
1988  }
1989 
1991  pwalletMain->TopUpKeyPool(kpSize);
1992 
1993  if (pwalletMain->GetKeyPoolSize() < (pwalletMain->IsHDEnabled() ? kpSize * 2 : kpSize))
1994  throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
1995 
1996  return NullUniValue;
1997 }
1998 
1999 
2000 static void LockWallet(CWallet* pWallet)
2001 {
2003  nWalletUnlockTime = 0;
2004  pWallet->Lock();
2005 }
2006 
2007 UniValue walletpassphrase(const UniValue& params, bool fHelp)
2008 {
2009  if (!EnsureWalletIsAvailable(fHelp))
2010  return NullUniValue;
2011 
2012  if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3))
2013  throw runtime_error(
2014  "walletpassphrase \"passphrase\" timeout ( mixingonly )\n"
2015  "\nStores the wallet decryption key in memory for 'timeout' seconds.\n"
2016  "This is needed prior to performing transactions related to private keys such as sending dashs\n"
2017  "\nArguments:\n"
2018  "1. \"passphrase\" (string, required) The wallet passphrase\n"
2019  "2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
2020  "3. mixingonly (boolean, optional, default=false) If is true sending functions are disabled."
2021  "\nNote:\n"
2022  "Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
2023  "time that overrides the old one.\n"
2024  "\nExamples:\n"
2025  "\nUnlock the wallet for 60 seconds\n"
2026  + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") +
2027  "\nUnlock the wallet for 60 seconds but allow PrivateSend mixing only\n"
2028  + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60 true") +
2029  "\nLock the wallet again (before 60 seconds)\n"
2030  + HelpExampleCli("walletlock", "") +
2031  "\nAs json rpc call\n"
2032  + HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")
2033  );
2034 
2036 
2037  if (fHelp)
2038  return true;
2039  if (!pwalletMain->IsCrypted())
2040  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
2041 
2042  // Note that the walletpassphrase is stored in params[0] which is not mlock()ed
2043  SecureString strWalletPass;
2044  strWalletPass.reserve(100);
2045  // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
2046  // Alternately, find a way to make params[0] mlock()'d to begin with.
2047  strWalletPass = params[0].get_str().c_str();
2048 
2049  int64_t nSleepTime = params[1].get_int64();
2050 
2051  bool fForMixingOnly = false;
2052  if (params.size() >= 3)
2053  fForMixingOnly = params[2].get_bool();
2054 
2055  if (fForMixingOnly && !pwalletMain->IsLocked(true) && pwalletMain->IsLocked())
2056  throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked for mixing only.");
2057 
2058  if (!pwalletMain->IsLocked())
2059  throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already fully unlocked.");
2060 
2061  if (!pwalletMain->Unlock(strWalletPass, fForMixingOnly))
2062  throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
2063 
2065 
2067  nWalletUnlockTime = GetTime() + nSleepTime;
2068  RPCRunLater("lockwallet", boost::bind(LockWallet, pwalletMain), nSleepTime);
2069 
2070  return NullUniValue;
2071 }
2072 
2073 
2074 UniValue walletpassphrasechange(const UniValue& params, bool fHelp)
2075 {
2076  if (!EnsureWalletIsAvailable(fHelp))
2077  return NullUniValue;
2078 
2079  if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
2080  throw runtime_error(
2081  "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n"
2082  "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n"
2083  "\nArguments:\n"
2084  "1. \"oldpassphrase\" (string) The current passphrase\n"
2085  "2. \"newpassphrase\" (string) The new passphrase\n"
2086  "\nExamples:\n"
2087  + HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"")
2088  + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"")
2089  );
2090 
2092 
2093  if (fHelp)
2094  return true;
2095  if (!pwalletMain->IsCrypted())
2096  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
2097 
2098  // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
2099  // Alternately, find a way to make params[0] mlock()'d to begin with.
2100  SecureString strOldWalletPass;
2101  strOldWalletPass.reserve(100);
2102  strOldWalletPass = params[0].get_str().c_str();
2103 
2104  SecureString strNewWalletPass;
2105  strNewWalletPass.reserve(100);
2106  strNewWalletPass = params[1].get_str().c_str();
2107 
2108  if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
2109  throw runtime_error(
2110  "walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
2111  "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
2112 
2113  if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass))
2114  throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
2115 
2116  return NullUniValue;
2117 }
2118 
2119 
2120 UniValue walletlock(const UniValue& params, bool fHelp)
2121 {
2122  if (!EnsureWalletIsAvailable(fHelp))
2123  return NullUniValue;
2124 
2125  if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0))
2126  throw runtime_error(
2127  "walletlock\n"
2128  "\nRemoves the wallet encryption key from memory, locking the wallet.\n"
2129  "After calling this method, you will need to call walletpassphrase again\n"
2130  "before being able to call any methods which require the wallet to be unlocked.\n"
2131  "\nExamples:\n"
2132  "\nSet the passphrase for 2 minutes to perform a transaction\n"
2133  + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") +
2134  "\nPerform a send (requires passphrase set)\n"
2135  + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 1.0") +
2136  "\nClear the passphrase since we are done before 2 minutes is up\n"
2137  + HelpExampleCli("walletlock", "") +
2138  "\nAs json rpc call\n"
2139  + HelpExampleRpc("walletlock", "")
2140  );
2141 
2143 
2144  if (fHelp)
2145  return true;
2146  if (!pwalletMain->IsCrypted())
2147  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
2148 
2149  {
2151  pwalletMain->Lock();
2152  nWalletUnlockTime = 0;
2153  }
2154 
2155  return NullUniValue;
2156 }
2157 
2158 
2159 UniValue encryptwallet(const UniValue& params, bool fHelp)
2160 {
2161  if (!EnsureWalletIsAvailable(fHelp))
2162  return NullUniValue;
2163 
2164  if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1))
2165  throw runtime_error(
2166  "encryptwallet \"passphrase\"\n"
2167  "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n"
2168  "After this, any calls that interact with private keys such as sending or signing \n"
2169  "will require the passphrase to be set prior the making these calls.\n"
2170  "Use the walletpassphrase call for this, and then walletlock call.\n"
2171  "If the wallet is already encrypted, use the walletpassphrasechange call.\n"
2172  "Note that this will shutdown the server.\n"
2173  "\nArguments:\n"
2174  "1. \"passphrase\" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.\n"
2175  "\nExamples:\n"
2176  "\nEncrypt you wallet\n"
2177  + HelpExampleCli("encryptwallet", "\"my pass phrase\"") +
2178  "\nNow set the passphrase to use the wallet, such as for signing or sending dash\n"
2179  + HelpExampleCli("walletpassphrase", "\"my pass phrase\"") +
2180  "\nNow we can so something like sign\n"
2181  + HelpExampleCli("signmessage", "\"dashaddress\" \"test message\"") +
2182  "\nNow lock the wallet again by removing the passphrase\n"
2183  + HelpExampleCli("walletlock", "") +
2184  "\nAs a json rpc call\n"
2185  + HelpExampleRpc("encryptwallet", "\"my pass phrase\"")
2186  );
2187 
2189 
2190  if (fHelp)
2191  return true;
2192  if (pwalletMain->IsCrypted())
2193  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
2194 
2195  // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
2196  // Alternately, find a way to make params[0] mlock()'d to begin with.
2197  SecureString strWalletPass;
2198  strWalletPass.reserve(100);
2199  strWalletPass = params[0].get_str().c_str();
2200 
2201  if (strWalletPass.length() < 1)
2202  throw runtime_error(
2203  "encryptwallet <passphrase>\n"
2204  "Encrypts the wallet with <passphrase>.");
2205 
2206  if (!pwalletMain->EncryptWallet(strWalletPass))
2207  throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
2208 
2209  // BDB seems to have a bad habit of writing old data into
2210  // slack space in .dat files; that is bad if the old data is
2211  // unencrypted private keys. So:
2212  StartShutdown();
2213  return "Wallet encrypted; Dash Core server stopping, restart to run with encrypted wallet. The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.";
2214 }
2215 
2216 UniValue lockunspent(const UniValue& params, bool fHelp)
2217 {
2218  if (!EnsureWalletIsAvailable(fHelp))
2219  return NullUniValue;
2220 
2221  if (fHelp || params.size() < 1 || params.size() > 2)
2222  throw runtime_error(
2223  "lockunspent unlock [{\"txid\":\"txid\",\"vout\":n},...]\n"
2224  "\nUpdates list of temporarily unspendable outputs.\n"
2225  "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
2226  "A locked transaction output will not be chosen by automatic coin selection, when spending dashs.\n"
2227  "Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n"
2228  "is always cleared (by virtue of process exit) when a node stops or fails.\n"
2229  "Also see the listunspent call\n"
2230  "\nArguments:\n"
2231  "1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions\n"
2232  "2. \"transactions\" (string, required) A json array of objects. Each object the txid (string) vout (numeric)\n"
2233  " [ (json array of json objects)\n"
2234  " {\n"
2235  " \"txid\":\"id\", (string) The transaction id\n"
2236  " \"vout\": n (numeric) The output number\n"
2237  " }\n"
2238  " ,...\n"
2239  " ]\n"
2240 
2241  "\nResult:\n"
2242  "true|false (boolean) Whether the command was successful or not\n"
2243 
2244  "\nExamples:\n"
2245  "\nList the unspent transactions\n"
2246  + HelpExampleCli("listunspent", "") +
2247  "\nLock an unspent transaction\n"
2248  + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2249  "\nList the locked transactions\n"
2250  + HelpExampleCli("listlockunspent", "") +
2251  "\nUnlock the transaction again\n"
2252  + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2253  "\nAs a json rpc call\n"
2254  + HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
2255  );
2256 
2258 
2259  if (params.size() == 1)
2260  RPCTypeCheck(params, boost::assign::list_of(UniValue::VBOOL));
2261  else
2262  RPCTypeCheck(params, boost::assign::list_of(UniValue::VBOOL)(UniValue::VARR));
2263 
2264  bool fUnlock = params[0].get_bool();
2265 
2266  if (params.size() == 1) {
2267  if (fUnlock)
2269  return true;
2270  }
2271 
2272  UniValue outputs = params[1].get_array();
2273  for (unsigned int idx = 0; idx < outputs.size(); idx++) {
2274  const UniValue& output = outputs[idx];
2275  if (!output.isObject())
2276  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
2277  const UniValue& o = output.get_obj();
2278 
2279  RPCTypeCheckObj(o, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM));
2280 
2281  string txid = find_value(o, "txid").get_str();
2282  if (!IsHex(txid))
2283  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid");
2284 
2285  int nOutput = find_value(o, "vout").get_int();
2286  if (nOutput < 0)
2287  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
2288 
2289  COutPoint outpt(uint256S(txid), nOutput);
2290 
2291  if (fUnlock)
2292  pwalletMain->UnlockCoin(outpt);
2293  else
2294  pwalletMain->LockCoin(outpt);
2295  }
2296 
2297  return true;
2298 }
2299 
2300 UniValue listlockunspent(const UniValue& params, bool fHelp)
2301 {
2302  if (!EnsureWalletIsAvailable(fHelp))
2303  return NullUniValue;
2304 
2305  if (fHelp || params.size() > 0)
2306  throw runtime_error(
2307  "listlockunspent\n"
2308  "\nReturns list of temporarily unspendable outputs.\n"
2309  "See the lockunspent call to lock and unlock transactions for spending.\n"
2310  "\nResult:\n"
2311  "[\n"
2312  " {\n"
2313  " \"txid\" : \"transactionid\", (string) The transaction id locked\n"
2314  " \"vout\" : n (numeric) The vout value\n"
2315  " }\n"
2316  " ,...\n"
2317  "]\n"
2318  "\nExamples:\n"
2319  "\nList the unspent transactions\n"
2320  + HelpExampleCli("listunspent", "") +
2321  "\nLock an unspent transaction\n"
2322  + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2323  "\nList the locked transactions\n"
2324  + HelpExampleCli("listlockunspent", "") +
2325  "\nUnlock the transaction again\n"
2326  + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2327  "\nAs a json rpc call\n"
2328  + HelpExampleRpc("listlockunspent", "")
2329  );
2330 
2332 
2333  vector<COutPoint> vOutpts;
2334  pwalletMain->ListLockedCoins(vOutpts);
2335 
2336  UniValue ret(UniValue::VARR);
2337 
2338  BOOST_FOREACH(COutPoint &outpt, vOutpts) {
2340 
2341  o.push_back(Pair("txid", outpt.hash.GetHex()));
2342  o.push_back(Pair("vout", (int)outpt.n));
2343  ret.push_back(o);
2344  }
2345 
2346  return ret;
2347 }
2348 
2349 UniValue settxfee(const UniValue& params, bool fHelp)
2350 {
2351  if (!EnsureWalletIsAvailable(fHelp))
2352  return NullUniValue;
2353 
2354  if (fHelp || params.size() < 1 || params.size() > 1)
2355  throw runtime_error(
2356  "settxfee amount\n"
2357  "\nSet the transaction fee per kB. Overwrites the paytxfee parameter.\n"
2358  "\nArguments:\n"
2359  "1. amount (numeric or sting, required) The transaction fee in " + CURRENCY_UNIT + "/kB\n"
2360  "\nResult\n"
2361  "true|false (boolean) Returns true if successful\n"
2362  "\nExamples:\n"
2363  + HelpExampleCli("settxfee", "0.00001")
2364  + HelpExampleRpc("settxfee", "0.00001")
2365  );
2366 
2368 
2369  // Amount
2370  CAmount nAmount = AmountFromValue(params[0]);
2371 
2372  payTxFee = CFeeRate(nAmount, 1000);
2373  return true;
2374 }
2375 
2376 UniValue getwalletinfo(const UniValue& params, bool fHelp)
2377 {
2378  if (!EnsureWalletIsAvailable(fHelp))
2379  return NullUniValue;
2380 
2381  if (fHelp || params.size() != 0)
2382  throw runtime_error(
2383  "getwalletinfo\n"
2384  "Returns an object containing various wallet state info.\n"
2385  "\nResult:\n"
2386  "{\n"
2387  " \"walletversion\": xxxxx, (numeric) the wallet version\n"
2388  " \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2389  " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2390  " \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n"
2391  " \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
2392  " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
2393  " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated (only counts external keys)\n"
2394  " \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)\n"
2395  " \"keys_left\": xxxx, (numeric) how many new keys are left since last automatic backup\n"
2396  " \"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"
2397  " \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
2398  " \"hdchainid\": \"<hash>\", (string) the ID of the HD chain\n"
2399  " \"hdaccountcount\": xxx, (numeric) how many accounts of the HD chain are in this wallet\n"
2400  " [\n"
2401  " {\n"
2402  " \"hdaccountindex\": xxx, (numeric) the index of the account\n"
2403  " \"hdexternalkeyindex\": xxxx, (numeric) current external childkey index\n"
2404  " \"hdinternalkeyindex\": xxxx, (numeric) current internal childkey index\n"
2405  " }\n"
2406  " ,...\n"
2407  " ]\n"
2408  "}\n"
2409  "\nExamples:\n"
2410  + HelpExampleCli("getwalletinfo", "")
2411  + HelpExampleRpc("getwalletinfo", "")
2412  );
2413 
2415 
2416  CHDChain hdChainCurrent;
2417  bool fHDEnabled = pwalletMain->GetHDChain(hdChainCurrent);
2418  UniValue obj(UniValue::VOBJ);
2419  obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
2420  obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
2421  obj.push_back(Pair("unconfirmed_balance", ValueFromAmount(pwalletMain->GetUnconfirmedBalance())));
2422  obj.push_back(Pair("immature_balance", ValueFromAmount(pwalletMain->GetImmatureBalance())));
2423  obj.push_back(Pair("txcount", (int)pwalletMain->mapWallet.size()));
2424  obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
2425  obj.push_back(Pair("keypoolsize", (int64_t)pwalletMain->KeypoolCountExternalKeys()));
2426  if (fHDEnabled) {
2427  obj.push_back(Pair("keypoolsize_hd_internal", (int64_t)(pwalletMain->KeypoolCountInternalKeys())));
2428  }
2429  obj.push_back(Pair("keys_left", pwalletMain->nKeysLeftSinceAutoBackup));
2430  if (pwalletMain->IsCrypted())
2431  obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
2432  obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
2433  if (fHDEnabled) {
2434  obj.push_back(Pair("hdchainid", hdChainCurrent.GetID().GetHex()));
2435  obj.push_back(Pair("hdaccountcount", (int64_t)hdChainCurrent.CountAccounts()));
2436  UniValue accounts(UniValue::VARR);
2437  for (size_t i = 0; i < hdChainCurrent.CountAccounts(); ++i)
2438  {
2439  CHDAccount acc;
2440  UniValue account(UniValue::VOBJ);
2441  account.push_back(Pair("hdaccountindex", (int64_t)i));
2442  if(hdChainCurrent.GetAccount(i, acc)) {
2443  account.push_back(Pair("hdexternalkeyindex", (int64_t)acc.nExternalChainCounter));
2444  account.push_back(Pair("hdinternalkeyindex", (int64_t)acc.nInternalChainCounter));
2445  } else {
2446  account.push_back(Pair("error", strprintf("account %d is missing", i)));
2447  }
2448  accounts.push_back(account);
2449  }
2450  obj.push_back(Pair("hdaccounts", accounts));
2451  }
2452  return obj;
2453 }
2454 
2455 UniValue keepass(const UniValue& params, bool fHelp) {
2456  string strCommand;
2457 
2458  if (params.size() >= 1)
2459  strCommand = params[0].get_str();
2460 
2461  if (fHelp ||
2462  (strCommand != "genkey" && strCommand != "init" && strCommand != "setpassphrase"))
2463  throw runtime_error(
2464  "keepass <genkey|init|setpassphrase>\n");
2465 
2466  if (strCommand == "genkey")
2467  {
2468  SecureString sResult;
2469  // Generate RSA key
2471  sResult = "Generated Key: ";
2472  sResult += sKey;
2473  return sResult.c_str();
2474  }
2475  else if(strCommand == "init")
2476  {
2477  // Generate base64 encoded 256 bit RSA key and associate with KeePassHttp
2478  SecureString sResult;
2479  SecureString sKey;
2480  std::string strId;
2481  keePassInt.rpcAssociate(strId, sKey);
2482  sResult = "Association successful. Id: ";
2483  sResult += strId.c_str();
2484  sResult += " - Key: ";
2485  sResult += sKey.c_str();
2486  return sResult.c_str();
2487  }
2488  else if(strCommand == "setpassphrase")
2489  {
2490  if(params.size() != 2) {
2491  return "setlogin: invalid number of parameters. Requires a passphrase";
2492  }
2493 
2494  SecureString sPassphrase = SecureString(params[1].get_str().c_str());
2495 
2496  keePassInt.updatePassphrase(sPassphrase);
2497 
2498  return "setlogin: Updated credentials.";
2499  }
2500 
2501  return "Invalid command";
2502 
2503 }
2504 
2505 UniValue resendwallettransactions(const UniValue& params, bool fHelp)
2506 {
2507  if (!EnsureWalletIsAvailable(fHelp))
2508  return NullUniValue;
2509 
2510  if (fHelp || params.size() != 0)
2511  throw runtime_error(
2512  "resendwallettransactions\n"
2513  "Immediately re-broadcast unconfirmed wallet transactions to all peers.\n"
2514  "Intended only for testing; the wallet code periodically re-broadcasts\n"
2515  "automatically.\n"
2516  "Returns array of transaction ids that were re-broadcast.\n"
2517  );
2518 
2519  if (!g_connman)
2520  throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
2521 
2523 
2524  std::vector<uint256> txids = pwalletMain->ResendWalletTransactionsBefore(GetTime(), g_connman.get());
2526  BOOST_FOREACH(const uint256& txid, txids)
2527  {
2528  result.push_back(txid.ToString());
2529  }
2530  return result;
2531 }
2532 
2533 UniValue listunspent(const UniValue& params, bool fHelp)
2534 {
2535  if (!EnsureWalletIsAvailable(fHelp))
2536  return NullUniValue;
2537 
2538  if (fHelp || params.size() > 3)
2539  throw runtime_error(
2540  "listunspent ( minconf maxconf [\"address\",...] )\n"
2541  "\nReturns array of unspent transaction outputs\n"
2542  "with between minconf and maxconf (inclusive) confirmations.\n"
2543  "Optionally filter to only include txouts paid to specified addresses.\n"
2544  "Results are an array of Objects, each of which has:\n"
2545  "{txid, vout, scriptPubKey, amount, confirmations}\n"
2546  "\nArguments:\n"
2547  "1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n"
2548  "2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
2549  "3. \"addresses\" (string) A json array of dash addresses to filter\n"
2550  " [\n"
2551  " \"address\" (string) dash address\n"
2552  " ,...\n"
2553  " ]\n"
2554  "\nResult\n"
2555  "[ (array of json object)\n"
2556  " {\n"
2557  " \"txid\" : \"txid\", (string) the transaction id \n"
2558  " \"vout\" : n, (numeric) the vout value\n"
2559  " \"address\" : \"address\", (string) the dash address\n"
2560  " \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
2561  " \"scriptPubKey\" : \"key\", (string) the script key\n"
2562  " \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n"
2563  " \"confirmations\" : n (numeric) The number of confirmations\n"
2564  " \"ps_rounds\" : n (numeric) The number of PS round\n"
2565  " \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
2566  " \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
2567  " }\n"
2568  " ,...\n"
2569  "]\n"
2570 
2571  "\nExamples\n"
2572  + HelpExampleCli("listunspent", "")
2573  + HelpExampleCli("listunspent", "6 9999999 \"[\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\",\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\"]\"")
2574  + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\",\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\"]\"")
2575  );
2576 
2577  RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)(UniValue::VNUM)(UniValue::VARR));
2578 
2579  int nMinDepth = 1;
2580  if (params.size() > 0)
2581  nMinDepth = params[0].get_int();
2582 
2583  int nMaxDepth = 9999999;
2584  if (params.size() > 1)
2585  nMaxDepth = params[1].get_int();
2586 
2587  set<CBitcoinAddress> setAddress;
2588  if (params.size() > 2) {
2589  UniValue inputs = params[2].get_array();
2590  for (unsigned int idx = 0; idx < inputs.size(); idx++) {
2591  const UniValue& input = inputs[idx];
2592  CBitcoinAddress address(input.get_str());
2593  if (!address.IsValid())
2594  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Dash address: ")+input.get_str());
2595  if (setAddress.count(address))
2596  throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+input.get_str());
2597  setAddress.insert(address);
2598  }
2599  }
2600 
2601  UniValue results(UniValue::VARR);
2602  vector<COutput> vecOutputs;
2603  assert(pwalletMain != NULL);
2605  pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
2606  BOOST_FOREACH(const COutput& out, vecOutputs) {
2607  if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
2608  continue;
2609 
2610  if (setAddress.size()) {
2611  CTxDestination address;
2612  if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
2613  continue;
2614 
2615  if (!setAddress.count(address))
2616  continue;
2617  }
2618 
2619  CAmount nValue = out.tx->vout[out.i].nValue;
2620  const CScript& pk = out.tx->vout[out.i].scriptPubKey;
2621  UniValue entry(UniValue::VOBJ);
2622  entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
2623  entry.push_back(Pair("vout", out.i));
2624  CTxDestination address;
2625  if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
2626  entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
2627  if (pwalletMain->mapAddressBook.count(address))
2628  entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
2629  }
2630  entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
2631  if (pk.IsPayToScriptHash()) {
2632  CTxDestination address;
2633  if (ExtractDestination(pk, address)) {
2634  const CScriptID& hash = boost::get<CScriptID>(address);
2635  CScript redeemScript;
2636  if (pwalletMain->GetCScript(hash, redeemScript))
2637  entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
2638  }
2639  }
2640  entry.push_back(Pair("amount",ValueFromAmount(nValue)));
2641  entry.push_back(Pair("confirmations",out.nDepth));
2642  entry.push_back(Pair("ps_rounds", pwalletMain->GetOutpointPrivateSendRounds(COutPoint(out.tx->GetHash(), out.i))));
2643  entry.push_back(Pair("spendable", out.fSpendable));
2644  entry.push_back(Pair("solvable", out.fSolvable));
2645  results.push_back(entry);
2646  }
2647 
2648  return results;
2649 }
2650 
2651 UniValue fundrawtransaction(const UniValue& params, bool fHelp)
2652 {
2653  if (!EnsureWalletIsAvailable(fHelp))
2654  return NullUniValue;
2655 
2656  if (fHelp || params.size() < 1 || params.size() > 2)
2657  throw runtime_error(
2658  "fundrawtransaction \"hexstring\" includeWatching\n"
2659  "\nAdd inputs to a transaction until it has enough in value to meet its out value.\n"
2660  "This will not modify existing inputs, and will add one change output to the outputs.\n"
2661  "Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n"
2662  "The inputs added will not be signed, use signrawtransaction for that.\n"
2663  "Note that all existing inputs must have their previous output transaction be in the wallet.\n"
2664  "Note that all inputs selected must be of standard form and P2SH scripts must be"
2665  "in the wallet using importaddress or addmultisigaddress (to calculate fees).\n"
2666  "You can see whether this is the case by checking the \"solvable\" field in the listunspent output.\n"
2667  "Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only\n"
2668  "\nArguments:\n"
2669  "1. \"hexstring\" (string, required) The hex string of the raw transaction\n"
2670  "2. includeWatching (boolean, optional, default false) Also select inputs which are watch only\n"
2671  "\nResult:\n"
2672  "{\n"
2673  " \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
2674  " \"fee\": n, (numeric) Fee the resulting transaction pays\n"
2675  " \"changepos\": n (numeric) The position of the added change output, or -1\n"
2676  "}\n"
2677  "\"hex\" \n"
2678  "\nExamples:\n"
2679  "\nCreate a transaction with no inputs\n"
2680  + HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
2681  "\nAdd sufficient unsigned inputs to meet the output value\n"
2682  + HelpExampleCli("fundrawtransaction", "\"rawtransactionhex\"") +
2683  "\nSign the transaction\n"
2684  + HelpExampleCli("signrawtransaction", "\"fundedtransactionhex\"") +
2685  "\nSend the transaction\n"
2686  + HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")
2687  );
2688 
2689  RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL));
2690 
2691  // parse hex string from parameter
2692  CTransaction origTx;
2693  if (!DecodeHexTx(origTx, params[0].get_str()))
2694  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
2695 
2696  if (origTx.vout.size() == 0)
2697  throw JSONRPCError(RPC_INVALID_PARAMETER, "TX must have at least one output");
2698 
2699  bool includeWatching = false;
2700  if (params.size() > 1)
2701  includeWatching = params[1].get_bool();
2702 
2703  CMutableTransaction tx(origTx);
2704  CAmount nFee;
2705  string strFailReason;
2706  int nChangePos = -1;
2707  if(!pwalletMain->FundTransaction(tx, nFee, nChangePos, strFailReason, includeWatching))
2708  throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason);
2709 
2711  result.push_back(Pair("hex", EncodeHexTx(tx)));
2712  result.push_back(Pair("changepos", nChangePos));
2713  result.push_back(Pair("fee", ValueFromAmount(nFee)));
2714 
2715  return result;
2716 }
UniValue movecmd(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:885
CAmount GetCredit(const isminefilter &filter) const
Definition: wallet.cpp:1824
uint32_t n
Definition: transaction.h:19
static CCriticalSection cs_nWalletUnlockTime
Definition: rpcwallet.cpp:33
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const
Definition: keystore.cpp:57
UniValue fundrawtransaction(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2651
UniValue getnewaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:113
bool IsCrypted() const
Definition: crypter.h:153
bool isAbandoned() const
Definition: wallet.h:267
unsigned int GetKeyPoolSize()
Definition: wallet.h:978
bool EnsureWalletIsAvailable(bool avoidException)
Definition: rpcwallet.cpp:42
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
Definition: standard.h:69
UniValue getunconfirmedbalance(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:869
CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
Definition: rpcwallet.cpp:155
bool push_backV(const std::vector< UniValue > &vec)
Definition: univalue.cpp:185
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: standard.cpp:164
Invalid account name.
Definition: protocol.h:72
UniValue walletpassphrasechange(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2074
std::set< CTxDestination > GetAccountAddresses(const std::string &strAccount) const
Definition: wallet.cpp:4087
Keypool ran out, call keypoolrefill first.
Definition: protocol.h:73
bool AddAccountingEntry(const CAccountingEntry &, CWalletDB &pwalletdb)
Definition: wallet.cpp:3579
std::string strOtherAccount
Definition: wallet.h:541
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:3683
UniValue keepass(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2455
TxItems wtxOrdered
Definition: wallet.h:743
UniValue walletlock(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2120
Failed to encrypt the wallet.
Definition: protocol.h:77
bool IsHDEnabled()
Definition: wallet.cpp:1485
bool IsValid() const
Definition: base58.cpp:247
#define strprintf
Definition: tinyformat.h:1011
string AccountFromValue(const UniValue &value)
Definition: rpcwallet.cpp:105
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.h:458
int nIndex
Definition: wallet.h:223
CCriticalSection cs_wallet
Definition: wallet.h:672
const std::string CURRENCY_UNIT
Definition: amount.cpp:10
CAmount GetUnconfirmedBalance() const
Definition: wallet.cpp:2286
int64_t IncOrderPosNext(CWalletDB *pwalletdb=NULL)
Definition: wallet.cpp:856
UniValue getaccountaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:192
std::multimap< int64_t, TxPair > TxItems
Definition: wallet.h:742
bool AbandonTransaction(const uint256 &hashTx)
Definition: wallet.cpp:1066
void StartShutdown()
Definition: init.cpp:164
CCriticalSection cs_main
Definition: validation.cpp:62
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
UniValue getreceivedbyaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:641
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
CAmount nValue
Definition: transaction.h:136
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:61
bool Unlock(const SecureString &strWalletPassphrase, bool fForMixingOnly=false)
Definition: wallet.cpp:404
UniValue getwalletinfo(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2376
bool fIsWatchonly
Definition: rpcwallet.cpp:1205
Definition: pubkey.h:27
mapValue_t mapValue
Definition: wallet.h:281
void UnlockAllCoins()
Definition: wallet.cpp:4215
UniValue listsinceblock(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1726
const char * TX
Definition: protocol.cpp:24
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:586
uint32_t nInternalChainCounter
Definition: hdchain.h:14
bool GetBroadcastTransactions() const
Definition: wallet.h:1027
CWallet * pwalletMain
bool IsHex(const string &str)
std::set< uint256 > GetConflicts() const
Definition: wallet.cpp:1781
size_t CountAccounts()
Definition: hdchain.cpp:203
std::string name
Definition: wallet.h:161
CAmount GetValueOut() const
UniValue resendwallettransactions(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2505
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, std::string strCommand="tx")
Definition: wallet.cpp:3527
indexed_transaction_set mapTx
Definition: txmempool.h:403
bool BackupWallet(const CWallet &wallet, const string &strDest)
Definition: walletdb.cpp:904
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:3779
static const unsigned int DEFAULT_KEYPOOL_SIZE
Definition: wallet.h:45
CScript _createmultisig_redeemScript(const UniValue &params)
Definition: misc.cpp:340
bool push_back(const UniValue &val)
Definition: univalue.cpp:176
UniValue listtransactions(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1518
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:144
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:738
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:122
void EnsureWalletIsUnlocked()
Definition: rpcwallet.cpp:54
const std::string strWalletFile
Definition: wallet.h:675
Ran out of memory during operation.
Definition: protocol.h:46
unsigned int nTimeReceived
Definition: wallet.h:284
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:280
std::string strComment
Definition: wallet.h:542
std::string ToString() const
Definition: base58.cpp:193
string EncodeBase64(const unsigned char *pch, size_t len)
bool AddCScript(const CScript &redeemScript)
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
Definition: wallet.cpp:349
int64_t get_int64() const
Definition: univalue.cpp:327
bool GetKey(const CKeyID &address, CKey &keyOut) const
GetKey implementation that can derive a HD private key on the fly.
Definition: wallet.cpp:216
bool GetAccount(uint32_t nAccountIndex, CHDAccount &hdAccountRet)
Definition: hdchain.cpp:184
void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry)
Definition: rpcwallet.cpp:60
UniValue listlockunspent(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2300
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
Definition: wallet.h:993
int64_t CAmount
Definition: amount.h:14
bool exists(uint256 hash) const
Definition: txmempool.h:563
bool GetHDChain(CHDChain &hdChainRet) const
Definition: crypter.cpp:525
uint256 GetHash()
Definition: hash.h:254
int vout
Definition: wallet.h:205
Enter the wallet passphrase with walletpassphrase first.
Definition: protocol.h:74
iterator end()
Definition: prevector.h:272
#define LOCK2(cs1, cs2)
Definition: sync.h:169
CAmount GetBalance() const
Definition: wallet.cpp:2139
CAmount nCreditDebit
Definition: wallet.h:539
void push_back(const T &value)
Definition: prevector.h:381
UniValue getreceivedbyaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:701
const UniValue & get_obj() const
Definition: univalue.cpp:347
size_t KeypoolCountInternalKeys()
Definition: wallet.cpp:3773
bool GetKeyFromPool(CPubKey &key, bool fInternal)
Definition: wallet.cpp:3903
CCriticalSection cs
Definition: txmempool.h:402
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosRet, std::string &strFailReason, const CCoinControl *coinControl=NULL, bool sign=true, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false)
Definition: wallet.cpp:3173
bool CheckFinalTx(const CTransaction &tx, int flags)
Definition: validation.cpp:213
int64_t GetOldestKeyPoolTime()
Definition: wallet.cpp:3933
UniValue listaccounts(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1645
CPubKey vchPubKey
Definition: wallet.h:1083
bool ReadAccount(const std::string &strAccount, CAccount &account)
Definition: walletdb.cpp:179
std::list< CAccountingEntry > laccentries
Definition: wallet.h:739
std::vector< std::string > getKeys() const
Definition: univalue.cpp:289
void UnlockCoin(COutPoint &output)
Definition: wallet.cpp:4204
void RPCRunLater(const std::string &name, boost::function< void(void)> func, int64_t nSeconds)
Definition: server.cpp:604
UniValue listunspent(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2533
#define LOCK(cs)
Definition: sync.h:168
int64_t GetTxTime() const
Definition: wallet.cpp:1540
bool Set(const CKeyID &id)
Definition: base58.cpp:230
void clear()
Definition: univalue.cpp:80
uint256 uint256S(const char *str)
Definition: uint256.h:140
UniValue signmessage(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:585
CAmount GetFeePerK() const
Definition: amount.h:47
uint32_t nExternalChainCounter
Definition: hdchain.h:13
bool isNull() const
Definition: univalue.h:77
Server is in safe mode, and command is not allowed in safe mode.
Definition: protocol.h:43
The wallet passphrase entered was incorrect.
Definition: protocol.h:75
int Height() const
Definition: chain.h:397
bool IsRBFOptIn(const CTxMemPoolEntry &entry, CTxMemPool &pool)
Definition: rbf.cpp:17
std::vector< uint256 > ResendWalletTransactionsBefore(int64_t nTime, CConnman *connman)
Definition: wallet.cpp:2081
UniValue listaddressgroupings(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:534
CInstantSend instantsend
Definition: instantx.cpp:30
bool IsLocked(bool fForMixing=false) const
Definition: crypter.h:166
UniValue setaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:259
General application defined errors.
Definition: protocol.h:41
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
Definition: wallet.cpp:1793
bool IsLockedInstantSendTransaction(const uint256 &txHash)
Definition: instantx.cpp:770
bool IsPayToScriptHash() const
Definition: script.cpp:238
CChain chainActive
Definition: validation.cpp:65
void ListTransactions(const CWalletTx &wtx, const string &strAccount, int nMinDepth, bool fLong, UniValue &ret, const isminefilter &filter)
Definition: rpcwallet.cpp:1425
std::string ToString() const
Definition: uint256.cpp:65
Unexpected type was passed as parameter.
Definition: protocol.h:44
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:262
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:581
void GetAmounts(std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, std::string &strSentAccount, const isminefilter &filter) const
Definition: wallet.cpp:1585
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:166
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:110
void KeepKey()
Definition: wallet.cpp:4120
uint8_t isminefilter
Definition: wallet_ismine.h:29
Not enough funds in wallet or account.
Definition: protocol.h:71
std::string FormatMoney(const CAmount &n)
UniValue backupwallet(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1937
CScript scriptPubKey
Definition: transaction.h:137
UniValue getrawchangeaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:224
bool TxnCommit()
Definition: db.h:280
UniValue settxfee(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2349
void RPCTypeCheckObj(const UniValue &o, const map< string, UniValue::VType > &typesExpected, bool fAllowNull)
Definition: server.cpp:91
UniValue listreceivedbyaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1380
int nInstantSendDepth
Definition: instantx.cpp:27
UniValue listreceivedbyaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1339
Invalid, missing or duplicate parameter.
Definition: protocol.h:47
std::string strFromAccount
Definition: wallet.h:287
size_t KeypoolCountExternalKeys()
Definition: wallet.cpp:3767
Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
Definition: protocol.h:76
UniValue keypoolrefill(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1963
bool GetReservedKey(CPubKey &pubkey, bool fInternalIn)
Definition: wallet.cpp:4101
std::string EncodeHexTx(const CTransaction &tx)
Definition: core_write.cpp:119
const char * TXLOCKREQUEST
Definition: protocol.cpp:39
CTxDestination Get() const
Definition: base58.cpp:260
void RPCTypeCheck(const UniValue &params, const list< UniValue::VType > &typesExpected, bool fAllowNull)
Definition: server.cpp:70
CTxMemPool mempool
int GetOutpointPrivateSendRounds(const COutPoint &outpoint) const
Definition: wallet.cpp:1321
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:723
uint256 GetID() const
Definition: hdchain.h:111
bool setArray()
Definition: univalue.cpp:162
UniValue getbalance(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:792
CAmount nAmount
Definition: rpcwallet.cpp:1202
void updatePassphrase(const SecureString &sWalletPassphrase)
Definition: keepass.cpp:613
CKeePassIntegrator keePassInt
Definition: keepass.cpp:35
bool SignalsOptInRBF(const CTransaction &tx)
Definition: rbf.cpp:7
const uint256 & GetHash() const
Definition: transaction.h:262
vector< uint256 > txids
Definition: rpcwallet.cpp:1204
Unspecified problem with wallet (key not found etc.)
Definition: protocol.h:70
bool Lock(bool fAllowMixing=false)
Definition: crypter.cpp:233
UniValue encryptwallet(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2159
CAmount GetAccountCreditDebit(const std::string &strAccount)
Definition: walletdb.cpp:200
int64_t GetAdjustedTime()
Definition: timedata.cpp:33
void GetAccountAmounts(const std::string &strAccount, CAmount &nReceived, CAmount &nSent, CAmount &nFee, const isminefilter &filter) const
Definition: wallet.cpp:1641
UniValue addmultisigaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1151
bool IsTrusted() const
Definition: wallet.cpp:2041
UniValue instantsendtoaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:476
uint256 GetBlockHash() const
Definition: chain.h:218
bool IsCoinBase() const
Definition: transaction.h:284
bool get_bool() const
Definition: univalue.cpp:303
static SecureString generateKeePassKey()
Definition: keepass.cpp:533
UniValue sendtoaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:409
int64_t nWalletUnlockTime
Definition: rpcwallet.cpp:32
std::string GetHex() const
Definition: uint256.cpp:21
UniValue sendmany(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1024
std::map< CTxDestination, CAmount > GetAddressBalances()
Definition: wallet.cpp:3954
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:103
const UniValue NullUniValue
Definition: univalue.cpp:78
void rpcAssociate(std::string &strId, SecureString &sKeyBase64)
Definition: keepass.cpp:540
bool IsValid() const
Definition: pubkey.h:160
bool WriteAccount(const std::string &strAccount, const CAccount &account)
Definition: walletdb.cpp:185
std::string HelpRequiringPassphrase()
Definition: rpcwallet.cpp:35
const std::vector< CTxOut > vout
Definition: transaction.h:234
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE)
UniValue walletpassphrase(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2007
bool GetKeyID(CKeyID &keyID) const
Definition: base58.cpp:291
bool FundTransaction(CMutableTransaction &tx, CAmount &nFeeRet, int &nChangePosRet, std::string &strFailReason, bool includeWatching)
Definition: wallet.cpp:2727
UniValue abandontransaction(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1902
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:748
int get_int() const
Definition: univalue.cpp:317
iterator begin()
Definition: prevector.h:270
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:447
UniValue getaddressesbyaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:337
UniValue sendfrom(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:958
Definition: pubkey.h:37
Wallet errors.
Definition: protocol.h:69
CTxDestination destination
Definition: wallet.h:203
Invalid IP/Subnet.
Definition: protocol.h:66
CAmount amount
Definition: wallet.h:204
int64_t GetTime()
For unit testing.
Definition: utiltime.cpp:20
std::string strAccount
Definition: wallet.h:538
void LockCoin(COutPoint &output)
Definition: wallet.cpp:4193
void AcentryToJSON(const CAccountingEntry &acentry, const string &strAccount, UniValue &ret)
Definition: rpcwallet.cpp:1501
static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx &wtxNew, bool fUseInstantSend=false, bool fUsePrivateSend=false)
Definition: rpcwallet.cpp:374
bool isObject() const
Definition: univalue.h:84
static void LockWallet(CWallet *pWallet)
Definition: rpcwallet.cpp:2000
int64_t nTime
Definition: wallet.h:540
const string strMessageMagic
Definition: validation.cpp:109
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
Definition: wallet.cpp:4229
int64_t nOrderPos
Definition: wallet.h:544
void SetHex(const char *psz)
Definition: uint256.cpp:30
static void MaybePushAddress(UniValue &entry, const CTxDestination &dest)
Definition: rpcwallet.cpp:1418
Definition: key.h:35
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:113
CAmount GetImmatureBalance() const
Definition: wallet.cpp:2301
#define PAIRTYPE(t1, t2)
uint256 hash
Definition: transaction.h:18
int GetBlocksToMaturity() const
Definition: wallet.cpp:4449
int GetDepthInMainChain(const CBlockIndex *&pindexRet, bool enableIX=true) const
Definition: wallet.cpp:4416
UniValue JSONRPCError(int code, const string &message)
Definition: protocol.cpp:57
int64_t nKeysLeftSinceAutoBackup
Definition: wallet.h:755
BlockMap mapBlockIndex
Definition: validation.cpp:64
size_t size() const
Definition: univalue.h:69
uint256 hashBlock
Definition: wallet.h:216
const UniValue & get_array() const
Definition: univalue.cpp:354
CAmount GetAccountBalance(CWalletDB &walletdb, const string &strAccount, int nMinDepth, const isminefilter &filter, bool fAddLockConf)
Definition: rpcwallet.cpp:760
std::string get_str() const
Definition: univalue.cpp:310
bool TxnBegin()
Definition: db.h:269
std::string itostr(int n)
Database error.
Definition: protocol.h:48
UniValue gettransaction(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1821
UniValue getaccount(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:305
std::set< std::set< CTxDestination > > GetAddressGroupings()
Definition: wallet.cpp:3994
result
Definition: rpcuser.py:37
bool DecodeHexTx(CTransaction &tx, const std::string &strHexTx)
Definition: core_read.cpp:93
UniValue ListReceived(const UniValue &params, bool fByAccounts)
Definition: rpcwallet.cpp:1214
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool fIncludeZeroValue=false, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false) const
Definition: wallet.cpp:2360
std::vector< UniValue > getValues() const
Definition: univalue.cpp:296
UniValue lockunspent(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2216