[wallet] [rpc] print wallet name in getwalletinfo
[bitcoinplatinum.git] / src / wallet / rpcwallet.cpp
blob030f203d26a6f2b636be7bbf3eed3bbc784e97e5
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "amount.h"
7 #include "base58.h"
8 #include "chain.h"
9 #include "consensus/validation.h"
10 #include "core_io.h"
11 #include "init.h"
12 #include "httpserver.h"
13 #include "validation.h"
14 #include "net.h"
15 #include "policy/feerate.h"
16 #include "policy/fees.h"
17 #include "policy/policy.h"
18 #include "policy/rbf.h"
19 #include "rpc/mining.h"
20 #include "rpc/server.h"
21 #include "script/sign.h"
22 #include "timedata.h"
23 #include "util.h"
24 #include "utilmoneystr.h"
25 #include "wallet/coincontrol.h"
26 #include "wallet/feebumper.h"
27 #include "wallet/wallet.h"
28 #include "wallet/walletdb.h"
30 #include <stdint.h>
32 #include <univalue.h>
34 static const std::string WALLET_ENDPOINT_BASE = "/wallet/";
36 CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
38 if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {
39 // wallet endpoint was used
40 std::string requestedWallet = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
41 for (CWalletRef pwallet : ::vpwallets) {
42 if (pwallet->GetName() == requestedWallet) {
43 return pwallet;
46 throw JSONRPCError(RPC_INVALID_PARAMETER, "Requested wallet does not exist or is not loaded");
48 return ::vpwallets.size() == 1 || (request.fHelp && ::vpwallets.size() > 0) ? ::vpwallets[0] : nullptr;
51 std::string HelpRequiringPassphrase(CWallet * const pwallet)
53 return pwallet && pwallet->IsCrypted()
54 ? "\nRequires wallet passphrase to be set with walletpassphrase call."
55 : "";
58 bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException)
60 if (!pwallet) {
61 if (!avoidException)
62 throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
63 else
64 return false;
66 return true;
69 void EnsureWalletIsUnlocked(CWallet * const pwallet)
71 if (pwallet->IsLocked()) {
72 throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
76 void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
78 int confirms = wtx.GetDepthInMainChain();
79 entry.push_back(Pair("confirmations", confirms));
80 if (wtx.IsCoinBase())
81 entry.push_back(Pair("generated", true));
82 if (confirms > 0)
84 entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
85 entry.push_back(Pair("blockindex", wtx.nIndex));
86 entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()));
87 } else {
88 entry.push_back(Pair("trusted", wtx.IsTrusted()));
90 uint256 hash = wtx.GetHash();
91 entry.push_back(Pair("txid", hash.GetHex()));
92 UniValue conflicts(UniValue::VARR);
93 for (const uint256& conflict : wtx.GetConflicts())
94 conflicts.push_back(conflict.GetHex());
95 entry.push_back(Pair("walletconflicts", conflicts));
96 entry.push_back(Pair("time", wtx.GetTxTime()));
97 entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
99 // Add opt-in RBF status
100 std::string rbfStatus = "no";
101 if (confirms <= 0) {
102 LOCK(mempool.cs);
103 RBFTransactionState rbfState = IsRBFOptIn(wtx, mempool);
104 if (rbfState == RBF_TRANSACTIONSTATE_UNKNOWN)
105 rbfStatus = "unknown";
106 else if (rbfState == RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125)
107 rbfStatus = "yes";
109 entry.push_back(Pair("bip125-replaceable", rbfStatus));
111 for (const std::pair<std::string, std::string>& item : wtx.mapValue)
112 entry.push_back(Pair(item.first, item.second));
115 std::string AccountFromValue(const UniValue& value)
117 std::string strAccount = value.get_str();
118 if (strAccount == "*")
119 throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name");
120 return strAccount;
123 UniValue getnewaddress(const JSONRPCRequest& request)
125 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
126 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
127 return NullUniValue;
130 if (request.fHelp || request.params.size() > 1)
131 throw std::runtime_error(
132 "getnewaddress ( \"account\" )\n"
133 "\nReturns a new Bitcoin address for receiving payments.\n"
134 "If 'account' is specified (DEPRECATED), it is added to the address book \n"
135 "so payments received with the address will be credited to 'account'.\n"
136 "\nArguments:\n"
137 "1. \"account\" (string, optional) DEPRECATED. The account name for the address to be linked to. If not provided, the default account \"\" is used. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created if there is no account by the given name.\n"
138 "\nResult:\n"
139 "\"address\" (string) The new bitcoin address\n"
140 "\nExamples:\n"
141 + HelpExampleCli("getnewaddress", "")
142 + HelpExampleRpc("getnewaddress", "")
145 LOCK2(cs_main, pwallet->cs_wallet);
147 // Parse the account first so we don't generate a key if there's an error
148 std::string strAccount;
149 if (!request.params[0].isNull())
150 strAccount = AccountFromValue(request.params[0]);
152 if (!pwallet->IsLocked()) {
153 pwallet->TopUpKeyPool();
156 // Generate a new key that is added to wallet
157 CPubKey newKey;
158 if (!pwallet->GetKeyFromPool(newKey)) {
159 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
161 CKeyID keyID = newKey.GetID();
163 pwallet->SetAddressBook(keyID, strAccount, "receive");
165 return CBitcoinAddress(keyID).ToString();
169 CBitcoinAddress GetAccountAddress(CWallet* const pwallet, std::string strAccount, bool bForceNew=false)
171 CPubKey pubKey;
172 if (!pwallet->GetAccountPubkey(pubKey, strAccount, bForceNew)) {
173 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
176 return CBitcoinAddress(pubKey.GetID());
179 UniValue getaccountaddress(const JSONRPCRequest& request)
181 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
182 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
183 return NullUniValue;
186 if (request.fHelp || request.params.size() != 1)
187 throw std::runtime_error(
188 "getaccountaddress \"account\"\n"
189 "\nDEPRECATED. Returns the current Bitcoin address for receiving payments to this account.\n"
190 "\nArguments:\n"
191 "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"
192 "\nResult:\n"
193 "\"address\" (string) The account bitcoin address\n"
194 "\nExamples:\n"
195 + HelpExampleCli("getaccountaddress", "")
196 + HelpExampleCli("getaccountaddress", "\"\"")
197 + HelpExampleCli("getaccountaddress", "\"myaccount\"")
198 + HelpExampleRpc("getaccountaddress", "\"myaccount\"")
201 LOCK2(cs_main, pwallet->cs_wallet);
203 // Parse the account first so we don't generate a key if there's an error
204 std::string strAccount = AccountFromValue(request.params[0]);
206 UniValue ret(UniValue::VSTR);
208 ret = GetAccountAddress(pwallet, strAccount).ToString();
209 return ret;
213 UniValue getrawchangeaddress(const JSONRPCRequest& request)
215 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
216 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
217 return NullUniValue;
220 if (request.fHelp || request.params.size() > 0)
221 throw std::runtime_error(
222 "getrawchangeaddress\n"
223 "\nReturns a new Bitcoin address, for receiving change.\n"
224 "This is for use with raw transactions, NOT normal use.\n"
225 "\nResult:\n"
226 "\"address\" (string) The address\n"
227 "\nExamples:\n"
228 + HelpExampleCli("getrawchangeaddress", "")
229 + HelpExampleRpc("getrawchangeaddress", "")
232 LOCK2(cs_main, pwallet->cs_wallet);
234 if (!pwallet->IsLocked()) {
235 pwallet->TopUpKeyPool();
238 CReserveKey reservekey(pwallet);
239 CPubKey vchPubKey;
240 if (!reservekey.GetReservedKey(vchPubKey, true))
241 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
243 reservekey.KeepKey();
245 CKeyID keyID = vchPubKey.GetID();
247 return CBitcoinAddress(keyID).ToString();
251 UniValue setaccount(const JSONRPCRequest& request)
253 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
254 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
255 return NullUniValue;
258 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
259 throw std::runtime_error(
260 "setaccount \"address\" \"account\"\n"
261 "\nDEPRECATED. Sets the account associated with the given address.\n"
262 "\nArguments:\n"
263 "1. \"address\" (string, required) The bitcoin address to be associated with an account.\n"
264 "2. \"account\" (string, required) The account to assign the address to.\n"
265 "\nExamples:\n"
266 + HelpExampleCli("setaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"")
267 + HelpExampleRpc("setaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")
270 LOCK2(cs_main, pwallet->cs_wallet);
272 CBitcoinAddress address(request.params[0].get_str());
273 if (!address.IsValid())
274 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
276 std::string strAccount;
277 if (request.params.size() > 1)
278 strAccount = AccountFromValue(request.params[1]);
280 // Only add the account if the address is yours.
281 if (IsMine(*pwallet, address.Get())) {
282 // Detect when changing the account of an address that is the 'unused current key' of another account:
283 if (pwallet->mapAddressBook.count(address.Get())) {
284 std::string strOldAccount = pwallet->mapAddressBook[address.Get()].name;
285 if (address == GetAccountAddress(pwallet, strOldAccount)) {
286 GetAccountAddress(pwallet, strOldAccount, true);
289 pwallet->SetAddressBook(address.Get(), strAccount, "receive");
291 else
292 throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address");
294 return NullUniValue;
298 UniValue getaccount(const JSONRPCRequest& request)
300 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
301 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
302 return NullUniValue;
305 if (request.fHelp || request.params.size() != 1)
306 throw std::runtime_error(
307 "getaccount \"address\"\n"
308 "\nDEPRECATED. Returns the account associated with the given address.\n"
309 "\nArguments:\n"
310 "1. \"address\" (string, required) The bitcoin address for account lookup.\n"
311 "\nResult:\n"
312 "\"accountname\" (string) the account address\n"
313 "\nExamples:\n"
314 + HelpExampleCli("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")
315 + HelpExampleRpc("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")
318 LOCK2(cs_main, pwallet->cs_wallet);
320 CBitcoinAddress address(request.params[0].get_str());
321 if (!address.IsValid())
322 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
324 std::string strAccount;
325 std::map<CTxDestination, CAddressBookData>::iterator mi = pwallet->mapAddressBook.find(address.Get());
326 if (mi != pwallet->mapAddressBook.end() && !(*mi).second.name.empty()) {
327 strAccount = (*mi).second.name;
329 return strAccount;
333 UniValue getaddressesbyaccount(const JSONRPCRequest& request)
335 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
336 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
337 return NullUniValue;
340 if (request.fHelp || request.params.size() != 1)
341 throw std::runtime_error(
342 "getaddressesbyaccount \"account\"\n"
343 "\nDEPRECATED. Returns the list of addresses for the given account.\n"
344 "\nArguments:\n"
345 "1. \"account\" (string, required) The account name.\n"
346 "\nResult:\n"
347 "[ (json array of string)\n"
348 " \"address\" (string) a bitcoin address associated with the given account\n"
349 " ,...\n"
350 "]\n"
351 "\nExamples:\n"
352 + HelpExampleCli("getaddressesbyaccount", "\"tabby\"")
353 + HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")
356 LOCK2(cs_main, pwallet->cs_wallet);
358 std::string strAccount = AccountFromValue(request.params[0]);
360 // Find all addresses that have the given account
361 UniValue ret(UniValue::VARR);
362 for (const std::pair<CBitcoinAddress, CAddressBookData>& item : pwallet->mapAddressBook) {
363 const CBitcoinAddress& address = item.first;
364 const std::string& strName = item.second.name;
365 if (strName == strAccount)
366 ret.push_back(address.ToString());
368 return ret;
371 static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, const CCoinControl& coin_control)
373 CAmount curBalance = pwallet->GetBalance();
375 // Check amount
376 if (nValue <= 0)
377 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
379 if (nValue > curBalance)
380 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
382 if (pwallet->GetBroadcastTransactions() && !g_connman) {
383 throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
386 // Parse Bitcoin address
387 CScript scriptPubKey = GetScriptForDestination(address);
389 // Create and send the transaction
390 CReserveKey reservekey(pwallet);
391 CAmount nFeeRequired;
392 std::string strError;
393 std::vector<CRecipient> vecSend;
394 int nChangePosRet = -1;
395 CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount};
396 vecSend.push_back(recipient);
397 if (!pwallet->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError, coin_control)) {
398 if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance)
399 strError = strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired));
400 throw JSONRPCError(RPC_WALLET_ERROR, strError);
402 CValidationState state;
403 if (!pwallet->CommitTransaction(wtxNew, reservekey, g_connman.get(), state)) {
404 strError = strprintf("Error: The transaction was rejected! Reason given: %s", state.GetRejectReason());
405 throw JSONRPCError(RPC_WALLET_ERROR, strError);
409 UniValue sendtoaddress(const JSONRPCRequest& request)
411 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
412 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
413 return NullUniValue;
416 if (request.fHelp || request.params.size() < 2 || request.params.size() > 8)
417 throw std::runtime_error(
418 "sendtoaddress \"address\" amount ( \"comment\" \"comment_to\" subtractfeefromamount replaceable conf_target \"estimate_mode\")\n"
419 "\nSend an amount to a given address.\n"
420 + HelpRequiringPassphrase(pwallet) +
421 "\nArguments:\n"
422 "1. \"address\" (string, required) The bitcoin address to send to.\n"
423 "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n"
424 "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
425 " This is not part of the transaction, just kept in your wallet.\n"
426 "4. \"comment_to\" (string, optional) A comment to store the name of the person or organization \n"
427 " to which you're sending the transaction. This is not part of the \n"
428 " transaction, just kept in your wallet.\n"
429 "5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
430 " The recipient will receive less bitcoins than you enter in the amount field.\n"
431 "6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125\n"
432 "7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
433 "8. \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
434 " \"UNSET\"\n"
435 " \"ECONOMICAL\"\n"
436 " \"CONSERVATIVE\"\n"
437 "\nResult:\n"
438 "\"txid\" (string) The transaction id.\n"
439 "\nExamples:\n"
440 + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1")
441 + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"donation\" \"seans outpost\"")
442 + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"\" \"\" true")
443 + HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.1, \"donation\", \"seans outpost\"")
446 LOCK2(cs_main, pwallet->cs_wallet);
448 CBitcoinAddress address(request.params[0].get_str());
449 if (!address.IsValid())
450 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
452 // Amount
453 CAmount nAmount = AmountFromValue(request.params[1]);
454 if (nAmount <= 0)
455 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
457 // Wallet comments
458 CWalletTx wtx;
459 if (request.params.size() > 2 && !request.params[2].isNull() && !request.params[2].get_str().empty())
460 wtx.mapValue["comment"] = request.params[2].get_str();
461 if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty())
462 wtx.mapValue["to"] = request.params[3].get_str();
464 bool fSubtractFeeFromAmount = false;
465 if (request.params.size() > 4 && !request.params[4].isNull()) {
466 fSubtractFeeFromAmount = request.params[4].get_bool();
469 CCoinControl coin_control;
470 if (request.params.size() > 5 && !request.params[5].isNull()) {
471 coin_control.signalRbf = request.params[5].get_bool();
474 if (request.params.size() > 6 && !request.params[6].isNull()) {
475 coin_control.m_confirm_target = ParseConfirmTarget(request.params[6]);
478 if (request.params.size() > 7 && !request.params[7].isNull()) {
479 if (!FeeModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) {
480 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
485 EnsureWalletIsUnlocked(pwallet);
487 SendMoney(pwallet, address.Get(), nAmount, fSubtractFeeFromAmount, wtx, coin_control);
489 return wtx.GetHash().GetHex();
492 UniValue listaddressgroupings(const JSONRPCRequest& request)
494 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
495 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
496 return NullUniValue;
499 if (request.fHelp || request.params.size() != 0)
500 throw std::runtime_error(
501 "listaddressgroupings\n"
502 "\nLists groups of addresses which have had their common ownership\n"
503 "made public by common use as inputs or as the resulting change\n"
504 "in past transactions\n"
505 "\nResult:\n"
506 "[\n"
507 " [\n"
508 " [\n"
509 " \"address\", (string) The bitcoin address\n"
510 " amount, (numeric) The amount in " + CURRENCY_UNIT + "\n"
511 " \"account\" (string, optional) DEPRECATED. The account\n"
512 " ]\n"
513 " ,...\n"
514 " ]\n"
515 " ,...\n"
516 "]\n"
517 "\nExamples:\n"
518 + HelpExampleCli("listaddressgroupings", "")
519 + HelpExampleRpc("listaddressgroupings", "")
522 LOCK2(cs_main, pwallet->cs_wallet);
524 UniValue jsonGroupings(UniValue::VARR);
525 std::map<CTxDestination, CAmount> balances = pwallet->GetAddressBalances();
526 for (std::set<CTxDestination> grouping : pwallet->GetAddressGroupings()) {
527 UniValue jsonGrouping(UniValue::VARR);
528 for (CTxDestination address : grouping)
530 UniValue addressInfo(UniValue::VARR);
531 addressInfo.push_back(CBitcoinAddress(address).ToString());
532 addressInfo.push_back(ValueFromAmount(balances[address]));
534 if (pwallet->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwallet->mapAddressBook.end()) {
535 addressInfo.push_back(pwallet->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name);
538 jsonGrouping.push_back(addressInfo);
540 jsonGroupings.push_back(jsonGrouping);
542 return jsonGroupings;
545 UniValue signmessage(const JSONRPCRequest& request)
547 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
548 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
549 return NullUniValue;
552 if (request.fHelp || request.params.size() != 2)
553 throw std::runtime_error(
554 "signmessage \"address\" \"message\"\n"
555 "\nSign a message with the private key of an address"
556 + HelpRequiringPassphrase(pwallet) + "\n"
557 "\nArguments:\n"
558 "1. \"address\" (string, required) The bitcoin address to use for the private key.\n"
559 "2. \"message\" (string, required) The message to create a signature of.\n"
560 "\nResult:\n"
561 "\"signature\" (string) The signature of the message encoded in base 64\n"
562 "\nExamples:\n"
563 "\nUnlock the wallet for 30 seconds\n"
564 + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
565 "\nCreate the signature\n"
566 + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
567 "\nVerify the signature\n"
568 + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
569 "\nAs json rpc\n"
570 + HelpExampleRpc("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")
573 LOCK2(cs_main, pwallet->cs_wallet);
575 EnsureWalletIsUnlocked(pwallet);
577 std::string strAddress = request.params[0].get_str();
578 std::string strMessage = request.params[1].get_str();
580 CBitcoinAddress addr(strAddress);
581 if (!addr.IsValid())
582 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
584 CKeyID keyID;
585 if (!addr.GetKeyID(keyID))
586 throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
588 CKey key;
589 if (!pwallet->GetKey(keyID, key)) {
590 throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
593 CHashWriter ss(SER_GETHASH, 0);
594 ss << strMessageMagic;
595 ss << strMessage;
597 std::vector<unsigned char> vchSig;
598 if (!key.SignCompact(ss.GetHash(), vchSig))
599 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
601 return EncodeBase64(&vchSig[0], vchSig.size());
604 UniValue getreceivedbyaddress(const JSONRPCRequest& request)
606 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
607 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
608 return NullUniValue;
611 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
612 throw std::runtime_error(
613 "getreceivedbyaddress \"address\" ( minconf )\n"
614 "\nReturns the total amount received by the given address in transactions with at least minconf confirmations.\n"
615 "\nArguments:\n"
616 "1. \"address\" (string, required) The bitcoin address for transactions.\n"
617 "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
618 "\nResult:\n"
619 "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n"
620 "\nExamples:\n"
621 "\nThe amount from transactions with at least 1 confirmation\n"
622 + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"") +
623 "\nThe amount including unconfirmed transactions, zero confirmations\n"
624 + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 0") +
625 "\nThe amount with at least 6 confirmation, very safe\n"
626 + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 6") +
627 "\nAs a json rpc call\n"
628 + HelpExampleRpc("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6")
631 LOCK2(cs_main, pwallet->cs_wallet);
633 // Bitcoin address
634 CBitcoinAddress address = CBitcoinAddress(request.params[0].get_str());
635 if (!address.IsValid())
636 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
637 CScript scriptPubKey = GetScriptForDestination(address.Get());
638 if (!IsMine(*pwallet, scriptPubKey)) {
639 return ValueFromAmount(0);
642 // Minimum confirmations
643 int nMinDepth = 1;
644 if (!request.params[1].isNull())
645 nMinDepth = request.params[1].get_int();
647 // Tally
648 CAmount nAmount = 0;
649 for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
650 const CWalletTx& wtx = pairWtx.second;
651 if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
652 continue;
654 for (const CTxOut& txout : wtx.tx->vout)
655 if (txout.scriptPubKey == scriptPubKey)
656 if (wtx.GetDepthInMainChain() >= nMinDepth)
657 nAmount += txout.nValue;
660 return ValueFromAmount(nAmount);
664 UniValue getreceivedbyaccount(const JSONRPCRequest& request)
666 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
667 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
668 return NullUniValue;
671 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
672 throw std::runtime_error(
673 "getreceivedbyaccount \"account\" ( minconf )\n"
674 "\nDEPRECATED. Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.\n"
675 "\nArguments:\n"
676 "1. \"account\" (string, required) The selected account, may be the default account using \"\".\n"
677 "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
678 "\nResult:\n"
679 "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
680 "\nExamples:\n"
681 "\nAmount received by the default account with at least 1 confirmation\n"
682 + HelpExampleCli("getreceivedbyaccount", "\"\"") +
683 "\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n"
684 + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") +
685 "\nThe amount with at least 6 confirmation, very safe\n"
686 + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") +
687 "\nAs a json rpc call\n"
688 + HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6")
691 LOCK2(cs_main, pwallet->cs_wallet);
693 // Minimum confirmations
694 int nMinDepth = 1;
695 if (!request.params[1].isNull())
696 nMinDepth = request.params[1].get_int();
698 // Get the set of pub keys assigned to account
699 std::string strAccount = AccountFromValue(request.params[0]);
700 std::set<CTxDestination> setAddress = pwallet->GetAccountAddresses(strAccount);
702 // Tally
703 CAmount nAmount = 0;
704 for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
705 const CWalletTx& wtx = pairWtx.second;
706 if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
707 continue;
709 for (const CTxOut& txout : wtx.tx->vout)
711 CTxDestination address;
712 if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwallet, address) && setAddress.count(address)) {
713 if (wtx.GetDepthInMainChain() >= nMinDepth)
714 nAmount += txout.nValue;
719 return ValueFromAmount(nAmount);
723 UniValue getbalance(const JSONRPCRequest& request)
725 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
726 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
727 return NullUniValue;
730 if (request.fHelp || request.params.size() > 3)
731 throw std::runtime_error(
732 "getbalance ( \"account\" minconf include_watchonly )\n"
733 "\nIf account is not specified, returns the server's total available balance.\n"
734 "If account is specified (DEPRECATED), returns the balance in the account.\n"
735 "Note that the account \"\" is not the same as leaving the parameter out.\n"
736 "The server total may be different to the balance in the default \"\" account.\n"
737 "\nArguments:\n"
738 "1. \"account\" (string, optional) DEPRECATED. The account string may be given as a\n"
739 " specific account name to find the balance associated with wallet keys in\n"
740 " a named account, or as the empty string (\"\") to find the balance\n"
741 " associated with wallet keys not in any named account, or as \"*\" to find\n"
742 " the balance associated with all wallet keys regardless of account.\n"
743 " When this option is specified, it calculates the balance in a different\n"
744 " way than when it is not specified, and which can count spends twice when\n"
745 " there are conflicting pending transactions (such as those created by\n"
746 " the bumpfee command), temporarily resulting in low or even negative\n"
747 " balances. In general, account balance calculation is not considered\n"
748 " reliable and has resulted in confusing outcomes, so it is recommended to\n"
749 " avoid passing this argument.\n"
750 "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
751 "3. include_watchonly (bool, optional, default=false) Also include balance in watch-only addresses (see 'importaddress')\n"
752 "\nResult:\n"
753 "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
754 "\nExamples:\n"
755 "\nThe total amount in the wallet with 1 or more confirmations\n"
756 + HelpExampleCli("getbalance", "") +
757 "\nThe total amount in the wallet at least 6 blocks confirmed\n"
758 + HelpExampleCli("getbalance", "\"*\" 6") +
759 "\nAs a json rpc call\n"
760 + HelpExampleRpc("getbalance", "\"*\", 6")
763 LOCK2(cs_main, pwallet->cs_wallet);
765 if (request.params.size() == 0)
766 return ValueFromAmount(pwallet->GetBalance());
768 const std::string& account_param = request.params[0].get_str();
769 const std::string* account = account_param != "*" ? &account_param : nullptr;
771 int nMinDepth = 1;
772 if (!request.params[1].isNull())
773 nMinDepth = request.params[1].get_int();
774 isminefilter filter = ISMINE_SPENDABLE;
775 if(!request.params[2].isNull())
776 if(request.params[2].get_bool())
777 filter = filter | ISMINE_WATCH_ONLY;
779 return ValueFromAmount(pwallet->GetLegacyBalance(filter, nMinDepth, account));
782 UniValue getunconfirmedbalance(const JSONRPCRequest &request)
784 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
785 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
786 return NullUniValue;
789 if (request.fHelp || request.params.size() > 0)
790 throw std::runtime_error(
791 "getunconfirmedbalance\n"
792 "Returns the server's total unconfirmed balance\n");
794 LOCK2(cs_main, pwallet->cs_wallet);
796 return ValueFromAmount(pwallet->GetUnconfirmedBalance());
800 UniValue movecmd(const JSONRPCRequest& request)
802 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
803 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
804 return NullUniValue;
807 if (request.fHelp || request.params.size() < 3 || request.params.size() > 5)
808 throw std::runtime_error(
809 "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
810 "\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n"
811 "\nArguments:\n"
812 "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
813 "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
814 "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n"
815 "4. (dummy) (numeric, optional) Ignored. Remains for backward compatibility.\n"
816 "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
817 "\nResult:\n"
818 "true|false (boolean) true if successful.\n"
819 "\nExamples:\n"
820 "\nMove 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby\n"
821 + HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
822 "\nMove 0.01 " + CURRENCY_UNIT + " timotei to akiko with a comment and funds have 6 confirmations\n"
823 + HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") +
824 "\nAs a json rpc call\n"
825 + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")
828 LOCK2(cs_main, pwallet->cs_wallet);
830 std::string strFrom = AccountFromValue(request.params[0]);
831 std::string strTo = AccountFromValue(request.params[1]);
832 CAmount nAmount = AmountFromValue(request.params[2]);
833 if (nAmount <= 0)
834 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
835 if (request.params.size() > 3)
836 // unused parameter, used to be nMinDepth, keep type-checking it though
837 (void)request.params[3].get_int();
838 std::string strComment;
839 if (request.params.size() > 4)
840 strComment = request.params[4].get_str();
842 if (!pwallet->AccountMove(strFrom, strTo, nAmount, strComment)) {
843 throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
846 return true;
850 UniValue sendfrom(const JSONRPCRequest& request)
852 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
853 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
854 return NullUniValue;
857 if (request.fHelp || request.params.size() < 3 || request.params.size() > 6)
858 throw std::runtime_error(
859 "sendfrom \"fromaccount\" \"toaddress\" amount ( minconf \"comment\" \"comment_to\" )\n"
860 "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a bitcoin address."
861 + HelpRequiringPassphrase(pwallet) + "\n"
862 "\nArguments:\n"
863 "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n"
864 " Specifying an account does not influence coin selection, but it does associate the newly created\n"
865 " transaction with the account, so the account's balance computation and transaction history can reflect\n"
866 " the spend.\n"
867 "2. \"toaddress\" (string, required) The bitcoin address to send funds to.\n"
868 "3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n"
869 "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
870 "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
871 " This is not part of the transaction, just kept in your wallet.\n"
872 "6. \"comment_to\" (string, optional) An optional comment to store the name of the person or organization \n"
873 " to which you're sending the transaction. This is not part of the transaction, \n"
874 " it is just kept in your wallet.\n"
875 "\nResult:\n"
876 "\"txid\" (string) The transaction id.\n"
877 "\nExamples:\n"
878 "\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n"
879 + HelpExampleCli("sendfrom", "\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") +
880 "\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n"
881 + HelpExampleCli("sendfrom", "\"tabby\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 6 \"donation\" \"seans outpost\"") +
882 "\nAs a json rpc call\n"
883 + HelpExampleRpc("sendfrom", "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.01, 6, \"donation\", \"seans outpost\"")
886 LOCK2(cs_main, pwallet->cs_wallet);
888 std::string strAccount = AccountFromValue(request.params[0]);
889 CBitcoinAddress address(request.params[1].get_str());
890 if (!address.IsValid())
891 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
892 CAmount nAmount = AmountFromValue(request.params[2]);
893 if (nAmount <= 0)
894 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
895 int nMinDepth = 1;
896 if (request.params.size() > 3)
897 nMinDepth = request.params[3].get_int();
899 CWalletTx wtx;
900 wtx.strFromAccount = strAccount;
901 if (request.params.size() > 4 && !request.params[4].isNull() && !request.params[4].get_str().empty())
902 wtx.mapValue["comment"] = request.params[4].get_str();
903 if (request.params.size() > 5 && !request.params[5].isNull() && !request.params[5].get_str().empty())
904 wtx.mapValue["to"] = request.params[5].get_str();
906 EnsureWalletIsUnlocked(pwallet);
908 // Check funds
909 CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
910 if (nAmount > nBalance)
911 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
913 CCoinControl no_coin_control; // This is a deprecated API
914 SendMoney(pwallet, address.Get(), nAmount, false, wtx, no_coin_control);
916 return wtx.GetHash().GetHex();
920 UniValue sendmany(const JSONRPCRequest& request)
922 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
923 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
924 return NullUniValue;
927 if (request.fHelp || request.params.size() < 2 || request.params.size() > 8)
928 throw std::runtime_error(
929 "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] replaceable conf_target \"estimate_mode\")\n"
930 "\nSend multiple times. Amounts are double-precision floating point numbers."
931 + HelpRequiringPassphrase(pwallet) + "\n"
932 "\nArguments:\n"
933 "1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n"
934 "2. \"amounts\" (string, required) A json object with addresses and amounts\n"
935 " {\n"
936 " \"address\":amount (numeric or string) The bitcoin address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value\n"
937 " ,...\n"
938 " }\n"
939 "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
940 "4. \"comment\" (string, optional) A comment\n"
941 "5. subtractfeefrom (array, optional) A json array with addresses.\n"
942 " The fee will be equally deducted from the amount of each selected address.\n"
943 " Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
944 " If no addresses are specified here, the sender pays the fee.\n"
945 " [\n"
946 " \"address\" (string) Subtract fee from this address\n"
947 " ,...\n"
948 " ]\n"
949 "6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125\n"
950 "7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
951 "8. \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
952 " \"UNSET\"\n"
953 " \"ECONOMICAL\"\n"
954 " \"CONSERVATIVE\"\n"
955 "\nResult:\n"
956 "\"txid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
957 " the number of addresses.\n"
958 "\nExamples:\n"
959 "\nSend two amounts to two different addresses:\n"
960 + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"") +
961 "\nSend two amounts to two different addresses setting the confirmation and comment:\n"
962 + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 6 \"testing\"") +
963 "\nSend two amounts to two different addresses, subtract fee from amount:\n"
964 + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 1 \"\" \"[\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\",\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") +
965 "\nAs a json rpc call\n"
966 + HelpExampleRpc("sendmany", "\"\", \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\", 6, \"testing\"")
969 LOCK2(cs_main, pwallet->cs_wallet);
971 if (pwallet->GetBroadcastTransactions() && !g_connman) {
972 throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
975 std::string strAccount = AccountFromValue(request.params[0]);
976 UniValue sendTo = request.params[1].get_obj();
977 int nMinDepth = 1;
978 if (!request.params[2].isNull())
979 nMinDepth = request.params[2].get_int();
981 CWalletTx wtx;
982 wtx.strFromAccount = strAccount;
983 if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty())
984 wtx.mapValue["comment"] = request.params[3].get_str();
986 UniValue subtractFeeFromAmount(UniValue::VARR);
987 if (request.params.size() > 4 && !request.params[4].isNull())
988 subtractFeeFromAmount = request.params[4].get_array();
990 CCoinControl coin_control;
991 if (request.params.size() > 5 && !request.params[5].isNull()) {
992 coin_control.signalRbf = request.params[5].get_bool();
995 if (request.params.size() > 6 && !request.params[6].isNull()) {
996 coin_control.m_confirm_target = ParseConfirmTarget(request.params[6]);
999 if (request.params.size() > 7 && !request.params[7].isNull()) {
1000 if (!FeeModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) {
1001 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
1005 std::set<CBitcoinAddress> setAddress;
1006 std::vector<CRecipient> vecSend;
1008 CAmount totalAmount = 0;
1009 std::vector<std::string> keys = sendTo.getKeys();
1010 for (const std::string& name_ : keys)
1012 CBitcoinAddress address(name_);
1013 if (!address.IsValid())
1014 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ")+name_);
1016 if (setAddress.count(address))
1017 throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+name_);
1018 setAddress.insert(address);
1020 CScript scriptPubKey = GetScriptForDestination(address.Get());
1021 CAmount nAmount = AmountFromValue(sendTo[name_]);
1022 if (nAmount <= 0)
1023 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
1024 totalAmount += nAmount;
1026 bool fSubtractFeeFromAmount = false;
1027 for (unsigned int idx = 0; idx < subtractFeeFromAmount.size(); idx++) {
1028 const UniValue& addr = subtractFeeFromAmount[idx];
1029 if (addr.get_str() == name_)
1030 fSubtractFeeFromAmount = true;
1033 CRecipient recipient = {scriptPubKey, nAmount, fSubtractFeeFromAmount};
1034 vecSend.push_back(recipient);
1037 EnsureWalletIsUnlocked(pwallet);
1039 // Check funds
1040 CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
1041 if (totalAmount > nBalance)
1042 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
1044 // Send
1045 CReserveKey keyChange(pwallet);
1046 CAmount nFeeRequired = 0;
1047 int nChangePosRet = -1;
1048 std::string strFailReason;
1049 bool fCreated = pwallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason, coin_control);
1050 if (!fCreated)
1051 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
1052 CValidationState state;
1053 if (!pwallet->CommitTransaction(wtx, keyChange, g_connman.get(), state)) {
1054 strFailReason = strprintf("Transaction commit failed:: %s", state.GetRejectReason());
1055 throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
1058 return wtx.GetHash().GetHex();
1061 // Defined in rpc/misc.cpp
1062 extern CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& params);
1064 UniValue addmultisigaddress(const JSONRPCRequest& request)
1066 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1067 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1068 return NullUniValue;
1071 if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
1073 std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
1074 "\nAdd a nrequired-to-sign multisignature address to the wallet.\n"
1075 "Each key is a Bitcoin address or hex-encoded public key.\n"
1076 "If 'account' is specified (DEPRECATED), assign address to that account.\n"
1078 "\nArguments:\n"
1079 "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
1080 "2. \"keys\" (string, required) A json array of bitcoin addresses or hex-encoded public keys\n"
1081 " [\n"
1082 " \"address\" (string) bitcoin address or hex-encoded public key\n"
1083 " ...,\n"
1084 " ]\n"
1085 "3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n"
1087 "\nResult:\n"
1088 "\"address\" (string) A bitcoin address associated with the keys.\n"
1090 "\nExamples:\n"
1091 "\nAdd a multisig address from 2 addresses\n"
1092 + HelpExampleCli("addmultisigaddress", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
1093 "\nAs json rpc call\n"
1094 + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
1096 throw std::runtime_error(msg);
1099 LOCK2(cs_main, pwallet->cs_wallet);
1101 std::string strAccount;
1102 if (request.params.size() > 2)
1103 strAccount = AccountFromValue(request.params[2]);
1105 // Construct using pay-to-script-hash:
1106 CScript inner = _createmultisig_redeemScript(pwallet, request.params);
1107 CScriptID innerID(inner);
1108 pwallet->AddCScript(inner);
1110 pwallet->SetAddressBook(innerID, strAccount, "send");
1111 return CBitcoinAddress(innerID).ToString();
1114 class Witnessifier : public boost::static_visitor<bool>
1116 public:
1117 CWallet * const pwallet;
1118 CScriptID result;
1120 Witnessifier(CWallet *_pwallet) : pwallet(_pwallet) {}
1122 bool operator()(const CNoDestination &dest) const { return false; }
1124 bool operator()(const CKeyID &keyID) {
1125 if (pwallet) {
1126 CScript basescript = GetScriptForDestination(keyID);
1127 isminetype typ;
1128 typ = IsMine(*pwallet, basescript, SIGVERSION_WITNESS_V0);
1129 if (typ != ISMINE_SPENDABLE && typ != ISMINE_WATCH_SOLVABLE)
1130 return false;
1131 CScript witscript = GetScriptForWitness(basescript);
1132 pwallet->AddCScript(witscript);
1133 result = CScriptID(witscript);
1134 return true;
1136 return false;
1139 bool operator()(const CScriptID &scriptID) {
1140 CScript subscript;
1141 if (pwallet && pwallet->GetCScript(scriptID, subscript)) {
1142 int witnessversion;
1143 std::vector<unsigned char> witprog;
1144 if (subscript.IsWitnessProgram(witnessversion, witprog)) {
1145 result = scriptID;
1146 return true;
1148 isminetype typ;
1149 typ = IsMine(*pwallet, subscript, SIGVERSION_WITNESS_V0);
1150 if (typ != ISMINE_SPENDABLE && typ != ISMINE_WATCH_SOLVABLE)
1151 return false;
1152 CScript witscript = GetScriptForWitness(subscript);
1153 pwallet->AddCScript(witscript);
1154 result = CScriptID(witscript);
1155 return true;
1157 return false;
1161 UniValue addwitnessaddress(const JSONRPCRequest& request)
1163 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1164 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1165 return NullUniValue;
1168 if (request.fHelp || request.params.size() < 1 || request.params.size() > 1)
1170 std::string msg = "addwitnessaddress \"address\"\n"
1171 "\nAdd a witness address for a script (with pubkey or redeemscript known).\n"
1172 "It returns the witness script.\n"
1174 "\nArguments:\n"
1175 "1. \"address\" (string, required) An address known to the wallet\n"
1177 "\nResult:\n"
1178 "\"witnessaddress\", (string) The value of the new address (P2SH of witness script).\n"
1179 "}\n"
1181 throw std::runtime_error(msg);
1185 LOCK(cs_main);
1186 if (!IsWitnessEnabled(chainActive.Tip(), Params().GetConsensus()) && !GetBoolArg("-walletprematurewitness", false)) {
1187 throw JSONRPCError(RPC_WALLET_ERROR, "Segregated witness not enabled on network");
1191 CBitcoinAddress address(request.params[0].get_str());
1192 if (!address.IsValid())
1193 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
1195 Witnessifier w(pwallet);
1196 CTxDestination dest = address.Get();
1197 bool ret = boost::apply_visitor(w, dest);
1198 if (!ret) {
1199 throw JSONRPCError(RPC_WALLET_ERROR, "Public key or redeemscript not known to wallet, or the key is uncompressed");
1202 pwallet->SetAddressBook(w.result, "", "receive");
1204 return CBitcoinAddress(w.result).ToString();
1207 struct tallyitem
1209 CAmount nAmount;
1210 int nConf;
1211 std::vector<uint256> txids;
1212 bool fIsWatchonly;
1213 tallyitem()
1215 nAmount = 0;
1216 nConf = std::numeric_limits<int>::max();
1217 fIsWatchonly = false;
1221 UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bool fByAccounts)
1223 // Minimum confirmations
1224 int nMinDepth = 1;
1225 if (!params[0].isNull())
1226 nMinDepth = params[0].get_int();
1228 // Whether to include empty accounts
1229 bool fIncludeEmpty = false;
1230 if (!params[1].isNull())
1231 fIncludeEmpty = params[1].get_bool();
1233 isminefilter filter = ISMINE_SPENDABLE;
1234 if(!params[2].isNull())
1235 if(params[2].get_bool())
1236 filter = filter | ISMINE_WATCH_ONLY;
1238 // Tally
1239 std::map<CBitcoinAddress, tallyitem> mapTally;
1240 for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
1241 const CWalletTx& wtx = pairWtx.second;
1243 if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
1244 continue;
1246 int nDepth = wtx.GetDepthInMainChain();
1247 if (nDepth < nMinDepth)
1248 continue;
1250 for (const CTxOut& txout : wtx.tx->vout)
1252 CTxDestination address;
1253 if (!ExtractDestination(txout.scriptPubKey, address))
1254 continue;
1256 isminefilter mine = IsMine(*pwallet, address);
1257 if(!(mine & filter))
1258 continue;
1260 tallyitem& item = mapTally[address];
1261 item.nAmount += txout.nValue;
1262 item.nConf = std::min(item.nConf, nDepth);
1263 item.txids.push_back(wtx.GetHash());
1264 if (mine & ISMINE_WATCH_ONLY)
1265 item.fIsWatchonly = true;
1269 // Reply
1270 UniValue ret(UniValue::VARR);
1271 std::map<std::string, tallyitem> mapAccountTally;
1272 for (const std::pair<CBitcoinAddress, CAddressBookData>& item : pwallet->mapAddressBook) {
1273 const CBitcoinAddress& address = item.first;
1274 const std::string& strAccount = item.second.name;
1275 std::map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address);
1276 if (it == mapTally.end() && !fIncludeEmpty)
1277 continue;
1279 CAmount nAmount = 0;
1280 int nConf = std::numeric_limits<int>::max();
1281 bool fIsWatchonly = false;
1282 if (it != mapTally.end())
1284 nAmount = (*it).second.nAmount;
1285 nConf = (*it).second.nConf;
1286 fIsWatchonly = (*it).second.fIsWatchonly;
1289 if (fByAccounts)
1291 tallyitem& _item = mapAccountTally[strAccount];
1292 _item.nAmount += nAmount;
1293 _item.nConf = std::min(_item.nConf, nConf);
1294 _item.fIsWatchonly = fIsWatchonly;
1296 else
1298 UniValue obj(UniValue::VOBJ);
1299 if(fIsWatchonly)
1300 obj.push_back(Pair("involvesWatchonly", true));
1301 obj.push_back(Pair("address", address.ToString()));
1302 obj.push_back(Pair("account", strAccount));
1303 obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1304 obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1305 if (!fByAccounts)
1306 obj.push_back(Pair("label", strAccount));
1307 UniValue transactions(UniValue::VARR);
1308 if (it != mapTally.end())
1310 for (const uint256& _item : (*it).second.txids)
1312 transactions.push_back(_item.GetHex());
1315 obj.push_back(Pair("txids", transactions));
1316 ret.push_back(obj);
1320 if (fByAccounts)
1322 for (std::map<std::string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
1324 CAmount nAmount = (*it).second.nAmount;
1325 int nConf = (*it).second.nConf;
1326 UniValue obj(UniValue::VOBJ);
1327 if((*it).second.fIsWatchonly)
1328 obj.push_back(Pair("involvesWatchonly", true));
1329 obj.push_back(Pair("account", (*it).first));
1330 obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1331 obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1332 ret.push_back(obj);
1336 return ret;
1339 UniValue listreceivedbyaddress(const JSONRPCRequest& request)
1341 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1342 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1343 return NullUniValue;
1346 if (request.fHelp || request.params.size() > 3)
1347 throw std::runtime_error(
1348 "listreceivedbyaddress ( minconf include_empty include_watchonly)\n"
1349 "\nList balances by receiving address.\n"
1350 "\nArguments:\n"
1351 "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1352 "2. include_empty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n"
1353 "3. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress').\n"
1355 "\nResult:\n"
1356 "[\n"
1357 " {\n"
1358 " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
1359 " \"address\" : \"receivingaddress\", (string) The receiving address\n"
1360 " \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n"
1361 " \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address\n"
1362 " \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n"
1363 " \"label\" : \"label\", (string) A comment for the address/transaction, if any\n"
1364 " \"txids\": [\n"
1365 " n, (numeric) The ids of transactions received with the address \n"
1366 " ...\n"
1367 " ]\n"
1368 " }\n"
1369 " ,...\n"
1370 "]\n"
1372 "\nExamples:\n"
1373 + HelpExampleCli("listreceivedbyaddress", "")
1374 + HelpExampleCli("listreceivedbyaddress", "6 true")
1375 + HelpExampleRpc("listreceivedbyaddress", "6, true, true")
1378 LOCK2(cs_main, pwallet->cs_wallet);
1380 return ListReceived(pwallet, request.params, false);
1383 UniValue listreceivedbyaccount(const JSONRPCRequest& request)
1385 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1386 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1387 return NullUniValue;
1390 if (request.fHelp || request.params.size() > 3)
1391 throw std::runtime_error(
1392 "listreceivedbyaccount ( minconf include_empty include_watchonly)\n"
1393 "\nDEPRECATED. List balances by account.\n"
1394 "\nArguments:\n"
1395 "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1396 "2. include_empty (bool, optional, default=false) Whether to include accounts that haven't received any payments.\n"
1397 "3. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress').\n"
1399 "\nResult:\n"
1400 "[\n"
1401 " {\n"
1402 " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
1403 " \"account\" : \"accountname\", (string) The account name of the receiving account\n"
1404 " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
1405 " \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n"
1406 " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
1407 " }\n"
1408 " ,...\n"
1409 "]\n"
1411 "\nExamples:\n"
1412 + HelpExampleCli("listreceivedbyaccount", "")
1413 + HelpExampleCli("listreceivedbyaccount", "6 true")
1414 + HelpExampleRpc("listreceivedbyaccount", "6, true, true")
1417 LOCK2(cs_main, pwallet->cs_wallet);
1419 return ListReceived(pwallet, request.params, true);
1422 static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
1424 CBitcoinAddress addr;
1425 if (addr.Set(dest))
1426 entry.push_back(Pair("address", addr.ToString()));
1429 void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, const std::string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter)
1431 CAmount nFee;
1432 std::string strSentAccount;
1433 std::list<COutputEntry> listReceived;
1434 std::list<COutputEntry> listSent;
1436 wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
1438 bool fAllAccounts = (strAccount == std::string("*"));
1439 bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
1441 // Sent
1442 if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
1444 for (const COutputEntry& s : listSent)
1446 UniValue entry(UniValue::VOBJ);
1447 if (involvesWatchonly || (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) {
1448 entry.push_back(Pair("involvesWatchonly", true));
1450 entry.push_back(Pair("account", strSentAccount));
1451 MaybePushAddress(entry, s.destination);
1452 entry.push_back(Pair("category", "send"));
1453 entry.push_back(Pair("amount", ValueFromAmount(-s.amount)));
1454 if (pwallet->mapAddressBook.count(s.destination)) {
1455 entry.push_back(Pair("label", pwallet->mapAddressBook[s.destination].name));
1457 entry.push_back(Pair("vout", s.vout));
1458 entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
1459 if (fLong)
1460 WalletTxToJSON(wtx, entry);
1461 entry.push_back(Pair("abandoned", wtx.isAbandoned()));
1462 ret.push_back(entry);
1466 // Received
1467 if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
1469 for (const COutputEntry& r : listReceived)
1471 std::string account;
1472 if (pwallet->mapAddressBook.count(r.destination)) {
1473 account = pwallet->mapAddressBook[r.destination].name;
1475 if (fAllAccounts || (account == strAccount))
1477 UniValue entry(UniValue::VOBJ);
1478 if (involvesWatchonly || (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) {
1479 entry.push_back(Pair("involvesWatchonly", true));
1481 entry.push_back(Pair("account", account));
1482 MaybePushAddress(entry, r.destination);
1483 if (wtx.IsCoinBase())
1485 if (wtx.GetDepthInMainChain() < 1)
1486 entry.push_back(Pair("category", "orphan"));
1487 else if (wtx.GetBlocksToMaturity() > 0)
1488 entry.push_back(Pair("category", "immature"));
1489 else
1490 entry.push_back(Pair("category", "generate"));
1492 else
1494 entry.push_back(Pair("category", "receive"));
1496 entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
1497 if (pwallet->mapAddressBook.count(r.destination)) {
1498 entry.push_back(Pair("label", account));
1500 entry.push_back(Pair("vout", r.vout));
1501 if (fLong)
1502 WalletTxToJSON(wtx, entry);
1503 ret.push_back(entry);
1509 void AcentryToJSON(const CAccountingEntry& acentry, const std::string& strAccount, UniValue& ret)
1511 bool fAllAccounts = (strAccount == std::string("*"));
1513 if (fAllAccounts || acentry.strAccount == strAccount)
1515 UniValue entry(UniValue::VOBJ);
1516 entry.push_back(Pair("account", acentry.strAccount));
1517 entry.push_back(Pair("category", "move"));
1518 entry.push_back(Pair("time", acentry.nTime));
1519 entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit)));
1520 entry.push_back(Pair("otheraccount", acentry.strOtherAccount));
1521 entry.push_back(Pair("comment", acentry.strComment));
1522 ret.push_back(entry);
1526 UniValue listtransactions(const JSONRPCRequest& request)
1528 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1529 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1530 return NullUniValue;
1533 if (request.fHelp || request.params.size() > 4)
1534 throw std::runtime_error(
1535 "listtransactions ( \"account\" count skip include_watchonly)\n"
1536 "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
1537 "\nArguments:\n"
1538 "1. \"account\" (string, optional) DEPRECATED. The account name. Should be \"*\".\n"
1539 "2. count (numeric, optional, default=10) The number of transactions to return\n"
1540 "3. skip (numeric, optional, default=0) The number of transactions to skip\n"
1541 "4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n"
1542 "\nResult:\n"
1543 "[\n"
1544 " {\n"
1545 " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. \n"
1546 " It will be \"\" for the default account.\n"
1547 " \"address\":\"address\", (string) The bitcoin address of the transaction. Not present for \n"
1548 " move transactions (category = move).\n"
1549 " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
1550 " transaction between accounts, and not associated with an address,\n"
1551 " transaction id or block. 'send' and 'receive' transactions are \n"
1552 " associated with an address, transaction id and block details\n"
1553 " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the\n"
1554 " 'move' category for moves outbound. It is positive for the 'receive' category,\n"
1555 " and for the 'move' category for inbound funds.\n"
1556 " \"label\": \"label\", (string) A comment for the address/transaction, if any\n"
1557 " \"vout\": n, (numeric) the vout value\n"
1558 " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
1559 " 'send' category of transactions.\n"
1560 " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n"
1561 " 'receive' category of transactions. Negative confirmations indicate the\n"
1562 " transaction conflicts with the block chain\n"
1563 " \"trusted\": xxx, (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n"
1564 " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
1565 " category of transactions.\n"
1566 " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n"
1567 " category of transactions.\n"
1568 " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
1569 " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1570 " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
1571 " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
1572 " for 'send' and 'receive' category of transactions.\n"
1573 " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1574 " \"otheraccount\": \"accountname\", (string) DEPRECATED. For the 'move' category of transactions, the account the funds came \n"
1575 " from (for receiving funds, positive amounts), or went to (for sending funds,\n"
1576 " negative amounts).\n"
1577 " \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1578 " may be unknown for unconfirmed transactions not in the mempool\n"
1579 " \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
1580 " 'send' category of transactions.\n"
1581 " }\n"
1582 "]\n"
1584 "\nExamples:\n"
1585 "\nList the most recent 10 transactions in the systems\n"
1586 + HelpExampleCli("listtransactions", "") +
1587 "\nList transactions 100 to 120\n"
1588 + HelpExampleCli("listtransactions", "\"*\" 20 100") +
1589 "\nAs a json rpc call\n"
1590 + HelpExampleRpc("listtransactions", "\"*\", 20, 100")
1593 LOCK2(cs_main, pwallet->cs_wallet);
1595 std::string strAccount = "*";
1596 if (!request.params[0].isNull())
1597 strAccount = request.params[0].get_str();
1598 int nCount = 10;
1599 if (!request.params[1].isNull())
1600 nCount = request.params[1].get_int();
1601 int nFrom = 0;
1602 if (!request.params[2].isNull())
1603 nFrom = request.params[2].get_int();
1604 isminefilter filter = ISMINE_SPENDABLE;
1605 if(!request.params[3].isNull())
1606 if(request.params[3].get_bool())
1607 filter = filter | ISMINE_WATCH_ONLY;
1609 if (nCount < 0)
1610 throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
1611 if (nFrom < 0)
1612 throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
1614 UniValue ret(UniValue::VARR);
1616 const CWallet::TxItems & txOrdered = pwallet->wtxOrdered;
1618 // iterate backwards until we have nCount items to return:
1619 for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
1621 CWalletTx *const pwtx = (*it).second.first;
1622 if (pwtx != 0)
1623 ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
1624 CAccountingEntry *const pacentry = (*it).second.second;
1625 if (pacentry != 0)
1626 AcentryToJSON(*pacentry, strAccount, ret);
1628 if ((int)ret.size() >= (nCount+nFrom)) break;
1630 // ret is newest to oldest
1632 if (nFrom > (int)ret.size())
1633 nFrom = ret.size();
1634 if ((nFrom + nCount) > (int)ret.size())
1635 nCount = ret.size() - nFrom;
1637 std::vector<UniValue> arrTmp = ret.getValues();
1639 std::vector<UniValue>::iterator first = arrTmp.begin();
1640 std::advance(first, nFrom);
1641 std::vector<UniValue>::iterator last = arrTmp.begin();
1642 std::advance(last, nFrom+nCount);
1644 if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end());
1645 if (first != arrTmp.begin()) arrTmp.erase(arrTmp.begin(), first);
1647 std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
1649 ret.clear();
1650 ret.setArray();
1651 ret.push_backV(arrTmp);
1653 return ret;
1656 UniValue listaccounts(const JSONRPCRequest& request)
1658 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1659 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1660 return NullUniValue;
1663 if (request.fHelp || request.params.size() > 2)
1664 throw std::runtime_error(
1665 "listaccounts ( minconf include_watchonly)\n"
1666 "\nDEPRECATED. Returns Object that has account names as keys, account balances as values.\n"
1667 "\nArguments:\n"
1668 "1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n"
1669 "2. include_watchonly (bool, optional, default=false) Include balances in watch-only addresses (see 'importaddress')\n"
1670 "\nResult:\n"
1671 "{ (json object where keys are account names, and values are numeric balances\n"
1672 " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
1673 " ...\n"
1674 "}\n"
1675 "\nExamples:\n"
1676 "\nList account balances where there at least 1 confirmation\n"
1677 + HelpExampleCli("listaccounts", "") +
1678 "\nList account balances including zero confirmation transactions\n"
1679 + HelpExampleCli("listaccounts", "0") +
1680 "\nList account balances for 6 or more confirmations\n"
1681 + HelpExampleCli("listaccounts", "6") +
1682 "\nAs json rpc call\n"
1683 + HelpExampleRpc("listaccounts", "6")
1686 LOCK2(cs_main, pwallet->cs_wallet);
1688 int nMinDepth = 1;
1689 if (request.params.size() > 0)
1690 nMinDepth = request.params[0].get_int();
1691 isminefilter includeWatchonly = ISMINE_SPENDABLE;
1692 if(request.params.size() > 1)
1693 if(request.params[1].get_bool())
1694 includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
1696 std::map<std::string, CAmount> mapAccountBalances;
1697 for (const std::pair<CTxDestination, CAddressBookData>& entry : pwallet->mapAddressBook) {
1698 if (IsMine(*pwallet, entry.first) & includeWatchonly) { // This address belongs to me
1699 mapAccountBalances[entry.second.name] = 0;
1703 for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
1704 const CWalletTx& wtx = pairWtx.second;
1705 CAmount nFee;
1706 std::string strSentAccount;
1707 std::list<COutputEntry> listReceived;
1708 std::list<COutputEntry> listSent;
1709 int nDepth = wtx.GetDepthInMainChain();
1710 if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
1711 continue;
1712 wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
1713 mapAccountBalances[strSentAccount] -= nFee;
1714 for (const COutputEntry& s : listSent)
1715 mapAccountBalances[strSentAccount] -= s.amount;
1716 if (nDepth >= nMinDepth)
1718 for (const COutputEntry& r : listReceived)
1719 if (pwallet->mapAddressBook.count(r.destination)) {
1720 mapAccountBalances[pwallet->mapAddressBook[r.destination].name] += r.amount;
1722 else
1723 mapAccountBalances[""] += r.amount;
1727 const std::list<CAccountingEntry>& acentries = pwallet->laccentries;
1728 for (const CAccountingEntry& entry : acentries)
1729 mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
1731 UniValue ret(UniValue::VOBJ);
1732 for (const std::pair<std::string, CAmount>& accountBalance : mapAccountBalances) {
1733 ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
1735 return ret;
1738 UniValue listsinceblock(const JSONRPCRequest& request)
1740 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1741 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1742 return NullUniValue;
1745 if (request.fHelp || request.params.size() > 3)
1746 throw std::runtime_error(
1747 "listsinceblock ( \"blockhash\" target_confirmations include_watchonly)\n"
1748 "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
1749 "\nArguments:\n"
1750 "1. \"blockhash\" (string, optional) The block hash to list transactions since\n"
1751 "2. target_confirmations: (numeric, optional) The confirmations required, must be 1 or more\n"
1752 "3. include_watchonly: (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')"
1753 "\nResult:\n"
1754 "{\n"
1755 " \"transactions\": [\n"
1756 " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. Will be \"\" for the default account.\n"
1757 " \"address\":\"address\", (string) The bitcoin address of the transaction. Not present for move transactions (category = move).\n"
1758 " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
1759 " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n"
1760 " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
1761 " \"vout\" : n, (numeric) the vout value\n"
1762 " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n"
1763 " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
1764 " When it's < 0, it means the transaction conflicted that many blocks ago.\n"
1765 " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
1766 " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions.\n"
1767 " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
1768 " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1769 " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n"
1770 " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n"
1771 " \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1772 " may be unknown for unconfirmed transactions not in the mempool\n"
1773 " \"abandoned\": xxx, (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the 'send' category of transactions.\n"
1774 " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1775 " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
1776 " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n"
1777 " ],\n"
1778 " \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n"
1779 "}\n"
1780 "\nExamples:\n"
1781 + HelpExampleCli("listsinceblock", "")
1782 + HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6")
1783 + HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6")
1786 LOCK2(cs_main, pwallet->cs_wallet);
1788 const CBlockIndex *pindex = NULL;
1789 int target_confirms = 1;
1790 isminefilter filter = ISMINE_SPENDABLE;
1792 if (!request.params[0].isNull())
1794 uint256 blockId;
1796 blockId.SetHex(request.params[0].get_str());
1797 BlockMap::iterator it = mapBlockIndex.find(blockId);
1798 if (it != mapBlockIndex.end())
1800 pindex = it->second;
1801 if (chainActive[pindex->nHeight] != pindex)
1803 // the block being asked for is a part of a deactivated chain;
1804 // we don't want to depend on its perceived height in the block
1805 // chain, we want to instead use the last common ancestor
1806 pindex = chainActive.FindFork(pindex);
1811 if (!request.params[1].isNull())
1813 target_confirms = request.params[1].get_int();
1815 if (target_confirms < 1)
1816 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
1819 if (request.params.size() > 2 && request.params[2].get_bool())
1821 filter = filter | ISMINE_WATCH_ONLY;
1824 int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
1826 UniValue transactions(UniValue::VARR);
1828 for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
1829 CWalletTx tx = pairWtx.second;
1831 if (depth == -1 || tx.GetDepthInMainChain() < depth)
1832 ListTransactions(pwallet, tx, "*", 0, true, transactions, filter);
1835 CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
1836 uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : uint256();
1838 UniValue ret(UniValue::VOBJ);
1839 ret.push_back(Pair("transactions", transactions));
1840 ret.push_back(Pair("lastblock", lastblock.GetHex()));
1842 return ret;
1845 UniValue gettransaction(const JSONRPCRequest& request)
1847 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1848 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1849 return NullUniValue;
1852 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
1853 throw std::runtime_error(
1854 "gettransaction \"txid\" ( include_watchonly )\n"
1855 "\nGet detailed information about in-wallet transaction <txid>\n"
1856 "\nArguments:\n"
1857 "1. \"txid\" (string, required) The transaction id\n"
1858 "2. \"include_watchonly\" (bool, optional, default=false) Whether to include watch-only addresses in balance calculation and details[]\n"
1859 "\nResult:\n"
1860 "{\n"
1861 " \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n"
1862 " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
1863 " 'send' category of transactions.\n"
1864 " \"confirmations\" : n, (numeric) The number of confirmations\n"
1865 " \"blockhash\" : \"hash\", (string) The block hash\n"
1866 " \"blockindex\" : xx, (numeric) The index of the transaction in the block that includes it\n"
1867 " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n"
1868 " \"txid\" : \"transactionid\", (string) The transaction id.\n"
1869 " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n"
1870 " \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n"
1871 " \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1872 " may be unknown for unconfirmed transactions not in the mempool\n"
1873 " \"details\" : [\n"
1874 " {\n"
1875 " \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n"
1876 " \"address\" : \"address\", (string) The bitcoin address involved in the transaction\n"
1877 " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
1878 " \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + "\n"
1879 " \"label\" : \"label\", (string) A comment for the address/transaction, if any\n"
1880 " \"vout\" : n, (numeric) the vout value\n"
1881 " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
1882 " 'send' category of transactions.\n"
1883 " \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
1884 " 'send' category of transactions.\n"
1885 " }\n"
1886 " ,...\n"
1887 " ],\n"
1888 " \"hex\" : \"data\" (string) Raw data for transaction\n"
1889 "}\n"
1891 "\nExamples:\n"
1892 + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1893 + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
1894 + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1897 LOCK2(cs_main, pwallet->cs_wallet);
1899 uint256 hash;
1900 hash.SetHex(request.params[0].get_str());
1902 isminefilter filter = ISMINE_SPENDABLE;
1903 if(!request.params[1].isNull())
1904 if(request.params[1].get_bool())
1905 filter = filter | ISMINE_WATCH_ONLY;
1907 UniValue entry(UniValue::VOBJ);
1908 if (!pwallet->mapWallet.count(hash)) {
1909 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
1911 const CWalletTx& wtx = pwallet->mapWallet[hash];
1913 CAmount nCredit = wtx.GetCredit(filter);
1914 CAmount nDebit = wtx.GetDebit(filter);
1915 CAmount nNet = nCredit - nDebit;
1916 CAmount nFee = (wtx.IsFromMe(filter) ? wtx.tx->GetValueOut() - nDebit : 0);
1918 entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
1919 if (wtx.IsFromMe(filter))
1920 entry.push_back(Pair("fee", ValueFromAmount(nFee)));
1922 WalletTxToJSON(wtx, entry);
1924 UniValue details(UniValue::VARR);
1925 ListTransactions(pwallet, wtx, "*", 0, false, details, filter);
1926 entry.push_back(Pair("details", details));
1928 std::string strHex = EncodeHexTx(static_cast<CTransaction>(wtx), RPCSerializationFlags());
1929 entry.push_back(Pair("hex", strHex));
1931 return entry;
1934 UniValue abandontransaction(const JSONRPCRequest& request)
1936 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1937 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1938 return NullUniValue;
1941 if (request.fHelp || request.params.size() != 1)
1942 throw std::runtime_error(
1943 "abandontransaction \"txid\"\n"
1944 "\nMark in-wallet transaction <txid> as abandoned\n"
1945 "This will mark this transaction and all its in-wallet descendants as abandoned which will allow\n"
1946 "for their inputs to be respent. It can be used to replace \"stuck\" or evicted transactions.\n"
1947 "It only works on transactions which are not included in a block and are not currently in the mempool.\n"
1948 "It has no effect on transactions which are already conflicted or abandoned.\n"
1949 "\nArguments:\n"
1950 "1. \"txid\" (string, required) The transaction id\n"
1951 "\nResult:\n"
1952 "\nExamples:\n"
1953 + HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1954 + HelpExampleRpc("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1957 LOCK2(cs_main, pwallet->cs_wallet);
1959 uint256 hash;
1960 hash.SetHex(request.params[0].get_str());
1962 if (!pwallet->mapWallet.count(hash)) {
1963 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
1965 if (!pwallet->AbandonTransaction(hash)) {
1966 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not eligible for abandonment");
1969 return NullUniValue;
1973 UniValue backupwallet(const JSONRPCRequest& request)
1975 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
1976 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
1977 return NullUniValue;
1980 if (request.fHelp || request.params.size() != 1)
1981 throw std::runtime_error(
1982 "backupwallet \"destination\"\n"
1983 "\nSafely copies current wallet file to destination, which can be a directory or a path with filename.\n"
1984 "\nArguments:\n"
1985 "1. \"destination\" (string) The destination directory or file\n"
1986 "\nExamples:\n"
1987 + HelpExampleCli("backupwallet", "\"backup.dat\"")
1988 + HelpExampleRpc("backupwallet", "\"backup.dat\"")
1991 LOCK2(cs_main, pwallet->cs_wallet);
1993 std::string strDest = request.params[0].get_str();
1994 if (!pwallet->BackupWallet(strDest)) {
1995 throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
1998 return NullUniValue;
2002 UniValue keypoolrefill(const JSONRPCRequest& request)
2004 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2005 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2006 return NullUniValue;
2009 if (request.fHelp || request.params.size() > 1)
2010 throw std::runtime_error(
2011 "keypoolrefill ( newsize )\n"
2012 "\nFills the keypool."
2013 + HelpRequiringPassphrase(pwallet) + "\n"
2014 "\nArguments\n"
2015 "1. newsize (numeric, optional, default=100) The new keypool size\n"
2016 "\nExamples:\n"
2017 + HelpExampleCli("keypoolrefill", "")
2018 + HelpExampleRpc("keypoolrefill", "")
2021 LOCK2(cs_main, pwallet->cs_wallet);
2023 // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
2024 unsigned int kpSize = 0;
2025 if (!request.params[0].isNull()) {
2026 if (request.params[0].get_int() < 0)
2027 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
2028 kpSize = (unsigned int)request.params[0].get_int();
2031 EnsureWalletIsUnlocked(pwallet);
2032 pwallet->TopUpKeyPool(kpSize);
2034 if (pwallet->GetKeyPoolSize() < kpSize) {
2035 throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
2038 return NullUniValue;
2042 static void LockWallet(CWallet* pWallet)
2044 LOCK(pWallet->cs_wallet);
2045 pWallet->nRelockTime = 0;
2046 pWallet->Lock();
2049 UniValue walletpassphrase(const JSONRPCRequest& request)
2051 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2052 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2053 return NullUniValue;
2056 if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) {
2057 throw std::runtime_error(
2058 "walletpassphrase \"passphrase\" timeout\n"
2059 "\nStores the wallet decryption key in memory for 'timeout' seconds.\n"
2060 "This is needed prior to performing transactions related to private keys such as sending bitcoins\n"
2061 "\nArguments:\n"
2062 "1. \"passphrase\" (string, required) The wallet passphrase\n"
2063 "2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
2064 "\nNote:\n"
2065 "Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
2066 "time that overrides the old one.\n"
2067 "\nExamples:\n"
2068 "\nunlock the wallet for 60 seconds\n"
2069 + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") +
2070 "\nLock the wallet again (before 60 seconds)\n"
2071 + HelpExampleCli("walletlock", "") +
2072 "\nAs json rpc call\n"
2073 + HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")
2077 LOCK2(cs_main, pwallet->cs_wallet);
2079 if (request.fHelp)
2080 return true;
2081 if (!pwallet->IsCrypted()) {
2082 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
2085 // Note that the walletpassphrase is stored in request.params[0] which is not mlock()ed
2086 SecureString strWalletPass;
2087 strWalletPass.reserve(100);
2088 // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
2089 // Alternately, find a way to make request.params[0] mlock()'d to begin with.
2090 strWalletPass = request.params[0].get_str().c_str();
2092 if (strWalletPass.length() > 0)
2094 if (!pwallet->Unlock(strWalletPass)) {
2095 throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
2098 else
2099 throw std::runtime_error(
2100 "walletpassphrase <passphrase> <timeout>\n"
2101 "Stores the wallet decryption key in memory for <timeout> seconds.");
2103 pwallet->TopUpKeyPool();
2105 int64_t nSleepTime = request.params[1].get_int64();
2106 pwallet->nRelockTime = GetTime() + nSleepTime;
2107 RPCRunLater(strprintf("lockwallet(%s)", pwallet->GetName()), boost::bind(LockWallet, pwallet), nSleepTime);
2109 return NullUniValue;
2113 UniValue walletpassphrasechange(const JSONRPCRequest& request)
2115 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2116 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2117 return NullUniValue;
2120 if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) {
2121 throw std::runtime_error(
2122 "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n"
2123 "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n"
2124 "\nArguments:\n"
2125 "1. \"oldpassphrase\" (string) The current passphrase\n"
2126 "2. \"newpassphrase\" (string) The new passphrase\n"
2127 "\nExamples:\n"
2128 + HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"")
2129 + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"")
2133 LOCK2(cs_main, pwallet->cs_wallet);
2135 if (request.fHelp)
2136 return true;
2137 if (!pwallet->IsCrypted()) {
2138 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
2141 // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
2142 // Alternately, find a way to make request.params[0] mlock()'d to begin with.
2143 SecureString strOldWalletPass;
2144 strOldWalletPass.reserve(100);
2145 strOldWalletPass = request.params[0].get_str().c_str();
2147 SecureString strNewWalletPass;
2148 strNewWalletPass.reserve(100);
2149 strNewWalletPass = request.params[1].get_str().c_str();
2151 if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
2152 throw std::runtime_error(
2153 "walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
2154 "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
2156 if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
2157 throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
2160 return NullUniValue;
2164 UniValue walletlock(const JSONRPCRequest& request)
2166 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2167 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2168 return NullUniValue;
2171 if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) {
2172 throw std::runtime_error(
2173 "walletlock\n"
2174 "\nRemoves the wallet encryption key from memory, locking the wallet.\n"
2175 "After calling this method, you will need to call walletpassphrase again\n"
2176 "before being able to call any methods which require the wallet to be unlocked.\n"
2177 "\nExamples:\n"
2178 "\nSet the passphrase for 2 minutes to perform a transaction\n"
2179 + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") +
2180 "\nPerform a send (requires passphrase set)\n"
2181 + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") +
2182 "\nClear the passphrase since we are done before 2 minutes is up\n"
2183 + HelpExampleCli("walletlock", "") +
2184 "\nAs json rpc call\n"
2185 + HelpExampleRpc("walletlock", "")
2189 LOCK2(cs_main, pwallet->cs_wallet);
2191 if (request.fHelp)
2192 return true;
2193 if (!pwallet->IsCrypted()) {
2194 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
2197 pwallet->Lock();
2198 pwallet->nRelockTime = 0;
2200 return NullUniValue;
2204 UniValue encryptwallet(const JSONRPCRequest& request)
2206 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2207 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2208 return NullUniValue;
2211 if (!pwallet->IsCrypted() && (request.fHelp || request.params.size() != 1)) {
2212 throw std::runtime_error(
2213 "encryptwallet \"passphrase\"\n"
2214 "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n"
2215 "After this, any calls that interact with private keys such as sending or signing \n"
2216 "will require the passphrase to be set prior the making these calls.\n"
2217 "Use the walletpassphrase call for this, and then walletlock call.\n"
2218 "If the wallet is already encrypted, use the walletpassphrasechange call.\n"
2219 "Note that this will shutdown the server.\n"
2220 "\nArguments:\n"
2221 "1. \"passphrase\" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.\n"
2222 "\nExamples:\n"
2223 "\nEncrypt you wallet\n"
2224 + HelpExampleCli("encryptwallet", "\"my pass phrase\"") +
2225 "\nNow set the passphrase to use the wallet, such as for signing or sending bitcoin\n"
2226 + HelpExampleCli("walletpassphrase", "\"my pass phrase\"") +
2227 "\nNow we can so something like sign\n"
2228 + HelpExampleCli("signmessage", "\"address\" \"test message\"") +
2229 "\nNow lock the wallet again by removing the passphrase\n"
2230 + HelpExampleCli("walletlock", "") +
2231 "\nAs a json rpc call\n"
2232 + HelpExampleRpc("encryptwallet", "\"my pass phrase\"")
2236 LOCK2(cs_main, pwallet->cs_wallet);
2238 if (request.fHelp)
2239 return true;
2240 if (pwallet->IsCrypted()) {
2241 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
2244 // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
2245 // Alternately, find a way to make request.params[0] mlock()'d to begin with.
2246 SecureString strWalletPass;
2247 strWalletPass.reserve(100);
2248 strWalletPass = request.params[0].get_str().c_str();
2250 if (strWalletPass.length() < 1)
2251 throw std::runtime_error(
2252 "encryptwallet <passphrase>\n"
2253 "Encrypts the wallet with <passphrase>.");
2255 if (!pwallet->EncryptWallet(strWalletPass)) {
2256 throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
2259 // BDB seems to have a bad habit of writing old data into
2260 // slack space in .dat files; that is bad if the old data is
2261 // unencrypted private keys. So:
2262 StartShutdown();
2263 return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.";
2266 UniValue lockunspent(const JSONRPCRequest& request)
2268 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2269 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2270 return NullUniValue;
2273 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
2274 throw std::runtime_error(
2275 "lockunspent unlock ([{\"txid\":\"txid\",\"vout\":n},...])\n"
2276 "\nUpdates list of temporarily unspendable outputs.\n"
2277 "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
2278 "If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n"
2279 "A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.\n"
2280 "Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n"
2281 "is always cleared (by virtue of process exit) when a node stops or fails.\n"
2282 "Also see the listunspent call\n"
2283 "\nArguments:\n"
2284 "1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions\n"
2285 "2. \"transactions\" (string, optional) A json array of objects. Each object the txid (string) vout (numeric)\n"
2286 " [ (json array of json objects)\n"
2287 " {\n"
2288 " \"txid\":\"id\", (string) The transaction id\n"
2289 " \"vout\": n (numeric) The output number\n"
2290 " }\n"
2291 " ,...\n"
2292 " ]\n"
2294 "\nResult:\n"
2295 "true|false (boolean) Whether the command was successful or not\n"
2297 "\nExamples:\n"
2298 "\nList the unspent transactions\n"
2299 + HelpExampleCli("listunspent", "") +
2300 "\nLock an unspent transaction\n"
2301 + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2302 "\nList the locked transactions\n"
2303 + HelpExampleCli("listlockunspent", "") +
2304 "\nUnlock the transaction again\n"
2305 + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2306 "\nAs a json rpc call\n"
2307 + HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
2310 LOCK2(cs_main, pwallet->cs_wallet);
2312 if (request.params.size() == 1)
2313 RPCTypeCheck(request.params, {UniValue::VBOOL});
2314 else
2315 RPCTypeCheck(request.params, {UniValue::VBOOL, UniValue::VARR});
2317 bool fUnlock = request.params[0].get_bool();
2319 if (request.params.size() == 1) {
2320 if (fUnlock)
2321 pwallet->UnlockAllCoins();
2322 return true;
2325 UniValue outputs = request.params[1].get_array();
2326 for (unsigned int idx = 0; idx < outputs.size(); idx++) {
2327 const UniValue& output = outputs[idx];
2328 if (!output.isObject())
2329 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
2330 const UniValue& o = output.get_obj();
2332 RPCTypeCheckObj(o,
2334 {"txid", UniValueType(UniValue::VSTR)},
2335 {"vout", UniValueType(UniValue::VNUM)},
2338 std::string txid = find_value(o, "txid").get_str();
2339 if (!IsHex(txid))
2340 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid");
2342 int nOutput = find_value(o, "vout").get_int();
2343 if (nOutput < 0)
2344 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
2346 COutPoint outpt(uint256S(txid), nOutput);
2348 if (fUnlock)
2349 pwallet->UnlockCoin(outpt);
2350 else
2351 pwallet->LockCoin(outpt);
2354 return true;
2357 UniValue listlockunspent(const JSONRPCRequest& request)
2359 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2360 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2361 return NullUniValue;
2364 if (request.fHelp || request.params.size() > 0)
2365 throw std::runtime_error(
2366 "listlockunspent\n"
2367 "\nReturns list of temporarily unspendable outputs.\n"
2368 "See the lockunspent call to lock and unlock transactions for spending.\n"
2369 "\nResult:\n"
2370 "[\n"
2371 " {\n"
2372 " \"txid\" : \"transactionid\", (string) The transaction id locked\n"
2373 " \"vout\" : n (numeric) The vout value\n"
2374 " }\n"
2375 " ,...\n"
2376 "]\n"
2377 "\nExamples:\n"
2378 "\nList the unspent transactions\n"
2379 + HelpExampleCli("listunspent", "") +
2380 "\nLock an unspent transaction\n"
2381 + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2382 "\nList the locked transactions\n"
2383 + HelpExampleCli("listlockunspent", "") +
2384 "\nUnlock the transaction again\n"
2385 + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2386 "\nAs a json rpc call\n"
2387 + HelpExampleRpc("listlockunspent", "")
2390 LOCK2(cs_main, pwallet->cs_wallet);
2392 std::vector<COutPoint> vOutpts;
2393 pwallet->ListLockedCoins(vOutpts);
2395 UniValue ret(UniValue::VARR);
2397 for (COutPoint &outpt : vOutpts) {
2398 UniValue o(UniValue::VOBJ);
2400 o.push_back(Pair("txid", outpt.hash.GetHex()));
2401 o.push_back(Pair("vout", (int)outpt.n));
2402 ret.push_back(o);
2405 return ret;
2408 UniValue settxfee(const JSONRPCRequest& request)
2410 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2411 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2412 return NullUniValue;
2415 if (request.fHelp || request.params.size() < 1 || request.params.size() > 1)
2416 throw std::runtime_error(
2417 "settxfee amount\n"
2418 "\nSet the transaction fee per kB. Overwrites the paytxfee parameter.\n"
2419 "\nArguments:\n"
2420 "1. amount (numeric or string, required) The transaction fee in " + CURRENCY_UNIT + "/kB\n"
2421 "\nResult\n"
2422 "true|false (boolean) Returns true if successful\n"
2423 "\nExamples:\n"
2424 + HelpExampleCli("settxfee", "0.00001")
2425 + HelpExampleRpc("settxfee", "0.00001")
2428 LOCK2(cs_main, pwallet->cs_wallet);
2430 // Amount
2431 CAmount nAmount = AmountFromValue(request.params[0]);
2433 payTxFee = CFeeRate(nAmount, 1000);
2434 return true;
2437 UniValue getwalletinfo(const JSONRPCRequest& request)
2439 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2440 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2441 return NullUniValue;
2444 if (request.fHelp || request.params.size() != 0)
2445 throw std::runtime_error(
2446 "getwalletinfo\n"
2447 "Returns an object containing various wallet state info.\n"
2448 "\nResult:\n"
2449 "{\n"
2450 " \"walletname\": xxxxx, (string) the wallet name\n"
2451 " \"walletversion\": xxxxx, (numeric) the wallet version\n"
2452 " \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2453 " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2454 " \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n"
2455 " \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
2456 " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n"
2457 " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated (only counts external keys)\n"
2458 " \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)\n"
2459 " \"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"
2460 " \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
2461 " \"hdmasterkeyid\": \"<hash160>\" (string) the Hash160 of the HD master pubkey\n"
2462 "}\n"
2463 "\nExamples:\n"
2464 + HelpExampleCli("getwalletinfo", "")
2465 + HelpExampleRpc("getwalletinfo", "")
2468 LOCK2(cs_main, pwallet->cs_wallet);
2470 UniValue obj(UniValue::VOBJ);
2472 size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
2473 obj.push_back(Pair("walletname", pwallet->GetName()));
2474 obj.push_back(Pair("walletversion", pwallet->GetVersion()));
2475 obj.push_back(Pair("balance", ValueFromAmount(pwallet->GetBalance())));
2476 obj.push_back(Pair("unconfirmed_balance", ValueFromAmount(pwallet->GetUnconfirmedBalance())));
2477 obj.push_back(Pair("immature_balance", ValueFromAmount(pwallet->GetImmatureBalance())));
2478 obj.push_back(Pair("txcount", (int)pwallet->mapWallet.size()));
2479 obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime()));
2480 obj.push_back(Pair("keypoolsize", (int64_t)kpExternalSize));
2481 CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID;
2482 if (!masterKeyID.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) {
2483 obj.push_back(Pair("keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize)));
2485 if (pwallet->IsCrypted()) {
2486 obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
2488 obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
2489 if (!masterKeyID.IsNull())
2490 obj.push_back(Pair("hdmasterkeyid", masterKeyID.GetHex()));
2491 return obj;
2494 UniValue resendwallettransactions(const JSONRPCRequest& request)
2496 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2497 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2498 return NullUniValue;
2501 if (request.fHelp || request.params.size() != 0)
2502 throw std::runtime_error(
2503 "resendwallettransactions\n"
2504 "Immediately re-broadcast unconfirmed wallet transactions to all peers.\n"
2505 "Intended only for testing; the wallet code periodically re-broadcasts\n"
2506 "automatically.\n"
2507 "Returns array of transaction ids that were re-broadcast.\n"
2510 if (!g_connman)
2511 throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
2513 LOCK2(cs_main, pwallet->cs_wallet);
2515 std::vector<uint256> txids = pwallet->ResendWalletTransactionsBefore(GetTime(), g_connman.get());
2516 UniValue result(UniValue::VARR);
2517 for (const uint256& txid : txids)
2519 result.push_back(txid.ToString());
2521 return result;
2524 UniValue listunspent(const JSONRPCRequest& request)
2526 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2527 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2528 return NullUniValue;
2531 if (request.fHelp || request.params.size() > 5)
2532 throw std::runtime_error(
2533 "listunspent ( minconf maxconf [\"addresses\",...] [include_unsafe] [query_options])\n"
2534 "\nReturns array of unspent transaction outputs\n"
2535 "with between minconf and maxconf (inclusive) confirmations.\n"
2536 "Optionally filter to only include txouts paid to specified addresses.\n"
2537 "\nArguments:\n"
2538 "1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n"
2539 "2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
2540 "3. \"addresses\" (string) A json array of bitcoin addresses to filter\n"
2541 " [\n"
2542 " \"address\" (string) bitcoin address\n"
2543 " ,...\n"
2544 " ]\n"
2545 "4. include_unsafe (bool, optional, default=true) Include outputs that are not safe to spend\n"
2546 " See description of \"safe\" attribute below.\n"
2547 "5. query_options (json, optional) JSON with query options\n"
2548 " {\n"
2549 " \"minimumAmount\" (numeric or string, default=0) Minimum value of each UTXO in " + CURRENCY_UNIT + "\n"
2550 " \"maximumAmount\" (numeric or string, default=unlimited) Maximum value of each UTXO in " + CURRENCY_UNIT + "\n"
2551 " \"maximumCount\" (numeric or string, default=unlimited) Maximum number of UTXOs\n"
2552 " \"minimumSumAmount\" (numeric or string, default=unlimited) Minimum sum value of all UTXOs in " + CURRENCY_UNIT + "\n"
2553 " }\n"
2554 "\nResult\n"
2555 "[ (array of json object)\n"
2556 " {\n"
2557 " \"txid\" : \"txid\", (string) the transaction id \n"
2558 " \"vout\" : n, (numeric) the vout value\n"
2559 " \"address\" : \"address\", (string) the bitcoin address\n"
2560 " \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
2561 " \"scriptPubKey\" : \"key\", (string) the script key\n"
2562 " \"amount\" : x.xxx, (numeric) the transaction output amount in " + CURRENCY_UNIT + "\n"
2563 " \"confirmations\" : n, (numeric) The number of confirmations\n"
2564 " \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
2565 " \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
2566 " \"solvable\" : xxx, (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
2567 " \"safe\" : xxx (bool) Whether this output is considered safe to spend. Unconfirmed transactions\n"
2568 " from outside keys and unconfirmed replacement transactions are considered unsafe\n"
2569 " and are not eligible for spending by fundrawtransaction and sendtoaddress.\n"
2570 " }\n"
2571 " ,...\n"
2572 "]\n"
2574 "\nExamples\n"
2575 + HelpExampleCli("listunspent", "")
2576 + HelpExampleCli("listunspent", "6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
2577 + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
2578 + HelpExampleCli("listunspent", "6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'")
2579 + HelpExampleRpc("listunspent", "6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")
2582 int nMinDepth = 1;
2583 if (request.params.size() > 0 && !request.params[0].isNull()) {
2584 RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
2585 nMinDepth = request.params[0].get_int();
2588 int nMaxDepth = 9999999;
2589 if (request.params.size() > 1 && !request.params[1].isNull()) {
2590 RPCTypeCheckArgument(request.params[1], UniValue::VNUM);
2591 nMaxDepth = request.params[1].get_int();
2594 std::set<CBitcoinAddress> setAddress;
2595 if (request.params.size() > 2 && !request.params[2].isNull()) {
2596 RPCTypeCheckArgument(request.params[2], UniValue::VARR);
2597 UniValue inputs = request.params[2].get_array();
2598 for (unsigned int idx = 0; idx < inputs.size(); idx++) {
2599 const UniValue& input = inputs[idx];
2600 CBitcoinAddress address(input.get_str());
2601 if (!address.IsValid())
2602 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ")+input.get_str());
2603 if (setAddress.count(address))
2604 throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+input.get_str());
2605 setAddress.insert(address);
2609 bool include_unsafe = true;
2610 if (request.params.size() > 3 && !request.params[3].isNull()) {
2611 RPCTypeCheckArgument(request.params[3], UniValue::VBOOL);
2612 include_unsafe = request.params[3].get_bool();
2615 CAmount nMinimumAmount = 0;
2616 CAmount nMaximumAmount = MAX_MONEY;
2617 CAmount nMinimumSumAmount = MAX_MONEY;
2618 uint64_t nMaximumCount = 0;
2620 if (!request.params[4].isNull()) {
2621 const UniValue& options = request.params[4].get_obj();
2623 if (options.exists("minimumAmount"))
2624 nMinimumAmount = AmountFromValue(options["minimumAmount"]);
2626 if (options.exists("maximumAmount"))
2627 nMaximumAmount = AmountFromValue(options["maximumAmount"]);
2629 if (options.exists("minimumSumAmount"))
2630 nMinimumSumAmount = AmountFromValue(options["minimumSumAmount"]);
2632 if (options.exists("maximumCount"))
2633 nMaximumCount = options["maximumCount"].get_int64();
2636 UniValue results(UniValue::VARR);
2637 std::vector<COutput> vecOutputs;
2638 assert(pwallet != NULL);
2639 LOCK2(cs_main, pwallet->cs_wallet);
2641 pwallet->AvailableCoins(vecOutputs, !include_unsafe, NULL, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth);
2642 for (const COutput& out : vecOutputs) {
2643 CTxDestination address;
2644 const CScript& scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey;
2645 bool fValidAddress = ExtractDestination(scriptPubKey, address);
2647 if (setAddress.size() && (!fValidAddress || !setAddress.count(address)))
2648 continue;
2650 UniValue entry(UniValue::VOBJ);
2651 entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
2652 entry.push_back(Pair("vout", out.i));
2654 if (fValidAddress) {
2655 entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
2657 if (pwallet->mapAddressBook.count(address)) {
2658 entry.push_back(Pair("account", pwallet->mapAddressBook[address].name));
2661 if (scriptPubKey.IsPayToScriptHash()) {
2662 const CScriptID& hash = boost::get<CScriptID>(address);
2663 CScript redeemScript;
2664 if (pwallet->GetCScript(hash, redeemScript)) {
2665 entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
2670 entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
2671 entry.push_back(Pair("amount", ValueFromAmount(out.tx->tx->vout[out.i].nValue)));
2672 entry.push_back(Pair("confirmations", out.nDepth));
2673 entry.push_back(Pair("spendable", out.fSpendable));
2674 entry.push_back(Pair("solvable", out.fSolvable));
2675 entry.push_back(Pair("safe", out.fSafe));
2676 results.push_back(entry);
2679 return results;
2682 UniValue fundrawtransaction(const JSONRPCRequest& request)
2684 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2685 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2686 return NullUniValue;
2689 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
2690 throw std::runtime_error(
2691 "fundrawtransaction \"hexstring\" ( options )\n"
2692 "\nAdd inputs to a transaction until it has enough in value to meet its out value.\n"
2693 "This will not modify existing inputs, and will add at most one change output to the outputs.\n"
2694 "No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n"
2695 "Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n"
2696 "The inputs added will not be signed, use signrawtransaction for that.\n"
2697 "Note that all existing inputs must have their previous output transaction be in the wallet.\n"
2698 "Note that all inputs selected must be of standard form and P2SH scripts must be\n"
2699 "in the wallet using importaddress or addmultisigaddress (to calculate fees).\n"
2700 "You can see whether this is the case by checking the \"solvable\" field in the listunspent output.\n"
2701 "Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only\n"
2702 "\nArguments:\n"
2703 "1. \"hexstring\" (string, required) The hex string of the raw transaction\n"
2704 "2. options (object, optional)\n"
2705 " {\n"
2706 " \"changeAddress\" (string, optional, default pool address) The bitcoin address to receive the change\n"
2707 " \"changePosition\" (numeric, optional, default random) The index of the change output\n"
2708 " \"includeWatching\" (boolean, optional, default false) Also select inputs which are watch only\n"
2709 " \"lockUnspents\" (boolean, optional, default false) Lock selected unspent outputs\n"
2710 " \"feeRate\" (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate (" + CURRENCY_UNIT + " per KB)\n"
2711 " \"subtractFeeFromOutputs\" (array, optional) A json array of integers.\n"
2712 " The fee will be equally deducted from the amount of each specified output.\n"
2713 " The outputs are specified by their zero-based index, before any change output is added.\n"
2714 " Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
2715 " If no outputs are specified here, the sender pays the fee.\n"
2716 " [vout_index,...]\n"
2717 " \"replaceable\" (boolean, optional) Marks this transaction as BIP125 replaceable.\n"
2718 " Allows this transaction to be replaced by a transaction with higher fees\n"
2719 " \"conf_target\" (numeric, optional) Confirmation target (in blocks)\n"
2720 " \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
2721 " \"UNSET\"\n"
2722 " \"ECONOMICAL\"\n"
2723 " \"CONSERVATIVE\"\n"
2724 " }\n"
2725 " for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n"
2726 "\nResult:\n"
2727 "{\n"
2728 " \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
2729 " \"fee\": n, (numeric) Fee in " + CURRENCY_UNIT + " the resulting transaction pays\n"
2730 " \"changepos\": n (numeric) The position of the added change output, or -1\n"
2731 "}\n"
2732 "\nExamples:\n"
2733 "\nCreate a transaction with no inputs\n"
2734 + HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
2735 "\nAdd sufficient unsigned inputs to meet the output value\n"
2736 + HelpExampleCli("fundrawtransaction", "\"rawtransactionhex\"") +
2737 "\nSign the transaction\n"
2738 + HelpExampleCli("signrawtransaction", "\"fundedtransactionhex\"") +
2739 "\nSend the transaction\n"
2740 + HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")
2743 RPCTypeCheck(request.params, {UniValue::VSTR});
2745 CCoinControl coinControl;
2746 int changePosition = -1;
2747 bool lockUnspents = false;
2748 UniValue subtractFeeFromOutputs;
2749 std::set<int> setSubtractFeeFromOutputs;
2751 if (!request.params[1].isNull()) {
2752 if (request.params[1].type() == UniValue::VBOOL) {
2753 // backward compatibility bool only fallback
2754 coinControl.fAllowWatchOnly = request.params[1].get_bool();
2756 else {
2757 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ});
2759 UniValue options = request.params[1];
2761 RPCTypeCheckObj(options,
2763 {"changeAddress", UniValueType(UniValue::VSTR)},
2764 {"changePosition", UniValueType(UniValue::VNUM)},
2765 {"includeWatching", UniValueType(UniValue::VBOOL)},
2766 {"lockUnspents", UniValueType(UniValue::VBOOL)},
2767 {"reserveChangeKey", UniValueType(UniValue::VBOOL)}, // DEPRECATED (and ignored), should be removed in 0.16 or so.
2768 {"feeRate", UniValueType()}, // will be checked below
2769 {"subtractFeeFromOutputs", UniValueType(UniValue::VARR)},
2770 {"replaceable", UniValueType(UniValue::VBOOL)},
2771 {"conf_target", UniValueType(UniValue::VNUM)},
2772 {"estimate_mode", UniValueType(UniValue::VSTR)},
2774 true, true);
2776 if (options.exists("changeAddress")) {
2777 CBitcoinAddress address(options["changeAddress"].get_str());
2779 if (!address.IsValid())
2780 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "changeAddress must be a valid bitcoin address");
2782 coinControl.destChange = address.Get();
2785 if (options.exists("changePosition"))
2786 changePosition = options["changePosition"].get_int();
2788 if (options.exists("includeWatching"))
2789 coinControl.fAllowWatchOnly = options["includeWatching"].get_bool();
2791 if (options.exists("lockUnspents"))
2792 lockUnspents = options["lockUnspents"].get_bool();
2794 if (options.exists("feeRate"))
2796 coinControl.m_feerate = CFeeRate(AmountFromValue(options["feeRate"]));
2797 coinControl.fOverrideFeeRate = true;
2800 if (options.exists("subtractFeeFromOutputs"))
2801 subtractFeeFromOutputs = options["subtractFeeFromOutputs"].get_array();
2803 if (options.exists("replaceable")) {
2804 coinControl.signalRbf = options["replaceable"].get_bool();
2806 if (options.exists("conf_target")) {
2807 coinControl.m_confirm_target = ParseConfirmTarget(options["conf_target"]);
2809 if (options.exists("estimate_mode")) {
2810 if (!FeeModeFromString(options["estimate_mode"].get_str(), coinControl.m_fee_mode)) {
2811 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
2817 // parse hex string from parameter
2818 CMutableTransaction tx;
2819 if (!DecodeHexTx(tx, request.params[0].get_str(), true))
2820 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
2822 if (tx.vout.size() == 0)
2823 throw JSONRPCError(RPC_INVALID_PARAMETER, "TX must have at least one output");
2825 if (changePosition != -1 && (changePosition < 0 || (unsigned int)changePosition > tx.vout.size()))
2826 throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds");
2828 for (unsigned int idx = 0; idx < subtractFeeFromOutputs.size(); idx++) {
2829 int pos = subtractFeeFromOutputs[idx].get_int();
2830 if (setSubtractFeeFromOutputs.count(pos))
2831 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, duplicated position: %d", pos));
2832 if (pos < 0)
2833 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, negative position: %d", pos));
2834 if (pos >= int(tx.vout.size()))
2835 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, position too large: %d", pos));
2836 setSubtractFeeFromOutputs.insert(pos);
2839 CAmount nFeeOut;
2840 std::string strFailReason;
2842 if (!pwallet->FundTransaction(tx, nFeeOut, changePosition, strFailReason, lockUnspents, setSubtractFeeFromOutputs, coinControl)) {
2843 throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
2846 UniValue result(UniValue::VOBJ);
2847 result.push_back(Pair("hex", EncodeHexTx(tx)));
2848 result.push_back(Pair("changepos", changePosition));
2849 result.push_back(Pair("fee", ValueFromAmount(nFeeOut)));
2851 return result;
2854 UniValue bumpfee(const JSONRPCRequest& request)
2856 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2858 if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
2859 return NullUniValue;
2861 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
2862 throw std::runtime_error(
2863 "bumpfee \"txid\" ( options ) \n"
2864 "\nBumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B.\n"
2865 "An opt-in RBF transaction with the given txid must be in the wallet.\n"
2866 "The command will pay the additional fee by decreasing (or perhaps removing) its change output.\n"
2867 "If the change output is not big enough to cover the increased fee, the command will currently fail\n"
2868 "instead of adding new inputs to compensate. (A future implementation could improve this.)\n"
2869 "The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.\n"
2870 "By default, the new fee will be calculated automatically using estimatefee.\n"
2871 "The user can specify a confirmation target for estimatefee.\n"
2872 "Alternatively, the user can specify totalFee, or use RPC settxfee to set a higher fee rate.\n"
2873 "At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee\n"
2874 "returned by getnetworkinfo) to enter the node's mempool.\n"
2875 "\nArguments:\n"
2876 "1. txid (string, required) The txid to be bumped\n"
2877 "2. options (object, optional)\n"
2878 " {\n"
2879 " \"confTarget\" (numeric, optional) Confirmation target (in blocks)\n"
2880 " \"totalFee\" (numeric, optional) Total fee (NOT feerate) to pay, in satoshis.\n"
2881 " In rare cases, the actual fee paid might be slightly higher than the specified\n"
2882 " totalFee if the tx change output has to be removed because it is too close to\n"
2883 " the dust threshold.\n"
2884 " \"replaceable\" (boolean, optional, default true) Whether the new transaction should still be\n"
2885 " marked bip-125 replaceable. If true, the sequence numbers in the transaction will\n"
2886 " be left unchanged from the original. If false, any input sequence numbers in the\n"
2887 " original transaction that were less than 0xfffffffe will be increased to 0xfffffffe\n"
2888 " so the new transaction will not be explicitly bip-125 replaceable (though it may\n"
2889 " still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
2890 " are replaceable).\n"
2891 " \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
2892 " \"UNSET\"\n"
2893 " \"ECONOMICAL\"\n"
2894 " \"CONSERVATIVE\"\n"
2895 " }\n"
2896 "\nResult:\n"
2897 "{\n"
2898 " \"txid\": \"value\", (string) The id of the new transaction\n"
2899 " \"origfee\": n, (numeric) Fee of the replaced transaction\n"
2900 " \"fee\": n, (numeric) Fee of the new transaction\n"
2901 " \"errors\": [ str... ] (json array of strings) Errors encountered during processing (may be empty)\n"
2902 "}\n"
2903 "\nExamples:\n"
2904 "\nBump the fee, get the new transaction\'s txid\n" +
2905 HelpExampleCli("bumpfee", "<txid>"));
2908 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ});
2909 uint256 hash;
2910 hash.SetHex(request.params[0].get_str());
2912 // optional parameters
2913 CAmount totalFee = 0;
2914 CCoinControl coin_control;
2915 coin_control.signalRbf = true;
2916 if (!request.params[1].isNull()) {
2917 UniValue options = request.params[1];
2918 RPCTypeCheckObj(options,
2920 {"confTarget", UniValueType(UniValue::VNUM)},
2921 {"totalFee", UniValueType(UniValue::VNUM)},
2922 {"replaceable", UniValueType(UniValue::VBOOL)},
2923 {"estimate_mode", UniValueType(UniValue::VSTR)},
2925 true, true);
2927 if (options.exists("confTarget") && options.exists("totalFee")) {
2928 throw JSONRPCError(RPC_INVALID_PARAMETER, "confTarget and totalFee options should not both be set. Please provide either a confirmation target for fee estimation or an explicit total fee for the transaction.");
2929 } else if (options.exists("confTarget")) { // TODO: alias this to conf_target
2930 coin_control.m_confirm_target = ParseConfirmTarget(options["confTarget"]);
2931 } else if (options.exists("totalFee")) {
2932 totalFee = options["totalFee"].get_int64();
2933 if (totalFee <= 0) {
2934 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid totalFee %s (must be greater than 0)", FormatMoney(totalFee)));
2938 if (options.exists("replaceable")) {
2939 coin_control.signalRbf = options["replaceable"].get_bool();
2941 if (options.exists("estimate_mode")) {
2942 if (!FeeModeFromString(options["estimate_mode"].get_str(), coin_control.m_fee_mode)) {
2943 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
2948 LOCK2(cs_main, pwallet->cs_wallet);
2949 EnsureWalletIsUnlocked(pwallet);
2951 CFeeBumper feeBump(pwallet, hash, coin_control, totalFee);
2952 BumpFeeResult res = feeBump.getResult();
2953 if (res != BumpFeeResult::OK)
2955 switch(res) {
2956 case BumpFeeResult::INVALID_ADDRESS_OR_KEY:
2957 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, feeBump.getErrors()[0]);
2958 break;
2959 case BumpFeeResult::INVALID_REQUEST:
2960 throw JSONRPCError(RPC_INVALID_REQUEST, feeBump.getErrors()[0]);
2961 break;
2962 case BumpFeeResult::INVALID_PARAMETER:
2963 throw JSONRPCError(RPC_INVALID_PARAMETER, feeBump.getErrors()[0]);
2964 break;
2965 case BumpFeeResult::WALLET_ERROR:
2966 throw JSONRPCError(RPC_WALLET_ERROR, feeBump.getErrors()[0]);
2967 break;
2968 default:
2969 throw JSONRPCError(RPC_MISC_ERROR, feeBump.getErrors()[0]);
2970 break;
2974 // sign bumped transaction
2975 if (!feeBump.signTransaction(pwallet)) {
2976 throw JSONRPCError(RPC_WALLET_ERROR, "Can't sign transaction.");
2978 // commit the bumped transaction
2979 if(!feeBump.commit(pwallet)) {
2980 throw JSONRPCError(RPC_WALLET_ERROR, feeBump.getErrors()[0]);
2982 UniValue result(UniValue::VOBJ);
2983 result.push_back(Pair("txid", feeBump.getBumpedTxId().GetHex()));
2984 result.push_back(Pair("origfee", ValueFromAmount(feeBump.getOldFee())));
2985 result.push_back(Pair("fee", ValueFromAmount(feeBump.getNewFee())));
2986 UniValue errors(UniValue::VARR);
2987 for (const std::string& err: feeBump.getErrors())
2988 errors.push_back(err);
2989 result.push_back(Pair("errors", errors));
2991 return result;
2994 UniValue generate(const JSONRPCRequest& request)
2996 CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
2998 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2999 return NullUniValue;
3002 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
3003 throw std::runtime_error(
3004 "generate nblocks ( maxtries )\n"
3005 "\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n"
3006 "\nArguments:\n"
3007 "1. nblocks (numeric, required) How many blocks are generated immediately.\n"
3008 "2. maxtries (numeric, optional) How many iterations to try (default = 1000000).\n"
3009 "\nResult:\n"
3010 "[ blockhashes ] (array) hashes of blocks generated\n"
3011 "\nExamples:\n"
3012 "\nGenerate 11 blocks\n"
3013 + HelpExampleCli("generate", "11")
3017 int num_generate = request.params[0].get_int();
3018 uint64_t max_tries = 1000000;
3019 if (request.params.size() > 1 && !request.params[1].isNull()) {
3020 max_tries = request.params[1].get_int();
3023 std::shared_ptr<CReserveScript> coinbase_script;
3024 pwallet->GetScriptForMining(coinbase_script);
3026 // If the keypool is exhausted, no script is returned at all. Catch this.
3027 if (!coinbase_script) {
3028 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
3031 //throw an error if no script was provided
3032 if (coinbase_script->reserveScript.empty()) {
3033 throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available");
3036 return generateBlocks(coinbase_script, num_generate, max_tries, true);
3039 extern UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp
3040 extern UniValue dumpprivkey(const JSONRPCRequest& request); // in rpcdump.cpp
3041 extern UniValue importprivkey(const JSONRPCRequest& request);
3042 extern UniValue importaddress(const JSONRPCRequest& request);
3043 extern UniValue importpubkey(const JSONRPCRequest& request);
3044 extern UniValue dumpwallet(const JSONRPCRequest& request);
3045 extern UniValue importwallet(const JSONRPCRequest& request);
3046 extern UniValue importprunedfunds(const JSONRPCRequest& request);
3047 extern UniValue removeprunedfunds(const JSONRPCRequest& request);
3048 extern UniValue importmulti(const JSONRPCRequest& request);
3050 static const CRPCCommand commands[] =
3051 { // category name actor (function) okSafeMode
3052 // --------------------- ------------------------ ----------------------- ----------
3053 { "rawtransactions", "fundrawtransaction", &fundrawtransaction, false, {"hexstring","options"} },
3054 { "hidden", "resendwallettransactions", &resendwallettransactions, true, {} },
3055 { "wallet", "abandontransaction", &abandontransaction, false, {"txid"} },
3056 { "wallet", "abortrescan", &abortrescan, false, {} },
3057 { "wallet", "addmultisigaddress", &addmultisigaddress, true, {"nrequired","keys","account"} },
3058 { "wallet", "addwitnessaddress", &addwitnessaddress, true, {"address"} },
3059 { "wallet", "backupwallet", &backupwallet, true, {"destination"} },
3060 { "wallet", "bumpfee", &bumpfee, true, {"txid", "options"} },
3061 { "wallet", "dumpprivkey", &dumpprivkey, true, {"address"} },
3062 { "wallet", "dumpwallet", &dumpwallet, true, {"filename"} },
3063 { "wallet", "encryptwallet", &encryptwallet, true, {"passphrase"} },
3064 { "wallet", "getaccountaddress", &getaccountaddress, true, {"account"} },
3065 { "wallet", "getaccount", &getaccount, true, {"address"} },
3066 { "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true, {"account"} },
3067 { "wallet", "getbalance", &getbalance, false, {"account","minconf","include_watchonly"} },
3068 { "wallet", "getnewaddress", &getnewaddress, true, {"account"} },
3069 { "wallet", "getrawchangeaddress", &getrawchangeaddress, true, {} },
3070 { "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false, {"account","minconf"} },
3071 { "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false, {"address","minconf"} },
3072 { "wallet", "gettransaction", &gettransaction, false, {"txid","include_watchonly"} },
3073 { "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false, {} },
3074 { "wallet", "getwalletinfo", &getwalletinfo, false, {} },
3075 { "wallet", "importmulti", &importmulti, true, {"requests","options"} },
3076 { "wallet", "importprivkey", &importprivkey, true, {"privkey","label","rescan"} },
3077 { "wallet", "importwallet", &importwallet, true, {"filename"} },
3078 { "wallet", "importaddress", &importaddress, true, {"address","label","rescan","p2sh"} },
3079 { "wallet", "importprunedfunds", &importprunedfunds, true, {"rawtransaction","txoutproof"} },
3080 { "wallet", "importpubkey", &importpubkey, true, {"pubkey","label","rescan"} },
3081 { "wallet", "keypoolrefill", &keypoolrefill, true, {"newsize"} },
3082 { "wallet", "listaccounts", &listaccounts, false, {"minconf","include_watchonly"} },
3083 { "wallet", "listaddressgroupings", &listaddressgroupings, false, {} },
3084 { "wallet", "listlockunspent", &listlockunspent, false, {} },
3085 { "wallet", "listreceivedbyaccount", &listreceivedbyaccount, false, {"minconf","include_empty","include_watchonly"} },
3086 { "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false, {"minconf","include_empty","include_watchonly"} },
3087 { "wallet", "listsinceblock", &listsinceblock, false, {"blockhash","target_confirmations","include_watchonly"} },
3088 { "wallet", "listtransactions", &listtransactions, false, {"account","count","skip","include_watchonly"} },
3089 { "wallet", "listunspent", &listunspent, false, {"minconf","maxconf","addresses","include_unsafe","query_options"} },
3090 { "wallet", "lockunspent", &lockunspent, true, {"unlock","transactions"} },
3091 { "wallet", "move", &movecmd, false, {"fromaccount","toaccount","amount","minconf","comment"} },
3092 { "wallet", "sendfrom", &sendfrom, false, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} },
3093 { "wallet", "sendmany", &sendmany, false, {"fromaccount","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode"} },
3094 { "wallet", "sendtoaddress", &sendtoaddress, false, {"address","amount","comment","comment_to","subtractfeefromamount","replaceable","conf_target","estimate_mode"} },
3095 { "wallet", "setaccount", &setaccount, true, {"address","account"} },
3096 { "wallet", "settxfee", &settxfee, true, {"amount"} },
3097 { "wallet", "signmessage", &signmessage, true, {"address","message"} },
3098 { "wallet", "walletlock", &walletlock, true, {} },
3099 { "wallet", "walletpassphrasechange", &walletpassphrasechange, true, {"oldpassphrase","newpassphrase"} },
3100 { "wallet", "walletpassphrase", &walletpassphrase, true, {"passphrase","timeout"} },
3101 { "wallet", "removeprunedfunds", &removeprunedfunds, true, {"txid"} },
3103 { "generating", "generate", &generate, true, {"nblocks","maxtries"} },
3106 void RegisterWalletRPCCommands(CRPCTable &t)
3108 if (GetBoolArg("-disablewallet", false))
3109 return;
3111 for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
3112 t.appendCommand(commands[vcidx].name, &commands[vcidx]);