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 auto& [
_, wtx] :
wallet.mapWallet) {
60 int depth{
wallet.GetTxDepthInMainChain(wtx)};
63 || (wtx.IsCoinBase() && (depth < 1))
64 || (
wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase))
69 for (
const CTxOut& txout : wtx.tx->vout) {
83 "getreceivedbyaddress",
84 "Returns 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 "getreceivedbylabel",
126 "Returns the total amount received by addresses with <label> in transactions with at least [minconf] confirmations.\n",
136 "\nAmount received by the default label with at least 1 confirmation\n" 138 "\nAmount received at the tabby label including unconfirmed amounts with zero confirmations\n" 140 "\nThe amount with at least 6 confirmations\n" 142 "\nThe amount with at least 6 confirmations including immature coinbase outputs\n" 144 "\nAs a JSON-RPC call\n" 154 pwallet->BlockUntilSyncedToCurrentChain();
156 LOCK(pwallet->cs_wallet);
168 "Returns the total available balance.\n" 169 "The available balance is what the wallet considers currently spendable, and is\n" 170 "thus affected by options which limit spendability such as -spendzeroconfchange.\n",
175 {
"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."},
181 "\nThe total amount in the wallet with 0 or more confirmations\n" 183 "\nThe total amount in the wallet with at least 6 confirmations\n" 185 "\nAs a JSON-RPC call\n" 195 pwallet->BlockUntilSyncedToCurrentChain();
197 LOCK(pwallet->cs_wallet);
199 if (
self.MaybeArg<std::string_view>(
"dummy").value_or(
"*") !=
"*") {
203 const auto min_depth{
self.Arg<
int>(
"minconf")};
207 const auto bal =
GetBalance(*pwallet, min_depth, avoid_reuse);
218 "Updates list of temporarily unspendable outputs.\n" 219 "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n" 220 "If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n" 221 "A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.\n" 222 "Manually selected coins are automatically unlocked.\n" 223 "Locks are stored in memory only, unless persistent=true, in which case they will be written to the\n" 224 "wallet database and loaded on node start. Unwritten (persistent=false) locks are always cleared\n" 225 "(by virtue of process exit) when a node stops or fails. Unlocking will clear both persistent and not.\n" 226 "Also see the listunspent call\n",
239 {
"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."},
245 "\nList the unspent transactions\n" 247 "\nLock an unspent transaction\n" 248 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
249 "\nList the locked transactions\n" 251 "\nUnlock the transaction again\n" 252 +
HelpExampleCli(
"lockunspent",
"true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
253 "\nLock the transaction persistently in the wallet database\n" 254 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\" true") +
255 "\nAs a JSON-RPC call\n" 256 +
HelpExampleRpc(
"lockunspent",
"false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
265 pwallet->BlockUntilSyncedToCurrentChain();
267 LOCK(pwallet->cs_wallet);
269 bool fUnlock = request.params[0].get_bool();
271 const bool persistent{request.params[2].isNull() ? false : request.params[2].get_bool()};
273 if (request.params[1].isNull()) {
275 if (!pwallet->UnlockAllCoins())
285 std::vector<COutPoint> outputs;
288 for (
unsigned int idx = 0; idx < output_params.
size(); idx++) {
305 const auto it = pwallet->mapWallet.find(outpt.
hash);
306 if (it == pwallet->mapWallet.end()) {
312 if (outpt.
n >= trans.
tx->vout.size()) {
316 if (pwallet->IsSpent(outpt)) {
320 const bool is_locked = pwallet->IsLockedCoin(outpt);
322 if (fUnlock && !is_locked) {
326 if (!fUnlock && is_locked && !persistent) {
330 outputs.push_back(outpt);
351 "Returns list of temporarily unspendable outputs.\n" 352 "See the lockunspent call to lock and unlock transactions for spending.\n",
365 "\nList the unspent transactions\n" 367 "\nLock an unspent transaction\n" 368 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
369 "\nList the locked transactions\n" 371 "\nUnlock the transaction again\n" 372 +
HelpExampleCli(
"lockunspent",
"true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
373 "\nAs a JSON-RPC call\n" 381 LOCK(pwallet->cs_wallet);
383 std::vector<COutPoint> vOutpts;
384 pwallet->ListLockedCoins(vOutpts);
391 o.
pushKV(
"txid", outpt.hash.GetHex());
392 o.
pushKV(
"vout", outpt.n);
393 ret.push_back(std::move(o));
405 "Returns an object with all balances in " +
CURRENCY_UNIT +
".\n",
413 {
RPCResult::Type::STR_AMOUNT,
"untrusted_pending",
"untrusted pending balance (outputs created by others that are in the mempool)"},
415 {
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)"},
431 wallet.BlockUntilSyncedToCurrentChain();
440 balances_mine.pushKV(
"untrusted_pending",
ValueFromAmount(bal.m_mine_untrusted_pending));
441 balances_mine.pushKV(
"immature",
ValueFromAmount(bal.m_mine_immature));
446 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));
448 balances.pushKV(
"mine", std::move(balances_mine));
460 "Returns array of unspent transaction outputs\n" 461 "with between minconf and maxconf (inclusive) confirmations.\n" 462 "Optionally filter to only include txouts paid to specified addresses.\n",
472 "See description of \"safe\" attribute below."},
495 {
RPCResult::Type::NUM,
"ancestorcount",
true,
"The number of in-mempool ancestor transactions, including this one (if transaction is in the mempool)"},
496 {
RPCResult::Type::NUM,
"ancestorsize",
true,
"The virtual transaction size of in-mempool ancestors, including this one (if transaction is in the mempool)"},
497 {
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)"},
499 {
RPCResult::Type::STR,
"witnessScript",
true,
"witness script if the output script is P2WSH or P2SH-P2WSH"},
501 {
RPCResult::Type::BOOL,
"solvable",
"Whether we know how to spend this output, ignoring the lack of keys"},
502 {
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)"},
503 {
RPCResult::Type::STR,
"desc",
true,
"(only when solvable) A descriptor for spending this output"},
504 {
RPCResult::Type::ARR,
"parent_descs",
false,
"List of parent descriptors for the output script of this coin.", {
507 {
RPCResult::Type::BOOL,
"safe",
"Whether this output is considered safe to spend. Unconfirmed transactions\n" 508 "from outside keys and unconfirmed replacement transactions are considered unsafe\n" 509 "and are not eligible for spending by fundrawtransaction and sendtoaddress."},
517 +
HelpExampleCli(
"listunspent",
"6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'")
518 +
HelpExampleRpc(
"listunspent",
"6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")
526 if (!request.params[0].isNull()) {
527 nMinDepth = request.params[0].getInt<
int>();
530 int nMaxDepth = 9999999;
531 if (!request.params[1].isNull()) {
532 nMaxDepth = request.params[1].getInt<
int>();
535 std::set<CTxDestination> destinations;
536 if (!request.params[2].isNull()) {
538 for (
unsigned int idx = 0; idx < inputs.
size(); idx++) {
539 const UniValue& input = inputs[idx];
544 if (!destinations.insert(dest).second) {
550 bool include_unsafe =
true;
551 if (!request.params[3].isNull()) {
552 include_unsafe = request.params[3].
get_bool();
558 if (!request.params[4].isNull()) {
571 if (options.
exists(
"minimumAmount"))
574 if (options.
exists(
"maximumAmount"))
577 if (options.
exists(
"minimumSumAmount"))
580 if (options.
exists(
"maximumCount"))
583 if (options.
exists(
"include_immature_coinbase")) {
590 pwallet->BlockUntilSyncedToCurrentChain();
593 std::vector<COutput> vecOutputs;
601 LOCK(pwallet->cs_wallet);
605 LOCK(pwallet->cs_wallet);
611 const CScript& scriptPubKey =
out.txout.scriptPubKey;
613 bool reused = avoid_reuse && pwallet->IsSpentKey(scriptPubKey);
615 if (destinations.size() && (!fValidAddress || !destinations.contains(address)))
619 entry.
pushKV(
"txid",
out.outpoint.hash.GetHex());
625 const auto* address_book_entry = pwallet->FindAddressBookEntry(address);
626 if (address_book_entry) {
627 entry.
pushKV(
"label", address_book_entry->GetLabel());
630 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
635 if (provider->GetCScript(hash, redeemScript)) {
646 if (provider->GetCScript(
id, witnessScript)) {
655 if (provider->GetCScript(
id, witnessScript)) {
664 entry.
pushKV(
"confirmations",
out.depth);
666 size_t ancestor_count, unused_cluster_count, ancestor_size;
668 pwallet->chain().getTransactionAncestry(
out.outpoint.hash, ancestor_count, unused_cluster_count, &ancestor_size, &ancestor_fees);
669 if (ancestor_count) {
670 entry.
pushKV(
"ancestorcount", ancestor_count);
671 entry.
pushKV(
"ancestorsize", ancestor_size);
672 entry.
pushKV(
"ancestorfees", ancestor_fees);
675 entry.
pushKV(
"spendable",
true);
678 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
681 entry.
pushKV(
"desc", descriptor->ToString());
685 if (avoid_reuse) entry.
pushKV(
"reused", reused);
void push_back(UniValue val)
RPCHelpMan listlockunspent()
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
UniValue ValueFromAmount(const CAmount amount)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
iterator insert(iterator pos, const T &value)
std::vector< COutput > All() const
Concatenate and return all COutputs as one vector.
uint160 RIPEMD160(std::span< const unsigned char > data)
Compute the 160-bit RIPEMD-160 hash of an array.
bool IsPayToScriptHash() const
RPCHelpMan getreceivedbylabel()
bool check_version_trucness
#define CHECK_NONFATAL(condition)
Identity function.
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
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)
static const RPCResult RESULT_LAST_PROCESSED_BLOCK
consteval auto _(util::TranslatedLiteral str)
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
void reserve(size_t new_cap)
Invalid, missing or duplicate parameter.
int64_t CAmount
Amount in satoshis (Can be negative)
const UniValue & find_value(std::string_view key) const
A transaction with a bunch of additional info that only the owner cares about.
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
bool include_immature_coinbase
Special type that is a STR with only hex chars.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
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)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
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::string DefaultHint
Hint for default value.
An output of a transaction.
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)
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
RPC method is deprecated.
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Optional argument for which the default value is omitted from help text for one of two reasons: ...
#define EXCLUSIVE_LOCKS_REQUIRED(...)
int m_min_depth
Minimum chain depth value for coin availability.
Special string to represent a floating point amount.
void pushKV(std::string key, UniValue val)
Serialized script, used inside transaction inputs and outputs.
static transaction_identifier FromUint256(const uint256 &id)
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)
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Special type representing a floating point amount (can be either NUM or STR)
CoinsResult AvailableCoins(const CWallet &wallet, const CCoinControl *coinControl, std::optional< CFeeRate > feerate, const CoinFilterParams ¶ms)
Populate the CoinsResult struct with vectors of available COutputs, organized by OutputType.
bool GetAvoidReuseFlag(const CWallet &wallet, const UniValue ¶m)
CScriptID ToScriptID(const ScriptHash &script_hash)
A reference to a CScript: the Hash160 of its serialization.
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.
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
void AppendLastProcessedBlock(UniValue &entry, const CWallet &wallet)
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
bool IsPayToWitnessScriptHash() const