21 std::set<CTxDestination> address_set;
26 address_set =
wallet.GetLabelAddresses(label);
34 if (!
wallet.IsMine(script_pub_key)) {
37 address_set.insert(dest);
42 if (!params[1].isNull())
43 min_depth = params[1].get_int();
45 const bool include_immature_coinbase{params[2].isNull() ? false : params[2].get_bool()};
49 const bool include_coinbase{!
wallet.chain().rpcEnableDeprecated(
"exclude_coinbase")};
51 if (include_immature_coinbase && !include_coinbase) {
57 for (
const std::pair<const uint256, CWalletTx>& wtx_pair :
wallet.mapWallet) {
59 int depth{
wallet.GetTxDepthInMainChain(wtx)};
62 || (wtx.
IsCoinBase() && (depth < 1 || !include_coinbase))
63 || (
wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase))
68 for (
const CTxOut& txout : wtx.
tx->vout) {
83 "\nReturns the total amount received by the given address in transactions with at least minconf confirmations.\n",
93 "\nThe amount from transactions with at least 1 confirmation\n"
95 "\nThe amount including unconfirmed transactions, zero confirmations\n"
97 "\nThe amount with at least 6 confirmations\n"
99 "\nThe amount with at least 6 confirmations including immature coinbase outputs\n"
101 "\nAs a JSON-RPC call\n"
111 pwallet->BlockUntilSyncedToCurrentChain();
113 LOCK(pwallet->cs_wallet);
124 "\nReturns the total amount received by addresses with <label> in transactions with at least [minconf] confirmations.\n",
134 "\nAmount received by the default label with at least 1 confirmation\n"
136 "\nAmount received at the tabby label including unconfirmed amounts with zero confirmations\n"
138 "\nThe amount with at least 6 confirmations\n"
140 "\nThe amount with at least 6 confirmations including immature coinbase outputs\n"
142 "\nAs a JSON-RPC call\n"
152 pwallet->BlockUntilSyncedToCurrentChain();
154 LOCK(pwallet->cs_wallet);
165 "\nReturns the total available balance.\n"
166 "The available balance is what the wallet considers currently spendable, and is\n"
167 "thus affected by options which limit spendability such as -spendzeroconfchange.\n",
171 {
"include_watchonly",
RPCArg::Type::BOOL,
RPCArg::DefaultHint{
"true for watch-only wallets, otherwise false"},
"Also include balance in watch-only addresses (see 'importaddress')"},
172 {
"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."},
178 "\nThe total amount in the wallet with 0 or more confirmations\n"
180 "\nThe total amount in the wallet with at least 6 confirmations\n"
182 "\nAs a JSON-RPC call\n"
192 pwallet->BlockUntilSyncedToCurrentChain();
194 LOCK(pwallet->cs_wallet);
196 const UniValue& dummy_value = request.params[0];
202 if (!request.params[1].isNull()) {
203 min_depth = request.params[1].get_int();
210 const auto bal =
GetBalance(*pwallet, min_depth, avoid_reuse);
212 return ValueFromAmount(bal.m_mine_trusted + (include_watchonly ? bal.m_watchonly_trusted : 0));
220 "DEPRECATED\nIdentical to getbalances().mine.untrusted_pending\n",
231 pwallet->BlockUntilSyncedToCurrentChain();
233 LOCK(pwallet->cs_wallet);
243 "\nUpdates list of temporarily unspendable outputs.\n"
244 "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
245 "If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n"
246 "A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.\n"
247 "Manually selected coins are automatically unlocked.\n"
248 "Locks are stored in memory only, unless persistent=true, in which case they will be written to the\n"
249 "wallet database and loaded on node start. Unwritten (persistent=false) locks are always cleared\n"
250 "(by virtue of process exit) when a node stops or fails. Unlocking will clear both persistent and not.\n"
251 "Also see the listunspent call\n",
264 {
"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."},
270 "\nList the unspent transactions\n"
272 "\nLock an unspent transaction\n"
273 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
274 "\nList the locked transactions\n"
276 "\nUnlock the transaction again\n"
277 +
HelpExampleCli(
"lockunspent",
"true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
278 "\nLock the transaction persistently in the wallet database\n"
279 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\" true") +
280 "\nAs a JSON-RPC call\n"
281 +
HelpExampleRpc(
"lockunspent",
"false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
290 pwallet->BlockUntilSyncedToCurrentChain();
292 LOCK(pwallet->cs_wallet);
296 bool fUnlock = request.params[0].get_bool();
298 const bool persistent{request.params[2].isNull() ? false : request.params[2].get_bool()};
300 if (request.params[1].isNull()) {
302 if (!pwallet->UnlockAllCoins())
310 const UniValue& output_params = request.params[1];
314 std::vector<COutPoint> outputs;
315 outputs.reserve(output_params.
size());
317 for (
unsigned int idx = 0; idx < output_params.
size(); idx++) {
334 const auto it = pwallet->mapWallet.find(outpt.
hash);
335 if (it == pwallet->mapWallet.end()) {
341 if (outpt.
n >= trans.
tx->vout.size()) {
345 if (pwallet->IsSpent(outpt.
hash, outpt.
n)) {
349 const bool is_locked = pwallet->IsLockedCoin(outpt.
hash, outpt.
n);
351 if (fUnlock && !is_locked) {
355 if (!fUnlock && is_locked && !persistent) {
359 outputs.push_back(outpt);
362 std::unique_ptr<WalletBatch> batch =
nullptr;
364 if (fUnlock || persistent) batch = std::make_unique<WalletBatch>(pwallet->GetDatabase());
383 "\nReturns list of temporarily unspendable outputs.\n"
384 "See the lockunspent call to lock and unlock transactions for spending.\n",
397 "\nList the unspent transactions\n"
399 "\nLock an unspent transaction\n"
400 +
HelpExampleCli(
"lockunspent",
"false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
401 "\nList the locked transactions\n"
403 "\nUnlock the transaction again\n"
404 +
HelpExampleCli(
"lockunspent",
"true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
405 "\nAs a JSON-RPC call\n"
413 LOCK(pwallet->cs_wallet);
415 std::vector<COutPoint> vOutpts;
416 pwallet->ListLockedCoins(vOutpts);
423 o.
pushKV(
"txid", outpt.hash.GetHex());
424 o.
pushKV(
"vout", (
int)outpt.n);
437 "Returns an object with all balances in " +
CURRENCY_UNIT +
".\n",
445 {
RPCResult::Type::STR_AMOUNT,
"untrusted_pending",
"untrusted pending balance (outputs created by others that are in the mempool)"},
447 {
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)"},
449 {
RPCResult::Type::OBJ,
"watchonly",
true,
"watchonly balances (not present if wallet does not watch anything)",
452 {
RPCResult::Type::STR_AMOUNT,
"untrusted_pending",
"untrusted pending balance (outputs created by others that are in the mempool)"},
468 wallet.BlockUntilSyncedToCurrentChain();
477 balances_mine.pushKV(
"untrusted_pending",
ValueFromAmount(bal.m_mine_untrusted_pending));
478 balances_mine.pushKV(
"immature",
ValueFromAmount(bal.m_mine_immature));
483 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));
485 balances.pushKV(
"mine", balances_mine);
487 auto spk_man =
wallet.GetLegacyScriptPubKeyMan();
488 if (spk_man && spk_man->HaveWatchOnly()) {
490 balances_watchonly.pushKV(
"trusted",
ValueFromAmount(bal.m_watchonly_trusted));
491 balances_watchonly.pushKV(
"untrusted_pending",
ValueFromAmount(bal.m_watchonly_untrusted_pending));
492 balances_watchonly.pushKV(
"immature",
ValueFromAmount(bal.m_watchonly_immature));
493 balances.pushKV(
"watchonly", balances_watchonly);
504 "\nReturns array of unspent transaction outputs\n"
505 "with between minconf and maxconf (inclusive) confirmations.\n"
506 "Optionally filter to only include txouts paid to specified addresses.\n",
516 "See description of \"safe\" attribute below."},
538 {
RPCResult::Type::NUM,
"ancestorcount",
true,
"The number of in-mempool ancestor transactions, including this one (if transaction is in the mempool)"},
539 {
RPCResult::Type::NUM,
"ancestorsize",
true,
"The virtual transaction size of in-mempool ancestors, including this one (if transaction is in the mempool)"},
540 {
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)"},
542 {
RPCResult::Type::STR,
"witnessScript",
true,
"witnessScript if the scriptPubKey is P2WSH or P2SH-P2WSH"},
544 {
RPCResult::Type::BOOL,
"solvable",
"Whether we know how to spend this output, ignoring the lack of keys"},
545 {
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)"},
546 {
RPCResult::Type::STR,
"desc",
true,
"(only when solvable) A descriptor for spending this output"},
547 {
RPCResult::Type::BOOL,
"safe",
"Whether this output is considered safe to spend. Unconfirmed transactions\n"
548 "from outside keys and unconfirmed replacement transactions are considered unsafe\n"
549 "and are not eligible for spending by fundrawtransaction and sendtoaddress."},
557 +
HelpExampleCli(
"listunspent",
"6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'")
558 +
HelpExampleRpc(
"listunspent",
"6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")
566 if (!request.params[0].isNull()) {
568 nMinDepth = request.params[0].get_int();
571 int nMaxDepth = 9999999;
572 if (!request.params[1].isNull()) {
574 nMaxDepth = request.params[1].get_int();
577 std::set<CTxDestination> destinations;
578 if (!request.params[2].isNull()) {
581 for (
unsigned int idx = 0; idx < inputs.
size(); idx++) {
582 const UniValue& input = inputs[idx];
587 if (!destinations.insert(dest).second) {
593 bool include_unsafe =
true;
594 if (!request.params[3].isNull()) {
596 include_unsafe = request.params[3].get_bool();
602 uint64_t nMaximumCount = 0;
604 if (!request.params[4].isNull()) {
616 if (options.
exists(
"minimumAmount"))
619 if (options.
exists(
"maximumAmount"))
622 if (options.
exists(
"minimumSumAmount"))
625 if (options.
exists(
"maximumCount"))
626 nMaximumCount = options[
"maximumCount"].get_int64();
631 pwallet->BlockUntilSyncedToCurrentChain();
634 std::vector<COutput> vecOutputs;
641 LOCK(pwallet->cs_wallet);
642 AvailableCoins(*pwallet, vecOutputs, &cctl, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount);
645 LOCK(pwallet->cs_wallet);
649 for (
const COutput& out : vecOutputs) {
651 const CScript& scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey;
653 bool reused = avoid_reuse && pwallet->IsSpentKey(out.tx->GetHash(), out.i);
655 if (destinations.size() && (!fValidAddress || !destinations.count(address)))
659 entry.
pushKV(
"txid", out.tx->GetHash().GetHex());
660 entry.
pushKV(
"vout", out.i);
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)) {
687 if (provider->GetCScript(
id, witnessScript)) {
697 if (provider->GetCScript(
id, witnessScript)) {
706 entry.
pushKV(
"confirmations", out.nDepth);
708 size_t ancestor_count, descendant_count, ancestor_size;
710 pwallet->chain().getTransactionAncestry(out.tx->GetHash(), ancestor_count, descendant_count, &ancestor_size, &ancestor_fees);
711 if (ancestor_count) {
712 entry.
pushKV(
"ancestorcount", uint64_t(ancestor_count));
713 entry.
pushKV(
"ancestorsize", uint64_t(ancestor_size));
714 entry.
pushKV(
"ancestorfees", uint64_t(ancestor_fees));
717 entry.
pushKV(
"spendable", out.fSpendable);
718 entry.
pushKV(
"solvable", out.fSolvable);
720 std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
723 entry.
pushKV(
"desc", descriptor->ToString());
726 if (avoid_reuse) entry.
pushKV(
"reused", reused);
727 entry.
pushKV(
"safe", out.fSafe);