Anoncoin  0.9.4
P2P Digital Currency
rpcwallet.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2013-2014 The Anoncoin Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "base58.h"
8 #include "rpcserver.h"
9 #include "init.h"
10 #include "net.h"
11 #include "netbase.h"
12 #include "util.h"
13 #include "wallet.h"
14 #include "walletdb.h"
15 
16 #include <stdint.h>
17 
18 #include <boost/assign/list_of.hpp>
19 #include "json/json_spirit_utils.h"
20 #include "json/json_spirit_value.h"
21 
22 using namespace std;
23 using namespace boost;
24 using namespace boost::assign;
25 using namespace json_spirit;
26 
28 static CCriticalSection cs_nWalletUnlockTime;
29 
31 {
32  return pwalletMain && pwalletMain->IsCrypted()
33  ? "\nRequires wallet passphrase to be set with walletpassphrase call."
34  : "";
35 }
36 
38 {
39  if (pwalletMain->IsLocked())
40  throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
41 }
42 
43 void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
44 {
45  int confirms = wtx.GetDepthInMainChain();
46  entry.push_back(Pair("confirmations", confirms));
47  if (wtx.IsCoinBase())
48  entry.push_back(Pair("generated", true));
49  if (confirms > 0)
50  {
51  entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
52  entry.push_back(Pair("blockindex", wtx.nIndex));
53  entry.push_back(Pair("blocktime", (int64_t)(mapBlockIndex[wtx.hashBlock]->nTime)));
54  }
55  uint256 hash = wtx.GetHash();
56  entry.push_back(Pair("txid", hash.GetHex()));
57  Array conflicts;
58  BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts())
59  conflicts.push_back(conflict.GetHex());
60  entry.push_back(Pair("walletconflicts", conflicts));
61  entry.push_back(Pair("time", wtx.GetTxTime()));
62  entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
63  BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue)
64  entry.push_back(Pair(item.first, item.second));
65 }
66 
67 string AccountFromValue(const Value& value)
68 {
69  string strAccount = value.get_str();
70  if (strAccount == "*")
71  throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name");
72  return strAccount;
73 }
74 
75 Value getnewaddress(const Array& params, bool fHelp)
76 {
77  if (fHelp || params.size() > 1)
78  throw runtime_error(
79  "getnewaddress ( \"account\" )\n"
80  "\nReturns a new Anoncoin address for receiving payments.\n"
81  "If 'account' is specified (recommended), it is added to the address book \n"
82  "so payments received with the address will be credited to 'account'.\n"
83  "\nArguments:\n"
84  "1. \"account\" (string, optional) The account name for the address to be linked to. if not provided, the default account \"\" is used. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created if there is no account by the given name.\n"
85  "\nResult:\n"
86  "\"anoncoinaddress\" (string) The new anoncoin address\n"
87  "\nExamples:\n"
88  + HelpExampleCli("getnewaddress", "")
89  + HelpExampleCli("getnewaddress", "\"\"")
90  + HelpExampleCli("getnewaddress", "\"myaccount\"")
91  + HelpExampleRpc("getnewaddress", "\"myaccount\"")
92  );
93 
94  // Parse the account first so we don't generate a key if there's an error
95  string strAccount;
96  if (params.size() > 0)
97  strAccount = AccountFromValue(params[0]);
98 
99  if (!pwalletMain->IsLocked())
101 
102  // Generate a new key that is added to wallet
103  CPubKey newKey;
104  if (!pwalletMain->GetKeyFromPool(newKey))
105  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
106  CKeyID keyID = newKey.GetID();
107 
108  pwalletMain->SetAddressBook(keyID, strAccount, "receive");
109 
110  return CAnoncoinAddress(keyID).ToString();
111 }
112 
113 
114 CAnoncoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
115 {
117 
118  CAccount account;
119  walletdb.ReadAccount(strAccount, account);
120 
121  bool bKeyUsed = false;
122 
123  // Check if the current key has been used
124  if (account.vchPubKey.IsValid())
125  {
126  CScript scriptPubKey;
127  scriptPubKey.SetDestination(account.vchPubKey.GetID());
128  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
129  it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
130  ++it)
131  {
132  const CWalletTx& wtx = (*it).second;
133  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
134  if (txout.scriptPubKey == scriptPubKey)
135  bKeyUsed = true;
136  }
137  }
138 
139  // Generate a new key
140  if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed)
141  {
142  if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
143  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
144 
145  pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
146  walletdb.WriteAccount(strAccount, account);
147  }
148 
149  return CAnoncoinAddress(account.vchPubKey.GetID());
150 }
151 
152 Value getaccountaddress(const Array& params, bool fHelp)
153 {
154  if (fHelp || params.size() != 1)
155  throw runtime_error(
156  "getaccountaddress \"account\"\n"
157  "\nReturns the current Anoncoin address for receiving payments to this account.\n"
158  "\nArguments:\n"
159  "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"
160  "\nResult:\n"
161  "\"anoncoinaddress\" (string) The account anoncoin address\n"
162  "\nExamples:\n"
163  + HelpExampleCli("getaccountaddress", "")
164  + HelpExampleCli("getaccountaddress", "\"\"")
165  + HelpExampleCli("getaccountaddress", "\"myaccount\"")
166  + HelpExampleRpc("getaccountaddress", "\"myaccount\"")
167  );
168 
169  // Parse the account first so we don't generate a key if there's an error
170  string strAccount = AccountFromValue(params[0]);
171 
172  Value ret;
173 
174  ret = GetAccountAddress(strAccount).ToString();
175 
176  return ret;
177 }
178 
179 
180 Value getrawchangeaddress(const Array& params, bool fHelp)
181 {
182  if (fHelp || params.size() > 1)
183  throw runtime_error(
184  "getrawchangeaddress\n"
185  "\nReturns a new Anoncoin address, for receiving change.\n"
186  "This is for use with raw transactions, NOT normal use.\n"
187  "\nResult:\n"
188  "\"address\" (string) The address\n"
189  "\nExamples:\n"
190  + HelpExampleCli("getrawchangeaddress", "")
191  + HelpExampleRpc("getrawchangeaddress", "")
192  );
193 
194  if (!pwalletMain->IsLocked())
196 
197  CReserveKey reservekey(pwalletMain);
198  CPubKey vchPubKey;
199  if (!reservekey.GetReservedKey(vchPubKey))
200  throw JSONRPCError(RPC_WALLET_ERROR, "Error: Unable to obtain key for change");
201 
202  reservekey.KeepKey();
203 
204  CKeyID keyID = vchPubKey.GetID();
205 
206  return CAnoncoinAddress(keyID).ToString();
207 }
208 
209 
210 Value setaccount(const Array& params, bool fHelp)
211 {
212  if (fHelp || params.size() < 1 || params.size() > 2)
213  throw runtime_error(
214  "setaccount \"anoncoinaddress\" \"account\"\n"
215  "\nSets the account associated with the given address.\n"
216  "\nArguments:\n"
217  "1. \"anoncoinaddress\" (string, required) The anoncoin address to be associated with an account.\n"
218  "2. \"account\" (string, required) The account to assign the address to.\n"
219  "\nExamples:\n"
220  + HelpExampleCli("setaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"tabby\"")
221  + HelpExampleRpc("setaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"tabby\"")
222  );
223 
224  CAnoncoinAddress address(params[0].get_str());
225  if (!address.IsValid())
226  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
227 
228 
229  string strAccount;
230  if (params.size() > 1)
231  strAccount = AccountFromValue(params[1]);
232 
233  // Detect when changing the account of an address that is the 'unused current key' of another account:
234  if (pwalletMain->mapAddressBook.count(address.Get()))
235  {
236  string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
237  if (address == GetAccountAddress(strOldAccount))
238  GetAccountAddress(strOldAccount, true);
239  }
240 
241  pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
242 
243  return Value::null;
244 }
245 
246 
247 Value getaccount(const Array& params, bool fHelp)
248 {
249  if (fHelp || params.size() != 1)
250  throw runtime_error(
251  "getaccount \"anoncoinaddress\"\n"
252  "\nReturns the account associated with the given address.\n"
253  "\nArguments:\n"
254  "1. \"anoncoinaddress\" (string, required) The anoncoin address for account lookup.\n"
255  "\nResult:\n"
256  "\"accountname\" (string) the account address\n"
257  "\nExamples:\n"
258  + HelpExampleCli("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\"")
259  + HelpExampleRpc("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\"")
260  );
261 
262  CAnoncoinAddress address(params[0].get_str());
263  if (!address.IsValid())
264  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
265 
266  string strAccount;
267  map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
268  if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty())
269  strAccount = (*mi).second.name;
270  return strAccount;
271 }
272 
273 
274 Value getaddressesbyaccount(const Array& params, bool fHelp)
275 {
276  if (fHelp || params.size() != 1)
277  throw runtime_error(
278  "getaddressesbyaccount \"account\"\n"
279  "\nReturns the list of addresses for the given account.\n"
280  "\nArguments:\n"
281  "1. \"account\" (string, required) The account name.\n"
282  "\nResult:\n"
283  "[ (json array of string)\n"
284  " \"anoncoinaddress\" (string) a anoncoin address associated with the given account\n"
285  " ,...\n"
286  "]\n"
287  "\nExamples:\n"
288  + HelpExampleCli("getaddressesbyaccount", "\"tabby\"")
289  + HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")
290  );
291 
292  string strAccount = AccountFromValue(params[0]);
293 
294  // Find all addresses that have the given account
295  Array ret;
297  {
298  const CAnoncoinAddress& address = item.first;
299  const string& strName = item.second.name;
300  if (strName == strAccount)
301  ret.push_back(address.ToString());
302  }
303  return ret;
304 }
305 
306 Value sendtoaddress(const Array& params, bool fHelp)
307 {
308  if (fHelp || params.size() < 2 || params.size() > 4)
309  throw runtime_error(
310  "sendtoaddress \"anoncoinaddress\" amount ( \"comment\" \"comment-to\" )\n"
311  "\nSent an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n"
313  "\nArguments:\n"
314  "1. \"anoncoinaddress\" (string, required) The anoncoin address to send to.\n"
315  "2. \"amount\" (numeric, required) The amount in btc to send. eg 0.1\n"
316  "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
317  " This is not part of the transaction, just kept in your wallet.\n"
318  "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n"
319  " to which you're sending the transaction. This is not part of the \n"
320  " transaction, just kept in your wallet.\n"
321  "\nResult:\n"
322  "\"transactionid\" (string) The transaction id.\n"
323  "\nExamples:\n"
324  + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1")
325  + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"donation\" \"seans outpost\"")
326  + HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.1, \"donation\", \"seans outpost\"")
327  );
328 
329  CAnoncoinAddress address(params[0].get_str());
330  if (!address.IsValid())
331  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
332 
333  // Amount
334  int64_t nAmount = AmountFromValue(params[1]);
335 
336  // Wallet comments
337  CWalletTx wtx;
338  if (params.size() > 2 && params[2].type() != null_type && !params[2].get_str().empty())
339  wtx.mapValue["comment"] = params[2].get_str();
340  if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
341  wtx.mapValue["to"] = params[3].get_str();
342 
344 
345  string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
346  if (strError != "")
347  throw JSONRPCError(RPC_WALLET_ERROR, strError);
348 
349  return wtx.GetHash().GetHex();
350 }
351 
352 Value listaddressgroupings(const Array& params, bool fHelp)
353 {
354  if (fHelp)
355  throw runtime_error(
356  "listaddressgroupings\n"
357  "\nLists groups of addresses which have had their common ownership\n"
358  "made public by common use as inputs or as the resulting change\n"
359  "in past transactions\n"
360  "\nResult:\n"
361  "[\n"
362  " [\n"
363  " [\n"
364  " \"anoncoinaddress\", (string) The anoncoin address\n"
365  " amount, (numeric) The amount in btc\n"
366  " \"account\" (string, optional) The account\n"
367  " ]\n"
368  " ,...\n"
369  " ]\n"
370  " ,...\n"
371  "]\n"
372  "\nExamples:\n"
373  + HelpExampleCli("listaddressgroupings", "")
374  + HelpExampleRpc("listaddressgroupings", "")
375  );
376 
377  Array jsonGroupings;
378  map<CTxDestination, int64_t> balances = pwalletMain->GetAddressBalances();
379  BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
380  {
381  Array jsonGrouping;
382  BOOST_FOREACH(CTxDestination address, grouping)
383  {
384  Array addressInfo;
385  addressInfo.push_back(CAnoncoinAddress(address).ToString());
386  addressInfo.push_back(ValueFromAmount(balances[address]));
387  {
389  if (pwalletMain->mapAddressBook.find(CAnoncoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
390  addressInfo.push_back(pwalletMain->mapAddressBook.find(CAnoncoinAddress(address).Get())->second.name);
391  }
392  jsonGrouping.push_back(addressInfo);
393  }
394  jsonGroupings.push_back(jsonGrouping);
395  }
396  return jsonGroupings;
397 }
398 
399 Value signmessage(const Array& params, bool fHelp)
400 {
401  if (fHelp || params.size() != 2)
402  throw runtime_error(
403  "signmessage \"anoncoinaddress\" \"message\"\n"
404  "\nSign a message with the private key of an address"
405  + HelpRequiringPassphrase() + "\n"
406  "\nArguments:\n"
407  "1. \"anoncoinaddress\" (string, required) The anoncoin address to use for the private key.\n"
408  "2. \"message\" (string, required) The message to create a signature of.\n"
409  "\nResult:\n"
410  "\"signature\" (string) The signature of the message encoded in base 64\n"
411  "\nExamples:\n"
412  "\nUnlock the wallet for 30 seconds\n"
413  + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
414  "\nCreate the signature\n"
415  + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
416  "\nVerify the signature\n"
417  + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
418  "\nAs json rpc\n"
419  + HelpExampleRpc("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"my message\"")
420  );
421 
423 
424  string strAddress = params[0].get_str();
425  string strMessage = params[1].get_str();
426 
427  CAnoncoinAddress addr(strAddress);
428  if (!addr.IsValid())
429  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
430 
431  CKeyID keyID;
432  if (!addr.GetKeyID(keyID))
433  throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
434 
435  CKey key;
436  if (!pwalletMain->GetKey(keyID, key))
437  throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
438 
439  CHashWriter ss(SER_GETHASH, 0);
440  ss << strMessageMagic;
441  ss << strMessage;
442 
443  vector<unsigned char> vchSig;
444  if (!key.SignCompact(ss.GetHash(), vchSig))
445  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
446 
447  return EncodeBase64(&vchSig[0], vchSig.size());
448 }
449 
450 Value getreceivedbyaddress(const Array& params, bool fHelp)
451 {
452  if (fHelp || params.size() < 1 || params.size() > 2)
453  throw runtime_error(
454  "getreceivedbyaddress \"anoncoinaddress\" ( minconf )\n"
455  "\nReturns the total amount received by the given anoncoinaddress in transactions with at least minconf confirmations.\n"
456  "\nArguments:\n"
457  "1. \"anoncoinaddress\" (string, required) The anoncoin address for transactions.\n"
458  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
459  "\nResult:\n"
460  "amount (numeric) The total amount in btc received at this address.\n"
461  "\nExamples:\n"
462  "\nThe amount from transactions with at least 1 confirmation\n"
463  + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\"") +
464  "\nThe amount including unconfirmed transactions, zero confirmations\n"
465  + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" 0") +
466  "\nThe amount with at least 6 confirmation, very safe\n"
467  + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" 6") +
468  "\nAs a json rpc call\n"
469  + HelpExampleRpc("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", 6")
470  );
471 
472  // Anoncoin address
473  CAnoncoinAddress address = CAnoncoinAddress(params[0].get_str());
474  CScript scriptPubKey;
475  if (!address.IsValid())
476  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
477  scriptPubKey.SetDestination(address.Get());
478  if (!IsMine(*pwalletMain,scriptPubKey))
479  return (double)0.0;
480 
481  // Minimum confirmations
482  int nMinDepth = 1;
483  if (params.size() > 1)
484  nMinDepth = params[1].get_int();
485 
486  // Tally
487  int64_t nAmount = 0;
488  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
489  {
490  const CWalletTx& wtx = (*it).second;
491  if (wtx.IsCoinBase() || !IsFinalTx(wtx))
492  continue;
493 
494  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
495  if (txout.scriptPubKey == scriptPubKey)
496  if (wtx.GetDepthInMainChain() >= nMinDepth)
497  nAmount += txout.nValue;
498  }
499 
500  return ValueFromAmount(nAmount);
501 }
502 
503 
504 Value getreceivedbyaccount(const Array& params, bool fHelp)
505 {
506  if (fHelp || params.size() < 1 || params.size() > 2)
507  throw runtime_error(
508  "getreceivedbyaccount \"account\" ( minconf )\n"
509  "\nReturns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.\n"
510  "\nArguments:\n"
511  "1. \"account\" (string, required) The selected account, may be the default account using \"\".\n"
512  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
513  "\nResult:\n"
514  "amount (numeric) The total amount in btc received for this account.\n"
515  "\nExamples:\n"
516  "\nAmount received by the default account with at least 1 confirmation\n"
517  + HelpExampleCli("getreceivedbyaccount", "\"\"") +
518  "\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n"
519  + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") +
520  "\nThe amount with at least 6 confirmation, very safe\n"
521  + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") +
522  "\nAs a json rpc call\n"
523  + HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6")
524  );
525 
526  // Minimum confirmations
527  int nMinDepth = 1;
528  if (params.size() > 1)
529  nMinDepth = params[1].get_int();
530 
531  // Get the set of pub keys assigned to account
532  string strAccount = AccountFromValue(params[0]);
533  set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
534 
535  // Tally
536  int64_t nAmount = 0;
537  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
538  {
539  const CWalletTx& wtx = (*it).second;
540  if (wtx.IsCoinBase() || !IsFinalTx(wtx))
541  continue;
542 
543  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
544  {
545  CTxDestination address;
546  if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address))
547  if (wtx.GetDepthInMainChain() >= nMinDepth)
548  nAmount += txout.nValue;
549  }
550  }
551 
552  return (double)nAmount / (double)COIN;
553 }
554 
555 
556 int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
557 {
558  int64_t nBalance = 0;
559 
560  // Tally wallet transactions
561  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
562  {
563  const CWalletTx& wtx = (*it).second;
564  if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
565  continue;
566 
567  int64_t nReceived, nSent, nFee;
568  wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
569 
570  if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
571  nBalance += nReceived;
572  nBalance -= nSent + nFee;
573  }
574 
575  // Tally internal accounting entries
576  nBalance += walletdb.GetAccountCreditDebit(strAccount);
577 
578  return nBalance;
579 }
580 
581 int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
582 {
584  return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
585 }
586 
587 
588 Value getbalance(const Array& params, bool fHelp)
589 {
590  if (fHelp || params.size() > 3)
591  throw runtime_error(
592  "getbalance ( \"account\" minconf includeWatchonly )\n"
593  "\nIf account is not specified, returns the server's total available balance.\n"
594  "If account is specified, returns the balance in the account.\n"
595  "Note that the account \"\" is not the same as leaving the parameter out.\n"
596  "The server total may be different to the balance in the default \"\" account.\n"
597  "\nArguments:\n"
598  "1. \"account\" (string, optional) The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n"
599  "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
600  "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n"
601  "\nResult:\n"
602  "amount (numeric) The total amount in btc received for this account.\n"
603  "\nExamples:\n"
604  "\nThe total amount in the server across all accounts\n"
605  + HelpExampleCli("getbalance", "") +
606  "\nThe total amount in the server across all accounts, with at least 5 confirmations\n"
607  + HelpExampleCli("getbalance", "\"*\" 6") +
608  "\nThe total amount in the default account with at least 1 confirmation\n"
609  + HelpExampleCli("getbalance", "\"\"") +
610  "\nThe total amount in the account named tabby with at least 6 confirmations\n"
611  + HelpExampleCli("getbalance", "\"tabby\" 6") +
612  "\nAs a json rpc call\n"
613  + HelpExampleRpc("getbalance", "\"tabby\", 6")
614  );
615 
616  if (params.size() == 0)
618 
619  int nMinDepth = 1;
620  if (params.size() > 1)
621  nMinDepth = params[1].get_int();
623  if(params.size() > 2)
624  if(params[2].get_bool())
625  filter = filter | ISMINE_WATCH_ONLY;
626 
627  if (params[0].get_str() == "*") {
628  // Calculate total balance a different way from GetBalance()
629  // (GetBalance() sums up all unspent TxOuts)
630  // getbalance and getbalance '*' 0 should return the same number
631  int64_t nBalance = 0;
632  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
633  {
634  const CWalletTx& wtx = (*it).second;
635  if (!wtx.IsTrusted() || wtx.GetBlocksToMaturity() > 0)
636  continue;
637 
638  int64_t allFee;
639  string strSentAccount;
640  list<pair<CTxDestination, int64_t> > listReceived;
641  list<pair<CTxDestination, int64_t> > listSent;
642  wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
643  if (wtx.GetDepthInMainChain() >= nMinDepth)
644  {
645  BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
646  nBalance += r.second;
647  }
648  BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listSent)
649  nBalance -= r.second;
650  nBalance -= allFee;
651  }
652  return ValueFromAmount(nBalance);
653  }
654 
655  string strAccount = AccountFromValue(params[0]);
656 
657  int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
658 
659  return ValueFromAmount(nBalance);
660 }
661 
662 Value getunconfirmedbalance(const Array &params, bool fHelp)
663 {
664  if (fHelp || params.size() > 0)
665  throw runtime_error(
666  "getunconfirmedbalance\n"
667  "Returns the server's total unconfirmed balance\n");
669 }
670 
671 
672 Value movecmd(const Array& params, bool fHelp)
673 {
674  if (fHelp || params.size() < 3 || params.size() > 5)
675  throw runtime_error(
676  "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
677  "\nMove a specified amount from one account in your wallet to another.\n"
678  "\nArguments:\n"
679  "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
680  "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
681  "3. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
682  "4. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
683  "\nResult:\n"
684  "true|false (boolean) true if successfull.\n"
685  "\nExamples:\n"
686  "\nMove 0.01 btc from the default account to the account named tabby\n"
687  + HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
688  "\nMove 0.01 btc timotei to akiko with a comment and funds have 6 confirmations\n"
689  + HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") +
690  "\nAs a json rpc call\n"
691  + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")
692  );
693 
694  string strFrom = AccountFromValue(params[0]);
695  string strTo = AccountFromValue(params[1]);
696  int64_t nAmount = AmountFromValue(params[2]);
697  if (params.size() > 3)
698  // unused parameter, used to be nMinDepth, keep type-checking it though
699  (void)params[3].get_int();
700  string strComment;
701  if (params.size() > 4)
702  strComment = params[4].get_str();
703 
705  if (!walletdb.TxnBegin())
706  throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
707 
708  int64_t nNow = GetAdjustedTime();
709 
710  // Debit
711  CAccountingEntry debit;
712  debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
713  debit.strAccount = strFrom;
714  debit.nCreditDebit = -nAmount;
715  debit.nTime = nNow;
716  debit.strOtherAccount = strTo;
717  debit.strComment = strComment;
718  walletdb.WriteAccountingEntry(debit);
719 
720  // Credit
721  CAccountingEntry credit;
722  credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
723  credit.strAccount = strTo;
724  credit.nCreditDebit = nAmount;
725  credit.nTime = nNow;
726  credit.strOtherAccount = strFrom;
727  credit.strComment = strComment;
728  walletdb.WriteAccountingEntry(credit);
729 
730  if (!walletdb.TxnCommit())
731  throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
732 
733  return true;
734 }
735 
736 
737 Value sendfrom(const Array& params, bool fHelp)
738 {
739  if (fHelp || params.size() < 3 || params.size() > 6)
740  throw runtime_error(
741  "sendfrom \"fromaccount\" \"toanoncoinaddress\" amount ( minconf \"comment\" \"comment-to\" )\n"
742  "\nSent an amount from an account to a anoncoin address.\n"
743  "The amount is a real and is rounded to the nearest 0.00000001."
744  + HelpRequiringPassphrase() + "\n"
745  "\nArguments:\n"
746  "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n"
747  "2. \"toanoncoinaddress\" (string, required) The anoncoin address to send funds to.\n"
748  "3. amount (numeric, required) The amount in btc. (transaction fee is added on top).\n"
749  "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
750  "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
751  " This is not part of the transaction, just kept in your wallet.\n"
752  "6. \"comment-to\" (string, optional) An optional comment to store the name of the person or organization \n"
753  " to which you're sending the transaction. This is not part of the transaction, \n"
754  " it is just kept in your wallet.\n"
755  "\nResult:\n"
756  "\"transactionid\" (string) The transaction id.\n"
757  "\nExamples:\n"
758  "\nSend 0.01 btc from the default account to the address, must have at least 1 confirmation\n"
759  + HelpExampleCli("sendfrom", "\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") +
760  "\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n"
761  + HelpExampleCli("sendfrom", "\"tabby\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 6 \"donation\" \"seans outpost\"") +
762  "\nAs a json rpc call\n"
763  + HelpExampleRpc("sendfrom", "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.01, 6, \"donation\", \"seans outpost\"")
764  );
765 
766  string strAccount = AccountFromValue(params[0]);
767  CAnoncoinAddress address(params[1].get_str());
768  if (!address.IsValid())
769  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
770  int64_t nAmount = AmountFromValue(params[2]);
771  int nMinDepth = 1;
772  if (params.size() > 3)
773  nMinDepth = params[3].get_int();
774 
775  CWalletTx wtx;
776  wtx.strFromAccount = strAccount;
777  if (params.size() > 4 && params[4].type() != null_type && !params[4].get_str().empty())
778  wtx.mapValue["comment"] = params[4].get_str();
779  if (params.size() > 5 && params[5].type() != null_type && !params[5].get_str().empty())
780  wtx.mapValue["to"] = params[5].get_str();
781 
783 
784  // Check funds
785  int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
786  if (nAmount > nBalance)
787  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
788 
789  // Send
790  string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
791  if (strError != "")
792  throw JSONRPCError(RPC_WALLET_ERROR, strError);
793 
794  return wtx.GetHash().GetHex();
795 }
796 
797 
798 Value sendmany(const Array& params, bool fHelp)
799 {
800  if (fHelp || params.size() < 2 || params.size() > 4)
801  throw runtime_error(
802  "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" )\n"
803  "\nSend multiple times. Amounts are double-precision floating point numbers."
804  + HelpRequiringPassphrase() + "\n"
805  "\nArguments:\n"
806  "1. \"fromaccount\" (string, required) The account to send the funds from, can be \"\" for the default account\n"
807  "2. \"amounts\" (string, required) A json object with addresses and amounts\n"
808  " {\n"
809  " \"address\":amount (numeric) The anoncoin address is the key, the numeric amount in btc is the value\n"
810  " ,...\n"
811  " }\n"
812  "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
813  "4. \"comment\" (string, optional) A comment\n"
814  "\nResult:\n"
815  "\"transactionid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
816  " the number of addresses.\n"
817  "\nExamples:\n"
818  "\nSend two amounts to two different addresses:\n"
819  + HelpExampleCli("sendmany", "\"tabby\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"") +
820  "\nSend two amounts to two different addresses setting the confirmation and comment:\n"
821  + HelpExampleCli("sendmany", "\"tabby\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 6 \"testing\"") +
822  "\nAs a json rpc call\n"
823  + HelpExampleRpc("sendmany", "\"tabby\", \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\", 6, \"testing\"")
824  );
825 
826  string strAccount = AccountFromValue(params[0]);
827  Object sendTo = params[1].get_obj();
828  int nMinDepth = 1;
829  if (params.size() > 2)
830  nMinDepth = params[2].get_int();
831 
832  CWalletTx wtx;
833  wtx.strFromAccount = strAccount;
834  if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
835  wtx.mapValue["comment"] = params[3].get_str();
836 
837  set<CAnoncoinAddress> setAddress;
838  vector<pair<CScript, int64_t> > vecSend;
839 
840  int64_t totalAmount = 0;
841  BOOST_FOREACH(const Pair& s, sendTo)
842  {
843  CAnoncoinAddress address(s.name_);
844  if (!address.IsValid())
845  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Anoncoin address: ")+s.name_);
846 
847  if (setAddress.count(address))
848  throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_);
849  setAddress.insert(address);
850 
851  CScript scriptPubKey;
852  scriptPubKey.SetDestination(address.Get());
853  int64_t nAmount = AmountFromValue(s.value_);
854  totalAmount += nAmount;
855 
856  vecSend.push_back(make_pair(scriptPubKey, nAmount));
857  }
858 
860 
861  // Check funds
862  int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
863  if (totalAmount > nBalance)
864  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
865 
866  // Send
867  CReserveKey keyChange(pwalletMain);
868  int64_t nFeeRequired = 0;
869  string strFailReason;
870  bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason);
871  if (!fCreated)
872  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
873  if (!pwalletMain->CommitTransaction(wtx, keyChange))
874  throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed");
875 
876  return wtx.GetHash().GetHex();
877 }
878 
879 // Defined in rpcmisc.cpp
880 extern CScript _createmultisig_redeemScript(const Array& params);
881 
882 Value addmultisigaddress(const Array& params, bool fHelp)
883 {
884  if (fHelp || params.size() < 2 || params.size() > 3)
885  {
886  string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
887  "\nAdd a nrequired-to-sign multisignature address to the wallet.\n"
888  "Each key is a Anoncoin address or hex-encoded public key.\n"
889  "If 'account' is specified, assign address to that account.\n"
890 
891  "\nArguments:\n"
892  "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
893  "2. \"keysobject\" (string, required) A json array of anoncoin addresses or hex-encoded public keys\n"
894  " [\n"
895  " \"address\" (string) anoncoin address or hex-encoded public key\n"
896  " ...,\n"
897  " ]\n"
898  "3. \"account\" (string, optional) An account to assign the addresses to.\n"
899 
900  "\nResult:\n"
901  "\"anoncoinaddress\" (string) A anoncoin address associated with the keys.\n"
902 
903  "\nExamples:\n"
904  "\nAdd a multisig address from 2 addresses\n"
905  + HelpExampleCli("addmultisigaddress", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
906  "\nAs json rpc call\n"
907  + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
908  ;
909  throw runtime_error(msg);
910  }
911 
912  string strAccount;
913  if (params.size() > 2)
914  strAccount = AccountFromValue(params[2]);
915 
916  // Construct using pay-to-script-hash:
917  CScript inner = _createmultisig_redeemScript(params);
918  CScriptID innerID = inner.GetID();
919  pwalletMain->AddCScript(inner);
920 
921  pwalletMain->SetAddressBook(innerID, strAccount, "send");
922  return CAnoncoinAddress(innerID).ToString();
923 }
924 
925 
926 struct tallyitem
927 {
928  int64_t nAmount;
929  int nConf;
930  vector<uint256> txids;
933  {
934  nAmount = 0;
935  nConf = std::numeric_limits<int>::max();
936  fIsWatchonly = false;
937  }
938 };
939 
940 Value ListReceived(const Array& params, bool fByAccounts)
941 {
942  // Minimum confirmations
943  int nMinDepth = 1;
944  if (params.size() > 0)
945  nMinDepth = params[0].get_int();
946 
947  // Whether to include empty accounts
948  bool fIncludeEmpty = false;
949  if (params.size() > 1)
950  fIncludeEmpty = params[1].get_bool();
951 
953  if(params.size() > 2)
954  if(params[2].get_bool())
955  filter = filter | ISMINE_WATCH_ONLY;
956 
957  // Tally
958  map<CAnoncoinAddress, tallyitem> mapTally;
959  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
960  {
961  const CWalletTx& wtx = (*it).second;
962 
963  if (wtx.IsCoinBase() || !IsFinalTx(wtx))
964  continue;
965 
966  int nDepth = wtx.GetDepthInMainChain();
967  if (nDepth < nMinDepth)
968  continue;
969 
970  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
971  {
972  CTxDestination address;
973  if (!ExtractDestination(txout.scriptPubKey, address))
974  continue;
975 
976  isminefilter mine = IsMine(*pwalletMain, address);
977  if(!(mine & filter))
978  continue;
979 
980  tallyitem& item = mapTally[address];
981  item.nAmount += txout.nValue;
982  item.nConf = min(item.nConf, nDepth);
983  item.txids.push_back(wtx.GetHash());
984  if (mine & ISMINE_WATCH_ONLY)
985  item.fIsWatchonly = true;
986  }
987  }
988 
989  // Reply
990  Array ret;
991  map<string, tallyitem> mapAccountTally;
993  {
994  const CAnoncoinAddress& address = item.first;
995  const string& strAccount = item.second.name;
996  map<CAnoncoinAddress, tallyitem>::iterator it = mapTally.find(address);
997  if (it == mapTally.end() && !fIncludeEmpty)
998  continue;
999 
1000  int64_t nAmount = 0;
1001  int nConf = std::numeric_limits<int>::max();
1002  bool fIsWatchonly = false;
1003  if (it != mapTally.end())
1004  {
1005  nAmount = (*it).second.nAmount;
1006  nConf = (*it).second.nConf;
1007  fIsWatchonly = (*it).second.fIsWatchonly;
1008  }
1009 
1010  if (fByAccounts)
1011  {
1012  tallyitem& item = mapAccountTally[strAccount];
1013  item.nAmount += nAmount;
1014  item.nConf = min(item.nConf, nConf);
1015  item.fIsWatchonly = fIsWatchonly;
1016  }
1017  else
1018  {
1019  Object obj;
1020  if(fIsWatchonly)
1021  obj.push_back(Pair("involvesWatchonly", true));
1022  obj.push_back(Pair("address", address.ToString()));
1023  obj.push_back(Pair("account", strAccount));
1024  obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1025  obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1026  Array transactions;
1027  if (it != mapTally.end())
1028  {
1029  BOOST_FOREACH(const uint256& item, (*it).second.txids)
1030  {
1031  transactions.push_back(item.GetHex());
1032  }
1033  }
1034  obj.push_back(Pair("txids", transactions));
1035  ret.push_back(obj);
1036  }
1037  }
1038 
1039  if (fByAccounts)
1040  {
1041  for (map<string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
1042  {
1043  int64_t nAmount = (*it).second.nAmount;
1044  int nConf = (*it).second.nConf;
1045  Object obj;
1046  if((*it).second.fIsWatchonly)
1047  obj.push_back(Pair("involvesWatchonly", true));
1048  obj.push_back(Pair("account", (*it).first));
1049  obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1050  obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1051  ret.push_back(obj);
1052  }
1053  }
1054 
1055  return ret;
1056 }
1057 
1058 Value listreceivedbyaddress(const Array& params, bool fHelp)
1059 {
1060  if (fHelp || params.size() > 3)
1061  throw runtime_error(
1062  "listreceivedbyaddress ( minconf includeempty includeWatchonly)\n"
1063  "\nList balances by receiving address.\n"
1064  "\nArguments:\n"
1065  "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1066  "2. includeempty (numeric, optional, dafault=false) Whether to include addresses that haven't received any payments.\n"
1067  "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
1068 
1069  "\nResult:\n"
1070  "[\n"
1071  " {\n"
1072  " \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n"
1073  " \"address\" : \"receivingaddress\", (string) The receiving address\n"
1074  " \"account\" : \"accountname\", (string) The account of the receiving address. The default account is \"\".\n"
1075  " \"amount\" : x.xxx, (numeric) The total amount in btc received by the address\n"
1076  " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
1077  " }\n"
1078  " ,...\n"
1079  "]\n"
1080 
1081  "\nExamples:\n"
1082  + HelpExampleCli("listreceivedbyaddress", "")
1083  + HelpExampleCli("listreceivedbyaddress", "6 true")
1084  + HelpExampleRpc("listreceivedbyaddress", "6, true, true")
1085  );
1086 
1087  return ListReceived(params, false);
1088 }
1089 
1090 Value listreceivedbyaccount(const Array& params, bool fHelp)
1091 {
1092  if (fHelp || params.size() > 3)
1093  throw runtime_error(
1094  "listreceivedbyaccount ( minconf includeempty includeWatchonly)\n"
1095  "\nList balances by account.\n"
1096  "\nArguments:\n"
1097  "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1098  "2. includeempty (boolean, optional, default=false) Whether to include accounts that haven't received any payments.\n"
1099  "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
1100 
1101  "\nResult:\n"
1102  "[\n"
1103  " {\n"
1104  " \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n"
1105  " \"account\" : \"accountname\", (string) The account name of the receiving account\n"
1106  " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
1107  " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
1108  " }\n"
1109  " ,...\n"
1110  "]\n"
1111 
1112  "\nExamples:\n"
1113  + HelpExampleCli("listreceivedbyaccount", "")
1114  + HelpExampleCli("listreceivedbyaccount", "6 true")
1115  + HelpExampleRpc("listreceivedbyaccount", "6, true, true")
1116  );
1117 
1118  return ListReceived(params, true);
1119 }
1120 
1121 static void MaybePushAddress(Object & entry, const CTxDestination &dest)
1122 {
1123  CAnoncoinAddress addr;
1124  if (addr.Set(dest))
1125  entry.push_back(Pair("address", addr.ToString()));
1126 }
1127 
1128 void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter)
1129 {
1130  int64_t nFee;
1131  string strSentAccount;
1132  list<pair<CTxDestination, int64_t> > listReceived;
1133  list<pair<CTxDestination, int64_t> > listSent;
1134 
1135  wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
1136 
1137  bool fAllAccounts = (strAccount == string("*"));
1138  bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
1139 
1140  // Sent
1141  if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
1142  {
1143  BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
1144  {
1145  Object entry;
1146  if(involvesWatchonly || (::IsMine(*pwalletMain, s.first) & ISMINE_WATCH_ONLY))
1147  entry.push_back(Pair("involvesWatchonly", true));
1148  entry.push_back(Pair("account", strSentAccount));
1149  MaybePushAddress(entry, s.first);
1150  entry.push_back(Pair("category", "send"));
1151  entry.push_back(Pair("amount", ValueFromAmount(-s.second)));
1152  entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
1153  if (fLong)
1154  WalletTxToJSON(wtx, entry);
1155  ret.push_back(entry);
1156  }
1157  }
1158 
1159  // Received
1160  if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
1161  {
1162  BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived)
1163  {
1164  string account;
1165  if (pwalletMain->mapAddressBook.count(r.first))
1166  account = pwalletMain->mapAddressBook[r.first].name;
1167  if (fAllAccounts || (account == strAccount))
1168  {
1169  Object entry;
1170  if(involvesWatchonly || (::IsMine(*pwalletMain, r.first) & ISMINE_WATCH_ONLY))
1171  entry.push_back(Pair("involvesWatchonly", true));
1172  entry.push_back(Pair("account", account));
1173  MaybePushAddress(entry, r.first);
1174  if (wtx.IsCoinBase())
1175  {
1176  if (wtx.GetDepthInMainChain() < 1)
1177  entry.push_back(Pair("category", "orphan"));
1178  else if (wtx.GetBlocksToMaturity() > 0)
1179  entry.push_back(Pair("category", "immature"));
1180  else
1181  entry.push_back(Pair("category", "generate"));
1182  }
1183  else
1184  {
1185  entry.push_back(Pair("category", "receive"));
1186  }
1187  entry.push_back(Pair("amount", ValueFromAmount(r.second)));
1188  if (fLong)
1189  WalletTxToJSON(wtx, entry);
1190  ret.push_back(entry);
1191  }
1192  }
1193  }
1194 }
1195 
1196 void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Array& ret)
1197 {
1198  bool fAllAccounts = (strAccount == string("*"));
1199 
1200  if (fAllAccounts || acentry.strAccount == strAccount)
1201  {
1202  Object entry;
1203  entry.push_back(Pair("account", acentry.strAccount));
1204  entry.push_back(Pair("category", "move"));
1205  entry.push_back(Pair("time", acentry.nTime));
1206  entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit)));
1207  entry.push_back(Pair("otheraccount", acentry.strOtherAccount));
1208  entry.push_back(Pair("comment", acentry.strComment));
1209  ret.push_back(entry);
1210  }
1211 }
1212 
1213 Value listtransactions(const Array& params, bool fHelp)
1214 {
1215  if (fHelp || params.size() > 4)
1216  throw runtime_error(
1217  "listtransactions ( \"account\" count from includeWatchonly)\n"
1218  "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
1219  "\nArguments:\n"
1220  "1. \"account\" (string, optional) The account name. If not included, it will list all transactions for all accounts.\n"
1221  " If \"\" is set, it will list transactions for the default account.\n"
1222  "2. count (numeric, optional, default=10) The number of transactions to return\n"
1223  "3. from (numeric, optional, default=0) The number of transactions to skip\n"
1224  "4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')\n"
1225  "\nResult:\n"
1226  "[\n"
1227  " {\n"
1228  " \"account\":\"accountname\", (string) The account name associated with the transaction. \n"
1229  " It will be \"\" for the default account.\n"
1230  " \"address\":\"anoncoinaddress\", (string) The anoncoin address of the transaction. Not present for \n"
1231  " move transactions (category = move).\n"
1232  " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
1233  " transaction between accounts, and not associated with an address,\n"
1234  " transaction id or block. 'send' and 'receive' transactions are \n"
1235  " associated with an address, transaction id and block details\n"
1236  " \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the\n"
1237  " 'move' category for moves outbound. It is positive for the 'receive' category,\n"
1238  " and for the 'move' category for inbound funds.\n"
1239  " \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the \n"
1240  " 'send' category of transactions.\n"
1241  " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n"
1242  " 'receive' category of transactions.\n"
1243  " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
1244  " category of transactions.\n"
1245  " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n"
1246  " category of transactions.\n"
1247  " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1248  " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
1249  " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
1250  " for 'send' and 'receive' category of transactions.\n"
1251  " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1252  " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n"
1253  " from (for receiving funds, positive amounts), or went to (for sending funds,\n"
1254  " negative amounts).\n"
1255  " }\n"
1256  "]\n"
1257 
1258  "\nExamples:\n"
1259  "\nList the most recent 10 transactions in the systems\n"
1260  + HelpExampleCli("listtransactions", "") +
1261  "\nList the most recent 10 transactions for the tabby account\n"
1262  + HelpExampleCli("listtransactions", "\"tabby\"") +
1263  "\nList transactions 100 to 120 from the tabby account\n"
1264  + HelpExampleCli("listtransactions", "\"tabby\" 20 100") +
1265  "\nAs a json rpc call\n"
1266  + HelpExampleRpc("listtransactions", "\"tabby\", 20, 100")
1267  );
1268 
1269  string strAccount = "*";
1270  if (params.size() > 0)
1271  strAccount = params[0].get_str();
1272  int nCount = 10;
1273  if (params.size() > 1)
1274  nCount = params[1].get_int();
1275  int nFrom = 0;
1276  if (params.size() > 2)
1277  nFrom = params[2].get_int();
1278  isminefilter filter = ISMINE_SPENDABLE;
1279  if(params.size() > 3)
1280  if(params[3].get_bool())
1281  filter = filter | ISMINE_WATCH_ONLY;
1282 
1283  if (nCount < 0)
1284  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
1285  if (nFrom < 0)
1286  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
1287 
1288  Array ret;
1289 
1290  std::list<CAccountingEntry> acentries;
1291  CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(acentries, strAccount);
1292 
1293  // iterate backwards until we have nCount items to return:
1294  for (CWallet::TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
1295  {
1296  CWalletTx *const pwtx = (*it).second.first;
1297  if (pwtx != 0)
1298  ListTransactions(*pwtx, strAccount, 0, true, ret, filter);
1299  CAccountingEntry *const pacentry = (*it).second.second;
1300  if (pacentry != 0)
1301  AcentryToJSON(*pacentry, strAccount, ret);
1302 
1303  if ((int)ret.size() >= (nCount+nFrom)) break;
1304  }
1305  // ret is newest to oldest
1306 
1307  if (nFrom > (int)ret.size())
1308  nFrom = ret.size();
1309  if ((nFrom + nCount) > (int)ret.size())
1310  nCount = ret.size() - nFrom;
1311  Array::iterator first = ret.begin();
1312  std::advance(first, nFrom);
1313  Array::iterator last = ret.begin();
1314  std::advance(last, nFrom+nCount);
1315 
1316  if (last != ret.end()) ret.erase(last, ret.end());
1317  if (first != ret.begin()) ret.erase(ret.begin(), first);
1318 
1319  std::reverse(ret.begin(), ret.end()); // Return oldest to newest
1320 
1321  return ret;
1322 }
1323 
1324 Value listaccounts(const Array& params, bool fHelp)
1325 {
1326  if (fHelp || params.size() > 2)
1327  throw runtime_error(
1328  "listaccounts ( minconf includeWatchonly)\n"
1329  "\nReturns Object that has account names as keys, account balances as values.\n"
1330  "\nArguments:\n"
1331  "1. minconf (numeric, optional, default=1) Only onclude transactions with at least this many confirmations\n"
1332  "2. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n"
1333  "\nResult:\n"
1334  "{ (json object where keys are account names, and values are numeric balances\n"
1335  " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
1336  " ...\n"
1337  "}\n"
1338  "\nExamples:\n"
1339  "\nList account balances where there at least 1 confirmation\n"
1340  + HelpExampleCli("listaccounts", "") +
1341  "\nList account balances including zero confirmation transactions\n"
1342  + HelpExampleCli("listaccounts", "0") +
1343  "\nList account balances for 6 or more confirmations\n"
1344  + HelpExampleCli("listaccounts", "6") +
1345  "\nAs json rpc call\n"
1346  + HelpExampleRpc("listaccounts", "6")
1347  );
1348 
1349  int nMinDepth = 1;
1350  if (params.size() > 0)
1351  nMinDepth = params[0].get_int();
1352  isminefilter includeWatchonly = ISMINE_SPENDABLE;
1353  if(params.size() > 1)
1354  if(params[1].get_bool())
1355  includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
1356 
1357  map<string, int64_t> mapAccountBalances;
1358  BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
1359  if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
1360  mapAccountBalances[entry.second.name] = 0;
1361  }
1362 
1363  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
1364  {
1365  const CWalletTx& wtx = (*it).second;
1366  int64_t nFee;
1367  string strSentAccount;
1368  list<pair<CTxDestination, int64_t> > listReceived;
1369  list<pair<CTxDestination, int64_t> > listSent;
1370  int nDepth = wtx.GetDepthInMainChain();
1371  if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
1372  continue;
1373  wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
1374  mapAccountBalances[strSentAccount] -= nFee;
1375  BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
1376  mapAccountBalances[strSentAccount] -= s.second;
1377  if (nDepth >= nMinDepth)
1378  {
1379  BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived)
1380  if (pwalletMain->mapAddressBook.count(r.first))
1381  mapAccountBalances[pwalletMain->mapAddressBook[r.first].name] += r.second;
1382  else
1383  mapAccountBalances[""] += r.second;
1384  }
1385  }
1386 
1387  list<CAccountingEntry> acentries;
1389  BOOST_FOREACH(const CAccountingEntry& entry, acentries)
1390  mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
1391 
1392  Object ret;
1393  BOOST_FOREACH(const PAIRTYPE(string, int64_t)& accountBalance, mapAccountBalances) {
1394  ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
1395  }
1396  return ret;
1397 }
1398 
1399 Value listsinceblock(const Array& params, bool fHelp)
1400 {
1401  if (fHelp)
1402  throw runtime_error(
1403  "listsinceblock ( \"blockhash\" target-confirmations includeWatchonly)\n"
1404  "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
1405  "\nArguments:\n"
1406  "1. \"blockhash\" (string, optional) The block hash to list transactions since\n"
1407  "2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more\n"
1408  "3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')"
1409  "\nResult:\n"
1410  "{\n"
1411  " \"transactions\": [\n"
1412  " \"account\":\"accountname\", (string) The account name associated with the transaction. Will be \"\" for the default account.\n"
1413  " \"address\":\"anoncoinaddress\", (string) The anoncoin address of the transaction. Not present for move transactions (category = move).\n"
1414  " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
1415  " \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the 'move' category for moves \n"
1416  " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
1417  " \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the 'send' category of transactions.\n"
1418  " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
1419  " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
1420  " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
1421  " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
1422  " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1423  " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n"
1424  " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n"
1425  " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1426  " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n"
1427  " ],\n"
1428  " \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n"
1429  "}\n"
1430  "\nExamples:\n"
1431  + HelpExampleCli("listsinceblock", "")
1432  + HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6")
1433  + HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6")
1434  );
1435 
1436  CBlockIndex *pindex = NULL;
1437  int target_confirms = 1;
1438  isminefilter filter = ISMINE_SPENDABLE;
1439 
1440  if (params.size() > 0)
1441  {
1442  uint256 blockId = 0;
1443 
1444  blockId.SetHex(params[0].get_str());
1445  std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(blockId);
1446  if (it != mapBlockIndex.end())
1447  pindex = it->second;
1448  }
1449 
1450  if (params.size() > 1)
1451  {
1452  target_confirms = params[1].get_int();
1453 
1454  if (target_confirms < 1)
1455  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
1456  }
1457 
1458  if(params.size() > 2)
1459  if(params[2].get_bool())
1460  filter = filter | ISMINE_WATCH_ONLY;
1461 
1462  int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
1463 
1464  Array transactions;
1465 
1466  for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++)
1467  {
1468  CWalletTx tx = (*it).second;
1469 
1470  if (depth == -1 || tx.GetDepthInMainChain() < depth)
1471  ListTransactions(tx, "*", 0, true, transactions, filter);
1472  }
1473 
1474  CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
1475  uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : 0;
1476 
1477  Object ret;
1478  ret.push_back(Pair("transactions", transactions));
1479  ret.push_back(Pair("lastblock", lastblock.GetHex()));
1480 
1481  return ret;
1482 }
1483 
1484 Value gettransaction(const Array& params, bool fHelp)
1485 {
1486  if (fHelp || params.size() < 1 || params.size() > 2)
1487  throw runtime_error(
1488  "gettransaction \"txid\" ( includeWatchonly )\n"
1489  "\nGet detailed information about in-wallet transaction <txid>\n"
1490  "\nArguments:\n"
1491  "1. \"txid\" (string, required) The transaction id\n"
1492  "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n"
1493  "\nResult:\n"
1494  "{\n"
1495  " \"amount\" : x.xxx, (numeric) The transaction amount in btc\n"
1496  " \"confirmations\" : n, (numeric) The number of confirmations\n"
1497  " \"blockhash\" : \"hash\", (string) The block hash\n"
1498  " \"blockindex\" : xx, (numeric) The block index\n"
1499  " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n"
1500  " \"txid\" : \"transactionid\", (string) The transaction id.\n"
1501  " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n"
1502  " \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n"
1503  " \"details\" : [\n"
1504  " {\n"
1505  " \"account\" : \"accountname\", (string) The account name involved in the transaction, can be \"\" for the default account.\n"
1506  " \"address\" : \"anoncoinaddress\", (string) The anoncoin address involved in the transaction\n"
1507  " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
1508  " \"amount\" : x.xxx (numeric) The amount in btc\n"
1509  " }\n"
1510  " ,...\n"
1511  " ],\n"
1512  " \"hex\" : \"data\" (string) Raw data for transaction\n"
1513  "}\n"
1514 
1515  "\nbExamples\n"
1516  + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1517  + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
1518  + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1519  );
1520 
1521  uint256 hash;
1522  hash.SetHex(params[0].get_str());
1523 
1524  isminefilter filter = ISMINE_SPENDABLE;
1525  if(params.size() > 1)
1526  if(params[1].get_bool())
1527  filter = filter | ISMINE_WATCH_ONLY;
1528 
1529  Object entry;
1530  if (!pwalletMain->mapWallet.count(hash))
1531  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
1532  const CWalletTx& wtx = pwalletMain->mapWallet[hash];
1533 
1534  int64_t nCredit = wtx.GetCredit(filter);
1535  int64_t nDebit = wtx.GetDebit(filter);
1536  int64_t nNet = nCredit - nDebit;
1537  int64_t nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
1538 
1539  entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
1540  if (wtx.IsFromMe(filter))
1541  entry.push_back(Pair("fee", ValueFromAmount(nFee)));
1542 
1543  WalletTxToJSON(wtx, entry);
1544 
1545  Array details;
1546  ListTransactions(wtx, "*", 0, false, details, filter);
1547  entry.push_back(Pair("details", details));
1548 
1549  CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
1550  ssTx << static_cast<CTransaction>(wtx);
1551  string strHex = HexStr(ssTx.begin(), ssTx.end());
1552  entry.push_back(Pair("hex", strHex));
1553 
1554  return entry;
1555 }
1556 
1557 
1558 Value backupwallet(const Array& params, bool fHelp)
1559 {
1560  if (fHelp || params.size() != 1)
1561  throw runtime_error(
1562  "backupwallet \"destination\"\n"
1563  "\nSafely copies wallet.dat to destination, which can be a directory or a path with filename.\n"
1564  "\nArguments:\n"
1565  "1. \"destination\" (string) The destination directory or file\n"
1566  "\nExamples:\n"
1567  + HelpExampleCli("backupwallet", "\"backup.dat\"")
1568  + HelpExampleRpc("backupwallet", "\"backup.dat\"")
1569  );
1570 
1571  string strDest = params[0].get_str();
1572  if (!BackupWallet(*pwalletMain, strDest))
1573  throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
1574 
1575  return Value::null;
1576 }
1577 
1578 
1579 Value keypoolrefill(const Array& params, bool fHelp)
1580 {
1581  if (fHelp || params.size() > 1)
1582  throw runtime_error(
1583  "keypoolrefill ( newsize )\n"
1584  "\nFills the keypool."
1585  + HelpRequiringPassphrase() + "\n"
1586  "\nArguments\n"
1587  "1. newsize (numeric, optional, default=100) The new keypool size\n"
1588  "\nExamples:\n"
1589  + HelpExampleCli("keypoolrefill", "")
1590  + HelpExampleRpc("keypoolrefill", "")
1591  );
1592 
1593  // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
1594  unsigned int kpSize = 0;
1595  if (params.size() > 0) {
1596  if (params[0].get_int() < 0)
1597  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
1598  kpSize = (unsigned int)params[0].get_int();
1599  }
1600 
1602  pwalletMain->TopUpKeyPool(kpSize);
1603 
1604  if (pwalletMain->GetKeyPoolSize() < kpSize)
1605  throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
1606 
1607  return Value::null;
1608 }
1609 
1610 
1611 static void LockWallet(CWallet* pWallet)
1612 {
1613  LOCK(cs_nWalletUnlockTime);
1614  nWalletUnlockTime = 0;
1615  pWallet->Lock();
1616 }
1617 
1618 Value walletpassphrase(const Array& params, bool fHelp)
1619 {
1620  if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
1621  throw runtime_error(
1622  "walletpassphrase \"passphrase\" timeout\n"
1623  "\nStores the wallet decryption key in memory for 'timeout' seconds.\n"
1624  "This is needed prior to performing transactions related to private keys such as sending anoncoins\n"
1625  "\nArguments:\n"
1626  "1. \"passphrase\" (string, required) The wallet passphrase\n"
1627  "2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
1628  "\nNote:\n"
1629  "Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
1630  "time that overrides the old one.\n"
1631  "\nExamples:\n"
1632  "\nunlock the wallet for 60 seconds\n"
1633  + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") +
1634  "\nLock the wallet again (before 60 seconds)\n"
1635  + HelpExampleCli("walletlock", "") +
1636  "\nAs json rpc call\n"
1637  + HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")
1638  );
1639 
1640  if (fHelp)
1641  return true;
1642  if (!pwalletMain->IsCrypted())
1643  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
1644 
1645  // Note that the walletpassphrase is stored in params[0] which is not mlock()ed
1646  SecureString strWalletPass;
1647  strWalletPass.reserve(100);
1648  // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
1649  // Alternately, find a way to make params[0] mlock()'d to begin with.
1650  strWalletPass = params[0].get_str().c_str();
1651 
1652  if (strWalletPass.length() > 0)
1653  {
1654  if (!pwalletMain->Unlock(strWalletPass))
1655  throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
1656  }
1657  else
1658  throw runtime_error(
1659  "walletpassphrase <passphrase> <timeout>\n"
1660  "Stores the wallet decryption key in memory for <timeout> seconds.");
1661 
1663 
1664  int64_t nSleepTime = params[1].get_int64();
1665  LOCK(cs_nWalletUnlockTime);
1666  nWalletUnlockTime = GetTime() + nSleepTime;
1667  RPCRunLater("lockwallet", boost::bind(LockWallet, pwalletMain), nSleepTime);
1668 
1669  return Value::null;
1670 }
1671 
1672 
1673 Value walletpassphrasechange(const Array& params, bool fHelp)
1674 {
1675  if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
1676  throw runtime_error(
1677  "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n"
1678  "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n"
1679  "\nArguments:\n"
1680  "1. \"oldpassphrase\" (string) The current passphrase\n"
1681  "2. \"newpassphrase\" (string) The new passphrase\n"
1682  "\nExamples:\n"
1683  + HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"")
1684  + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"")
1685  );
1686 
1687  if (fHelp)
1688  return true;
1689  if (!pwalletMain->IsCrypted())
1690  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
1691 
1692  // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
1693  // Alternately, find a way to make params[0] mlock()'d to begin with.
1694  SecureString strOldWalletPass;
1695  strOldWalletPass.reserve(100);
1696  strOldWalletPass = params[0].get_str().c_str();
1697 
1698  SecureString strNewWalletPass;
1699  strNewWalletPass.reserve(100);
1700  strNewWalletPass = params[1].get_str().c_str();
1701 
1702  if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
1703  throw runtime_error(
1704  "walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
1705  "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
1706 
1707  if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass))
1708  throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
1709 
1710  return Value::null;
1711 }
1712 
1713 
1714 Value walletlock(const Array& params, bool fHelp)
1715 {
1716  if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0))
1717  throw runtime_error(
1718  "walletlock\n"
1719  "\nRemoves the wallet encryption key from memory, locking the wallet.\n"
1720  "After calling this method, you will need to call walletpassphrase again\n"
1721  "before being able to call any methods which require the wallet to be unlocked.\n"
1722  "\nExamples:\n"
1723  "\nSet the passphrase for 2 minutes to perform a transaction\n"
1724  + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") +
1725  "\nPerform a send (requires passphrase set)\n"
1726  + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") +
1727  "\nClear the passphrase since we are done before 2 minutes is up\n"
1728  + HelpExampleCli("walletlock", "") +
1729  "\nAs json rpc call\n"
1730  + HelpExampleRpc("walletlock", "")
1731  );
1732 
1733  if (fHelp)
1734  return true;
1735  if (!pwalletMain->IsCrypted())
1736  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
1737 
1738  {
1739  LOCK(cs_nWalletUnlockTime);
1740  pwalletMain->Lock();
1741  nWalletUnlockTime = 0;
1742  }
1743 
1744  return Value::null;
1745 }
1746 
1747 
1748 Value encryptwallet(const Array& params, bool fHelp)
1749 {
1750  if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1))
1751  throw runtime_error(
1752  "encryptwallet \"passphrase\"\n"
1753  "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n"
1754  "After this, any calls that interact with private keys such as sending or signing \n"
1755  "will require the passphrase to be set prior the making these calls.\n"
1756  "Use the walletpassphrase call for this, and then walletlock call.\n"
1757  "If the wallet is already encrypted, use the walletpassphrasechange call.\n"
1758  "Note that this will shutdown the server.\n"
1759  "\nArguments:\n"
1760  "1. \"passphrase\" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.\n"
1761  "\nExamples:\n"
1762  "\nEncrypt you wallet\n"
1763  + HelpExampleCli("encryptwallet", "\"my pass phrase\"") +
1764  "\nNow set the passphrase to use the wallet, such as for signing or sending anoncoin\n"
1765  + HelpExampleCli("walletpassphrase", "\"my pass phrase\"") +
1766  "\nNow we can so something like sign\n"
1767  + HelpExampleCli("signmessage", "\"anoncoinaddress\" \"test message\"") +
1768  "\nNow lock the wallet again by removing the passphrase\n"
1769  + HelpExampleCli("walletlock", "") +
1770  "\nAs a json rpc call\n"
1771  + HelpExampleRpc("encryptwallet", "\"my pass phrase\"")
1772  );
1773 
1774  if (fHelp)
1775  return true;
1776  if (pwalletMain->IsCrypted())
1777  throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
1778 
1779  // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
1780  // Alternately, find a way to make params[0] mlock()'d to begin with.
1781  SecureString strWalletPass;
1782  strWalletPass.reserve(100);
1783  strWalletPass = params[0].get_str().c_str();
1784 
1785  if (strWalletPass.length() < 1)
1786  throw runtime_error(
1787  "encryptwallet <passphrase>\n"
1788  "Encrypts the wallet with <passphrase>.");
1789 
1790  if (!pwalletMain->EncryptWallet(strWalletPass))
1791  throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
1792 
1793  // BDB seems to have a bad habit of writing old data into
1794  // slack space in .dat files; that is bad if the old data is
1795  // unencrypted private keys. So:
1796  StartShutdown();
1797  return "wallet encrypted; Anoncoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
1798 }
1799 
1800 Value lockunspent(const Array& params, bool fHelp)
1801 {
1802  if (fHelp || params.size() < 1 || params.size() > 2)
1803  throw runtime_error(
1804  "lockunspent unlock [{\"txid\":\"txid\",\"vout\":n},...]\n"
1805  "\nUpdates list of temporarily unspendable outputs.\n"
1806  "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
1807  "A locked transaction output will not be chosen by automatic coin selection, when spending anoncoins.\n"
1808  "Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n"
1809  "is always cleared (by virtue of process exit) when a node stops or fails.\n"
1810  "Also see the listunspent call\n"
1811  "\nArguments:\n"
1812  "1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions\n"
1813  "2. \"transactions\" (string, required) A json array of objects. Each object the txid (string) vout (numeric)\n"
1814  " [ (json array of json objects)\n"
1815  " {\n"
1816  " \"txid\":\"id\", (string) The transaction id\n"
1817  " \"vout\": n (numeric) The output number\n"
1818  " }\n"
1819  " ,...\n"
1820  " ]\n"
1821 
1822  "\nResult:\n"
1823  "true|false (boolean) Whether the command was successful or not\n"
1824 
1825  "\nExamples:\n"
1826  "\nList the unspent transactions\n"
1827  + HelpExampleCli("listunspent", "") +
1828  "\nLock an unspent transaction\n"
1829  + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
1830  "\nList the locked transactions\n"
1831  + HelpExampleCli("listlockunspent", "") +
1832  "\nUnlock the transaction again\n"
1833  + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
1834  "\nAs a json rpc call\n"
1835  + HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
1836  );
1837 
1838  if (params.size() == 1)
1839  RPCTypeCheck(params, list_of(bool_type));
1840  else
1841  RPCTypeCheck(params, list_of(bool_type)(array_type));
1842 
1843  bool fUnlock = params[0].get_bool();
1844 
1845  if (params.size() == 1) {
1846  if (fUnlock)
1848  return true;
1849  }
1850 
1851  Array outputs = params[1].get_array();
1852  BOOST_FOREACH(Value& output, outputs)
1853  {
1854  if (output.type() != obj_type)
1855  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
1856  const Object& o = output.get_obj();
1857 
1858  RPCTypeCheck(o, map_list_of("txid", str_type)("vout", int_type));
1859 
1860  string txid = find_value(o, "txid").get_str();
1861  if (!IsHex(txid))
1862  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid");
1863 
1864  int nOutput = find_value(o, "vout").get_int();
1865  if (nOutput < 0)
1866  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
1867 
1868  COutPoint outpt(uint256(txid), nOutput);
1869 
1870  if (fUnlock)
1871  pwalletMain->UnlockCoin(outpt);
1872  else
1873  pwalletMain->LockCoin(outpt);
1874  }
1875 
1876  return true;
1877 }
1878 
1879 Value listlockunspent(const Array& params, bool fHelp)
1880 {
1881  if (fHelp || params.size() > 0)
1882  throw runtime_error(
1883  "listlockunspent\n"
1884  "\nReturns list of temporarily unspendable outputs.\n"
1885  "See the lockunspent call to lock and unlock transactions for spending.\n"
1886  "\nResult:\n"
1887  "[\n"
1888  " {\n"
1889  " \"txid\" : \"transactionid\", (string) The transaction id locked\n"
1890  " \"vout\" : n (numeric) The vout value\n"
1891  " }\n"
1892  " ,...\n"
1893  "]\n"
1894  "\nExamples:\n"
1895  "\nList the unspent transactions\n"
1896  + HelpExampleCli("listunspent", "") +
1897  "\nLock an unspent transaction\n"
1898  + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
1899  "\nList the locked transactions\n"
1900  + HelpExampleCli("listlockunspent", "") +
1901  "\nUnlock the transaction again\n"
1902  + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
1903  "\nAs a json rpc call\n"
1904  + HelpExampleRpc("listlockunspent", "")
1905  );
1906 
1907  vector<COutPoint> vOutpts;
1908  pwalletMain->ListLockedCoins(vOutpts);
1909 
1910  Array ret;
1911 
1912  BOOST_FOREACH(COutPoint &outpt, vOutpts) {
1913  Object o;
1914 
1915  o.push_back(Pair("txid", outpt.hash.GetHex()));
1916  o.push_back(Pair("vout", (int)outpt.n));
1917  ret.push_back(o);
1918  }
1919 
1920  return ret;
1921 }
1922 
1923 Value settxfee(const Array& params, bool fHelp)
1924 {
1925  if (fHelp || params.size() < 1 || params.size() > 1)
1926  throw runtime_error(
1927  "settxfee amount\n"
1928  "\nSet the transaction fee per kB.\n"
1929  "\nArguments:\n"
1930  "1. amount (numeric, required) The transaction fee in ANC/kB rounded to the nearest 0.00000001\n"
1931  "\nResult\n"
1932  "true|false (boolean) Returns true if successful\n"
1933  "\nExamples:\n"
1934  + HelpExampleCli("settxfee", "0.00001")
1935  + HelpExampleRpc("settxfee", "0.00001")
1936  );
1937 
1938  // Amount
1939  int64_t nAmount = 0;
1940  if (params[0].get_real() != 0.0)
1941  nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts
1942 
1943  nTransactionFee = nAmount;
1944  return true;
1945 }
1946 
1947 Value getwalletinfo(const Array& params, bool fHelp)
1948 {
1949  if (fHelp || params.size() != 0)
1950  throw runtime_error(
1951  "getwalletinfo\n"
1952  "Returns an object containing various wallet state info.\n"
1953  "\nResult:\n"
1954  "{\n"
1955  " \"walletversion\": xxxxx, (numeric) the wallet version\n"
1956  " \"balance\": xxxxxxx, (numeric) the total anoncoin balance of the wallet\n"
1957  " \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
1958  " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
1959  " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
1960  " \"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"
1961  "}\n"
1962  "\nExamples:\n"
1963  + HelpExampleCli("getwalletinfo", "")
1964  + HelpExampleRpc("getwalletinfo", "")
1965  );
1966 
1967  Object obj;
1968  obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
1969  obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
1970  obj.push_back(Pair("txcount", (int)pwalletMain->mapWallet.size()));
1971  obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
1972  obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
1973  if (pwalletMain->IsCrypted())
1974  obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
1975  return obj;
1976 }
Value getaccount(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:247
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Definition: main.cpp:617
Value sendmany(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:798
void SetHex(const char *psz)
Definition: uint256.h:306
void GetAmounts(std::list< std::pair< CTxDestination, int64_t > > &listReceived, std::list< std::pair< CTxDestination, int64_t > > &listSent, int64_t &nFee, std::string &strSentAccount, const isminefilter &filter) const
Definition: wallet.cpp:789
Value keypoolrefill(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1579
int64_t GetValueOut() const
Definition: core.cpp:110
bool IsCrypted() const
Definition: crypter.h:138
Account information.
Definition: wallet.h:887
Value getreceivedbyaddress(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:450
int64_t nOrderPos
Definition: wallet.h:924
void RPCRunLater(const std::string &name, boost::function< void(void)> func, int64_t nSeconds)
Definition: rpcserver.cpp:682
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:1638
Value settxfee(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1923
bool WriteAccount(const std::string &strAccount, const CAccount &account)
Definition: walletdb.cpp:179
Value getaddressesbyaccount(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:274
const_iterator begin() const
Definition: serialize.h:933
void KeepKey()
Definition: wallet.cpp:2014
CScript scriptPubKey
Definition: core.h:125
bool Set(const CKeyID &id)
Definition: base58.cpp:202
Definition: init.h:14
int64_t nAmount
Definition: rpcwallet.cpp:928
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
Definition: wallet.cpp:2087
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:174
#define PAIRTYPE(t1, t2)
Definition: util.h:49
CCriticalSection cs_wallet
Main wallet lock.
Definition: wallet.h:133
int nIndex
Definition: main.h:444
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
Definition: script.cpp:1450
std::string strFromAccount
Definition: wallet.h:476
Value getwalletinfo(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1947
std::map< CTxDestination, int64_t > GetAddressBalances()
Definition: wallet.cpp:1846
std::string HelpExampleRpc(string methodname, string args)
Definition: rpcserver.cpp:903
void StartShutdown()
Definition: init.cpp:103
uint256 hashBlock
Definition: main.h:442
CTxDestination Get() const
Definition: base58.cpp:223
Value backupwallet(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1558
bool fIsWatchonly
Definition: rpcwallet.cpp:931
uint256 GetHash() const
Definition: core.cpp:76
bool GetKeyID(CKeyID &keyID) const
Definition: base58.cpp:236
bool IsLocked() const
Definition: crypter.h:143
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &acentries)
Definition: walletdb.cpp:206
unsigned int GetKeyPoolSize()
Definition: wallet.h:373
bool IsHex(const string &str)
Definition: util.cpp:409
Double ended buffer combining vector and stream-like interfaces.
Definition: serialize.h:848
std::string name
Definition: wallet.h:86
Object JSONRPCError(int code, const string &message)
Value getreceivedbyaccount(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:504
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry &acentry)
Definition: walletdb.cpp:184
unsigned int n
Definition: core.h:28
bool BackupWallet(const CWallet &wallet, const string &strDest)
Definition: walletdb.cpp:851
void RPCTypeCheck(const Array &params, const list< Value_type > &typesExpected, bool fAllowNull)
Definition: rpcserver.cpp:49
bool IsTrusted() const
Definition: wallet.h:784
bool GetKey(const CKeyID &address, CKey &keyOut) const
Definition: crypter.cpp:212
const string strMessageMagic
Definition: main.cpp:77
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:43
bool IsValid() const
Definition: base58.cpp:216
void EnsureWalletIsUnlocked()
Definition: rpcwallet.cpp:37
Value listlockunspent(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1879
bool TxnBegin()
Definition: db.h:266
Value ListReceived(const Array &params, bool fByAccounts)
Definition: rpcwallet.cpp:940
int64_t IncOrderPosNext(CWalletDB *pwalletdb=NULL)
Increment the next transaction order id.
Definition: wallet.cpp:475
mapValue_t mapValue
Definition: wallet.h:470
void SetDestination(const CTxDestination &address)
Definition: script.cpp:1945
std::multimap< int64_t, TxPair > TxItems
Definition: wallet.h:244
Value getunconfirmedbalance(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:662
Value listreceivedbyaddress(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1058
int64_t GetBalance() const
Definition: wallet.cpp:1019
void AcentryToJSON(const CAccountingEntry &acentry, const string &strAccount, Array &ret)
Definition: rpcwallet.cpp:1196
bool CreateTransaction(const std::vector< std::pair< CScript, int64_t > > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, int64_t &nFeeRet, std::string &strFailReason, const CCoinControl *coinControl=NULL)
int GetBlocksToMaturity() const
Definition: main.cpp:1059
std::string strComment
Definition: wallet.h:922
string EncodeBase64(const unsigned char *pch, size_t len)
Definition: util.cpp:548
Value lockunspent(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1800
int Height() const
Return the maximal height in the chain.
Definition: main.h:1055
int64_t GetAdjustedTime()
Definition: util.cpp:1241
Value listreceivedbyaccount(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1090
void LockCoin(COutPoint &output)
Definition: wallet.cpp:2061
Value ValueFromAmount(int64_t amount)
Definition: rpcserver.cpp:100
Value walletlock(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1714
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:205
int64_t nTransactionFee
Definition: wallet.cpp:20
int64_t GetAccountCreditDebit(const std::string &strAccount)
Definition: walletdb.cpp:194
Value getaccountaddress(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:152
int64_t GetOldestKeyPoolTime()
Definition: wallet.cpp:1835
int64_t nCreditDebit
Definition: wallet.h:919
#define LOCK(cs)
Definition: sync.h:157
Value walletpassphrase(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1618
std::vector< CTxOut > vout
Definition: core.h:187
Value sendfrom(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:737
int GetVersion()
Definition: wallet.h:388
void UnlockCoin(COutPoint &output)
Definition: wallet.cpp:2067
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: allocators.h:254
An encapsulated public key.
Definition: key.h:43
bool TxnCommit()
Definition: db.h:277
Value walletpassphrasechange(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1673
base58-encoded Anoncoin addresses.
Definition: base58.h:102
std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, CWalletTx &wtxNew)
Definition: wallet.cpp:1568
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:1722
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey)
Definition: wallet.cpp:1491
std::string ToString() const
Definition: base58.cpp:175
Value movecmd(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:672
An output of a transaction.
Definition: core.h:121
bool GetReservedKey(CPubKey &pubkey)
Definition: wallet.cpp:1993
std::set< std::set< CTxDestination > > GetAddressGroupings()
Definition: wallet.cpp:1886
int64_t GetAccountBalance(CWalletDB &walletdb, const string &strAccount, int nMinDepth, const isminefilter &filter)
Definition: rpcwallet.cpp:556
Value getrawchangeaddress(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:180
Value sendtoaddress(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:306
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.h:779
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: core.h:24
uint8_t isminefilter
used for bitflags of isminetype
Definition: script.h:205
string AccountFromValue(const Value &value)
Definition: rpcwallet.cpp:67
std::set< CTxDestination > GetAccountAddresses(std::string strAccount) const
Definition: wallet.cpp:1979
std::string GetHex() const
Definition: uint256.h:298
Value addmultisigaddress(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:882
int64_t GetTime()
Definition: util.cpp:1220
Access to the wallet database (wallet.dat)
Definition: walletdb.h:73
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:464
int64_t GetTxTime() const
Definition: wallet.cpp:744
std::string strWalletFile
Definition: wallet.h:136
CPubKey vchPubKey
Definition: wallet.h:890
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: keystore.h:17
int64_t GetCredit(const isminefilter &filter) const
Definition: wallet.h:644
int64_t GetDebit(const isminefilter &filter) const
Definition: wallet.h:613
uint256 GetHash()
Definition: hash.h:53
256-bit unsigned integer
Definition: uint256.h:532
CAnoncoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
Definition: rpcwallet.cpp:114
Value signmessage(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:399
int64_t GetUnconfirmedBalance() const
Definition: wallet.cpp:1035
CScript _createmultisig_redeemScript(const Array &params)
Definition: rpcmisc.cpp:195
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:394
A key allocated from the key pool.
Definition: wallet.h:415
Address book data.
Definition: wallet.h:83
bool SignCompact(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Definition: key.cpp:414
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: main.h:698
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:413
Value getnewaddress(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:75
vector< uint256 > txids
Definition: rpcwallet.cpp:930
void ListTransactions(const CWalletTx &wtx, const string &strAccount, int nMinDepth, bool fLong, Array &ret, const isminefilter &filter)
Definition: rpcwallet.cpp:1128
A reference to a CKey: the Hash160 of its serialized public key.
Definition: key.h:27
Internal transfers.
Definition: wallet.h:915
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: script.cpp:1513
int64_t nWalletUnlockTime
Definition: rpcwallet.cpp:27
bool Unlock(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:185
CScriptID GetID() const
Definition: script.h:720
void WalletTxToJSON(const CWalletTx &wtx, Object &entry)
Definition: rpcwallet.cpp:43
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:101
std::set< uint256 > GetConflicts() const
Definition: wallet.cpp:958
bool IsValid() const
Definition: key.h:144
int GetDepthInMainChain(CBlockIndex *&pindexRet) const
Definition: main.cpp:1049
std::string HelpRequiringPassphrase()
Definition: rpcwallet.cpp:30
int64_t AmountFromValue(const Value &value)
Definition: rpcserver.cpp:89
void UnlockAllCoins()
Definition: wallet.cpp:2073
Value listaccounts(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1324
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:169
Value gettransaction(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1484
Value listaddressgroupings(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:352
bool IsCoinBase() const
Definition: core.h:228
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: key.h:35
bool AddCScript(const CScript &redeemScript)
Definition: wallet.cpp:130
std::string HelpExampleCli(string methodname, string args)
Definition: rpcserver.cpp:899
Value listtransactions(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1213
bool GetKeyFromPool(CPubKey &key)
Definition: wallet.cpp:1816
void GetAccountAmounts(const std::string &strAccount, int64_t &nReceived, int64_t &nSent, int64_t &nFee, const isminefilter &filter) const
Definition: wallet.cpp:842
unsigned int nTimeReceived
Definition: wallet.h:473
An encapsulated private key.
Definition: key.h:180
int nHeight
Definition: main.h:708
Value listsinceblock(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1399
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: util.h:256
Value setaccount(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:210
Value getbalance(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:588
CKeyID GetID() const
Definition: key.h:132
Value encryptwallet(const Array &params, bool fHelp)
Definition: rpcwallet.cpp:1748
std::string strOtherAccount
Definition: wallet.h:921
map< uint256, CBlockIndex * > mapBlockIndex
Definition: main.cpp:42
bool ReadAccount(const std::string &strAccount, CAccount &account)
Definition: walletdb.cpp:173
int64_t nTime
Definition: wallet.h:920
CWallet * pwalletMain
uint256 GetBlockHash() const
Definition: main.h:815
int64_t nValue
Definition: core.h:124
const_iterator end() const
Definition: serialize.h:935
TxItems OrderedTxItems(std::list< CAccountingEntry > &acentries, std::string strAccount="")
Get the wallet's activity log.
Definition: wallet.cpp:487
uint256 hash
Definition: core.h:27
std::string strAccount
Definition: wallet.h:918