23 std::vector<CTxDestination> addresses;
34 addresses.emplace_back(dest);
38 std::set<CScript> output_scripts;
39 for (
const auto& address : addresses) {
41 if (
wallet.IsMine(output_script)) {
42 output_scripts.
insert(output_script);
46 if (output_scripts.empty()) {
52 if (!params[1].isNull())
53 min_depth = params[1].getInt<
int>();
55 const bool include_immature_coinbase{params[2].isNull() ? false : params[2].get_bool()};
59 for (
const std::pair<const uint256, CWalletTx>& wtx_pair :
wallet.mapWallet) {
61 int depth{
wallet.GetTxDepthInMainChain(wtx)};
65 || (
wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase))
70 for (
const CTxOut& txout : wtx.
tx->vout) {
84 "\nReturns the total amount received by the given address in transactions with at least minconf confirmations.\n",
94 "\nThe amount from transactions with at least 1 confirmation\n"
96 "\nThe amount including unconfirmed transactions, zero confirmations\n"
98 "\nThe amount with at least 6 confirmations\n"
100 "\nThe amount with at least 6 confirmations including immature coinbase outputs\n"
102 "\nAs a JSON-RPC call\n"
112 pwallet->BlockUntilSyncedToCurrentChain();
114 LOCK(pwallet->cs_wallet);
125 "\nReturns the total amount received by addresses with <label> in transactions with at least [minconf] confirmations.\n",
135 "\nAmount received by the default label with at least 1 confirmation\n"
137 "\nAmount received at the tabby label including unconfirmed amounts with zero confirmations\n"
139 "\nThe amount with at least 6 confirmations\n"
141 "\nThe amount with at least 6 confirmations including immature coinbase outputs\n"
143 "\nAs a JSON-RPC call\n"
153 pwallet->BlockUntilSyncedToCurrentChain();
155 LOCK(pwallet->cs_wallet);
166 "\nReturns the total available balance.\n"
167 "The available balance is what the wallet considers currently spendable, and is\n"
168 "thus affected by options which limit spendability such as -spendzeroconfchange.\n",
172 {
"include_watchonly",
RPCArg::Type::BOOL,
RPCArg::DefaultHint{
"true for watch-only wallets, otherwise false"},
"Also include balance in watch-only addresses (see 'importaddress')"},
173 {
"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."},
179 "\nThe total amount in the wallet with 0 or more confirmations\n"
181 "\nThe total amount in the wallet with at least 6 confirmations\n"
183 "\nAs a JSON-RPC call\n"
193 pwallet->BlockUntilSyncedToCurrentChain();
195 LOCK(pwallet->cs_wallet);
197 const auto dummy_value{self.
MaybeArg<std::string>(
"dummy")};
198 if (dummy_value && *dummy_value !=
"*") {
202 const auto min_depth{self.
Arg<
int>(
"minconf")};
208 const auto bal =
GetBalance(*pwallet, min_depth, avoid_reuse);
210 return ValueFromAmount(bal.m_mine_trusted + (include_watchonly ? bal.m_watchonly_trusted : 0));
218 "DEPRECATED\nIdentical to getbalances().mine.untrusted_pending\n",
229 pwallet->BlockUntilSyncedToCurrentChain();
231 LOCK(pwallet->cs_wallet);
241 "\nUpdates list of temporarily unspendable outputs.\n"
242 "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
243 "If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n"
244 "A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.\n"
245 "Manually selected coins are automatically unlocked.\n"
246 "Locks are stored in memory only, unless persistent=true, in which case they will be written to the\n"
247 "wallet database and loaded on node start. Unwritten (persistent=false) locks are always cleared\n"
248 "(by virtue of process exit) when a node stops or fails. Unlocking will clear both persistent and not.\n"
249 "Also see the listunspent call\n",
262 {
"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."},
268 "\nList the unspent transactions\n"
270 "\nLock an unspent transaction\n"
271 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
272 "\nList the locked transactions\n"
274 "\nUnlock the transaction again\n"
275 +
HelpExampleCli(
"lockunspent",
"true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
276 "\nLock the transaction persistently in the wallet database\n"
277 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\" true") +
278 "\nAs a JSON-RPC call\n"
279 +
HelpExampleRpc(
"lockunspent",
"false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
288 pwallet->BlockUntilSyncedToCurrentChain();
290 LOCK(pwallet->cs_wallet);
292 bool fUnlock = request.params[0].get_bool();
294 const bool persistent{request.params[2].isNull() ? false : request.params[2].get_bool()};
296 if (request.params[1].isNull()) {
298 if (!pwallet->UnlockAllCoins())
308 std::vector<COutPoint> outputs;
309 outputs.reserve(output_params.
size());
311 for (
unsigned int idx = 0; idx < output_params.
size(); idx++) {
328 const auto it = pwallet->mapWallet.find(outpt.
hash);
329 if (it == pwallet->mapWallet.end()) {
335 if (outpt.
n >= trans.
tx->vout.size()) {
339 if (pwallet->IsSpent(outpt)) {
343 const bool is_locked = pwallet->IsLockedCoin(outpt);
345 if (fUnlock && !is_locked) {
349 if (!fUnlock && is_locked && !persistent) {
353 outputs.push_back(outpt);
356 std::unique_ptr<WalletBatch> batch =
nullptr;
358 if (fUnlock || persistent) batch = std::make_unique<WalletBatch>(pwallet->GetDatabase());
377 "\nReturns list of temporarily unspendable outputs.\n"
378 "See the lockunspent call to lock and unlock transactions for spending.\n",
391 "\nList the unspent transactions\n"
393 "\nLock an unspent transaction\n"
394 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
395 "\nList the locked transactions\n"
397 "\nUnlock the transaction again\n"
398 +
HelpExampleCli(
"lockunspent",
"true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
399 "\nAs a JSON-RPC call\n"
407 LOCK(pwallet->cs_wallet);
409 std::vector<COutPoint> vOutpts;
410 pwallet->ListLockedCoins(vOutpts);
417 o.
pushKV(
"txid", outpt.hash.GetHex());
418 o.
pushKV(
"vout", (
int)outpt.n);
419 ret.push_back(std::move(o));
431 "Returns an object with all balances in " +
CURRENCY_UNIT +
".\n",
439 {
RPCResult::Type::STR_AMOUNT,
"untrusted_pending",
"untrusted pending balance (outputs created by others that are in the mempool)"},
441 {
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)"},
443 {
RPCResult::Type::OBJ,
"watchonly",
true,
"watchonly balances (not present if wallet does not watch anything)",
446 {
RPCResult::Type::STR_AMOUNT,
"untrusted_pending",
"untrusted pending balance (outputs created by others that are in the mempool)"},
463 wallet.BlockUntilSyncedToCurrentChain();
472 balances_mine.pushKV(
"untrusted_pending",
ValueFromAmount(bal.m_mine_untrusted_pending));
473 balances_mine.pushKV(
"immature",
ValueFromAmount(bal.m_mine_immature));
478 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));
480 balances.pushKV(
"mine", std::move(balances_mine));
482 auto spk_man =
wallet.GetLegacyScriptPubKeyMan();
483 if (spk_man && spk_man->HaveWatchOnly()) {
485 balances_watchonly.pushKV(
"trusted",
ValueFromAmount(bal.m_watchonly_trusted));
486 balances_watchonly.pushKV(
"untrusted_pending",
ValueFromAmount(bal.m_watchonly_untrusted_pending));
487 balances_watchonly.pushKV(
"immature",
ValueFromAmount(bal.m_watchonly_immature));
488 balances.pushKV(
"watchonly", std::move(balances_watchonly));
501 "\nReturns array of unspent transaction outputs\n"
502 "with between minconf and maxconf (inclusive) confirmations.\n"
503 "Optionally filter to only include txouts paid to specified addresses.\n",
513 "See description of \"safe\" attribute below."},
536 {
RPCResult::Type::NUM,
"ancestorcount",
true,
"The number of in-mempool ancestor transactions, including this one (if transaction is in the mempool)"},
537 {
RPCResult::Type::NUM,
"ancestorsize",
true,
"The virtual transaction size of in-mempool ancestors, including this one (if transaction is in the mempool)"},
538 {
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)"},
540 {
RPCResult::Type::STR,
"witnessScript",
true,
"witness script if the output script is P2WSH or P2SH-P2WSH"},
542 {
RPCResult::Type::BOOL,
"solvable",
"Whether we know how to spend this output, ignoring the lack of keys"},
543 {
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)"},
544 {
RPCResult::Type::STR,
"desc",
true,
"(only when solvable) A descriptor for spending this output"},
545 {
RPCResult::Type::ARR,
"parent_descs",
false,
"List of parent descriptors for the output script of this coin.", {
548 {
RPCResult::Type::BOOL,
"safe",
"Whether this output is considered safe to spend. Unconfirmed transactions\n"
549 "from outside keys and unconfirmed replacement transactions are considered unsafe\n"
550 "and are not eligible for spending by fundrawtransaction and sendtoaddress."},
558 +
HelpExampleCli(
"listunspent",
"6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'")
559 +
HelpExampleRpc(
"listunspent",
"6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")
567 if (!request.params[0].isNull()) {
568 nMinDepth = request.params[0].getInt<
int>();
571 int nMaxDepth = 9999999;
572 if (!request.params[1].isNull()) {
573 nMaxDepth = request.params[1].getInt<
int>();
576 std::set<CTxDestination> destinations;
577 if (!request.params[2].isNull()) {
579 for (
unsigned int idx = 0; idx < inputs.
size(); idx++) {
580 const UniValue& input = inputs[idx];
585 if (!destinations.insert(dest).second) {
591 bool include_unsafe =
true;
592 if (!request.params[3].isNull()) {
593 include_unsafe = request.params[3].get_bool();
599 if (!request.params[4].isNull()) {
612 if (options.
exists(
"minimumAmount"))
615 if (options.
exists(
"maximumAmount"))
618 if (options.
exists(
"minimumSumAmount"))
621 if (options.
exists(
"maximumCount"))
624 if (options.
exists(
"include_immature_coinbase")) {
631 pwallet->BlockUntilSyncedToCurrentChain();
634 std::vector<COutput> vecOutputs;
641 LOCK(pwallet->cs_wallet);
645 LOCK(pwallet->cs_wallet);
651 const CScript& scriptPubKey =
out.txout.scriptPubKey;
653 bool reused = avoid_reuse && pwallet->IsSpentKey(scriptPubKey);
655 if (destinations.size() && (!fValidAddress || !destinations.count(address)))
659 entry.
pushKV(
"txid",
out.outpoint.hash.GetHex());
660 entry.
pushKV(
"vout", (
int)
out.outpoint.n);
665 const auto* address_book_entry = pwallet->FindAddressBookEntry(address);
666 if (address_book_entry) {
667 entry.
pushKV(
"label", address_book_entry->GetLabel());
670 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
675 if (provider->GetCScript(hash, redeemScript)) {
686 if (provider->GetCScript(
id, witnessScript)) {
695 if (provider->GetCScript(
id, witnessScript)) {
704 entry.
pushKV(
"confirmations",
out.depth);
706 size_t ancestor_count, descendant_count, ancestor_size;
708 pwallet->chain().getTransactionAncestry(
out.outpoint.hash, ancestor_count, descendant_count, &ancestor_size, &ancestor_fees);
709 if (ancestor_count) {
710 entry.
pushKV(
"ancestorcount", uint64_t(ancestor_count));
711 entry.
pushKV(
"ancestorsize", uint64_t(ancestor_size));
712 entry.
pushKV(
"ancestorfees", uint64_t(ancestor_fees));
715 entry.
pushKV(
"spendable",
out.spendable);
718 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
721 entry.
pushKV(
"desc", descriptor->ToString());
725 if (avoid_reuse) entry.
pushKV(
"reused", reused);
CScriptID ToScriptID(const ScriptHash &script_hash)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
int64_t CAmount
Amount in satoshis (Can be negative)
static CAmount AmountFromValue(const UniValue &value)
#define CHECK_NONFATAL(condition)
Identity function.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
bool IsPayToScriptHash() const
bool IsPayToWitnessScriptHash() const
A reference to a CScript: the Hash160 of its serialization.
An output of a transaction.
auto Arg(std::string_view key) const
Helper to get a required or default-valued request argument.
auto MaybeArg(std::string_view key) const
Helper to get an optional request argument.
void push_back(UniValue val)
const std::string & get_str() const
const UniValue & find_value(std::string_view key) const
const UniValue & get_obj() const
const UniValue & get_array() const
bool exists(const std::string &key) const
void pushKV(std::string key, UniValue val)
iterator insert(iterator pos, const T &value)
static transaction_identifier FromUint256(const uint256 &id)
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
int m_min_depth
Minimum chain depth value for coin availability.
int m_max_depth
Maximum chain depth value for coin availability.
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
UniValue ValueFromAmount(const CAmount amount)
const std::string CURRENCY_ATOM
const std::string CURRENCY_UNIT
uint160 RIPEMD160(Span< const unsigned char > data)
Compute the 160-bit RIPEMD-160 hash of an array.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
std::string EncodeDestination(const CTxDestination &dest)
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
RPCHelpMan listlockunspent()
static const RPCResult RESULT_LAST_PROCESSED_BLOCK
RPCHelpMan getreceivedbyaddress()
void PushParentDescriptors(const CWallet &wallet, const CScript &script_pubkey, UniValue &entry)
Fetch parent descriptors of this scriptPubKey.
std::string LabelFromValue(const UniValue &value)
void AppendLastProcessedBlock(UniValue &entry, const CWallet &wallet)
CoinsResult AvailableCoinsListUnspent(const CWallet &wallet, const CCoinControl *coinControl, CoinFilterParams params)
Wrapper function for AvailableCoins which skips the feerate and CoinFilterParams::only_spendable para...
bool ParseIncludeWatchonly(const UniValue &include_watchonly, const CWallet &wallet)
Used by RPC commands that have an include_watchonly parameter.
RPCHelpMan getreceivedbylabel()
static CAmount GetReceived(const CWallet &wallet, const UniValue ¶ms, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue ¶m)
@ WALLET_FLAG_AVOID_REUSE
RPCHelpMan getunconfirmedbalance()
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_METHOD_DEPRECATED
RPC method is deprecated.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_WALLET_ERROR
Wallet errors.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
@ STR_HEX
Special type that is a STR with only hex chars.
@ AMOUNT
Special type representing a floating point amount (can be either NUM or STR)
@ OBJ_NAMED_PARAMS
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
std::string DefaultHint
Hint for default value.
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
CAmount m_mine_untrusted_pending
Untrusted, but in mempool (pending)
A UTXO under consideration for use in funding a new transaction.
bool include_immature_coinbase
std::vector< COutput > All() const
Concatenate and return all COutputs as one vector.
#define EXCLUSIVE_LOCKS_REQUIRED(...)