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.
9 #include "consensus/validation.h"
12 #include "httpserver.h"
13 #include "validation.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"
24 #include "utilmoneystr.h"
25 #include "wallet/coincontrol.h"
26 #include "wallet/feebumper.h"
27 #include "wallet/wallet.h"
28 #include "wallet/walletdb.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
) {
46 throw JSONRPCError(RPC_WALLET_NOT_FOUND
, "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."
58 bool EnsureWalletIsAvailable(CWallet
* const pwallet
, bool avoidException
)
60 if (pwallet
) return true;
61 if (avoidException
) return false;
62 if (::vpwallets
.empty()) {
63 // Note: It isn't currently possible to trigger this error because
64 // wallet RPC methods aren't registered unless a wallet is loaded. But
65 // this error is being kept as a precaution, because it's possible in
66 // the future that wallet RPC methods might get or remain registered
67 // when no wallets are loaded.
69 RPC_METHOD_NOT_FOUND
, "Method not found (wallet method is disabled because no wallet is loaded)");
71 throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED
,
72 "Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).");
75 void EnsureWalletIsUnlocked(CWallet
* const pwallet
)
77 if (pwallet
->IsLocked()) {
78 throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED
, "Error: Please enter the wallet passphrase with walletpassphrase first.");
82 void WalletTxToJSON(const CWalletTx
& wtx
, UniValue
& entry
)
84 int confirms
= wtx
.GetDepthInMainChain();
85 entry
.push_back(Pair("confirmations", confirms
));
87 entry
.push_back(Pair("generated", true));
90 entry
.push_back(Pair("blockhash", wtx
.hashBlock
.GetHex()));
91 entry
.push_back(Pair("blockindex", wtx
.nIndex
));
92 entry
.push_back(Pair("blocktime", mapBlockIndex
[wtx
.hashBlock
]->GetBlockTime()));
94 entry
.push_back(Pair("trusted", wtx
.IsTrusted()));
96 uint256 hash
= wtx
.GetHash();
97 entry
.push_back(Pair("txid", hash
.GetHex()));
98 UniValue
conflicts(UniValue::VARR
);
99 for (const uint256
& conflict
: wtx
.GetConflicts())
100 conflicts
.push_back(conflict
.GetHex());
101 entry
.push_back(Pair("walletconflicts", conflicts
));
102 entry
.push_back(Pair("time", wtx
.GetTxTime()));
103 entry
.push_back(Pair("timereceived", (int64_t)wtx
.nTimeReceived
));
105 // Add opt-in RBF status
106 std::string rbfStatus
= "no";
109 RBFTransactionState rbfState
= IsRBFOptIn(wtx
, mempool
);
110 if (rbfState
== RBF_TRANSACTIONSTATE_UNKNOWN
)
111 rbfStatus
= "unknown";
112 else if (rbfState
== RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125
)
115 entry
.push_back(Pair("bip125-replaceable", rbfStatus
));
117 for (const std::pair
<std::string
, std::string
>& item
: wtx
.mapValue
)
118 entry
.push_back(Pair(item
.first
, item
.second
));
121 std::string
AccountFromValue(const UniValue
& value
)
123 std::string strAccount
= value
.get_str();
124 if (strAccount
== "*")
125 throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME
, "Invalid account name");
129 UniValue
getnewaddress(const JSONRPCRequest
& request
)
131 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
132 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
136 if (request
.fHelp
|| request
.params
.size() > 1)
137 throw std::runtime_error(
138 "getnewaddress ( \"account\" )\n"
139 "\nReturns a new Bitcoin address for receiving payments.\n"
140 "If 'account' is specified (DEPRECATED), it is added to the address book \n"
141 "so payments received with the address will be credited to 'account'.\n"
143 "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"
145 "\"address\" (string) The new bitcoin address\n"
147 + HelpExampleCli("getnewaddress", "")
148 + HelpExampleRpc("getnewaddress", "")
151 LOCK2(cs_main
, pwallet
->cs_wallet
);
153 // Parse the account first so we don't generate a key if there's an error
154 std::string strAccount
;
155 if (!request
.params
[0].isNull())
156 strAccount
= AccountFromValue(request
.params
[0]);
158 if (!pwallet
->IsLocked()) {
159 pwallet
->TopUpKeyPool();
162 // Generate a new key that is added to wallet
164 if (!pwallet
->GetKeyFromPool(newKey
)) {
165 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT
, "Error: Keypool ran out, please call keypoolrefill first");
167 CKeyID keyID
= newKey
.GetID();
169 pwallet
->SetAddressBook(keyID
, strAccount
, "receive");
171 return CBitcoinAddress(keyID
).ToString();
175 CBitcoinAddress
GetAccountAddress(CWallet
* const pwallet
, std::string strAccount
, bool bForceNew
=false)
178 if (!pwallet
->GetAccountPubkey(pubKey
, strAccount
, bForceNew
)) {
179 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT
, "Error: Keypool ran out, please call keypoolrefill first");
182 return CBitcoinAddress(pubKey
.GetID());
185 UniValue
getaccountaddress(const JSONRPCRequest
& request
)
187 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
188 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
192 if (request
.fHelp
|| request
.params
.size() != 1)
193 throw std::runtime_error(
194 "getaccountaddress \"account\"\n"
195 "\nDEPRECATED. Returns the current Bitcoin address for receiving payments to this account.\n"
197 "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"
199 "\"address\" (string) The account bitcoin address\n"
201 + HelpExampleCli("getaccountaddress", "")
202 + HelpExampleCli("getaccountaddress", "\"\"")
203 + HelpExampleCli("getaccountaddress", "\"myaccount\"")
204 + HelpExampleRpc("getaccountaddress", "\"myaccount\"")
207 LOCK2(cs_main
, pwallet
->cs_wallet
);
209 // Parse the account first so we don't generate a key if there's an error
210 std::string strAccount
= AccountFromValue(request
.params
[0]);
212 UniValue
ret(UniValue::VSTR
);
214 ret
= GetAccountAddress(pwallet
, strAccount
).ToString();
219 UniValue
getrawchangeaddress(const JSONRPCRequest
& request
)
221 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
222 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
226 if (request
.fHelp
|| request
.params
.size() > 0)
227 throw std::runtime_error(
228 "getrawchangeaddress\n"
229 "\nReturns a new Bitcoin address, for receiving change.\n"
230 "This is for use with raw transactions, NOT normal use.\n"
232 "\"address\" (string) The address\n"
234 + HelpExampleCli("getrawchangeaddress", "")
235 + HelpExampleRpc("getrawchangeaddress", "")
238 LOCK2(cs_main
, pwallet
->cs_wallet
);
240 if (!pwallet
->IsLocked()) {
241 pwallet
->TopUpKeyPool();
244 CReserveKey
reservekey(pwallet
);
246 if (!reservekey
.GetReservedKey(vchPubKey
, true))
247 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT
, "Error: Keypool ran out, please call keypoolrefill first");
249 reservekey
.KeepKey();
251 CKeyID keyID
= vchPubKey
.GetID();
253 return CBitcoinAddress(keyID
).ToString();
257 UniValue
setaccount(const JSONRPCRequest
& request
)
259 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
260 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
264 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 2)
265 throw std::runtime_error(
266 "setaccount \"address\" \"account\"\n"
267 "\nDEPRECATED. Sets the account associated with the given address.\n"
269 "1. \"address\" (string, required) The bitcoin address to be associated with an account.\n"
270 "2. \"account\" (string, required) The account to assign the address to.\n"
272 + HelpExampleCli("setaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"")
273 + HelpExampleRpc("setaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")
276 LOCK2(cs_main
, pwallet
->cs_wallet
);
278 CBitcoinAddress
address(request
.params
[0].get_str());
279 if (!address
.IsValid())
280 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Invalid Bitcoin address");
282 std::string strAccount
;
283 if (request
.params
.size() > 1)
284 strAccount
= AccountFromValue(request
.params
[1]);
286 // Only add the account if the address is yours.
287 if (IsMine(*pwallet
, address
.Get())) {
288 // Detect when changing the account of an address that is the 'unused current key' of another account:
289 if (pwallet
->mapAddressBook
.count(address
.Get())) {
290 std::string strOldAccount
= pwallet
->mapAddressBook
[address
.Get()].name
;
291 if (address
== GetAccountAddress(pwallet
, strOldAccount
)) {
292 GetAccountAddress(pwallet
, strOldAccount
, true);
295 pwallet
->SetAddressBook(address
.Get(), strAccount
, "receive");
298 throw JSONRPCError(RPC_MISC_ERROR
, "setaccount can only be used with own address");
304 UniValue
getaccount(const JSONRPCRequest
& request
)
306 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
307 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
311 if (request
.fHelp
|| request
.params
.size() != 1)
312 throw std::runtime_error(
313 "getaccount \"address\"\n"
314 "\nDEPRECATED. Returns the account associated with the given address.\n"
316 "1. \"address\" (string, required) The bitcoin address for account lookup.\n"
318 "\"accountname\" (string) the account address\n"
320 + HelpExampleCli("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")
321 + HelpExampleRpc("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")
324 LOCK2(cs_main
, pwallet
->cs_wallet
);
326 CBitcoinAddress
address(request
.params
[0].get_str());
327 if (!address
.IsValid())
328 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Invalid Bitcoin address");
330 std::string strAccount
;
331 std::map
<CTxDestination
, CAddressBookData
>::iterator mi
= pwallet
->mapAddressBook
.find(address
.Get());
332 if (mi
!= pwallet
->mapAddressBook
.end() && !(*mi
).second
.name
.empty()) {
333 strAccount
= (*mi
).second
.name
;
339 UniValue
getaddressesbyaccount(const JSONRPCRequest
& request
)
341 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
342 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
346 if (request
.fHelp
|| request
.params
.size() != 1)
347 throw std::runtime_error(
348 "getaddressesbyaccount \"account\"\n"
349 "\nDEPRECATED. Returns the list of addresses for the given account.\n"
351 "1. \"account\" (string, required) The account name.\n"
353 "[ (json array of string)\n"
354 " \"address\" (string) a bitcoin address associated with the given account\n"
358 + HelpExampleCli("getaddressesbyaccount", "\"tabby\"")
359 + HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")
362 LOCK2(cs_main
, pwallet
->cs_wallet
);
364 std::string strAccount
= AccountFromValue(request
.params
[0]);
366 // Find all addresses that have the given account
367 UniValue
ret(UniValue::VARR
);
368 for (const std::pair
<CBitcoinAddress
, CAddressBookData
>& item
: pwallet
->mapAddressBook
) {
369 const CBitcoinAddress
& address
= item
.first
;
370 const std::string
& strName
= item
.second
.name
;
371 if (strName
== strAccount
)
372 ret
.push_back(address
.ToString());
377 static void SendMoney(CWallet
* const pwallet
, const CTxDestination
&address
, CAmount nValue
, bool fSubtractFeeFromAmount
, CWalletTx
& wtxNew
, const CCoinControl
& coin_control
)
379 CAmount curBalance
= pwallet
->GetBalance();
383 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid amount");
385 if (nValue
> curBalance
)
386 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS
, "Insufficient funds");
388 if (pwallet
->GetBroadcastTransactions() && !g_connman
) {
389 throw JSONRPCError(RPC_CLIENT_P2P_DISABLED
, "Error: Peer-to-peer functionality missing or disabled");
392 // Parse Bitcoin address
393 CScript scriptPubKey
= GetScriptForDestination(address
);
395 // Create and send the transaction
396 CReserveKey
reservekey(pwallet
);
397 CAmount nFeeRequired
;
398 std::string strError
;
399 std::vector
<CRecipient
> vecSend
;
400 int nChangePosRet
= -1;
401 CRecipient recipient
= {scriptPubKey
, nValue
, fSubtractFeeFromAmount
};
402 vecSend
.push_back(recipient
);
403 if (!pwallet
->CreateTransaction(vecSend
, wtxNew
, reservekey
, nFeeRequired
, nChangePosRet
, strError
, coin_control
)) {
404 if (!fSubtractFeeFromAmount
&& nValue
+ nFeeRequired
> curBalance
)
405 strError
= strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired
));
406 throw JSONRPCError(RPC_WALLET_ERROR
, strError
);
408 CValidationState state
;
409 if (!pwallet
->CommitTransaction(wtxNew
, reservekey
, g_connman
.get(), state
)) {
410 strError
= strprintf("Error: The transaction was rejected! Reason given: %s", state
.GetRejectReason());
411 throw JSONRPCError(RPC_WALLET_ERROR
, strError
);
415 UniValue
sendtoaddress(const JSONRPCRequest
& request
)
417 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
418 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
422 if (request
.fHelp
|| request
.params
.size() < 2 || request
.params
.size() > 8)
423 throw std::runtime_error(
424 "sendtoaddress \"address\" amount ( \"comment\" \"comment_to\" subtractfeefromamount replaceable conf_target \"estimate_mode\")\n"
425 "\nSend an amount to a given address.\n"
426 + HelpRequiringPassphrase(pwallet
) +
428 "1. \"address\" (string, required) The bitcoin address to send to.\n"
429 "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT
+ " to send. eg 0.1\n"
430 "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
431 " This is not part of the transaction, just kept in your wallet.\n"
432 "4. \"comment_to\" (string, optional) A comment to store the name of the person or organization \n"
433 " to which you're sending the transaction. This is not part of the \n"
434 " transaction, just kept in your wallet.\n"
435 "5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
436 " The recipient will receive less bitcoins than you enter in the amount field.\n"
437 "6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125\n"
438 "7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
439 "8. \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
442 " \"CONSERVATIVE\"\n"
444 "\"txid\" (string) The transaction id.\n"
446 + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1")
447 + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"donation\" \"seans outpost\"")
448 + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"\" \"\" true")
449 + HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.1, \"donation\", \"seans outpost\"")
452 LOCK2(cs_main
, pwallet
->cs_wallet
);
454 CBitcoinAddress
address(request
.params
[0].get_str());
455 if (!address
.IsValid())
456 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Invalid Bitcoin address");
459 CAmount nAmount
= AmountFromValue(request
.params
[1]);
461 throw JSONRPCError(RPC_TYPE_ERROR
, "Invalid amount for send");
465 if (request
.params
.size() > 2 && !request
.params
[2].isNull() && !request
.params
[2].get_str().empty())
466 wtx
.mapValue
["comment"] = request
.params
[2].get_str();
467 if (request
.params
.size() > 3 && !request
.params
[3].isNull() && !request
.params
[3].get_str().empty())
468 wtx
.mapValue
["to"] = request
.params
[3].get_str();
470 bool fSubtractFeeFromAmount
= false;
471 if (request
.params
.size() > 4 && !request
.params
[4].isNull()) {
472 fSubtractFeeFromAmount
= request
.params
[4].get_bool();
475 CCoinControl coin_control
;
476 if (request
.params
.size() > 5 && !request
.params
[5].isNull()) {
477 coin_control
.signalRbf
= request
.params
[5].get_bool();
480 if (request
.params
.size() > 6 && !request
.params
[6].isNull()) {
481 coin_control
.m_confirm_target
= ParseConfirmTarget(request
.params
[6]);
484 if (request
.params
.size() > 7 && !request
.params
[7].isNull()) {
485 if (!FeeModeFromString(request
.params
[7].get_str(), coin_control
.m_fee_mode
)) {
486 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid estimate_mode parameter");
491 EnsureWalletIsUnlocked(pwallet
);
493 SendMoney(pwallet
, address
.Get(), nAmount
, fSubtractFeeFromAmount
, wtx
, coin_control
);
495 return wtx
.GetHash().GetHex();
498 UniValue
listaddressgroupings(const JSONRPCRequest
& request
)
500 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
501 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
505 if (request
.fHelp
|| request
.params
.size() != 0)
506 throw std::runtime_error(
507 "listaddressgroupings\n"
508 "\nLists groups of addresses which have had their common ownership\n"
509 "made public by common use as inputs or as the resulting change\n"
510 "in past transactions\n"
515 " \"address\", (string) The bitcoin address\n"
516 " amount, (numeric) The amount in " + CURRENCY_UNIT
+ "\n"
517 " \"account\" (string, optional) DEPRECATED. The account\n"
524 + HelpExampleCli("listaddressgroupings", "")
525 + HelpExampleRpc("listaddressgroupings", "")
528 LOCK2(cs_main
, pwallet
->cs_wallet
);
530 UniValue
jsonGroupings(UniValue::VARR
);
531 std::map
<CTxDestination
, CAmount
> balances
= pwallet
->GetAddressBalances();
532 for (std::set
<CTxDestination
> grouping
: pwallet
->GetAddressGroupings()) {
533 UniValue
jsonGrouping(UniValue::VARR
);
534 for (CTxDestination address
: grouping
)
536 UniValue
addressInfo(UniValue::VARR
);
537 addressInfo
.push_back(CBitcoinAddress(address
).ToString());
538 addressInfo
.push_back(ValueFromAmount(balances
[address
]));
540 if (pwallet
->mapAddressBook
.find(CBitcoinAddress(address
).Get()) != pwallet
->mapAddressBook
.end()) {
541 addressInfo
.push_back(pwallet
->mapAddressBook
.find(CBitcoinAddress(address
).Get())->second
.name
);
544 jsonGrouping
.push_back(addressInfo
);
546 jsonGroupings
.push_back(jsonGrouping
);
548 return jsonGroupings
;
551 UniValue
signmessage(const JSONRPCRequest
& request
)
553 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
554 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
558 if (request
.fHelp
|| request
.params
.size() != 2)
559 throw std::runtime_error(
560 "signmessage \"address\" \"message\"\n"
561 "\nSign a message with the private key of an address"
562 + HelpRequiringPassphrase(pwallet
) + "\n"
564 "1. \"address\" (string, required) The bitcoin address to use for the private key.\n"
565 "2. \"message\" (string, required) The message to create a signature of.\n"
567 "\"signature\" (string) The signature of the message encoded in base 64\n"
569 "\nUnlock the wallet for 30 seconds\n"
570 + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
571 "\nCreate the signature\n"
572 + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
573 "\nVerify the signature\n"
574 + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
576 + HelpExampleRpc("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")
579 LOCK2(cs_main
, pwallet
->cs_wallet
);
581 EnsureWalletIsUnlocked(pwallet
);
583 std::string strAddress
= request
.params
[0].get_str();
584 std::string strMessage
= request
.params
[1].get_str();
586 CBitcoinAddress
addr(strAddress
);
588 throw JSONRPCError(RPC_TYPE_ERROR
, "Invalid address");
591 if (!addr
.GetKeyID(keyID
))
592 throw JSONRPCError(RPC_TYPE_ERROR
, "Address does not refer to key");
595 if (!pwallet
->GetKey(keyID
, key
)) {
596 throw JSONRPCError(RPC_WALLET_ERROR
, "Private key not available");
599 CHashWriter
ss(SER_GETHASH
, 0);
600 ss
<< strMessageMagic
;
603 std::vector
<unsigned char> vchSig
;
604 if (!key
.SignCompact(ss
.GetHash(), vchSig
))
605 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Sign failed");
607 return EncodeBase64(&vchSig
[0], vchSig
.size());
610 UniValue
getreceivedbyaddress(const JSONRPCRequest
& request
)
612 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
613 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
617 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 2)
618 throw std::runtime_error(
619 "getreceivedbyaddress \"address\" ( minconf )\n"
620 "\nReturns the total amount received by the given address in transactions with at least minconf confirmations.\n"
622 "1. \"address\" (string, required) The bitcoin address for transactions.\n"
623 "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
625 "amount (numeric) The total amount in " + CURRENCY_UNIT
+ " received at this address.\n"
627 "\nThe amount from transactions with at least 1 confirmation\n"
628 + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"") +
629 "\nThe amount including unconfirmed transactions, zero confirmations\n"
630 + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 0") +
631 "\nThe amount with at least 6 confirmations\n"
632 + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 6") +
633 "\nAs a json rpc call\n"
634 + HelpExampleRpc("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6")
637 LOCK2(cs_main
, pwallet
->cs_wallet
);
640 CBitcoinAddress address
= CBitcoinAddress(request
.params
[0].get_str());
641 if (!address
.IsValid())
642 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Invalid Bitcoin address");
643 CScript scriptPubKey
= GetScriptForDestination(address
.Get());
644 if (!IsMine(*pwallet
, scriptPubKey
)) {
645 return ValueFromAmount(0);
648 // Minimum confirmations
650 if (!request
.params
[1].isNull())
651 nMinDepth
= request
.params
[1].get_int();
655 for (const std::pair
<uint256
, CWalletTx
>& pairWtx
: pwallet
->mapWallet
) {
656 const CWalletTx
& wtx
= pairWtx
.second
;
657 if (wtx
.IsCoinBase() || !CheckFinalTx(*wtx
.tx
))
660 for (const CTxOut
& txout
: wtx
.tx
->vout
)
661 if (txout
.scriptPubKey
== scriptPubKey
)
662 if (wtx
.GetDepthInMainChain() >= nMinDepth
)
663 nAmount
+= txout
.nValue
;
666 return ValueFromAmount(nAmount
);
670 UniValue
getreceivedbyaccount(const JSONRPCRequest
& request
)
672 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
673 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
677 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 2)
678 throw std::runtime_error(
679 "getreceivedbyaccount \"account\" ( minconf )\n"
680 "\nDEPRECATED. Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.\n"
682 "1. \"account\" (string, required) The selected account, may be the default account using \"\".\n"
683 "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
685 "amount (numeric) The total amount in " + CURRENCY_UNIT
+ " received for this account.\n"
687 "\nAmount received by the default account with at least 1 confirmation\n"
688 + HelpExampleCli("getreceivedbyaccount", "\"\"") +
689 "\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n"
690 + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") +
691 "\nThe amount with at least 6 confirmations\n"
692 + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") +
693 "\nAs a json rpc call\n"
694 + HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6")
697 LOCK2(cs_main
, pwallet
->cs_wallet
);
699 // Minimum confirmations
701 if (!request
.params
[1].isNull())
702 nMinDepth
= request
.params
[1].get_int();
704 // Get the set of pub keys assigned to account
705 std::string strAccount
= AccountFromValue(request
.params
[0]);
706 std::set
<CTxDestination
> setAddress
= pwallet
->GetAccountAddresses(strAccount
);
710 for (const std::pair
<uint256
, CWalletTx
>& pairWtx
: pwallet
->mapWallet
) {
711 const CWalletTx
& wtx
= pairWtx
.second
;
712 if (wtx
.IsCoinBase() || !CheckFinalTx(*wtx
.tx
))
715 for (const CTxOut
& txout
: wtx
.tx
->vout
)
717 CTxDestination address
;
718 if (ExtractDestination(txout
.scriptPubKey
, address
) && IsMine(*pwallet
, address
) && setAddress
.count(address
)) {
719 if (wtx
.GetDepthInMainChain() >= nMinDepth
)
720 nAmount
+= txout
.nValue
;
725 return ValueFromAmount(nAmount
);
729 UniValue
getbalance(const JSONRPCRequest
& request
)
731 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
732 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
736 if (request
.fHelp
|| request
.params
.size() > 3)
737 throw std::runtime_error(
738 "getbalance ( \"account\" minconf include_watchonly )\n"
739 "\nIf account is not specified, returns the server's total available balance.\n"
740 "If account is specified (DEPRECATED), returns the balance in the account.\n"
741 "Note that the account \"\" is not the same as leaving the parameter out.\n"
742 "The server total may be different to the balance in the default \"\" account.\n"
744 "1. \"account\" (string, optional) DEPRECATED. The account string may be given as a\n"
745 " specific account name to find the balance associated with wallet keys in\n"
746 " a named account, or as the empty string (\"\") to find the balance\n"
747 " associated with wallet keys not in any named account, or as \"*\" to find\n"
748 " the balance associated with all wallet keys regardless of account.\n"
749 " When this option is specified, it calculates the balance in a different\n"
750 " way than when it is not specified, and which can count spends twice when\n"
751 " there are conflicting pending transactions (such as those created by\n"
752 " the bumpfee command), temporarily resulting in low or even negative\n"
753 " balances. In general, account balance calculation is not considered\n"
754 " reliable and has resulted in confusing outcomes, so it is recommended to\n"
755 " avoid passing this argument.\n"
756 "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
757 "3. include_watchonly (bool, optional, default=false) Also include balance in watch-only addresses (see 'importaddress')\n"
759 "amount (numeric) The total amount in " + CURRENCY_UNIT
+ " received for this account.\n"
761 "\nThe total amount in the wallet with 1 or more confirmations\n"
762 + HelpExampleCli("getbalance", "") +
763 "\nThe total amount in the wallet at least 6 blocks confirmed\n"
764 + HelpExampleCli("getbalance", "\"*\" 6") +
765 "\nAs a json rpc call\n"
766 + HelpExampleRpc("getbalance", "\"*\", 6")
769 LOCK2(cs_main
, pwallet
->cs_wallet
);
771 if (request
.params
.size() == 0)
772 return ValueFromAmount(pwallet
->GetBalance());
774 const std::string
& account_param
= request
.params
[0].get_str();
775 const std::string
* account
= account_param
!= "*" ? &account_param
: nullptr;
778 if (!request
.params
[1].isNull())
779 nMinDepth
= request
.params
[1].get_int();
780 isminefilter filter
= ISMINE_SPENDABLE
;
781 if(!request
.params
[2].isNull())
782 if(request
.params
[2].get_bool())
783 filter
= filter
| ISMINE_WATCH_ONLY
;
785 return ValueFromAmount(pwallet
->GetLegacyBalance(filter
, nMinDepth
, account
));
788 UniValue
getunconfirmedbalance(const JSONRPCRequest
&request
)
790 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
791 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
795 if (request
.fHelp
|| request
.params
.size() > 0)
796 throw std::runtime_error(
797 "getunconfirmedbalance\n"
798 "Returns the server's total unconfirmed balance\n");
800 LOCK2(cs_main
, pwallet
->cs_wallet
);
802 return ValueFromAmount(pwallet
->GetUnconfirmedBalance());
806 UniValue
movecmd(const JSONRPCRequest
& request
)
808 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
809 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
813 if (request
.fHelp
|| request
.params
.size() < 3 || request
.params
.size() > 5)
814 throw std::runtime_error(
815 "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
816 "\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n"
818 "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
819 "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
820 "3. amount (numeric) Quantity of " + CURRENCY_UNIT
+ " to move between accounts.\n"
821 "4. (dummy) (numeric, optional) Ignored. Remains for backward compatibility.\n"
822 "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
824 "true|false (boolean) true if successful.\n"
826 "\nMove 0.01 " + CURRENCY_UNIT
+ " from the default account to the account named tabby\n"
827 + HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
828 "\nMove 0.01 " + CURRENCY_UNIT
+ " timotei to akiko with a comment and funds have 6 confirmations\n"
829 + HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") +
830 "\nAs a json rpc call\n"
831 + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")
834 LOCK2(cs_main
, pwallet
->cs_wallet
);
836 std::string strFrom
= AccountFromValue(request
.params
[0]);
837 std::string strTo
= AccountFromValue(request
.params
[1]);
838 CAmount nAmount
= AmountFromValue(request
.params
[2]);
840 throw JSONRPCError(RPC_TYPE_ERROR
, "Invalid amount for send");
841 if (request
.params
.size() > 3)
842 // unused parameter, used to be nMinDepth, keep type-checking it though
843 (void)request
.params
[3].get_int();
844 std::string strComment
;
845 if (request
.params
.size() > 4)
846 strComment
= request
.params
[4].get_str();
848 if (!pwallet
->AccountMove(strFrom
, strTo
, nAmount
, strComment
)) {
849 throw JSONRPCError(RPC_DATABASE_ERROR
, "database error");
856 UniValue
sendfrom(const JSONRPCRequest
& request
)
858 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
859 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
863 if (request
.fHelp
|| request
.params
.size() < 3 || request
.params
.size() > 6)
864 throw std::runtime_error(
865 "sendfrom \"fromaccount\" \"toaddress\" amount ( minconf \"comment\" \"comment_to\" )\n"
866 "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a bitcoin address."
867 + HelpRequiringPassphrase(pwallet
) + "\n"
869 "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n"
870 " Specifying an account does not influence coin selection, but it does associate the newly created\n"
871 " transaction with the account, so the account's balance computation and transaction history can reflect\n"
873 "2. \"toaddress\" (string, required) The bitcoin address to send funds to.\n"
874 "3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT
+ " (transaction fee is added on top).\n"
875 "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
876 "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
877 " This is not part of the transaction, just kept in your wallet.\n"
878 "6. \"comment_to\" (string, optional) An optional comment to store the name of the person or organization \n"
879 " to which you're sending the transaction. This is not part of the transaction, \n"
880 " it is just kept in your wallet.\n"
882 "\"txid\" (string) The transaction id.\n"
884 "\nSend 0.01 " + CURRENCY_UNIT
+ " from the default account to the address, must have at least 1 confirmation\n"
885 + HelpExampleCli("sendfrom", "\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") +
886 "\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n"
887 + HelpExampleCli("sendfrom", "\"tabby\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 6 \"donation\" \"seans outpost\"") +
888 "\nAs a json rpc call\n"
889 + HelpExampleRpc("sendfrom", "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.01, 6, \"donation\", \"seans outpost\"")
892 LOCK2(cs_main
, pwallet
->cs_wallet
);
894 std::string strAccount
= AccountFromValue(request
.params
[0]);
895 CBitcoinAddress
address(request
.params
[1].get_str());
896 if (!address
.IsValid())
897 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Invalid Bitcoin address");
898 CAmount nAmount
= AmountFromValue(request
.params
[2]);
900 throw JSONRPCError(RPC_TYPE_ERROR
, "Invalid amount for send");
902 if (request
.params
.size() > 3)
903 nMinDepth
= request
.params
[3].get_int();
906 wtx
.strFromAccount
= strAccount
;
907 if (request
.params
.size() > 4 && !request
.params
[4].isNull() && !request
.params
[4].get_str().empty())
908 wtx
.mapValue
["comment"] = request
.params
[4].get_str();
909 if (request
.params
.size() > 5 && !request
.params
[5].isNull() && !request
.params
[5].get_str().empty())
910 wtx
.mapValue
["to"] = request
.params
[5].get_str();
912 EnsureWalletIsUnlocked(pwallet
);
915 CAmount nBalance
= pwallet
->GetLegacyBalance(ISMINE_SPENDABLE
, nMinDepth
, &strAccount
);
916 if (nAmount
> nBalance
)
917 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS
, "Account has insufficient funds");
919 CCoinControl no_coin_control
; // This is a deprecated API
920 SendMoney(pwallet
, address
.Get(), nAmount
, false, wtx
, no_coin_control
);
922 return wtx
.GetHash().GetHex();
926 UniValue
sendmany(const JSONRPCRequest
& request
)
928 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
929 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
933 if (request
.fHelp
|| request
.params
.size() < 2 || request
.params
.size() > 8)
934 throw std::runtime_error(
935 "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] replaceable conf_target \"estimate_mode\")\n"
936 "\nSend multiple times. Amounts are double-precision floating point numbers."
937 + HelpRequiringPassphrase(pwallet
) + "\n"
939 "1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n"
940 "2. \"amounts\" (string, required) A json object with addresses and amounts\n"
942 " \"address\":amount (numeric or string) The bitcoin address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT
+ " is the value\n"
945 "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
946 "4. \"comment\" (string, optional) A comment\n"
947 "5. subtractfeefrom (array, optional) A json array with addresses.\n"
948 " The fee will be equally deducted from the amount of each selected address.\n"
949 " Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
950 " If no addresses are specified here, the sender pays the fee.\n"
952 " \"address\" (string) Subtract fee from this address\n"
955 "6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125\n"
956 "7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
957 "8. \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
960 " \"CONSERVATIVE\"\n"
962 "\"txid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
963 " the number of addresses.\n"
965 "\nSend two amounts to two different addresses:\n"
966 + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"") +
967 "\nSend two amounts to two different addresses setting the confirmation and comment:\n"
968 + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 6 \"testing\"") +
969 "\nSend two amounts to two different addresses, subtract fee from amount:\n"
970 + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 1 \"\" \"[\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\",\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") +
971 "\nAs a json rpc call\n"
972 + HelpExampleRpc("sendmany", "\"\", \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\", 6, \"testing\"")
975 LOCK2(cs_main
, pwallet
->cs_wallet
);
977 if (pwallet
->GetBroadcastTransactions() && !g_connman
) {
978 throw JSONRPCError(RPC_CLIENT_P2P_DISABLED
, "Error: Peer-to-peer functionality missing or disabled");
981 std::string strAccount
= AccountFromValue(request
.params
[0]);
982 UniValue sendTo
= request
.params
[1].get_obj();
984 if (!request
.params
[2].isNull())
985 nMinDepth
= request
.params
[2].get_int();
988 wtx
.strFromAccount
= strAccount
;
989 if (request
.params
.size() > 3 && !request
.params
[3].isNull() && !request
.params
[3].get_str().empty())
990 wtx
.mapValue
["comment"] = request
.params
[3].get_str();
992 UniValue
subtractFeeFromAmount(UniValue::VARR
);
993 if (request
.params
.size() > 4 && !request
.params
[4].isNull())
994 subtractFeeFromAmount
= request
.params
[4].get_array();
996 CCoinControl coin_control
;
997 if (request
.params
.size() > 5 && !request
.params
[5].isNull()) {
998 coin_control
.signalRbf
= request
.params
[5].get_bool();
1001 if (request
.params
.size() > 6 && !request
.params
[6].isNull()) {
1002 coin_control
.m_confirm_target
= ParseConfirmTarget(request
.params
[6]);
1005 if (request
.params
.size() > 7 && !request
.params
[7].isNull()) {
1006 if (!FeeModeFromString(request
.params
[7].get_str(), coin_control
.m_fee_mode
)) {
1007 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid estimate_mode parameter");
1011 std::set
<CBitcoinAddress
> setAddress
;
1012 std::vector
<CRecipient
> vecSend
;
1014 CAmount totalAmount
= 0;
1015 std::vector
<std::string
> keys
= sendTo
.getKeys();
1016 for (const std::string
& name_
: keys
)
1018 CBitcoinAddress
address(name_
);
1019 if (!address
.IsValid())
1020 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, std::string("Invalid Bitcoin address: ")+name_
);
1022 if (setAddress
.count(address
))
1023 throw JSONRPCError(RPC_INVALID_PARAMETER
, std::string("Invalid parameter, duplicated address: ")+name_
);
1024 setAddress
.insert(address
);
1026 CScript scriptPubKey
= GetScriptForDestination(address
.Get());
1027 CAmount nAmount
= AmountFromValue(sendTo
[name_
]);
1029 throw JSONRPCError(RPC_TYPE_ERROR
, "Invalid amount for send");
1030 totalAmount
+= nAmount
;
1032 bool fSubtractFeeFromAmount
= false;
1033 for (unsigned int idx
= 0; idx
< subtractFeeFromAmount
.size(); idx
++) {
1034 const UniValue
& addr
= subtractFeeFromAmount
[idx
];
1035 if (addr
.get_str() == name_
)
1036 fSubtractFeeFromAmount
= true;
1039 CRecipient recipient
= {scriptPubKey
, nAmount
, fSubtractFeeFromAmount
};
1040 vecSend
.push_back(recipient
);
1043 EnsureWalletIsUnlocked(pwallet
);
1046 CAmount nBalance
= pwallet
->GetLegacyBalance(ISMINE_SPENDABLE
, nMinDepth
, &strAccount
);
1047 if (totalAmount
> nBalance
)
1048 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS
, "Account has insufficient funds");
1051 CReserveKey
keyChange(pwallet
);
1052 CAmount nFeeRequired
= 0;
1053 int nChangePosRet
= -1;
1054 std::string strFailReason
;
1055 bool fCreated
= pwallet
->CreateTransaction(vecSend
, wtx
, keyChange
, nFeeRequired
, nChangePosRet
, strFailReason
, coin_control
);
1057 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS
, strFailReason
);
1058 CValidationState state
;
1059 if (!pwallet
->CommitTransaction(wtx
, keyChange
, g_connman
.get(), state
)) {
1060 strFailReason
= strprintf("Transaction commit failed:: %s", state
.GetRejectReason());
1061 throw JSONRPCError(RPC_WALLET_ERROR
, strFailReason
);
1064 return wtx
.GetHash().GetHex();
1067 // Defined in rpc/misc.cpp
1068 extern CScript
_createmultisig_redeemScript(CWallet
* const pwallet
, const UniValue
& params
);
1070 UniValue
addmultisigaddress(const JSONRPCRequest
& request
)
1072 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1073 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1074 return NullUniValue
;
1077 if (request
.fHelp
|| request
.params
.size() < 2 || request
.params
.size() > 3)
1079 std::string msg
= "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
1080 "\nAdd a nrequired-to-sign multisignature address to the wallet.\n"
1081 "Each key is a Bitcoin address or hex-encoded public key.\n"
1082 "If 'account' is specified (DEPRECATED), assign address to that account.\n"
1085 "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
1086 "2. \"keys\" (string, required) A json array of bitcoin addresses or hex-encoded public keys\n"
1088 " \"address\" (string) bitcoin address or hex-encoded public key\n"
1091 "3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n"
1094 "\"address\" (string) A bitcoin address associated with the keys.\n"
1097 "\nAdd a multisig address from 2 addresses\n"
1098 + HelpExampleCli("addmultisigaddress", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
1099 "\nAs json rpc call\n"
1100 + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
1102 throw std::runtime_error(msg
);
1105 LOCK2(cs_main
, pwallet
->cs_wallet
);
1107 std::string strAccount
;
1108 if (request
.params
.size() > 2)
1109 strAccount
= AccountFromValue(request
.params
[2]);
1111 // Construct using pay-to-script-hash:
1112 CScript inner
= _createmultisig_redeemScript(pwallet
, request
.params
);
1113 CScriptID
innerID(inner
);
1114 pwallet
->AddCScript(inner
);
1116 pwallet
->SetAddressBook(innerID
, strAccount
, "send");
1117 return CBitcoinAddress(innerID
).ToString();
1120 class Witnessifier
: public boost::static_visitor
<bool>
1123 CWallet
* const pwallet
;
1126 Witnessifier(CWallet
*_pwallet
) : pwallet(_pwallet
) {}
1128 bool operator()(const CNoDestination
&dest
) const { return false; }
1130 bool operator()(const CKeyID
&keyID
) {
1132 CScript basescript
= GetScriptForDestination(keyID
);
1133 CScript witscript
= GetScriptForWitness(basescript
);
1135 // This check is to make sure that the script we created can actually be solved for and signed by us
1136 // if we were to have the private keys. This is just to make sure that the script is valid and that,
1137 // if found in a transaction, we would still accept and relay that transcation.
1138 if (!ProduceSignature(DummySignatureCreator(pwallet
), witscript
, sigs
) ||
1139 !VerifyScript(sigs
.scriptSig
, witscript
, &sigs
.scriptWitness
, MANDATORY_SCRIPT_VERIFY_FLAGS
| SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
, DummySignatureCreator(pwallet
).Checker())) {
1142 pwallet
->AddCScript(witscript
);
1143 result
= CScriptID(witscript
);
1149 bool operator()(const CScriptID
&scriptID
) {
1151 if (pwallet
&& pwallet
->GetCScript(scriptID
, subscript
)) {
1153 std::vector
<unsigned char> witprog
;
1154 if (subscript
.IsWitnessProgram(witnessversion
, witprog
)) {
1158 CScript witscript
= GetScriptForWitness(subscript
);
1160 // This check is to make sure that the script we created can actually be solved for and signed by us
1161 // if we were to have the private keys. This is just to make sure that the script is valid and that,
1162 // if found in a transaction, we would still accept and relay that transcation.
1163 if (!ProduceSignature(DummySignatureCreator(pwallet
), witscript
, sigs
) ||
1164 !VerifyScript(sigs
.scriptSig
, witscript
, &sigs
.scriptWitness
, MANDATORY_SCRIPT_VERIFY_FLAGS
| SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
, DummySignatureCreator(pwallet
).Checker())) {
1167 pwallet
->AddCScript(witscript
);
1168 result
= CScriptID(witscript
);
1175 UniValue
addwitnessaddress(const JSONRPCRequest
& request
)
1177 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1178 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1179 return NullUniValue
;
1182 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 1)
1184 std::string msg
= "addwitnessaddress \"address\"\n"
1185 "\nAdd a witness address for a script (with pubkey or redeemscript known).\n"
1186 "It returns the witness script.\n"
1189 "1. \"address\" (string, required) An address known to the wallet\n"
1192 "\"witnessaddress\", (string) The value of the new address (P2SH of witness script).\n"
1195 throw std::runtime_error(msg
);
1200 if (!IsWitnessEnabled(chainActive
.Tip(), Params().GetConsensus()) && !GetBoolArg("-walletprematurewitness", false)) {
1201 throw JSONRPCError(RPC_WALLET_ERROR
, "Segregated witness not enabled on network");
1205 CBitcoinAddress
address(request
.params
[0].get_str());
1206 if (!address
.IsValid())
1207 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Invalid Bitcoin address");
1209 Witnessifier
w(pwallet
);
1210 CTxDestination dest
= address
.Get();
1211 bool ret
= boost::apply_visitor(w
, dest
);
1213 throw JSONRPCError(RPC_WALLET_ERROR
, "Public key or redeemscript not known to wallet, or the key is uncompressed");
1216 pwallet
->SetAddressBook(w
.result
, "", "receive");
1218 return CBitcoinAddress(w
.result
).ToString();
1225 std::vector
<uint256
> txids
;
1230 nConf
= std::numeric_limits
<int>::max();
1231 fIsWatchonly
= false;
1235 UniValue
ListReceived(CWallet
* const pwallet
, const UniValue
& params
, bool fByAccounts
)
1237 // Minimum confirmations
1239 if (!params
[0].isNull())
1240 nMinDepth
= params
[0].get_int();
1242 // Whether to include empty accounts
1243 bool fIncludeEmpty
= false;
1244 if (!params
[1].isNull())
1245 fIncludeEmpty
= params
[1].get_bool();
1247 isminefilter filter
= ISMINE_SPENDABLE
;
1248 if(!params
[2].isNull())
1249 if(params
[2].get_bool())
1250 filter
= filter
| ISMINE_WATCH_ONLY
;
1253 std::map
<CBitcoinAddress
, tallyitem
> mapTally
;
1254 for (const std::pair
<uint256
, CWalletTx
>& pairWtx
: pwallet
->mapWallet
) {
1255 const CWalletTx
& wtx
= pairWtx
.second
;
1257 if (wtx
.IsCoinBase() || !CheckFinalTx(*wtx
.tx
))
1260 int nDepth
= wtx
.GetDepthInMainChain();
1261 if (nDepth
< nMinDepth
)
1264 for (const CTxOut
& txout
: wtx
.tx
->vout
)
1266 CTxDestination address
;
1267 if (!ExtractDestination(txout
.scriptPubKey
, address
))
1270 isminefilter mine
= IsMine(*pwallet
, address
);
1271 if(!(mine
& filter
))
1274 tallyitem
& item
= mapTally
[address
];
1275 item
.nAmount
+= txout
.nValue
;
1276 item
.nConf
= std::min(item
.nConf
, nDepth
);
1277 item
.txids
.push_back(wtx
.GetHash());
1278 if (mine
& ISMINE_WATCH_ONLY
)
1279 item
.fIsWatchonly
= true;
1284 UniValue
ret(UniValue::VARR
);
1285 std::map
<std::string
, tallyitem
> mapAccountTally
;
1286 for (const std::pair
<CBitcoinAddress
, CAddressBookData
>& item
: pwallet
->mapAddressBook
) {
1287 const CBitcoinAddress
& address
= item
.first
;
1288 const std::string
& strAccount
= item
.second
.name
;
1289 std::map
<CBitcoinAddress
, tallyitem
>::iterator it
= mapTally
.find(address
);
1290 if (it
== mapTally
.end() && !fIncludeEmpty
)
1293 CAmount nAmount
= 0;
1294 int nConf
= std::numeric_limits
<int>::max();
1295 bool fIsWatchonly
= false;
1296 if (it
!= mapTally
.end())
1298 nAmount
= (*it
).second
.nAmount
;
1299 nConf
= (*it
).second
.nConf
;
1300 fIsWatchonly
= (*it
).second
.fIsWatchonly
;
1305 tallyitem
& _item
= mapAccountTally
[strAccount
];
1306 _item
.nAmount
+= nAmount
;
1307 _item
.nConf
= std::min(_item
.nConf
, nConf
);
1308 _item
.fIsWatchonly
= fIsWatchonly
;
1312 UniValue
obj(UniValue::VOBJ
);
1314 obj
.push_back(Pair("involvesWatchonly", true));
1315 obj
.push_back(Pair("address", address
.ToString()));
1316 obj
.push_back(Pair("account", strAccount
));
1317 obj
.push_back(Pair("amount", ValueFromAmount(nAmount
)));
1318 obj
.push_back(Pair("confirmations", (nConf
== std::numeric_limits
<int>::max() ? 0 : nConf
)));
1320 obj
.push_back(Pair("label", strAccount
));
1321 UniValue
transactions(UniValue::VARR
);
1322 if (it
!= mapTally
.end())
1324 for (const uint256
& _item
: (*it
).second
.txids
)
1326 transactions
.push_back(_item
.GetHex());
1329 obj
.push_back(Pair("txids", transactions
));
1336 for (std::map
<std::string
, tallyitem
>::iterator it
= mapAccountTally
.begin(); it
!= mapAccountTally
.end(); ++it
)
1338 CAmount nAmount
= (*it
).second
.nAmount
;
1339 int nConf
= (*it
).second
.nConf
;
1340 UniValue
obj(UniValue::VOBJ
);
1341 if((*it
).second
.fIsWatchonly
)
1342 obj
.push_back(Pair("involvesWatchonly", true));
1343 obj
.push_back(Pair("account", (*it
).first
));
1344 obj
.push_back(Pair("amount", ValueFromAmount(nAmount
)));
1345 obj
.push_back(Pair("confirmations", (nConf
== std::numeric_limits
<int>::max() ? 0 : nConf
)));
1353 UniValue
listreceivedbyaddress(const JSONRPCRequest
& request
)
1355 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1356 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1357 return NullUniValue
;
1360 if (request
.fHelp
|| request
.params
.size() > 3)
1361 throw std::runtime_error(
1362 "listreceivedbyaddress ( minconf include_empty include_watchonly)\n"
1363 "\nList balances by receiving address.\n"
1365 "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1366 "2. include_empty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n"
1367 "3. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress').\n"
1372 " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
1373 " \"address\" : \"receivingaddress\", (string) The receiving address\n"
1374 " \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n"
1375 " \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT
+ " received by the address\n"
1376 " \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n"
1377 " \"label\" : \"label\", (string) A comment for the address/transaction, if any\n"
1379 " n, (numeric) The ids of transactions received with the address \n"
1387 + HelpExampleCli("listreceivedbyaddress", "")
1388 + HelpExampleCli("listreceivedbyaddress", "6 true")
1389 + HelpExampleRpc("listreceivedbyaddress", "6, true, true")
1392 LOCK2(cs_main
, pwallet
->cs_wallet
);
1394 return ListReceived(pwallet
, request
.params
, false);
1397 UniValue
listreceivedbyaccount(const JSONRPCRequest
& request
)
1399 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1400 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1401 return NullUniValue
;
1404 if (request
.fHelp
|| request
.params
.size() > 3)
1405 throw std::runtime_error(
1406 "listreceivedbyaccount ( minconf include_empty include_watchonly)\n"
1407 "\nDEPRECATED. List balances by account.\n"
1409 "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
1410 "2. include_empty (bool, optional, default=false) Whether to include accounts that haven't received any payments.\n"
1411 "3. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress').\n"
1416 " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
1417 " \"account\" : \"accountname\", (string) The account name of the receiving account\n"
1418 " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
1419 " \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n"
1420 " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
1426 + HelpExampleCli("listreceivedbyaccount", "")
1427 + HelpExampleCli("listreceivedbyaccount", "6 true")
1428 + HelpExampleRpc("listreceivedbyaccount", "6, true, true")
1431 LOCK2(cs_main
, pwallet
->cs_wallet
);
1433 return ListReceived(pwallet
, request
.params
, true);
1436 static void MaybePushAddress(UniValue
& entry
, const CTxDestination
&dest
)
1438 CBitcoinAddress addr
;
1440 entry
.push_back(Pair("address", addr
.ToString()));
1444 * List transactions based on the given criteria.
1446 * @param pwallet The wallet.
1447 * @param wtx The wallet transaction.
1448 * @param strAccount The account, if any, or "*" for all.
1449 * @param nMinDepth The minimum confirmation depth.
1450 * @param fLong Whether to include the JSON version of the transaction.
1451 * @param ret The UniValue into which the result is stored.
1452 * @param filter The "is mine" filter bool.
1454 void ListTransactions(CWallet
* const pwallet
, const CWalletTx
& wtx
, const std::string
& strAccount
, int nMinDepth
, bool fLong
, UniValue
& ret
, const isminefilter
& filter
)
1457 std::string strSentAccount
;
1458 std::list
<COutputEntry
> listReceived
;
1459 std::list
<COutputEntry
> listSent
;
1461 wtx
.GetAmounts(listReceived
, listSent
, nFee
, strSentAccount
, filter
);
1463 bool fAllAccounts
= (strAccount
== std::string("*"));
1464 bool involvesWatchonly
= wtx
.IsFromMe(ISMINE_WATCH_ONLY
);
1467 if ((!listSent
.empty() || nFee
!= 0) && (fAllAccounts
|| strAccount
== strSentAccount
))
1469 for (const COutputEntry
& s
: listSent
)
1471 UniValue
entry(UniValue::VOBJ
);
1472 if (involvesWatchonly
|| (::IsMine(*pwallet
, s
.destination
) & ISMINE_WATCH_ONLY
)) {
1473 entry
.push_back(Pair("involvesWatchonly", true));
1475 entry
.push_back(Pair("account", strSentAccount
));
1476 MaybePushAddress(entry
, s
.destination
);
1477 entry
.push_back(Pair("category", "send"));
1478 entry
.push_back(Pair("amount", ValueFromAmount(-s
.amount
)));
1479 if (pwallet
->mapAddressBook
.count(s
.destination
)) {
1480 entry
.push_back(Pair("label", pwallet
->mapAddressBook
[s
.destination
].name
));
1482 entry
.push_back(Pair("vout", s
.vout
));
1483 entry
.push_back(Pair("fee", ValueFromAmount(-nFee
)));
1485 WalletTxToJSON(wtx
, entry
);
1486 entry
.push_back(Pair("abandoned", wtx
.isAbandoned()));
1487 ret
.push_back(entry
);
1492 if (listReceived
.size() > 0 && wtx
.GetDepthInMainChain() >= nMinDepth
)
1494 for (const COutputEntry
& r
: listReceived
)
1496 std::string account
;
1497 if (pwallet
->mapAddressBook
.count(r
.destination
)) {
1498 account
= pwallet
->mapAddressBook
[r
.destination
].name
;
1500 if (fAllAccounts
|| (account
== strAccount
))
1502 UniValue
entry(UniValue::VOBJ
);
1503 if (involvesWatchonly
|| (::IsMine(*pwallet
, r
.destination
) & ISMINE_WATCH_ONLY
)) {
1504 entry
.push_back(Pair("involvesWatchonly", true));
1506 entry
.push_back(Pair("account", account
));
1507 MaybePushAddress(entry
, r
.destination
);
1508 if (wtx
.IsCoinBase())
1510 if (wtx
.GetDepthInMainChain() < 1)
1511 entry
.push_back(Pair("category", "orphan"));
1512 else if (wtx
.GetBlocksToMaturity() > 0)
1513 entry
.push_back(Pair("category", "immature"));
1515 entry
.push_back(Pair("category", "generate"));
1519 entry
.push_back(Pair("category", "receive"));
1521 entry
.push_back(Pair("amount", ValueFromAmount(r
.amount
)));
1522 if (pwallet
->mapAddressBook
.count(r
.destination
)) {
1523 entry
.push_back(Pair("label", account
));
1525 entry
.push_back(Pair("vout", r
.vout
));
1527 WalletTxToJSON(wtx
, entry
);
1528 ret
.push_back(entry
);
1534 void AcentryToJSON(const CAccountingEntry
& acentry
, const std::string
& strAccount
, UniValue
& ret
)
1536 bool fAllAccounts
= (strAccount
== std::string("*"));
1538 if (fAllAccounts
|| acentry
.strAccount
== strAccount
)
1540 UniValue
entry(UniValue::VOBJ
);
1541 entry
.push_back(Pair("account", acentry
.strAccount
));
1542 entry
.push_back(Pair("category", "move"));
1543 entry
.push_back(Pair("time", acentry
.nTime
));
1544 entry
.push_back(Pair("amount", ValueFromAmount(acentry
.nCreditDebit
)));
1545 entry
.push_back(Pair("otheraccount", acentry
.strOtherAccount
));
1546 entry
.push_back(Pair("comment", acentry
.strComment
));
1547 ret
.push_back(entry
);
1551 UniValue
listtransactions(const JSONRPCRequest
& request
)
1553 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1554 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1555 return NullUniValue
;
1558 if (request
.fHelp
|| request
.params
.size() > 4)
1559 throw std::runtime_error(
1560 "listtransactions ( \"account\" count skip include_watchonly)\n"
1561 "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
1563 "1. \"account\" (string, optional) DEPRECATED. The account name. Should be \"*\".\n"
1564 "2. count (numeric, optional, default=10) The number of transactions to return\n"
1565 "3. skip (numeric, optional, default=0) The number of transactions to skip\n"
1566 "4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n"
1570 " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. \n"
1571 " It will be \"\" for the default account.\n"
1572 " \"address\":\"address\", (string) The bitcoin address of the transaction. Not present for \n"
1573 " move transactions (category = move).\n"
1574 " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
1575 " transaction between accounts, and not associated with an address,\n"
1576 " transaction id or block. 'send' and 'receive' transactions are \n"
1577 " associated with an address, transaction id and block details\n"
1578 " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT
+ ". This is negative for the 'send' category, and for the\n"
1579 " 'move' category for moves outbound. It is positive for the 'receive' category,\n"
1580 " and for the 'move' category for inbound funds.\n"
1581 " \"label\": \"label\", (string) A comment for the address/transaction, if any\n"
1582 " \"vout\": n, (numeric) the vout value\n"
1583 " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT
+ ". This is negative and only available for the \n"
1584 " 'send' category of transactions.\n"
1585 " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n"
1586 " 'receive' category of transactions. Negative confirmations indicate the\n"
1587 " transaction conflicts with the block chain\n"
1588 " \"trusted\": xxx, (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n"
1589 " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
1590 " category of transactions.\n"
1591 " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n"
1592 " category of transactions.\n"
1593 " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
1594 " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1595 " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
1596 " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
1597 " for 'send' and 'receive' category of transactions.\n"
1598 " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1599 " \"otheraccount\": \"accountname\", (string) DEPRECATED. For the 'move' category of transactions, the account the funds came \n"
1600 " from (for receiving funds, positive amounts), or went to (for sending funds,\n"
1601 " negative amounts).\n"
1602 " \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1603 " may be unknown for unconfirmed transactions not in the mempool\n"
1604 " \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
1605 " 'send' category of transactions.\n"
1610 "\nList the most recent 10 transactions in the systems\n"
1611 + HelpExampleCli("listtransactions", "") +
1612 "\nList transactions 100 to 120\n"
1613 + HelpExampleCli("listtransactions", "\"*\" 20 100") +
1614 "\nAs a json rpc call\n"
1615 + HelpExampleRpc("listtransactions", "\"*\", 20, 100")
1618 LOCK2(cs_main
, pwallet
->cs_wallet
);
1620 std::string strAccount
= "*";
1621 if (!request
.params
[0].isNull())
1622 strAccount
= request
.params
[0].get_str();
1624 if (!request
.params
[1].isNull())
1625 nCount
= request
.params
[1].get_int();
1627 if (!request
.params
[2].isNull())
1628 nFrom
= request
.params
[2].get_int();
1629 isminefilter filter
= ISMINE_SPENDABLE
;
1630 if(!request
.params
[3].isNull())
1631 if(request
.params
[3].get_bool())
1632 filter
= filter
| ISMINE_WATCH_ONLY
;
1635 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Negative count");
1637 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Negative from");
1639 UniValue
ret(UniValue::VARR
);
1641 const CWallet::TxItems
& txOrdered
= pwallet
->wtxOrdered
;
1643 // iterate backwards until we have nCount items to return:
1644 for (CWallet::TxItems::const_reverse_iterator it
= txOrdered
.rbegin(); it
!= txOrdered
.rend(); ++it
)
1646 CWalletTx
*const pwtx
= (*it
).second
.first
;
1648 ListTransactions(pwallet
, *pwtx
, strAccount
, 0, true, ret
, filter
);
1649 CAccountingEntry
*const pacentry
= (*it
).second
.second
;
1651 AcentryToJSON(*pacentry
, strAccount
, ret
);
1653 if ((int)ret
.size() >= (nCount
+nFrom
)) break;
1655 // ret is newest to oldest
1657 if (nFrom
> (int)ret
.size())
1659 if ((nFrom
+ nCount
) > (int)ret
.size())
1660 nCount
= ret
.size() - nFrom
;
1662 std::vector
<UniValue
> arrTmp
= ret
.getValues();
1664 std::vector
<UniValue
>::iterator first
= arrTmp
.begin();
1665 std::advance(first
, nFrom
);
1666 std::vector
<UniValue
>::iterator last
= arrTmp
.begin();
1667 std::advance(last
, nFrom
+nCount
);
1669 if (last
!= arrTmp
.end()) arrTmp
.erase(last
, arrTmp
.end());
1670 if (first
!= arrTmp
.begin()) arrTmp
.erase(arrTmp
.begin(), first
);
1672 std::reverse(arrTmp
.begin(), arrTmp
.end()); // Return oldest to newest
1676 ret
.push_backV(arrTmp
);
1681 UniValue
listaccounts(const JSONRPCRequest
& request
)
1683 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1684 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1685 return NullUniValue
;
1688 if (request
.fHelp
|| request
.params
.size() > 2)
1689 throw std::runtime_error(
1690 "listaccounts ( minconf include_watchonly)\n"
1691 "\nDEPRECATED. Returns Object that has account names as keys, account balances as values.\n"
1693 "1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n"
1694 "2. include_watchonly (bool, optional, default=false) Include balances in watch-only addresses (see 'importaddress')\n"
1696 "{ (json object where keys are account names, and values are numeric balances\n"
1697 " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
1701 "\nList account balances where there at least 1 confirmation\n"
1702 + HelpExampleCli("listaccounts", "") +
1703 "\nList account balances including zero confirmation transactions\n"
1704 + HelpExampleCli("listaccounts", "0") +
1705 "\nList account balances for 6 or more confirmations\n"
1706 + HelpExampleCli("listaccounts", "6") +
1707 "\nAs json rpc call\n"
1708 + HelpExampleRpc("listaccounts", "6")
1711 LOCK2(cs_main
, pwallet
->cs_wallet
);
1714 if (request
.params
.size() > 0)
1715 nMinDepth
= request
.params
[0].get_int();
1716 isminefilter includeWatchonly
= ISMINE_SPENDABLE
;
1717 if(request
.params
.size() > 1)
1718 if(request
.params
[1].get_bool())
1719 includeWatchonly
= includeWatchonly
| ISMINE_WATCH_ONLY
;
1721 std::map
<std::string
, CAmount
> mapAccountBalances
;
1722 for (const std::pair
<CTxDestination
, CAddressBookData
>& entry
: pwallet
->mapAddressBook
) {
1723 if (IsMine(*pwallet
, entry
.first
) & includeWatchonly
) { // This address belongs to me
1724 mapAccountBalances
[entry
.second
.name
] = 0;
1728 for (const std::pair
<uint256
, CWalletTx
>& pairWtx
: pwallet
->mapWallet
) {
1729 const CWalletTx
& wtx
= pairWtx
.second
;
1731 std::string strSentAccount
;
1732 std::list
<COutputEntry
> listReceived
;
1733 std::list
<COutputEntry
> listSent
;
1734 int nDepth
= wtx
.GetDepthInMainChain();
1735 if (wtx
.GetBlocksToMaturity() > 0 || nDepth
< 0)
1737 wtx
.GetAmounts(listReceived
, listSent
, nFee
, strSentAccount
, includeWatchonly
);
1738 mapAccountBalances
[strSentAccount
] -= nFee
;
1739 for (const COutputEntry
& s
: listSent
)
1740 mapAccountBalances
[strSentAccount
] -= s
.amount
;
1741 if (nDepth
>= nMinDepth
)
1743 for (const COutputEntry
& r
: listReceived
)
1744 if (pwallet
->mapAddressBook
.count(r
.destination
)) {
1745 mapAccountBalances
[pwallet
->mapAddressBook
[r
.destination
].name
] += r
.amount
;
1748 mapAccountBalances
[""] += r
.amount
;
1752 const std::list
<CAccountingEntry
>& acentries
= pwallet
->laccentries
;
1753 for (const CAccountingEntry
& entry
: acentries
)
1754 mapAccountBalances
[entry
.strAccount
] += entry
.nCreditDebit
;
1756 UniValue
ret(UniValue::VOBJ
);
1757 for (const std::pair
<std::string
, CAmount
>& accountBalance
: mapAccountBalances
) {
1758 ret
.push_back(Pair(accountBalance
.first
, ValueFromAmount(accountBalance
.second
)));
1763 UniValue
listsinceblock(const JSONRPCRequest
& request
)
1765 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1766 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1767 return NullUniValue
;
1770 if (request
.fHelp
|| request
.params
.size() > 4)
1771 throw std::runtime_error(
1772 "listsinceblock ( \"blockhash\" target_confirmations include_watchonly include_removed )\n"
1773 "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted.\n"
1774 "If \"blockhash\" is no longer a part of the main chain, transactions from the fork point onward are included.\n"
1775 "Additionally, if include_removed is set, transactions affecting the wallet which were removed are returned in the \"removed\" array.\n"
1777 "1. \"blockhash\" (string, optional) The block hash to list transactions since\n"
1778 "2. target_confirmations: (numeric, optional, default=1) Return the nth block hash from the main chain. e.g. 1 would mean the best block hash. Note: this is not used as a filter, but only affects [lastblock] in the return value\n"
1779 "3. include_watchonly: (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n"
1780 "4. include_removed: (bool, optional, default=true) Show transactions that were removed due to a reorg in the \"removed\" array\n"
1781 " (not guaranteed to work on pruned nodes)\n"
1784 " \"transactions\": [\n"
1785 " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. Will be \"\" for the default account.\n"
1786 " \"address\":\"address\", (string) The bitcoin address of the transaction. Not present for move transactions (category = move).\n"
1787 " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
1788 " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT
+ ". This is negative for the 'send' category, and for the 'move' category for moves \n"
1789 " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
1790 " \"vout\" : n, (numeric) the vout value\n"
1791 " \"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"
1792 " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
1793 " When it's < 0, it means the transaction conflicted that many blocks ago.\n"
1794 " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
1795 " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions.\n"
1796 " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
1797 " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
1798 " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n"
1799 " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n"
1800 " \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1801 " may be unknown for unconfirmed transactions not in the mempool\n"
1802 " \"abandoned\": xxx, (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the 'send' category of transactions.\n"
1803 " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
1804 " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
1805 " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n"
1808 " <structure is the same as \"transactions\" above, only present if include_removed=true>\n"
1809 " Note: transactions that were readded in the active chain will appear as-is in this array, and may thus have a positive confirmation count.\n"
1811 " \"lastblock\": \"lastblockhash\" (string) The hash of the block (target_confirmations-1) from the best block on the main chain. This is typically used to feed back into listsinceblock the next time you call it. So you would generally use a target_confirmations of say 6, so you will be continually re-notified of transactions until they've reached 6 confirmations plus any new ones\n"
1814 + HelpExampleCli("listsinceblock", "")
1815 + HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6")
1816 + HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6")
1819 LOCK2(cs_main
, pwallet
->cs_wallet
);
1821 const CBlockIndex
* pindex
= NULL
; // Block index of the specified block or the common ancestor, if the block provided was in a deactivated chain.
1822 const CBlockIndex
* paltindex
= NULL
; // Block index of the specified block, even if it's in a deactivated chain.
1823 int target_confirms
= 1;
1824 isminefilter filter
= ISMINE_SPENDABLE
;
1826 if (!request
.params
[0].isNull()) {
1829 blockId
.SetHex(request
.params
[0].get_str());
1830 BlockMap::iterator it
= mapBlockIndex
.find(blockId
);
1831 if (it
!= mapBlockIndex
.end()) {
1832 paltindex
= pindex
= it
->second
;
1833 if (chainActive
[pindex
->nHeight
] != pindex
) {
1834 // the block being asked for is a part of a deactivated chain;
1835 // we don't want to depend on its perceived height in the block
1836 // chain, we want to instead use the last common ancestor
1837 pindex
= chainActive
.FindFork(pindex
);
1842 if (!request
.params
[1].isNull()) {
1843 target_confirms
= request
.params
[1].get_int();
1845 if (target_confirms
< 1) {
1846 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid parameter");
1850 if (!request
.params
[2].isNull() && request
.params
[2].get_bool()) {
1851 filter
= filter
| ISMINE_WATCH_ONLY
;
1854 bool include_removed
= (request
.params
[3].isNull() || request
.params
[3].get_bool());
1856 int depth
= pindex
? (1 + chainActive
.Height() - pindex
->nHeight
) : -1;
1858 UniValue
transactions(UniValue::VARR
);
1860 for (const std::pair
<uint256
, CWalletTx
>& pairWtx
: pwallet
->mapWallet
) {
1861 CWalletTx tx
= pairWtx
.second
;
1863 if (depth
== -1 || tx
.GetDepthInMainChain() < depth
) {
1864 ListTransactions(pwallet
, tx
, "*", 0, true, transactions
, filter
);
1868 // when a reorg'd block is requested, we also list any relevant transactions
1869 // in the blocks of the chain that was detached
1870 UniValue
removed(UniValue::VARR
);
1871 while (include_removed
&& paltindex
&& paltindex
!= pindex
) {
1873 if (!ReadBlockFromDisk(block
, paltindex
, Params().GetConsensus())) {
1874 throw JSONRPCError(RPC_INTERNAL_ERROR
, "Can't read block from disk");
1876 for (const CTransactionRef
& tx
: block
.vtx
) {
1877 auto it
= pwallet
->mapWallet
.find(tx
->GetHash());
1878 if (it
!= pwallet
->mapWallet
.end()) {
1879 // We want all transactions regardless of confirmation count to appear here,
1880 // even negative confirmation ones, hence the big negative.
1881 ListTransactions(pwallet
, it
->second
, "*", -100000000, true, removed
, filter
);
1884 paltindex
= paltindex
->pprev
;
1887 CBlockIndex
*pblockLast
= chainActive
[chainActive
.Height() + 1 - target_confirms
];
1888 uint256 lastblock
= pblockLast
? pblockLast
->GetBlockHash() : uint256();
1890 UniValue
ret(UniValue::VOBJ
);
1891 ret
.push_back(Pair("transactions", transactions
));
1892 if (include_removed
) ret
.push_back(Pair("removed", removed
));
1893 ret
.push_back(Pair("lastblock", lastblock
.GetHex()));
1898 UniValue
gettransaction(const JSONRPCRequest
& request
)
1900 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1901 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1902 return NullUniValue
;
1905 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 2)
1906 throw std::runtime_error(
1907 "gettransaction \"txid\" ( include_watchonly )\n"
1908 "\nGet detailed information about in-wallet transaction <txid>\n"
1910 "1. \"txid\" (string, required) The transaction id\n"
1911 "2. \"include_watchonly\" (bool, optional, default=false) Whether to include watch-only addresses in balance calculation and details[]\n"
1914 " \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT
+ "\n"
1915 " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT
+ ". This is negative and only available for the \n"
1916 " 'send' category of transactions.\n"
1917 " \"confirmations\" : n, (numeric) The number of confirmations\n"
1918 " \"blockhash\" : \"hash\", (string) The block hash\n"
1919 " \"blockindex\" : xx, (numeric) The index of the transaction in the block that includes it\n"
1920 " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n"
1921 " \"txid\" : \"transactionid\", (string) The transaction id.\n"
1922 " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n"
1923 " \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n"
1924 " \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1925 " may be unknown for unconfirmed transactions not in the mempool\n"
1926 " \"details\" : [\n"
1928 " \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n"
1929 " \"address\" : \"address\", (string) The bitcoin address involved in the transaction\n"
1930 " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
1931 " \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT
+ "\n"
1932 " \"label\" : \"label\", (string) A comment for the address/transaction, if any\n"
1933 " \"vout\" : n, (numeric) the vout value\n"
1934 " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT
+ ". This is negative and only available for the \n"
1935 " 'send' category of transactions.\n"
1936 " \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
1937 " 'send' category of transactions.\n"
1941 " \"hex\" : \"data\" (string) Raw data for transaction\n"
1945 + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1946 + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
1947 + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
1950 LOCK2(cs_main
, pwallet
->cs_wallet
);
1953 hash
.SetHex(request
.params
[0].get_str());
1955 isminefilter filter
= ISMINE_SPENDABLE
;
1956 if(!request
.params
[1].isNull())
1957 if(request
.params
[1].get_bool())
1958 filter
= filter
| ISMINE_WATCH_ONLY
;
1960 UniValue
entry(UniValue::VOBJ
);
1961 auto it
= pwallet
->mapWallet
.find(hash
);
1962 if (it
== pwallet
->mapWallet
.end()) {
1963 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Invalid or non-wallet transaction id");
1965 const CWalletTx
& wtx
= it
->second
;
1967 CAmount nCredit
= wtx
.GetCredit(filter
);
1968 CAmount nDebit
= wtx
.GetDebit(filter
);
1969 CAmount nNet
= nCredit
- nDebit
;
1970 CAmount nFee
= (wtx
.IsFromMe(filter
) ? wtx
.tx
->GetValueOut() - nDebit
: 0);
1972 entry
.push_back(Pair("amount", ValueFromAmount(nNet
- nFee
)));
1973 if (wtx
.IsFromMe(filter
))
1974 entry
.push_back(Pair("fee", ValueFromAmount(nFee
)));
1976 WalletTxToJSON(wtx
, entry
);
1978 UniValue
details(UniValue::VARR
);
1979 ListTransactions(pwallet
, wtx
, "*", 0, false, details
, filter
);
1980 entry
.push_back(Pair("details", details
));
1982 std::string strHex
= EncodeHexTx(static_cast<CTransaction
>(wtx
), RPCSerializationFlags());
1983 entry
.push_back(Pair("hex", strHex
));
1988 UniValue
abandontransaction(const JSONRPCRequest
& request
)
1990 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
1991 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
1992 return NullUniValue
;
1995 if (request
.fHelp
|| request
.params
.size() != 1)
1996 throw std::runtime_error(
1997 "abandontransaction \"txid\"\n"
1998 "\nMark in-wallet transaction <txid> as abandoned\n"
1999 "This will mark this transaction and all its in-wallet descendants as abandoned which will allow\n"
2000 "for their inputs to be respent. It can be used to replace \"stuck\" or evicted transactions.\n"
2001 "It only works on transactions which are not included in a block and are not currently in the mempool.\n"
2002 "It has no effect on transactions which are already conflicted or abandoned.\n"
2004 "1. \"txid\" (string, required) The transaction id\n"
2007 + HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
2008 + HelpExampleRpc("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
2011 LOCK2(cs_main
, pwallet
->cs_wallet
);
2014 hash
.SetHex(request
.params
[0].get_str());
2016 if (!pwallet
->mapWallet
.count(hash
)) {
2017 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Invalid or non-wallet transaction id");
2019 if (!pwallet
->AbandonTransaction(hash
)) {
2020 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "Transaction not eligible for abandonment");
2023 return NullUniValue
;
2027 UniValue
backupwallet(const JSONRPCRequest
& request
)
2029 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2030 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2031 return NullUniValue
;
2034 if (request
.fHelp
|| request
.params
.size() != 1)
2035 throw std::runtime_error(
2036 "backupwallet \"destination\"\n"
2037 "\nSafely copies current wallet file to destination, which can be a directory or a path with filename.\n"
2039 "1. \"destination\" (string) The destination directory or file\n"
2041 + HelpExampleCli("backupwallet", "\"backup.dat\"")
2042 + HelpExampleRpc("backupwallet", "\"backup.dat\"")
2045 LOCK2(cs_main
, pwallet
->cs_wallet
);
2047 std::string strDest
= request
.params
[0].get_str();
2048 if (!pwallet
->BackupWallet(strDest
)) {
2049 throw JSONRPCError(RPC_WALLET_ERROR
, "Error: Wallet backup failed!");
2052 return NullUniValue
;
2056 UniValue
keypoolrefill(const JSONRPCRequest
& request
)
2058 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2059 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2060 return NullUniValue
;
2063 if (request
.fHelp
|| request
.params
.size() > 1)
2064 throw std::runtime_error(
2065 "keypoolrefill ( newsize )\n"
2066 "\nFills the keypool."
2067 + HelpRequiringPassphrase(pwallet
) + "\n"
2069 "1. newsize (numeric, optional, default=100) The new keypool size\n"
2071 + HelpExampleCli("keypoolrefill", "")
2072 + HelpExampleRpc("keypoolrefill", "")
2075 LOCK2(cs_main
, pwallet
->cs_wallet
);
2077 // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
2078 unsigned int kpSize
= 0;
2079 if (!request
.params
[0].isNull()) {
2080 if (request
.params
[0].get_int() < 0)
2081 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid parameter, expected valid size.");
2082 kpSize
= (unsigned int)request
.params
[0].get_int();
2085 EnsureWalletIsUnlocked(pwallet
);
2086 pwallet
->TopUpKeyPool(kpSize
);
2088 if (pwallet
->GetKeyPoolSize() < kpSize
) {
2089 throw JSONRPCError(RPC_WALLET_ERROR
, "Error refreshing keypool.");
2092 return NullUniValue
;
2096 static void LockWallet(CWallet
* pWallet
)
2098 LOCK(pWallet
->cs_wallet
);
2099 pWallet
->nRelockTime
= 0;
2103 UniValue
walletpassphrase(const JSONRPCRequest
& request
)
2105 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2106 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2107 return NullUniValue
;
2110 if (pwallet
->IsCrypted() && (request
.fHelp
|| request
.params
.size() != 2)) {
2111 throw std::runtime_error(
2112 "walletpassphrase \"passphrase\" timeout\n"
2113 "\nStores the wallet decryption key in memory for 'timeout' seconds.\n"
2114 "This is needed prior to performing transactions related to private keys such as sending bitcoins\n"
2116 "1. \"passphrase\" (string, required) The wallet passphrase\n"
2117 "2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
2119 "Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
2120 "time that overrides the old one.\n"
2122 "\nUnlock the wallet for 60 seconds\n"
2123 + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") +
2124 "\nLock the wallet again (before 60 seconds)\n"
2125 + HelpExampleCli("walletlock", "") +
2126 "\nAs json rpc call\n"
2127 + HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")
2131 LOCK2(cs_main
, pwallet
->cs_wallet
);
2135 if (!pwallet
->IsCrypted()) {
2136 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE
, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
2139 // Note that the walletpassphrase is stored in request.params[0] which is not mlock()ed
2140 SecureString strWalletPass
;
2141 strWalletPass
.reserve(100);
2142 // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
2143 // Alternately, find a way to make request.params[0] mlock()'d to begin with.
2144 strWalletPass
= request
.params
[0].get_str().c_str();
2146 if (strWalletPass
.length() > 0)
2148 if (!pwallet
->Unlock(strWalletPass
)) {
2149 throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT
, "Error: The wallet passphrase entered was incorrect.");
2153 throw std::runtime_error(
2154 "walletpassphrase <passphrase> <timeout>\n"
2155 "Stores the wallet decryption key in memory for <timeout> seconds.");
2157 pwallet
->TopUpKeyPool();
2159 int64_t nSleepTime
= request
.params
[1].get_int64();
2160 pwallet
->nRelockTime
= GetTime() + nSleepTime
;
2161 RPCRunLater(strprintf("lockwallet(%s)", pwallet
->GetName()), boost::bind(LockWallet
, pwallet
), nSleepTime
);
2163 return NullUniValue
;
2167 UniValue
walletpassphrasechange(const JSONRPCRequest
& request
)
2169 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2170 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2171 return NullUniValue
;
2174 if (pwallet
->IsCrypted() && (request
.fHelp
|| request
.params
.size() != 2)) {
2175 throw std::runtime_error(
2176 "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n"
2177 "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n"
2179 "1. \"oldpassphrase\" (string) The current passphrase\n"
2180 "2. \"newpassphrase\" (string) The new passphrase\n"
2182 + HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"")
2183 + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"")
2187 LOCK2(cs_main
, pwallet
->cs_wallet
);
2191 if (!pwallet
->IsCrypted()) {
2192 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE
, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
2195 // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
2196 // Alternately, find a way to make request.params[0] mlock()'d to begin with.
2197 SecureString strOldWalletPass
;
2198 strOldWalletPass
.reserve(100);
2199 strOldWalletPass
= request
.params
[0].get_str().c_str();
2201 SecureString strNewWalletPass
;
2202 strNewWalletPass
.reserve(100);
2203 strNewWalletPass
= request
.params
[1].get_str().c_str();
2205 if (strOldWalletPass
.length() < 1 || strNewWalletPass
.length() < 1)
2206 throw std::runtime_error(
2207 "walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
2208 "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
2210 if (!pwallet
->ChangeWalletPassphrase(strOldWalletPass
, strNewWalletPass
)) {
2211 throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT
, "Error: The wallet passphrase entered was incorrect.");
2214 return NullUniValue
;
2218 UniValue
walletlock(const JSONRPCRequest
& request
)
2220 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2221 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2222 return NullUniValue
;
2225 if (pwallet
->IsCrypted() && (request
.fHelp
|| request
.params
.size() != 0)) {
2226 throw std::runtime_error(
2228 "\nRemoves the wallet encryption key from memory, locking the wallet.\n"
2229 "After calling this method, you will need to call walletpassphrase again\n"
2230 "before being able to call any methods which require the wallet to be unlocked.\n"
2232 "\nSet the passphrase for 2 minutes to perform a transaction\n"
2233 + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") +
2234 "\nPerform a send (requires passphrase set)\n"
2235 + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") +
2236 "\nClear the passphrase since we are done before 2 minutes is up\n"
2237 + HelpExampleCli("walletlock", "") +
2238 "\nAs json rpc call\n"
2239 + HelpExampleRpc("walletlock", "")
2243 LOCK2(cs_main
, pwallet
->cs_wallet
);
2247 if (!pwallet
->IsCrypted()) {
2248 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE
, "Error: running with an unencrypted wallet, but walletlock was called.");
2252 pwallet
->nRelockTime
= 0;
2254 return NullUniValue
;
2258 UniValue
encryptwallet(const JSONRPCRequest
& request
)
2260 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2261 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2262 return NullUniValue
;
2265 if (!pwallet
->IsCrypted() && (request
.fHelp
|| request
.params
.size() != 1)) {
2266 throw std::runtime_error(
2267 "encryptwallet \"passphrase\"\n"
2268 "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n"
2269 "After this, any calls that interact with private keys such as sending or signing \n"
2270 "will require the passphrase to be set prior the making these calls.\n"
2271 "Use the walletpassphrase call for this, and then walletlock call.\n"
2272 "If the wallet is already encrypted, use the walletpassphrasechange call.\n"
2273 "Note that this will shutdown the server.\n"
2275 "1. \"passphrase\" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.\n"
2277 "\nEncrypt your wallet\n"
2278 + HelpExampleCli("encryptwallet", "\"my pass phrase\"") +
2279 "\nNow set the passphrase to use the wallet, such as for signing or sending bitcoin\n"
2280 + HelpExampleCli("walletpassphrase", "\"my pass phrase\"") +
2281 "\nNow we can do something like sign\n"
2282 + HelpExampleCli("signmessage", "\"address\" \"test message\"") +
2283 "\nNow lock the wallet again by removing the passphrase\n"
2284 + HelpExampleCli("walletlock", "") +
2285 "\nAs a json rpc call\n"
2286 + HelpExampleRpc("encryptwallet", "\"my pass phrase\"")
2290 LOCK2(cs_main
, pwallet
->cs_wallet
);
2294 if (pwallet
->IsCrypted()) {
2295 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE
, "Error: running with an encrypted wallet, but encryptwallet was called.");
2298 // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
2299 // Alternately, find a way to make request.params[0] mlock()'d to begin with.
2300 SecureString strWalletPass
;
2301 strWalletPass
.reserve(100);
2302 strWalletPass
= request
.params
[0].get_str().c_str();
2304 if (strWalletPass
.length() < 1)
2305 throw std::runtime_error(
2306 "encryptwallet <passphrase>\n"
2307 "Encrypts the wallet with <passphrase>.");
2309 if (!pwallet
->EncryptWallet(strWalletPass
)) {
2310 throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED
, "Error: Failed to encrypt the wallet.");
2313 // BDB seems to have a bad habit of writing old data into
2314 // slack space in .dat files; that is bad if the old data is
2315 // unencrypted private keys. So:
2317 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.";
2320 UniValue
lockunspent(const JSONRPCRequest
& request
)
2322 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2323 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2324 return NullUniValue
;
2327 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 2)
2328 throw std::runtime_error(
2329 "lockunspent unlock ([{\"txid\":\"txid\",\"vout\":n},...])\n"
2330 "\nUpdates list of temporarily unspendable outputs.\n"
2331 "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
2332 "If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n"
2333 "A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.\n"
2334 "Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n"
2335 "is always cleared (by virtue of process exit) when a node stops or fails.\n"
2336 "Also see the listunspent call\n"
2338 "1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions\n"
2339 "2. \"transactions\" (string, optional) A json array of objects. Each object the txid (string) vout (numeric)\n"
2340 " [ (json array of json objects)\n"
2342 " \"txid\":\"id\", (string) The transaction id\n"
2343 " \"vout\": n (numeric) The output number\n"
2349 "true|false (boolean) Whether the command was successful or not\n"
2352 "\nList the unspent transactions\n"
2353 + HelpExampleCli("listunspent", "") +
2354 "\nLock an unspent transaction\n"
2355 + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2356 "\nList the locked transactions\n"
2357 + HelpExampleCli("listlockunspent", "") +
2358 "\nUnlock the transaction again\n"
2359 + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2360 "\nAs a json rpc call\n"
2361 + HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
2364 LOCK2(cs_main
, pwallet
->cs_wallet
);
2366 if (request
.params
.size() == 1)
2367 RPCTypeCheck(request
.params
, {UniValue::VBOOL
});
2369 RPCTypeCheck(request
.params
, {UniValue::VBOOL
, UniValue::VARR
});
2371 bool fUnlock
= request
.params
[0].get_bool();
2373 if (request
.params
.size() == 1) {
2375 pwallet
->UnlockAllCoins();
2379 UniValue outputs
= request
.params
[1].get_array();
2380 for (unsigned int idx
= 0; idx
< outputs
.size(); idx
++) {
2381 const UniValue
& output
= outputs
[idx
];
2382 if (!output
.isObject())
2383 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid parameter, expected object");
2384 const UniValue
& o
= output
.get_obj();
2388 {"txid", UniValueType(UniValue::VSTR
)},
2389 {"vout", UniValueType(UniValue::VNUM
)},
2392 std::string txid
= find_value(o
, "txid").get_str();
2394 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid parameter, expected hex txid");
2396 int nOutput
= find_value(o
, "vout").get_int();
2398 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid parameter, vout must be positive");
2400 COutPoint
outpt(uint256S(txid
), nOutput
);
2403 pwallet
->UnlockCoin(outpt
);
2405 pwallet
->LockCoin(outpt
);
2411 UniValue
listlockunspent(const JSONRPCRequest
& request
)
2413 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2414 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2415 return NullUniValue
;
2418 if (request
.fHelp
|| request
.params
.size() > 0)
2419 throw std::runtime_error(
2421 "\nReturns list of temporarily unspendable outputs.\n"
2422 "See the lockunspent call to lock and unlock transactions for spending.\n"
2426 " \"txid\" : \"transactionid\", (string) The transaction id locked\n"
2427 " \"vout\" : n (numeric) The vout value\n"
2432 "\nList the unspent transactions\n"
2433 + HelpExampleCli("listunspent", "") +
2434 "\nLock an unspent transaction\n"
2435 + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2436 "\nList the locked transactions\n"
2437 + HelpExampleCli("listlockunspent", "") +
2438 "\nUnlock the transaction again\n"
2439 + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
2440 "\nAs a json rpc call\n"
2441 + HelpExampleRpc("listlockunspent", "")
2444 LOCK2(cs_main
, pwallet
->cs_wallet
);
2446 std::vector
<COutPoint
> vOutpts
;
2447 pwallet
->ListLockedCoins(vOutpts
);
2449 UniValue
ret(UniValue::VARR
);
2451 for (COutPoint
&outpt
: vOutpts
) {
2452 UniValue
o(UniValue::VOBJ
);
2454 o
.push_back(Pair("txid", outpt
.hash
.GetHex()));
2455 o
.push_back(Pair("vout", (int)outpt
.n
));
2462 UniValue
settxfee(const JSONRPCRequest
& request
)
2464 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2465 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2466 return NullUniValue
;
2469 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 1)
2470 throw std::runtime_error(
2472 "\nSet the transaction fee per kB. Overwrites the paytxfee parameter.\n"
2474 "1. amount (numeric or string, required) The transaction fee in " + CURRENCY_UNIT
+ "/kB\n"
2476 "true|false (boolean) Returns true if successful\n"
2478 + HelpExampleCli("settxfee", "0.00001")
2479 + HelpExampleRpc("settxfee", "0.00001")
2482 LOCK2(cs_main
, pwallet
->cs_wallet
);
2485 CAmount nAmount
= AmountFromValue(request
.params
[0]);
2487 payTxFee
= CFeeRate(nAmount
, 1000);
2491 UniValue
getwalletinfo(const JSONRPCRequest
& request
)
2493 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2494 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2495 return NullUniValue
;
2498 if (request
.fHelp
|| request
.params
.size() != 0)
2499 throw std::runtime_error(
2501 "Returns an object containing various wallet state info.\n"
2504 " \"walletname\": xxxxx, (string) the wallet name\n"
2505 " \"walletversion\": xxxxx, (numeric) the wallet version\n"
2506 " \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT
+ "\n"
2507 " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT
+ "\n"
2508 " \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT
+ "\n"
2509 " \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
2510 " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n"
2511 " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated (only counts external keys)\n"
2512 " \"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"
2513 " \"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"
2514 " \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT
+ "/kB\n"
2515 " \"hdmasterkeyid\": \"<hash160>\" (string) the Hash160 of the HD master pubkey\n"
2518 + HelpExampleCli("getwalletinfo", "")
2519 + HelpExampleRpc("getwalletinfo", "")
2522 LOCK2(cs_main
, pwallet
->cs_wallet
);
2524 UniValue
obj(UniValue::VOBJ
);
2526 size_t kpExternalSize
= pwallet
->KeypoolCountExternalKeys();
2527 obj
.push_back(Pair("walletname", pwallet
->GetName()));
2528 obj
.push_back(Pair("walletversion", pwallet
->GetVersion()));
2529 obj
.push_back(Pair("balance", ValueFromAmount(pwallet
->GetBalance())));
2530 obj
.push_back(Pair("unconfirmed_balance", ValueFromAmount(pwallet
->GetUnconfirmedBalance())));
2531 obj
.push_back(Pair("immature_balance", ValueFromAmount(pwallet
->GetImmatureBalance())));
2532 obj
.push_back(Pair("txcount", (int)pwallet
->mapWallet
.size()));
2533 obj
.push_back(Pair("keypoololdest", pwallet
->GetOldestKeyPoolTime()));
2534 obj
.push_back(Pair("keypoolsize", (int64_t)kpExternalSize
));
2535 CKeyID masterKeyID
= pwallet
->GetHDChain().masterKeyID
;
2536 if (!masterKeyID
.IsNull() && pwallet
->CanSupportFeature(FEATURE_HD_SPLIT
)) {
2537 obj
.push_back(Pair("keypoolsize_hd_internal", (int64_t)(pwallet
->GetKeyPoolSize() - kpExternalSize
)));
2539 if (pwallet
->IsCrypted()) {
2540 obj
.push_back(Pair("unlocked_until", pwallet
->nRelockTime
));
2542 obj
.push_back(Pair("paytxfee", ValueFromAmount(payTxFee
.GetFeePerK())));
2543 if (!masterKeyID
.IsNull())
2544 obj
.push_back(Pair("hdmasterkeyid", masterKeyID
.GetHex()));
2548 UniValue
listwallets(const JSONRPCRequest
& request
)
2550 if (request
.fHelp
|| request
.params
.size() != 0)
2551 throw std::runtime_error(
2553 "Returns a list of currently loaded wallets.\n"
2554 "For full information on the wallet, use \"getwalletinfo\"\n"
2556 "[ (json array of strings)\n"
2557 " \"walletname\" (string) the wallet name\n"
2561 + HelpExampleCli("listwallets", "")
2562 + HelpExampleRpc("listwallets", "")
2565 UniValue
obj(UniValue::VARR
);
2567 for (CWalletRef pwallet
: vpwallets
) {
2569 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2570 return NullUniValue
;
2573 LOCK(pwallet
->cs_wallet
);
2575 obj
.push_back(pwallet
->GetName());
2581 UniValue
resendwallettransactions(const JSONRPCRequest
& request
)
2583 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2584 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2585 return NullUniValue
;
2588 if (request
.fHelp
|| request
.params
.size() != 0)
2589 throw std::runtime_error(
2590 "resendwallettransactions\n"
2591 "Immediately re-broadcast unconfirmed wallet transactions to all peers.\n"
2592 "Intended only for testing; the wallet code periodically re-broadcasts\n"
2594 "Returns an RPC error if -walletbroadcast is set to false.\n"
2595 "Returns array of transaction ids that were re-broadcast.\n"
2599 throw JSONRPCError(RPC_CLIENT_P2P_DISABLED
, "Error: Peer-to-peer functionality missing or disabled");
2601 LOCK2(cs_main
, pwallet
->cs_wallet
);
2603 if (!pwallet
->GetBroadcastTransactions()) {
2604 throw JSONRPCError(RPC_WALLET_ERROR
, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast");
2607 std::vector
<uint256
> txids
= pwallet
->ResendWalletTransactionsBefore(GetTime(), g_connman
.get());
2608 UniValue
result(UniValue::VARR
);
2609 for (const uint256
& txid
: txids
)
2611 result
.push_back(txid
.ToString());
2616 UniValue
listunspent(const JSONRPCRequest
& request
)
2618 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2619 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2620 return NullUniValue
;
2623 if (request
.fHelp
|| request
.params
.size() > 5)
2624 throw std::runtime_error(
2625 "listunspent ( minconf maxconf [\"addresses\",...] [include_unsafe] [query_options])\n"
2626 "\nReturns array of unspent transaction outputs\n"
2627 "with between minconf and maxconf (inclusive) confirmations.\n"
2628 "Optionally filter to only include txouts paid to specified addresses.\n"
2630 "1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n"
2631 "2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
2632 "3. \"addresses\" (string) A json array of bitcoin addresses to filter\n"
2634 " \"address\" (string) bitcoin address\n"
2637 "4. include_unsafe (bool, optional, default=true) Include outputs that are not safe to spend\n"
2638 " See description of \"safe\" attribute below.\n"
2639 "5. query_options (json, optional) JSON with query options\n"
2641 " \"minimumAmount\" (numeric or string, default=0) Minimum value of each UTXO in " + CURRENCY_UNIT
+ "\n"
2642 " \"maximumAmount\" (numeric or string, default=unlimited) Maximum value of each UTXO in " + CURRENCY_UNIT
+ "\n"
2643 " \"maximumCount\" (numeric or string, default=unlimited) Maximum number of UTXOs\n"
2644 " \"minimumSumAmount\" (numeric or string, default=unlimited) Minimum sum value of all UTXOs in " + CURRENCY_UNIT
+ "\n"
2647 "[ (array of json object)\n"
2649 " \"txid\" : \"txid\", (string) the transaction id \n"
2650 " \"vout\" : n, (numeric) the vout value\n"
2651 " \"address\" : \"address\", (string) the bitcoin address\n"
2652 " \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
2653 " \"scriptPubKey\" : \"key\", (string) the script key\n"
2654 " \"amount\" : x.xxx, (numeric) the transaction output amount in " + CURRENCY_UNIT
+ "\n"
2655 " \"confirmations\" : n, (numeric) The number of confirmations\n"
2656 " \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
2657 " \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
2658 " \"solvable\" : xxx, (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
2659 " \"safe\" : xxx (bool) Whether this output is considered safe to spend. Unconfirmed transactions\n"
2660 " from outside keys and unconfirmed replacement transactions are considered unsafe\n"
2661 " and are not eligible for spending by fundrawtransaction and sendtoaddress.\n"
2667 + HelpExampleCli("listunspent", "")
2668 + HelpExampleCli("listunspent", "6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
2669 + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
2670 + HelpExampleCli("listunspent", "6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'")
2671 + HelpExampleRpc("listunspent", "6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")
2675 if (request
.params
.size() > 0 && !request
.params
[0].isNull()) {
2676 RPCTypeCheckArgument(request
.params
[0], UniValue::VNUM
);
2677 nMinDepth
= request
.params
[0].get_int();
2680 int nMaxDepth
= 9999999;
2681 if (request
.params
.size() > 1 && !request
.params
[1].isNull()) {
2682 RPCTypeCheckArgument(request
.params
[1], UniValue::VNUM
);
2683 nMaxDepth
= request
.params
[1].get_int();
2686 std::set
<CBitcoinAddress
> setAddress
;
2687 if (request
.params
.size() > 2 && !request
.params
[2].isNull()) {
2688 RPCTypeCheckArgument(request
.params
[2], UniValue::VARR
);
2689 UniValue inputs
= request
.params
[2].get_array();
2690 for (unsigned int idx
= 0; idx
< inputs
.size(); idx
++) {
2691 const UniValue
& input
= inputs
[idx
];
2692 CBitcoinAddress
address(input
.get_str());
2693 if (!address
.IsValid())
2694 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, std::string("Invalid Bitcoin address: ")+input
.get_str());
2695 if (setAddress
.count(address
))
2696 throw JSONRPCError(RPC_INVALID_PARAMETER
, std::string("Invalid parameter, duplicated address: ")+input
.get_str());
2697 setAddress
.insert(address
);
2701 bool include_unsafe
= true;
2702 if (request
.params
.size() > 3 && !request
.params
[3].isNull()) {
2703 RPCTypeCheckArgument(request
.params
[3], UniValue::VBOOL
);
2704 include_unsafe
= request
.params
[3].get_bool();
2707 CAmount nMinimumAmount
= 0;
2708 CAmount nMaximumAmount
= MAX_MONEY
;
2709 CAmount nMinimumSumAmount
= MAX_MONEY
;
2710 uint64_t nMaximumCount
= 0;
2712 if (!request
.params
[4].isNull()) {
2713 const UniValue
& options
= request
.params
[4].get_obj();
2715 if (options
.exists("minimumAmount"))
2716 nMinimumAmount
= AmountFromValue(options
["minimumAmount"]);
2718 if (options
.exists("maximumAmount"))
2719 nMaximumAmount
= AmountFromValue(options
["maximumAmount"]);
2721 if (options
.exists("minimumSumAmount"))
2722 nMinimumSumAmount
= AmountFromValue(options
["minimumSumAmount"]);
2724 if (options
.exists("maximumCount"))
2725 nMaximumCount
= options
["maximumCount"].get_int64();
2728 UniValue
results(UniValue::VARR
);
2729 std::vector
<COutput
> vecOutputs
;
2730 assert(pwallet
!= NULL
);
2731 LOCK2(cs_main
, pwallet
->cs_wallet
);
2733 pwallet
->AvailableCoins(vecOutputs
, !include_unsafe
, NULL
, nMinimumAmount
, nMaximumAmount
, nMinimumSumAmount
, nMaximumCount
, nMinDepth
, nMaxDepth
);
2734 for (const COutput
& out
: vecOutputs
) {
2735 CTxDestination address
;
2736 const CScript
& scriptPubKey
= out
.tx
->tx
->vout
[out
.i
].scriptPubKey
;
2737 bool fValidAddress
= ExtractDestination(scriptPubKey
, address
);
2739 if (setAddress
.size() && (!fValidAddress
|| !setAddress
.count(address
)))
2742 UniValue
entry(UniValue::VOBJ
);
2743 entry
.push_back(Pair("txid", out
.tx
->GetHash().GetHex()));
2744 entry
.push_back(Pair("vout", out
.i
));
2746 if (fValidAddress
) {
2747 entry
.push_back(Pair("address", CBitcoinAddress(address
).ToString()));
2749 if (pwallet
->mapAddressBook
.count(address
)) {
2750 entry
.push_back(Pair("account", pwallet
->mapAddressBook
[address
].name
));
2753 if (scriptPubKey
.IsPayToScriptHash()) {
2754 const CScriptID
& hash
= boost::get
<CScriptID
>(address
);
2755 CScript redeemScript
;
2756 if (pwallet
->GetCScript(hash
, redeemScript
)) {
2757 entry
.push_back(Pair("redeemScript", HexStr(redeemScript
.begin(), redeemScript
.end())));
2762 entry
.push_back(Pair("scriptPubKey", HexStr(scriptPubKey
.begin(), scriptPubKey
.end())));
2763 entry
.push_back(Pair("amount", ValueFromAmount(out
.tx
->tx
->vout
[out
.i
].nValue
)));
2764 entry
.push_back(Pair("confirmations", out
.nDepth
));
2765 entry
.push_back(Pair("spendable", out
.fSpendable
));
2766 entry
.push_back(Pair("solvable", out
.fSolvable
));
2767 entry
.push_back(Pair("safe", out
.fSafe
));
2768 results
.push_back(entry
);
2774 UniValue
fundrawtransaction(const JSONRPCRequest
& request
)
2776 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2777 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
2778 return NullUniValue
;
2781 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 2)
2782 throw std::runtime_error(
2783 "fundrawtransaction \"hexstring\" ( options )\n"
2784 "\nAdd inputs to a transaction until it has enough in value to meet its out value.\n"
2785 "This will not modify existing inputs, and will add at most one change output to the outputs.\n"
2786 "No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n"
2787 "Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n"
2788 "The inputs added will not be signed, use signrawtransaction for that.\n"
2789 "Note that all existing inputs must have their previous output transaction be in the wallet.\n"
2790 "Note that all inputs selected must be of standard form and P2SH scripts must be\n"
2791 "in the wallet using importaddress or addmultisigaddress (to calculate fees).\n"
2792 "You can see whether this is the case by checking the \"solvable\" field in the listunspent output.\n"
2793 "Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only\n"
2795 "1. \"hexstring\" (string, required) The hex string of the raw transaction\n"
2796 "2. options (object, optional)\n"
2798 " \"changeAddress\" (string, optional, default pool address) The bitcoin address to receive the change\n"
2799 " \"changePosition\" (numeric, optional, default random) The index of the change output\n"
2800 " \"includeWatching\" (boolean, optional, default false) Also select inputs which are watch only\n"
2801 " \"lockUnspents\" (boolean, optional, default false) Lock selected unspent outputs\n"
2802 " \"feeRate\" (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate (" + CURRENCY_UNIT
+ " per KB)\n"
2803 " \"subtractFeeFromOutputs\" (array, optional) A json array of integers.\n"
2804 " The fee will be equally deducted from the amount of each specified output.\n"
2805 " The outputs are specified by their zero-based index, before any change output is added.\n"
2806 " Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
2807 " If no outputs are specified here, the sender pays the fee.\n"
2808 " [vout_index,...]\n"
2809 " \"replaceable\" (boolean, optional) Marks this transaction as BIP125 replaceable.\n"
2810 " Allows this transaction to be replaced by a transaction with higher fees\n"
2811 " \"conf_target\" (numeric, optional) Confirmation target (in blocks)\n"
2812 " \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
2815 " \"CONSERVATIVE\"\n"
2817 " for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n"
2820 " \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
2821 " \"fee\": n, (numeric) Fee in " + CURRENCY_UNIT
+ " the resulting transaction pays\n"
2822 " \"changepos\": n (numeric) The position of the added change output, or -1\n"
2825 "\nCreate a transaction with no inputs\n"
2826 + HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
2827 "\nAdd sufficient unsigned inputs to meet the output value\n"
2828 + HelpExampleCli("fundrawtransaction", "\"rawtransactionhex\"") +
2829 "\nSign the transaction\n"
2830 + HelpExampleCli("signrawtransaction", "\"fundedtransactionhex\"") +
2831 "\nSend the transaction\n"
2832 + HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")
2835 RPCTypeCheck(request
.params
, {UniValue::VSTR
});
2837 CCoinControl coinControl
;
2838 int changePosition
= -1;
2839 bool lockUnspents
= false;
2840 UniValue subtractFeeFromOutputs
;
2841 std::set
<int> setSubtractFeeFromOutputs
;
2843 if (!request
.params
[1].isNull()) {
2844 if (request
.params
[1].type() == UniValue::VBOOL
) {
2845 // backward compatibility bool only fallback
2846 coinControl
.fAllowWatchOnly
= request
.params
[1].get_bool();
2849 RPCTypeCheck(request
.params
, {UniValue::VSTR
, UniValue::VOBJ
});
2851 UniValue options
= request
.params
[1];
2853 RPCTypeCheckObj(options
,
2855 {"changeAddress", UniValueType(UniValue::VSTR
)},
2856 {"changePosition", UniValueType(UniValue::VNUM
)},
2857 {"includeWatching", UniValueType(UniValue::VBOOL
)},
2858 {"lockUnspents", UniValueType(UniValue::VBOOL
)},
2859 {"reserveChangeKey", UniValueType(UniValue::VBOOL
)}, // DEPRECATED (and ignored), should be removed in 0.16 or so.
2860 {"feeRate", UniValueType()}, // will be checked below
2861 {"subtractFeeFromOutputs", UniValueType(UniValue::VARR
)},
2862 {"replaceable", UniValueType(UniValue::VBOOL
)},
2863 {"conf_target", UniValueType(UniValue::VNUM
)},
2864 {"estimate_mode", UniValueType(UniValue::VSTR
)},
2868 if (options
.exists("changeAddress")) {
2869 CBitcoinAddress
address(options
["changeAddress"].get_str());
2871 if (!address
.IsValid())
2872 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, "changeAddress must be a valid bitcoin address");
2874 coinControl
.destChange
= address
.Get();
2877 if (options
.exists("changePosition"))
2878 changePosition
= options
["changePosition"].get_int();
2880 if (options
.exists("includeWatching"))
2881 coinControl
.fAllowWatchOnly
= options
["includeWatching"].get_bool();
2883 if (options
.exists("lockUnspents"))
2884 lockUnspents
= options
["lockUnspents"].get_bool();
2886 if (options
.exists("feeRate"))
2888 coinControl
.m_feerate
= CFeeRate(AmountFromValue(options
["feeRate"]));
2889 coinControl
.fOverrideFeeRate
= true;
2892 if (options
.exists("subtractFeeFromOutputs"))
2893 subtractFeeFromOutputs
= options
["subtractFeeFromOutputs"].get_array();
2895 if (options
.exists("replaceable")) {
2896 coinControl
.signalRbf
= options
["replaceable"].get_bool();
2898 if (options
.exists("conf_target")) {
2899 if (options
.exists("feeRate")) {
2900 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Cannot specify both conf_target and feeRate");
2902 coinControl
.m_confirm_target
= ParseConfirmTarget(options
["conf_target"]);
2904 if (options
.exists("estimate_mode")) {
2905 if (options
.exists("feeRate")) {
2906 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Cannot specify both estimate_mode and feeRate");
2908 if (!FeeModeFromString(options
["estimate_mode"].get_str(), coinControl
.m_fee_mode
)) {
2909 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid estimate_mode parameter");
2915 // parse hex string from parameter
2916 CMutableTransaction tx
;
2917 if (!DecodeHexTx(tx
, request
.params
[0].get_str(), true))
2918 throw JSONRPCError(RPC_DESERIALIZATION_ERROR
, "TX decode failed");
2920 if (tx
.vout
.size() == 0)
2921 throw JSONRPCError(RPC_INVALID_PARAMETER
, "TX must have at least one output");
2923 if (changePosition
!= -1 && (changePosition
< 0 || (unsigned int)changePosition
> tx
.vout
.size()))
2924 throw JSONRPCError(RPC_INVALID_PARAMETER
, "changePosition out of bounds");
2926 for (unsigned int idx
= 0; idx
< subtractFeeFromOutputs
.size(); idx
++) {
2927 int pos
= subtractFeeFromOutputs
[idx
].get_int();
2928 if (setSubtractFeeFromOutputs
.count(pos
))
2929 throw JSONRPCError(RPC_INVALID_PARAMETER
, strprintf("Invalid parameter, duplicated position: %d", pos
));
2931 throw JSONRPCError(RPC_INVALID_PARAMETER
, strprintf("Invalid parameter, negative position: %d", pos
));
2932 if (pos
>= int(tx
.vout
.size()))
2933 throw JSONRPCError(RPC_INVALID_PARAMETER
, strprintf("Invalid parameter, position too large: %d", pos
));
2934 setSubtractFeeFromOutputs
.insert(pos
);
2938 std::string strFailReason
;
2940 if (!pwallet
->FundTransaction(tx
, nFeeOut
, changePosition
, strFailReason
, lockUnspents
, setSubtractFeeFromOutputs
, coinControl
)) {
2941 throw JSONRPCError(RPC_WALLET_ERROR
, strFailReason
);
2944 UniValue
result(UniValue::VOBJ
);
2945 result
.push_back(Pair("hex", EncodeHexTx(tx
)));
2946 result
.push_back(Pair("changepos", changePosition
));
2947 result
.push_back(Pair("fee", ValueFromAmount(nFeeOut
)));
2952 UniValue
bumpfee(const JSONRPCRequest
& request
)
2954 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
2956 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
))
2957 return NullUniValue
;
2959 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 2) {
2960 throw std::runtime_error(
2961 "bumpfee \"txid\" ( options ) \n"
2962 "\nBumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B.\n"
2963 "An opt-in RBF transaction with the given txid must be in the wallet.\n"
2964 "The command will pay the additional fee by decreasing (or perhaps removing) its change output.\n"
2965 "If the change output is not big enough to cover the increased fee, the command will currently fail\n"
2966 "instead of adding new inputs to compensate. (A future implementation could improve this.)\n"
2967 "The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.\n"
2968 "By default, the new fee will be calculated automatically using estimatefee.\n"
2969 "The user can specify a confirmation target for estimatefee.\n"
2970 "Alternatively, the user can specify totalFee, or use RPC settxfee to set a higher fee rate.\n"
2971 "At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee\n"
2972 "returned by getnetworkinfo) to enter the node's mempool.\n"
2974 "1. txid (string, required) The txid to be bumped\n"
2975 "2. options (object, optional)\n"
2977 " \"confTarget\" (numeric, optional) Confirmation target (in blocks)\n"
2978 " \"totalFee\" (numeric, optional) Total fee (NOT feerate) to pay, in satoshis.\n"
2979 " In rare cases, the actual fee paid might be slightly higher than the specified\n"
2980 " totalFee if the tx change output has to be removed because it is too close to\n"
2981 " the dust threshold.\n"
2982 " \"replaceable\" (boolean, optional, default true) Whether the new transaction should still be\n"
2983 " marked bip-125 replaceable. If true, the sequence numbers in the transaction will\n"
2984 " be left unchanged from the original. If false, any input sequence numbers in the\n"
2985 " original transaction that were less than 0xfffffffe will be increased to 0xfffffffe\n"
2986 " so the new transaction will not be explicitly bip-125 replaceable (though it may\n"
2987 " still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
2988 " are replaceable).\n"
2989 " \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
2992 " \"CONSERVATIVE\"\n"
2996 " \"txid\": \"value\", (string) The id of the new transaction\n"
2997 " \"origfee\": n, (numeric) Fee of the replaced transaction\n"
2998 " \"fee\": n, (numeric) Fee of the new transaction\n"
2999 " \"errors\": [ str... ] (json array of strings) Errors encountered during processing (may be empty)\n"
3002 "\nBump the fee, get the new transaction\'s txid\n" +
3003 HelpExampleCli("bumpfee", "<txid>"));
3006 RPCTypeCheck(request
.params
, {UniValue::VSTR
, UniValue::VOBJ
});
3008 hash
.SetHex(request
.params
[0].get_str());
3010 // optional parameters
3011 CAmount totalFee
= 0;
3012 CCoinControl coin_control
;
3013 coin_control
.signalRbf
= true;
3014 if (!request
.params
[1].isNull()) {
3015 UniValue options
= request
.params
[1];
3016 RPCTypeCheckObj(options
,
3018 {"confTarget", UniValueType(UniValue::VNUM
)},
3019 {"totalFee", UniValueType(UniValue::VNUM
)},
3020 {"replaceable", UniValueType(UniValue::VBOOL
)},
3021 {"estimate_mode", UniValueType(UniValue::VSTR
)},
3025 if (options
.exists("confTarget") && options
.exists("totalFee")) {
3026 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.");
3027 } else if (options
.exists("confTarget")) { // TODO: alias this to conf_target
3028 coin_control
.m_confirm_target
= ParseConfirmTarget(options
["confTarget"]);
3029 } else if (options
.exists("totalFee")) {
3030 totalFee
= options
["totalFee"].get_int64();
3031 if (totalFee
<= 0) {
3032 throw JSONRPCError(RPC_INVALID_PARAMETER
, strprintf("Invalid totalFee %s (must be greater than 0)", FormatMoney(totalFee
)));
3036 if (options
.exists("replaceable")) {
3037 coin_control
.signalRbf
= options
["replaceable"].get_bool();
3039 if (options
.exists("estimate_mode")) {
3040 if (!FeeModeFromString(options
["estimate_mode"].get_str(), coin_control
.m_fee_mode
)) {
3041 throw JSONRPCError(RPC_INVALID_PARAMETER
, "Invalid estimate_mode parameter");
3046 LOCK2(cs_main
, pwallet
->cs_wallet
);
3047 EnsureWalletIsUnlocked(pwallet
);
3049 CFeeBumper
feeBump(pwallet
, hash
, coin_control
, totalFee
);
3050 BumpFeeResult res
= feeBump
.getResult();
3051 if (res
!= BumpFeeResult::OK
)
3054 case BumpFeeResult::INVALID_ADDRESS_OR_KEY
:
3055 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY
, feeBump
.getErrors()[0]);
3057 case BumpFeeResult::INVALID_REQUEST
:
3058 throw JSONRPCError(RPC_INVALID_REQUEST
, feeBump
.getErrors()[0]);
3060 case BumpFeeResult::INVALID_PARAMETER
:
3061 throw JSONRPCError(RPC_INVALID_PARAMETER
, feeBump
.getErrors()[0]);
3063 case BumpFeeResult::WALLET_ERROR
:
3064 throw JSONRPCError(RPC_WALLET_ERROR
, feeBump
.getErrors()[0]);
3067 throw JSONRPCError(RPC_MISC_ERROR
, feeBump
.getErrors()[0]);
3072 // sign bumped transaction
3073 if (!feeBump
.signTransaction(pwallet
)) {
3074 throw JSONRPCError(RPC_WALLET_ERROR
, "Can't sign transaction.");
3076 // commit the bumped transaction
3077 if(!feeBump
.commit(pwallet
)) {
3078 throw JSONRPCError(RPC_WALLET_ERROR
, feeBump
.getErrors()[0]);
3080 UniValue
result(UniValue::VOBJ
);
3081 result
.push_back(Pair("txid", feeBump
.getBumpedTxId().GetHex()));
3082 result
.push_back(Pair("origfee", ValueFromAmount(feeBump
.getOldFee())));
3083 result
.push_back(Pair("fee", ValueFromAmount(feeBump
.getNewFee())));
3084 UniValue
errors(UniValue::VARR
);
3085 for (const std::string
& err
: feeBump
.getErrors())
3086 errors
.push_back(err
);
3087 result
.push_back(Pair("errors", errors
));
3092 UniValue
generate(const JSONRPCRequest
& request
)
3094 CWallet
* const pwallet
= GetWalletForJSONRPCRequest(request
);
3096 if (!EnsureWalletIsAvailable(pwallet
, request
.fHelp
)) {
3097 return NullUniValue
;
3100 if (request
.fHelp
|| request
.params
.size() < 1 || request
.params
.size() > 2) {
3101 throw std::runtime_error(
3102 "generate nblocks ( maxtries )\n"
3103 "\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n"
3105 "1. nblocks (numeric, required) How many blocks are generated immediately.\n"
3106 "2. maxtries (numeric, optional) How many iterations to try (default = 1000000).\n"
3108 "[ blockhashes ] (array) hashes of blocks generated\n"
3110 "\nGenerate 11 blocks\n"
3111 + HelpExampleCli("generate", "11")
3115 int num_generate
= request
.params
[0].get_int();
3116 uint64_t max_tries
= 1000000;
3117 if (request
.params
.size() > 1 && !request
.params
[1].isNull()) {
3118 max_tries
= request
.params
[1].get_int();
3121 std::shared_ptr
<CReserveScript
> coinbase_script
;
3122 pwallet
->GetScriptForMining(coinbase_script
);
3124 // If the keypool is exhausted, no script is returned at all. Catch this.
3125 if (!coinbase_script
) {
3126 throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT
, "Error: Keypool ran out, please call keypoolrefill first");
3129 //throw an error if no script was provided
3130 if (coinbase_script
->reserveScript
.empty()) {
3131 throw JSONRPCError(RPC_INTERNAL_ERROR
, "No coinbase script available");
3134 return generateBlocks(coinbase_script
, num_generate
, max_tries
, true);
3137 extern UniValue
abortrescan(const JSONRPCRequest
& request
); // in rpcdump.cpp
3138 extern UniValue
dumpprivkey(const JSONRPCRequest
& request
); // in rpcdump.cpp
3139 extern UniValue
importprivkey(const JSONRPCRequest
& request
);
3140 extern UniValue
importaddress(const JSONRPCRequest
& request
);
3141 extern UniValue
importpubkey(const JSONRPCRequest
& request
);
3142 extern UniValue
dumpwallet(const JSONRPCRequest
& request
);
3143 extern UniValue
importwallet(const JSONRPCRequest
& request
);
3144 extern UniValue
importprunedfunds(const JSONRPCRequest
& request
);
3145 extern UniValue
removeprunedfunds(const JSONRPCRequest
& request
);
3146 extern UniValue
importmulti(const JSONRPCRequest
& request
);
3148 static const CRPCCommand commands
[] =
3149 { // category name actor (function) okSafeMode
3150 // --------------------- ------------------------ ----------------------- ----------
3151 { "rawtransactions", "fundrawtransaction", &fundrawtransaction
, false, {"hexstring","options"} },
3152 { "hidden", "resendwallettransactions", &resendwallettransactions
, true, {} },
3153 { "wallet", "abandontransaction", &abandontransaction
, false, {"txid"} },
3154 { "wallet", "abortrescan", &abortrescan
, false, {} },
3155 { "wallet", "addmultisigaddress", &addmultisigaddress
, true, {"nrequired","keys","account"} },
3156 { "wallet", "addwitnessaddress", &addwitnessaddress
, true, {"address"} },
3157 { "wallet", "backupwallet", &backupwallet
, true, {"destination"} },
3158 { "wallet", "bumpfee", &bumpfee
, true, {"txid", "options"} },
3159 { "wallet", "dumpprivkey", &dumpprivkey
, true, {"address"} },
3160 { "wallet", "dumpwallet", &dumpwallet
, true, {"filename"} },
3161 { "wallet", "encryptwallet", &encryptwallet
, true, {"passphrase"} },
3162 { "wallet", "getaccountaddress", &getaccountaddress
, true, {"account"} },
3163 { "wallet", "getaccount", &getaccount
, true, {"address"} },
3164 { "wallet", "getaddressesbyaccount", &getaddressesbyaccount
, true, {"account"} },
3165 { "wallet", "getbalance", &getbalance
, false, {"account","minconf","include_watchonly"} },
3166 { "wallet", "getnewaddress", &getnewaddress
, true, {"account"} },
3167 { "wallet", "getrawchangeaddress", &getrawchangeaddress
, true, {} },
3168 { "wallet", "getreceivedbyaccount", &getreceivedbyaccount
, false, {"account","minconf"} },
3169 { "wallet", "getreceivedbyaddress", &getreceivedbyaddress
, false, {"address","minconf"} },
3170 { "wallet", "gettransaction", &gettransaction
, false, {"txid","include_watchonly"} },
3171 { "wallet", "getunconfirmedbalance", &getunconfirmedbalance
, false, {} },
3172 { "wallet", "getwalletinfo", &getwalletinfo
, false, {} },
3173 { "wallet", "importmulti", &importmulti
, true, {"requests","options"} },
3174 { "wallet", "importprivkey", &importprivkey
, true, {"privkey","label","rescan"} },
3175 { "wallet", "importwallet", &importwallet
, true, {"filename"} },
3176 { "wallet", "importaddress", &importaddress
, true, {"address","label","rescan","p2sh"} },
3177 { "wallet", "importprunedfunds", &importprunedfunds
, true, {"rawtransaction","txoutproof"} },
3178 { "wallet", "importpubkey", &importpubkey
, true, {"pubkey","label","rescan"} },
3179 { "wallet", "keypoolrefill", &keypoolrefill
, true, {"newsize"} },
3180 { "wallet", "listaccounts", &listaccounts
, false, {"minconf","include_watchonly"} },
3181 { "wallet", "listaddressgroupings", &listaddressgroupings
, false, {} },
3182 { "wallet", "listlockunspent", &listlockunspent
, false, {} },
3183 { "wallet", "listreceivedbyaccount", &listreceivedbyaccount
, false, {"minconf","include_empty","include_watchonly"} },
3184 { "wallet", "listreceivedbyaddress", &listreceivedbyaddress
, false, {"minconf","include_empty","include_watchonly"} },
3185 { "wallet", "listsinceblock", &listsinceblock
, false, {"blockhash","target_confirmations","include_watchonly","include_removed"} },
3186 { "wallet", "listtransactions", &listtransactions
, false, {"account","count","skip","include_watchonly"} },
3187 { "wallet", "listunspent", &listunspent
, false, {"minconf","maxconf","addresses","include_unsafe","query_options"} },
3188 { "wallet", "listwallets", &listwallets
, true, {} },
3189 { "wallet", "lockunspent", &lockunspent
, true, {"unlock","transactions"} },
3190 { "wallet", "move", &movecmd
, false, {"fromaccount","toaccount","amount","minconf","comment"} },
3191 { "wallet", "sendfrom", &sendfrom
, false, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} },
3192 { "wallet", "sendmany", &sendmany
, false, {"fromaccount","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode"} },
3193 { "wallet", "sendtoaddress", &sendtoaddress
, false, {"address","amount","comment","comment_to","subtractfeefromamount","replaceable","conf_target","estimate_mode"} },
3194 { "wallet", "setaccount", &setaccount
, true, {"address","account"} },
3195 { "wallet", "settxfee", &settxfee
, true, {"amount"} },
3196 { "wallet", "signmessage", &signmessage
, true, {"address","message"} },
3197 { "wallet", "walletlock", &walletlock
, true, {} },
3198 { "wallet", "walletpassphrasechange", &walletpassphrasechange
, true, {"oldpassphrase","newpassphrase"} },
3199 { "wallet", "walletpassphrase", &walletpassphrase
, true, {"passphrase","timeout"} },
3200 { "wallet", "removeprunedfunds", &removeprunedfunds
, true, {"txid"} },
3202 { "generating", "generate", &generate
, true, {"nblocks","maxtries"} },
3205 void RegisterWalletRPCCommands(CRPCTable
&t
)
3207 if (GetBoolArg("-disablewallet", false))
3210 for (unsigned int vcidx
= 0; vcidx
< ARRAYLEN(commands
); vcidx
++)
3211 t
.appendCommand(commands
[vcidx
].name
, &commands
[vcidx
]);