21 std::vector<CTxDestination> addresses;
32 addresses.emplace_back(dest);
36 std::set<CScript> output_scripts;
37 for (
const auto& address : addresses) {
39 if (
wallet.IsMine(output_script)) {
40 output_scripts.
insert(output_script);
44 if (output_scripts.empty()) {
50 if (!params[1].isNull())
51 min_depth = params[1].getInt<
int>();
53 const bool include_immature_coinbase{params[2].isNull() ? false : params[2].get_bool()};
57 for (
const std::pair<const uint256, CWalletTx>& wtx_pair :
wallet.mapWallet) {
59 int depth{
wallet.GetTxDepthInMainChain(wtx)};
63 || (
wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase))
68 for (
const CTxOut& txout : wtx.
tx->vout) {
82 "\nReturns the total amount received by the given address in transactions with at least minconf confirmations.\n",
92 "\nThe amount from transactions with at least 1 confirmation\n" 94 "\nThe amount including unconfirmed transactions, zero confirmations\n" 96 "\nThe amount with at least 6 confirmations\n" 98 "\nThe amount with at least 6 confirmations including immature coinbase outputs\n" 100 "\nAs a JSON-RPC call\n" 110 pwallet->BlockUntilSyncedToCurrentChain();
112 LOCK(pwallet->cs_wallet);
123 "\nReturns the total amount received by addresses with <label> in transactions with at least [minconf] confirmations.\n",
133 "\nAmount received by the default label with at least 1 confirmation\n" 135 "\nAmount received at the tabby label including unconfirmed amounts with zero confirmations\n" 137 "\nThe amount with at least 6 confirmations\n" 139 "\nThe amount with at least 6 confirmations including immature coinbase outputs\n" 141 "\nAs a JSON-RPC call\n" 151 pwallet->BlockUntilSyncedToCurrentChain();
153 LOCK(pwallet->cs_wallet);
164 "\nReturns the total available balance.\n" 165 "The available balance is what the wallet considers currently spendable, and is\n" 166 "thus affected by options which limit spendability such as -spendzeroconfchange.\n",
170 {
"include_watchonly",
RPCArg::Type::BOOL,
RPCArg::DefaultHint{
"true for watch-only wallets, otherwise false"},
"Also include balance in watch-only addresses (see 'importaddress')"},
171 {
"avoid_reuse",
RPCArg::Type::BOOL,
RPCArg::Default{
true},
"(only available if avoid_reuse wallet flag is set) Do not include balance in dirty outputs; addresses are considered dirty if they have previously been used in a transaction."},
177 "\nThe total amount in the wallet with 0 or more confirmations\n" 179 "\nThe total amount in the wallet with at least 6 confirmations\n" 181 "\nAs a JSON-RPC call\n" 191 pwallet->BlockUntilSyncedToCurrentChain();
193 LOCK(pwallet->cs_wallet);
195 const UniValue& dummy_value = request.params[0];
201 if (!request.params[1].isNull()) {
202 min_depth = request.params[1].getInt<
int>();
209 const auto bal =
GetBalance(*pwallet, min_depth, avoid_reuse);
211 return ValueFromAmount(bal.m_mine_trusted + (include_watchonly ? bal.m_watchonly_trusted : 0));
219 "DEPRECATED\nIdentical to getbalances().mine.untrusted_pending\n",
230 pwallet->BlockUntilSyncedToCurrentChain();
232 LOCK(pwallet->cs_wallet);
242 "\nUpdates list of temporarily unspendable outputs.\n" 243 "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n" 244 "If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n" 245 "A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.\n" 246 "Manually selected coins are automatically unlocked.\n" 247 "Locks are stored in memory only, unless persistent=true, in which case they will be written to the\n" 248 "wallet database and loaded on node start. Unwritten (persistent=false) locks are always cleared\n" 249 "(by virtue of process exit) when a node stops or fails. Unlocking will clear both persistent and not.\n" 250 "Also see the listunspent call\n",
263 {
"persistent",
RPCArg::Type::BOOL,
RPCArg::Default{
false},
"Whether to write/erase this lock in the wallet database, or keep the change in memory only. Ignored for unlocking."},
269 "\nList the unspent transactions\n" 271 "\nLock an unspent transaction\n" 272 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
273 "\nList the locked transactions\n" 275 "\nUnlock the transaction again\n" 276 +
HelpExampleCli(
"lockunspent",
"true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
277 "\nLock the transaction persistently in the wallet database\n" 278 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\" true") +
279 "\nAs a JSON-RPC call\n" 280 +
HelpExampleRpc(
"lockunspent",
"false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
289 pwallet->BlockUntilSyncedToCurrentChain();
291 LOCK(pwallet->cs_wallet);
295 bool fUnlock = request.params[0].get_bool();
297 const bool persistent{request.params[2].isNull() ? false : request.params[2].get_bool()};
299 if (request.params[1].isNull()) {
301 if (!pwallet->UnlockAllCoins())
309 const UniValue& output_params = request.params[1];
313 std::vector<COutPoint> outputs;
314 outputs.reserve(output_params.
size());
316 for (
unsigned int idx = 0; idx < output_params.
size(); idx++) {
333 const auto it = pwallet->mapWallet.find(outpt.
hash);
334 if (it == pwallet->mapWallet.end()) {
340 if (outpt.
n >= trans.
tx->vout.size()) {
344 if (pwallet->IsSpent(outpt)) {
348 const bool is_locked = pwallet->IsLockedCoin(outpt);
350 if (fUnlock && !is_locked) {
354 if (!fUnlock && is_locked && !persistent) {
358 outputs.push_back(outpt);
361 std::unique_ptr<WalletBatch> batch =
nullptr;
363 if (fUnlock || persistent) batch = std::make_unique<WalletBatch>(pwallet->GetDatabase());
382 "\nReturns list of temporarily unspendable outputs.\n" 383 "See the lockunspent call to lock and unlock transactions for spending.\n",
396 "\nList the unspent transactions\n" 398 "\nLock an unspent transaction\n" 399 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
400 "\nList the locked transactions\n" 402 "\nUnlock the transaction again\n" 403 +
HelpExampleCli(
"lockunspent",
"true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
404 "\nAs a JSON-RPC call\n" 412 LOCK(pwallet->cs_wallet);
414 std::vector<COutPoint> vOutpts;
415 pwallet->ListLockedCoins(vOutpts);
422 o.
pushKV(
"txid", outpt.hash.GetHex());
423 o.
pushKV(
"vout", (
int)outpt.n);
436 "Returns an object with all balances in " +
CURRENCY_UNIT +
".\n",
444 {
RPCResult::Type::STR_AMOUNT,
"untrusted_pending",
"untrusted pending balance (outputs created by others that are in the mempool)"},
446 {
RPCResult::Type::STR_AMOUNT,
"used",
true,
"(only present if avoid_reuse is set) balance from coins sent to addresses that were previously spent from (potentially privacy violating)"},
448 {
RPCResult::Type::OBJ,
"watchonly",
true,
"watchonly balances (not present if wallet does not watch anything)",
451 {
RPCResult::Type::STR_AMOUNT,
"untrusted_pending",
"untrusted pending balance (outputs created by others that are in the mempool)"},
467 wallet.BlockUntilSyncedToCurrentChain();
476 balances_mine.pushKV(
"untrusted_pending",
ValueFromAmount(bal.m_mine_untrusted_pending));
477 balances_mine.pushKV(
"immature",
ValueFromAmount(bal.m_mine_immature));
482 balances_mine.pushKV(
"used",
ValueFromAmount(full_bal.m_mine_trusted + full_bal.m_mine_untrusted_pending - bal.m_mine_trusted - bal.m_mine_untrusted_pending));
484 balances.pushKV(
"mine", balances_mine);
486 auto spk_man =
wallet.GetLegacyScriptPubKeyMan();
487 if (spk_man && spk_man->HaveWatchOnly()) {
489 balances_watchonly.pushKV(
"trusted",
ValueFromAmount(bal.m_watchonly_trusted));
490 balances_watchonly.pushKV(
"untrusted_pending",
ValueFromAmount(bal.m_watchonly_untrusted_pending));
491 balances_watchonly.pushKV(
"immature",
ValueFromAmount(bal.m_watchonly_immature));
492 balances.pushKV(
"watchonly", balances_watchonly);
503 "\nReturns array of unspent transaction outputs\n" 504 "with between minconf and maxconf (inclusive) confirmations.\n" 505 "Optionally filter to only include txouts paid to specified addresses.\n",
515 "See description of \"safe\" attribute below."},
537 {
RPCResult::Type::NUM,
"ancestorcount",
true,
"The number of in-mempool ancestor transactions, including this one (if transaction is in the mempool)"},
538 {
RPCResult::Type::NUM,
"ancestorsize",
true,
"The virtual transaction size of in-mempool ancestors, including this one (if transaction is in the mempool)"},
539 {
RPCResult::Type::STR_AMOUNT,
"ancestorfees",
true,
"The total fees of in-mempool ancestors (including this one) with fee deltas used for mining priority in " +
CURRENCY_ATOM +
" (if transaction is in the mempool)"},
541 {
RPCResult::Type::STR,
"witnessScript",
true,
"witnessScript if the scriptPubKey is P2WSH or P2SH-P2WSH"},
543 {
RPCResult::Type::BOOL,
"solvable",
"Whether we know how to spend this output, ignoring the lack of keys"},
544 {
RPCResult::Type::BOOL,
"reused",
true,
"(only present if avoid_reuse is set) Whether this output is reused/dirty (sent to an address that was previously spent from)"},
545 {
RPCResult::Type::STR,
"desc",
true,
"(only when solvable) A descriptor for spending this output"},
546 {
RPCResult::Type::ARR,
"parent_descs",
false,
"List of parent descriptors for the scriptPubKey of this coin.", {
549 {
RPCResult::Type::BOOL,
"safe",
"Whether this output is considered safe to spend. Unconfirmed transactions\n" 550 "from outside keys and unconfirmed replacement transactions are considered unsafe\n" 551 "and are not eligible for spending by fundrawtransaction and sendtoaddress."},
559 +
HelpExampleCli(
"listunspent",
"6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'")
560 +
HelpExampleRpc(
"listunspent",
"6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")
568 if (!request.params[0].isNull()) {
570 nMinDepth = request.params[0].getInt<
int>();
573 int nMaxDepth = 9999999;
574 if (!request.params[1].isNull()) {
576 nMaxDepth = request.params[1].getInt<
int>();
579 std::set<CTxDestination> destinations;
580 if (!request.params[2].isNull()) {
583 for (
unsigned int idx = 0; idx < inputs.
size(); idx++) {
584 const UniValue& input = inputs[idx];
589 if (!destinations.insert(dest).second) {
595 bool include_unsafe =
true;
596 if (!request.params[3].isNull()) {
598 include_unsafe = request.params[3].get_bool();
604 uint64_t nMaximumCount = 0;
606 if (!request.params[4].isNull()) {
618 if (options.
exists(
"minimumAmount"))
621 if (options.
exists(
"maximumAmount"))
624 if (options.
exists(
"minimumSumAmount"))
627 if (options.
exists(
"maximumCount"))
628 nMaximumCount = options[
"maximumCount"].getInt<int64_t>();
633 pwallet->BlockUntilSyncedToCurrentChain();
636 std::vector<COutput> vecOutputs;
643 LOCK(pwallet->cs_wallet);
647 LOCK(pwallet->cs_wallet);
651 for (
const COutput& out : vecOutputs) {
653 const CScript& scriptPubKey = out.txout.scriptPubKey;
655 bool reused = avoid_reuse && pwallet->IsSpentKey(scriptPubKey);
657 if (destinations.size() && (!fValidAddress || !destinations.count(address)))
661 entry.
pushKV(
"txid", out.outpoint.hash.GetHex());
662 entry.
pushKV(
"vout", (
int)out.outpoint.n);
667 const auto* address_book_entry = pwallet->FindAddressBookEntry(address);
668 if (address_book_entry) {
669 entry.
pushKV(
"label", address_book_entry->GetLabel());
672 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
677 if (provider->GetCScript(hash, redeemScript)) {
689 if (provider->GetCScript(
id, witnessScript)) {
699 if (provider->GetCScript(
id, witnessScript)) {
708 entry.
pushKV(
"confirmations", out.depth);
710 size_t ancestor_count, descendant_count, ancestor_size;
712 pwallet->chain().getTransactionAncestry(out.outpoint.hash, ancestor_count, descendant_count, &ancestor_size, &ancestor_fees);
713 if (ancestor_count) {
714 entry.
pushKV(
"ancestorcount", uint64_t(ancestor_count));
715 entry.
pushKV(
"ancestorsize", uint64_t(ancestor_size));
716 entry.
pushKV(
"ancestorfees", uint64_t(ancestor_fees));
719 entry.
pushKV(
"spendable", out.spendable);
720 entry.
pushKV(
"solvable", out.solvable);
722 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
725 entry.
pushKV(
"desc", descriptor->ToString());
729 if (avoid_reuse) entry.
pushKV(
"reused", reused);
730 entry.
pushKV(
"safe", out.safe);
void push_back(UniValue val)
RPCHelpMan listlockunspent()
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
iterator insert(iterator pos, const T &value)
std::vector< COutput > All() const
Concatenate and return all COutputs as one vector.
bool IsPayToScriptHash() const
RPCHelpMan getreceivedbylabel()
#define CHECK_NONFATAL(condition)
Identity function.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
bool ParseIncludeWatchonly(const UniValue &include_watchonly, const CWallet &wallet)
Used by RPC commands that have an include_watchonly parameter.
const std::string & get_str() const
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
const UniValue & get_array() const
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
Invalid, missing or duplicate parameter.
const UniValue & find_value(const UniValue &obj, const std::string &name)
int64_t CAmount
Amount in satoshis (Can be negative)
A transaction with a bunch of additional info that only the owner cares about.
void RPCTypeCheckArgument(const UniValue &value, const UniValueType &typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
Special type that is a STR with only hex chars.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
uint256 ParseHashO(const UniValue &o, std::string strKey)
UniValue JSONRPCError(int code, const std::string &message)
Special string with only hex chars.
const std::string CURRENCY_ATOM
std::string LabelFromValue(const UniValue &value)
static CAmount AmountFromValue(const UniValue &value)
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool exists(const std::string &key) const
const std::string CURRENCY_UNIT
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
An output of a transaction.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Optional arg that is a named argument and has a default value of null.
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
RPC method is deprecated.
CRIPEMD160 & Write(const unsigned char *data, size_t len)
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Optional argument with default value omitted because they are implicitly clear.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
RPCHelpMan getunconfirmedbalance()
int m_min_depth
Minimum chain depth value for coin availability.
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
Special string to represent a floating point amount.
void pushKV(std::string key, UniValue val)
Serialized script, used inside transaction inputs and outputs.
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
const UniValue & get_obj() const
static CAmount GetReceived(const CWallet &wallet, const UniValue ¶ms, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
Special type representing a floating point amount (can be either NUM or STR)
CAmount m_mine_untrusted_pending
Untrusted, but in mempool (pending)
UniValue ValueFromAmount(const CAmount amount)
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue ¶m)
A reference to a CScript: the Hash160 of its serialization (see script.h)
std::string EncodeDestination(const CTxDestination &dest)
RPCHelpMan getreceivedbyaddress()
int m_max_depth
Maximum chain depth value for coin availability.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
void PushParentDescriptors(const CWallet &wallet, const CScript &script_pubkey, UniValue &entry)
Fetch parent descriptors of this scriptPubKey.
A UTXO under consideration for use in funding a new transaction.
CoinsResult AvailableCoinsListUnspent(const CWallet &wallet, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount)
Wrapper function for AvailableCoins which skips the feerate parameter.
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
bool IsPayToWitnessScriptHash() const
A hasher class for RIPEMD-160.