Bitcoin Core  26.1.0
P2P Digital Currency
transactions.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <core_io.h>
6 #include <key_io.h>
7 #include <policy/rbf.h>
8 #include <rpc/util.h>
9 #include <util/vector.h>
10 #include <wallet/receive.h>
11 #include <wallet/rpc/util.h>
12 #include <wallet/wallet.h>
13 
15 
16 namespace wallet {
17 static void WalletTxToJSON(const CWallet& wallet, const CWalletTx& wtx, UniValue& entry)
19 {
20  interfaces::Chain& chain = wallet.chain();
21  int confirms = wallet.GetTxDepthInMainChain(wtx);
22  entry.pushKV("confirmations", confirms);
23  if (wtx.IsCoinBase())
24  entry.pushKV("generated", true);
25  if (auto* conf = wtx.state<TxStateConfirmed>())
26  {
27  entry.pushKV("blockhash", conf->confirmed_block_hash.GetHex());
28  entry.pushKV("blockheight", conf->confirmed_block_height);
29  entry.pushKV("blockindex", conf->position_in_block);
30  int64_t block_time;
31  CHECK_NONFATAL(chain.findBlock(conf->confirmed_block_hash, FoundBlock().time(block_time)));
32  entry.pushKV("blocktime", block_time);
33  } else {
34  entry.pushKV("trusted", CachedTxIsTrusted(wallet, wtx));
35  }
36  uint256 hash = wtx.GetHash();
37  entry.pushKV("txid", hash.GetHex());
38  entry.pushKV("wtxid", wtx.GetWitnessHash().GetHex());
39  UniValue conflicts(UniValue::VARR);
40  for (const uint256& conflict : wallet.GetTxConflicts(wtx))
41  conflicts.push_back(conflict.GetHex());
42  entry.pushKV("walletconflicts", conflicts);
43  entry.pushKV("time", wtx.GetTxTime());
44  entry.pushKV("timereceived", int64_t{wtx.nTimeReceived});
45 
46  // Add opt-in RBF status
47  std::string rbfStatus = "no";
48  if (confirms <= 0) {
49  RBFTransactionState rbfState = chain.isRBFOptIn(*wtx.tx);
50  if (rbfState == RBFTransactionState::UNKNOWN)
51  rbfStatus = "unknown";
52  else if (rbfState == RBFTransactionState::REPLACEABLE_BIP125)
53  rbfStatus = "yes";
54  }
55  entry.pushKV("bip125-replaceable", rbfStatus);
56 
57  for (const std::pair<const std::string, std::string>& item : wtx.mapValue)
58  entry.pushKV(item.first, item.second);
59 }
60 
61 struct tallyitem
62 {
64  int nConf{std::numeric_limits<int>::max()};
65  std::vector<uint256> txids;
66  bool fIsWatchonly{false};
67  tallyitem() = default;
68 };
69 
70 static UniValue ListReceived(const CWallet& wallet, const UniValue& params, const bool by_label, const bool include_immature_coinbase) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
71 {
72  // Minimum confirmations
73  int nMinDepth = 1;
74  if (!params[0].isNull())
75  nMinDepth = params[0].getInt<int>();
76 
77  // Whether to include empty labels
78  bool fIncludeEmpty = false;
79  if (!params[1].isNull())
80  fIncludeEmpty = params[1].get_bool();
81 
83 
84  if (ParseIncludeWatchonly(params[2], wallet)) {
85  filter |= ISMINE_WATCH_ONLY;
86  }
87 
88  std::optional<CTxDestination> filtered_address{std::nullopt};
89  if (!by_label && !params[3].isNull() && !params[3].get_str().empty()) {
90  if (!IsValidDestinationString(params[3].get_str())) {
91  throw JSONRPCError(RPC_WALLET_ERROR, "address_filter parameter was invalid");
92  }
93  filtered_address = DecodeDestination(params[3].get_str());
94  }
95 
96  // Tally
97  std::map<CTxDestination, tallyitem> mapTally;
98  for (const std::pair<const uint256, CWalletTx>& pairWtx : wallet.mapWallet) {
99  const CWalletTx& wtx = pairWtx.second;
100 
101  int nDepth = wallet.GetTxDepthInMainChain(wtx);
102  if (nDepth < nMinDepth)
103  continue;
104 
105  // Coinbase with less than 1 confirmation is no longer in the main chain
106  if ((wtx.IsCoinBase() && (nDepth < 1))
107  || (wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase)) {
108  continue;
109  }
110 
111  for (const CTxOut& txout : wtx.tx->vout) {
112  CTxDestination address;
113  if (!ExtractDestination(txout.scriptPubKey, address))
114  continue;
115 
116  if (filtered_address && !(filtered_address == address)) {
117  continue;
118  }
119 
120  isminefilter mine = wallet.IsMine(address);
121  if (!(mine & filter))
122  continue;
123 
124  tallyitem& item = mapTally[address];
125  item.nAmount += txout.nValue;
126  item.nConf = std::min(item.nConf, nDepth);
127  item.txids.push_back(wtx.GetHash());
128  if (mine & ISMINE_WATCH_ONLY)
129  item.fIsWatchonly = true;
130  }
131  }
132 
133  // Reply
135  std::map<std::string, tallyitem> label_tally;
136 
137  const auto& func = [&](const CTxDestination& address, const std::string& label, bool is_change, const std::optional<AddressPurpose>& purpose) {
138  if (is_change) return; // no change addresses
139 
140  auto it = mapTally.find(address);
141  if (it == mapTally.end() && !fIncludeEmpty)
142  return;
143 
144  CAmount nAmount = 0;
145  int nConf = std::numeric_limits<int>::max();
146  bool fIsWatchonly = false;
147  if (it != mapTally.end()) {
148  nAmount = (*it).second.nAmount;
149  nConf = (*it).second.nConf;
150  fIsWatchonly = (*it).second.fIsWatchonly;
151  }
152 
153  if (by_label) {
154  tallyitem& _item = label_tally[label];
155  _item.nAmount += nAmount;
156  _item.nConf = std::min(_item.nConf, nConf);
157  _item.fIsWatchonly = fIsWatchonly;
158  } else {
160  if (fIsWatchonly) obj.pushKV("involvesWatchonly", true);
161  obj.pushKV("address", EncodeDestination(address));
162  obj.pushKV("amount", ValueFromAmount(nAmount));
163  obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
164  obj.pushKV("label", label);
165  UniValue transactions(UniValue::VARR);
166  if (it != mapTally.end()) {
167  for (const uint256& _item : (*it).second.txids) {
168  transactions.push_back(_item.GetHex());
169  }
170  }
171  obj.pushKV("txids", transactions);
172  ret.push_back(obj);
173  }
174  };
175 
176  if (filtered_address) {
177  const auto& entry = wallet.FindAddressBookEntry(*filtered_address, /*allow_change=*/false);
178  if (entry) func(*filtered_address, entry->GetLabel(), entry->IsChange(), entry->purpose);
179  } else {
180  // No filtered addr, walk-through the addressbook entry
181  wallet.ForEachAddrBookEntry(func);
182  }
183 
184  if (by_label) {
185  for (const auto& entry : label_tally) {
186  CAmount nAmount = entry.second.nAmount;
187  int nConf = entry.second.nConf;
189  if (entry.second.fIsWatchonly)
190  obj.pushKV("involvesWatchonly", true);
191  obj.pushKV("amount", ValueFromAmount(nAmount));
192  obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
193  obj.pushKV("label", entry.first);
194  ret.push_back(obj);
195  }
196  }
197 
198  return ret;
199 }
200 
202 {
203  return RPCHelpMan{"listreceivedbyaddress",
204  "\nList balances by receiving address.\n",
205  {
206  {"minconf", RPCArg::Type::NUM, RPCArg::Default{1}, "The minimum number of confirmations before payments are included."},
207  {"include_empty", RPCArg::Type::BOOL, RPCArg::Default{false}, "Whether to include addresses that haven't received any payments."},
208  {"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Whether to include watch-only addresses (see 'importaddress')"},
209  {"address_filter", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "If present and non-empty, only return information on this address."},
210  {"include_immature_coinbase", RPCArg::Type::BOOL, RPCArg::Default{false}, "Include immature coinbase transactions."},
211  },
212  RPCResult{
213  RPCResult::Type::ARR, "", "",
214  {
215  {RPCResult::Type::OBJ, "", "",
216  {
217  {RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction"},
218  {RPCResult::Type::STR, "address", "The receiving address"},
219  {RPCResult::Type::STR_AMOUNT, "amount", "The total amount in " + CURRENCY_UNIT + " received by the address"},
220  {RPCResult::Type::NUM, "confirmations", "The number of confirmations of the most recent transaction included"},
221  {RPCResult::Type::STR, "label", "The label of the receiving address. The default label is \"\""},
222  {RPCResult::Type::ARR, "txids", "",
223  {
224  {RPCResult::Type::STR_HEX, "txid", "The ids of transactions received with the address"},
225  }},
226  }},
227  }
228  },
229  RPCExamples{
230  HelpExampleCli("listreceivedbyaddress", "")
231  + HelpExampleCli("listreceivedbyaddress", "6 true")
232  + HelpExampleCli("listreceivedbyaddress", "6 true true \"\" true")
233  + HelpExampleRpc("listreceivedbyaddress", "6, true, true")
234  + HelpExampleRpc("listreceivedbyaddress", "6, true, true, \"" + EXAMPLE_ADDRESS[0] + "\", true")
235  },
236  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
237 {
238  const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
239  if (!pwallet) return UniValue::VNULL;
240 
241  // Make sure the results are valid at least up to the most recent block
242  // the user could have gotten from another RPC command prior to now
243  pwallet->BlockUntilSyncedToCurrentChain();
244 
245  const bool include_immature_coinbase{request.params[4].isNull() ? false : request.params[4].get_bool()};
246 
247  LOCK(pwallet->cs_wallet);
248 
249  return ListReceived(*pwallet, request.params, false, include_immature_coinbase);
250 },
251  };
252 }
253 
255 {
256  return RPCHelpMan{"listreceivedbylabel",
257  "\nList received transactions by label.\n",
258  {
259  {"minconf", RPCArg::Type::NUM, RPCArg::Default{1}, "The minimum number of confirmations before payments are included."},
260  {"include_empty", RPCArg::Type::BOOL, RPCArg::Default{false}, "Whether to include labels that haven't received any payments."},
261  {"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Whether to include watch-only addresses (see 'importaddress')"},
262  {"include_immature_coinbase", RPCArg::Type::BOOL, RPCArg::Default{false}, "Include immature coinbase transactions."},
263  },
264  RPCResult{
265  RPCResult::Type::ARR, "", "",
266  {
267  {RPCResult::Type::OBJ, "", "",
268  {
269  {RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction"},
270  {RPCResult::Type::STR_AMOUNT, "amount", "The total amount received by addresses with this label"},
271  {RPCResult::Type::NUM, "confirmations", "The number of confirmations of the most recent transaction included"},
272  {RPCResult::Type::STR, "label", "The label of the receiving address. The default label is \"\""},
273  }},
274  }
275  },
276  RPCExamples{
277  HelpExampleCli("listreceivedbylabel", "")
278  + HelpExampleCli("listreceivedbylabel", "6 true")
279  + HelpExampleRpc("listreceivedbylabel", "6, true, true, true")
280  },
281  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
282 {
283  const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
284  if (!pwallet) return UniValue::VNULL;
285 
286  // Make sure the results are valid at least up to the most recent block
287  // the user could have gotten from another RPC command prior to now
288  pwallet->BlockUntilSyncedToCurrentChain();
289 
290  const bool include_immature_coinbase{request.params[3].isNull() ? false : request.params[3].get_bool()};
291 
292  LOCK(pwallet->cs_wallet);
293 
294  return ListReceived(*pwallet, request.params, true, include_immature_coinbase);
295 },
296  };
297 }
298 
299 static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
300 {
301  if (IsValidDestination(dest)) {
302  entry.pushKV("address", EncodeDestination(dest));
303  }
304 }
305 
317 template <class Vec>
318 static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nMinDepth, bool fLong,
319  Vec& ret, const isminefilter& filter_ismine, const std::optional<std::string>& filter_label,
320  bool include_change = false)
322 {
323  CAmount nFee;
324  std::list<COutputEntry> listReceived;
325  std::list<COutputEntry> listSent;
326 
327  CachedTxGetAmounts(wallet, wtx, listReceived, listSent, nFee, filter_ismine, include_change);
328 
329  bool involvesWatchonly = CachedTxIsFromMe(wallet, wtx, ISMINE_WATCH_ONLY);
330 
331  // Sent
332  if (!filter_label.has_value())
333  {
334  for (const COutputEntry& s : listSent)
335  {
336  UniValue entry(UniValue::VOBJ);
337  if (involvesWatchonly || (wallet.IsMine(s.destination) & ISMINE_WATCH_ONLY)) {
338  entry.pushKV("involvesWatchonly", true);
339  }
340  MaybePushAddress(entry, s.destination);
341  entry.pushKV("category", "send");
342  entry.pushKV("amount", ValueFromAmount(-s.amount));
343  const auto* address_book_entry = wallet.FindAddressBookEntry(s.destination);
344  if (address_book_entry) {
345  entry.pushKV("label", address_book_entry->GetLabel());
346  }
347  entry.pushKV("vout", s.vout);
348  entry.pushKV("fee", ValueFromAmount(-nFee));
349  if (fLong)
350  WalletTxToJSON(wallet, wtx, entry);
351  entry.pushKV("abandoned", wtx.isAbandoned());
352  ret.push_back(entry);
353  }
354  }
355 
356  // Received
357  if (listReceived.size() > 0 && wallet.GetTxDepthInMainChain(wtx) >= nMinDepth) {
358  for (const COutputEntry& r : listReceived)
359  {
360  std::string label;
361  const auto* address_book_entry = wallet.FindAddressBookEntry(r.destination);
362  if (address_book_entry) {
363  label = address_book_entry->GetLabel();
364  }
365  if (filter_label.has_value() && label != filter_label.value()) {
366  continue;
367  }
368  UniValue entry(UniValue::VOBJ);
369  if (involvesWatchonly || (wallet.IsMine(r.destination) & ISMINE_WATCH_ONLY)) {
370  entry.pushKV("involvesWatchonly", true);
371  }
372  MaybePushAddress(entry, r.destination);
373  PushParentDescriptors(wallet, wtx.tx->vout.at(r.vout).scriptPubKey, entry);
374  if (wtx.IsCoinBase())
375  {
376  if (wallet.GetTxDepthInMainChain(wtx) < 1)
377  entry.pushKV("category", "orphan");
378  else if (wallet.IsTxImmatureCoinBase(wtx))
379  entry.pushKV("category", "immature");
380  else
381  entry.pushKV("category", "generate");
382  }
383  else
384  {
385  entry.pushKV("category", "receive");
386  }
387  entry.pushKV("amount", ValueFromAmount(r.amount));
388  if (address_book_entry) {
389  entry.pushKV("label", label);
390  }
391  entry.pushKV("vout", r.vout);
392  entry.pushKV("abandoned", wtx.isAbandoned());
393  if (fLong)
394  WalletTxToJSON(wallet, wtx, entry);
395  ret.push_back(entry);
396  }
397  }
398 }
399 
400 
401 static std::vector<RPCResult> TransactionDescriptionString()
402 {
403  return{{RPCResult::Type::NUM, "confirmations", "The number of confirmations for the transaction. Negative confirmations means the\n"
404  "transaction conflicted that many blocks ago."},
405  {RPCResult::Type::BOOL, "generated", /*optional=*/true, "Only present if the transaction's only input is a coinbase one."},
406  {RPCResult::Type::BOOL, "trusted", /*optional=*/true, "Whether we consider the transaction to be trusted and safe to spend from.\n"
407  "Only present when the transaction has 0 confirmations (or negative confirmations, if conflicted)."},
408  {RPCResult::Type::STR_HEX, "blockhash", /*optional=*/true, "The block hash containing the transaction."},
409  {RPCResult::Type::NUM, "blockheight", /*optional=*/true, "The block height containing the transaction."},
410  {RPCResult::Type::NUM, "blockindex", /*optional=*/true, "The index of the transaction in the block that includes it."},
411  {RPCResult::Type::NUM_TIME, "blocktime", /*optional=*/true, "The block time expressed in " + UNIX_EPOCH_TIME + "."},
412  {RPCResult::Type::STR_HEX, "txid", "The transaction id."},
413  {RPCResult::Type::STR_HEX, "wtxid", "The hash of serialized transaction, including witness data."},
414  {RPCResult::Type::ARR, "walletconflicts", "Conflicting transaction ids.",
415  {
416  {RPCResult::Type::STR_HEX, "txid", "The transaction id."},
417  }},
418  {RPCResult::Type::STR_HEX, "replaced_by_txid", /*optional=*/true, "The txid if this tx was replaced."},
419  {RPCResult::Type::STR_HEX, "replaces_txid", /*optional=*/true, "The txid if the tx replaces one."},
420  {RPCResult::Type::STR, "to", /*optional=*/true, "If a comment to is associated with the transaction."},
421  {RPCResult::Type::NUM_TIME, "time", "The transaction time expressed in " + UNIX_EPOCH_TIME + "."},
422  {RPCResult::Type::NUM_TIME, "timereceived", "The time received expressed in " + UNIX_EPOCH_TIME + "."},
423  {RPCResult::Type::STR, "comment", /*optional=*/true, "If a comment is associated with the transaction, only present if not empty."},
424  {RPCResult::Type::STR, "bip125-replaceable", "(\"yes|no|unknown\") Whether this transaction signals BIP125 replaceability or has an unconfirmed ancestor signaling BIP125 replaceability.\n"
425  "May be unknown for unconfirmed transactions not in the mempool because their unconfirmed ancestors are unknown."},
426  {RPCResult::Type::ARR, "parent_descs", /*optional=*/true, "Only if 'category' is 'received'. List of parent descriptors for the scriptPubKey of this coin.", {
427  {RPCResult::Type::STR, "desc", "The descriptor string."},
428  }},
429  };
430 }
431 
433 {
434  return RPCHelpMan{"listtransactions",
435  "\nIf a label name is provided, this will return only incoming transactions paying to addresses with the specified label.\n"
436  "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions.\n",
437  {
438  {"label|dummy", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "If set, should be a valid label name to return only incoming transactions\n"
439  "with the specified label, or \"*\" to disable filtering and return all transactions."},
440  {"count", RPCArg::Type::NUM, RPCArg::Default{10}, "The number of transactions to return"},
441  {"skip", RPCArg::Type::NUM, RPCArg::Default{0}, "The number of transactions to skip"},
442  {"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Include transactions to watch-only addresses (see 'importaddress')"},
443  },
444  RPCResult{
445  RPCResult::Type::ARR, "", "",
446  {
447  {RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
448  {
449  {RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction."},
450  {RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address of the transaction (not returned if the output does not have an address, e.g. OP_RETURN null data)."},
451  {RPCResult::Type::STR, "category", "The transaction category.\n"
452  "\"send\" Transactions sent.\n"
453  "\"receive\" Non-coinbase transactions received.\n"
454  "\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
455  "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
456  "\"orphan\" Orphaned coinbase transactions received."},
457  {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n"
458  "for all other categories"},
459  {RPCResult::Type::STR, "label", /*optional=*/true, "A comment for the address/transaction, if any"},
460  {RPCResult::Type::NUM, "vout", "the vout value"},
461  {RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the\n"
462  "'send' category of transactions."},
463  },
465  {
466  {RPCResult::Type::BOOL, "abandoned", "'true' if the transaction has been abandoned (inputs are respendable)."},
467  })},
468  }
469  },
470  RPCExamples{
471  "\nList the most recent 10 transactions in the systems\n"
472  + HelpExampleCli("listtransactions", "") +
473  "\nList transactions 100 to 120\n"
474  + HelpExampleCli("listtransactions", "\"*\" 20 100") +
475  "\nAs a JSON-RPC call\n"
476  + HelpExampleRpc("listtransactions", "\"*\", 20, 100")
477  },
478  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
479 {
480  const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
481  if (!pwallet) return UniValue::VNULL;
482 
483  // Make sure the results are valid at least up to the most recent block
484  // the user could have gotten from another RPC command prior to now
485  pwallet->BlockUntilSyncedToCurrentChain();
486 
487  std::optional<std::string> filter_label;
488  if (!request.params[0].isNull() && request.params[0].get_str() != "*") {
489  filter_label.emplace(LabelFromValue(request.params[0]));
490  if (filter_label.value().empty()) {
491  throw JSONRPCError(RPC_INVALID_PARAMETER, "Label argument must be a valid label name or \"*\".");
492  }
493  }
494  int nCount = 10;
495  if (!request.params[1].isNull())
496  nCount = request.params[1].getInt<int>();
497  int nFrom = 0;
498  if (!request.params[2].isNull())
499  nFrom = request.params[2].getInt<int>();
501 
502  if (ParseIncludeWatchonly(request.params[3], *pwallet)) {
503  filter |= ISMINE_WATCH_ONLY;
504  }
505 
506  if (nCount < 0)
507  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
508  if (nFrom < 0)
509  throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
510 
511  std::vector<UniValue> ret;
512  {
513  LOCK(pwallet->cs_wallet);
514 
515  const CWallet::TxItems & txOrdered = pwallet->wtxOrdered;
516 
517  // iterate backwards until we have nCount items to return:
518  for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
519  {
520  CWalletTx *const pwtx = (*it).second;
521  ListTransactions(*pwallet, *pwtx, 0, true, ret, filter, filter_label);
522  if ((int)ret.size() >= (nCount+nFrom)) break;
523  }
524  }
525 
526  // ret is newest to oldest
527 
528  if (nFrom > (int)ret.size())
529  nFrom = ret.size();
530  if ((nFrom + nCount) > (int)ret.size())
531  nCount = ret.size() - nFrom;
532 
533  auto txs_rev_it{std::make_move_iterator(ret.rend())};
534  UniValue result{UniValue::VARR};
535  result.push_backV(txs_rev_it - nFrom - nCount, txs_rev_it - nFrom); // Return oldest to newest
536  return result;
537 },
538  };
539 }
540 
542 {
543  return RPCHelpMan{"listsinceblock",
544  "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted.\n"
545  "If \"blockhash\" is no longer a part of the main chain, transactions from the fork point onward are included.\n"
546  "Additionally, if include_removed is set, transactions affecting the wallet which were removed are returned in the \"removed\" array.\n",
547  {
548  {"blockhash", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "If set, the block hash to list transactions since, otherwise list all transactions."},
549  {"target_confirmations", RPCArg::Type::NUM, RPCArg::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"},
550  {"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Include transactions to watch-only addresses (see 'importaddress')"},
551  {"include_removed", RPCArg::Type::BOOL, RPCArg::Default{true}, "Show transactions that were removed due to a reorg in the \"removed\" array\n"
552  "(not guaranteed to work on pruned nodes)"},
553  {"include_change", RPCArg::Type::BOOL, RPCArg::Default{false}, "Also add entries for change outputs.\n"},
554  {"label", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Return only incoming transactions paying to addresses with the specified label.\n"},
555  },
556  RPCResult{
557  RPCResult::Type::OBJ, "", "",
558  {
559  {RPCResult::Type::ARR, "transactions", "",
560  {
561  {RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
562  {
563  {RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction."},
564  {RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address of the transaction (not returned if the output does not have an address, e.g. OP_RETURN null data)."},
565  {RPCResult::Type::STR, "category", "The transaction category.\n"
566  "\"send\" Transactions sent.\n"
567  "\"receive\" Non-coinbase transactions received.\n"
568  "\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
569  "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
570  "\"orphan\" Orphaned coinbase transactions received."},
571  {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n"
572  "for all other categories"},
573  {RPCResult::Type::NUM, "vout", "the vout value"},
574  {RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the\n"
575  "'send' category of transactions."},
576  },
578  {
579  {RPCResult::Type::BOOL, "abandoned", "'true' if the transaction has been abandoned (inputs are respendable)."},
580  {RPCResult::Type::STR, "label", /*optional=*/true, "A comment for the address/transaction, if any"},
581  })},
582  }},
583  {RPCResult::Type::ARR, "removed", /*optional=*/true, "<structure is the same as \"transactions\" above, only present if include_removed=true>\n"
584  "Note: transactions that were re-added in the active chain will appear as-is in this array, and may thus have a positive confirmation count."
585  , {{RPCResult::Type::ELISION, "", ""},}},
586  {RPCResult::Type::STR_HEX, "lastblock", "The hash of the block (target_confirmations-1) from the best block on the main chain, or the genesis hash if the referenced block does not exist yet. 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"},
587  }
588  },
589  RPCExamples{
590  HelpExampleCli("listsinceblock", "")
591  + HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6")
592  + HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6")
593  },
594  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
595 {
596  const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
597  if (!pwallet) return UniValue::VNULL;
598 
599  const CWallet& wallet = *pwallet;
600  // Make sure the results are valid at least up to the most recent block
601  // the user could have gotten from another RPC command prior to now
602  wallet.BlockUntilSyncedToCurrentChain();
603 
604  LOCK(wallet.cs_wallet);
605 
606  std::optional<int> height; // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
607  std::optional<int> altheight; // Height of the specified block, even if it's in a deactivated chain.
608  int target_confirms = 1;
610 
611  uint256 blockId;
612  if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
613  blockId = ParseHashV(request.params[0], "blockhash");
614  height = int{};
615  altheight = int{};
616  if (!wallet.chain().findCommonAncestor(blockId, wallet.GetLastBlockHash(), /*ancestor_out=*/FoundBlock().height(*height), /*block1_out=*/FoundBlock().height(*altheight))) {
617  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
618  }
619  }
620 
621  if (!request.params[1].isNull()) {
622  target_confirms = request.params[1].getInt<int>();
623 
624  if (target_confirms < 1) {
625  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
626  }
627  }
628 
629  if (ParseIncludeWatchonly(request.params[2], wallet)) {
630  filter |= ISMINE_WATCH_ONLY;
631  }
632 
633  bool include_removed = (request.params[3].isNull() || request.params[3].get_bool());
634  bool include_change = (!request.params[4].isNull() && request.params[4].get_bool());
635 
636  // Only set it if 'label' was provided.
637  std::optional<std::string> filter_label;
638  if (!request.params[5].isNull()) filter_label.emplace(LabelFromValue(request.params[5]));
639 
640  int depth = height ? wallet.GetLastBlockHeight() + 1 - *height : -1;
641 
642  UniValue transactions(UniValue::VARR);
643 
644  for (const std::pair<const uint256, CWalletTx>& pairWtx : wallet.mapWallet) {
645  const CWalletTx& tx = pairWtx.second;
646 
647  if (depth == -1 || abs(wallet.GetTxDepthInMainChain(tx)) < depth) {
648  ListTransactions(wallet, tx, 0, true, transactions, filter, filter_label, include_change);
649  }
650  }
651 
652  // when a reorg'd block is requested, we also list any relevant transactions
653  // in the blocks of the chain that was detached
654  UniValue removed(UniValue::VARR);
655  while (include_removed && altheight && *altheight > *height) {
656  CBlock block;
657  if (!wallet.chain().findBlock(blockId, FoundBlock().data(block)) || block.IsNull()) {
658  throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
659  }
660  for (const CTransactionRef& tx : block.vtx) {
661  auto it = wallet.mapWallet.find(tx->GetHash());
662  if (it != wallet.mapWallet.end()) {
663  // We want all transactions regardless of confirmation count to appear here,
664  // even negative confirmation ones, hence the big negative.
665  ListTransactions(wallet, it->second, -100000000, true, removed, filter, filter_label, include_change);
666  }
667  }
668  blockId = block.hashPrevBlock;
669  --*altheight;
670  }
671 
672  uint256 lastblock;
673  target_confirms = std::min(target_confirms, wallet.GetLastBlockHeight() + 1);
674  CHECK_NONFATAL(wallet.chain().findAncestorByHeight(wallet.GetLastBlockHash(), wallet.GetLastBlockHeight() + 1 - target_confirms, FoundBlock().hash(lastblock)));
675 
677  ret.pushKV("transactions", transactions);
678  if (include_removed) ret.pushKV("removed", removed);
679  ret.pushKV("lastblock", lastblock.GetHex());
680 
681  return ret;
682 },
683  };
684 }
685 
687 {
688  return RPCHelpMan{"gettransaction",
689  "\nGet detailed information about in-wallet transaction <txid>\n",
690  {
691  {"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"},
692  {"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"},
693  "Whether to include watch-only addresses in balance calculation and details[]"},
694  {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false},
695  "Whether to include a `decoded` field containing the decoded transaction (equivalent to RPC decoderawtransaction)"},
696  },
697  RPCResult{
698  RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
699  {
700  {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT},
701  {RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the\n"
702  "'send' category of transactions."},
703  },
705  {
706  {RPCResult::Type::ARR, "details", "",
707  {
708  {RPCResult::Type::OBJ, "", "",
709  {
710  {RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction."},
711  {RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address involved in the transaction."},
712  {RPCResult::Type::STR, "category", "The transaction category.\n"
713  "\"send\" Transactions sent.\n"
714  "\"receive\" Non-coinbase transactions received.\n"
715  "\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
716  "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
717  "\"orphan\" Orphaned coinbase transactions received."},
718  {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT},
719  {RPCResult::Type::STR, "label", /*optional=*/true, "A comment for the address/transaction, if any"},
720  {RPCResult::Type::NUM, "vout", "the vout value"},
721  {RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
722  "'send' category of transactions."},
723  {RPCResult::Type::BOOL, "abandoned", "'true' if the transaction has been abandoned (inputs are respendable)."},
724  {RPCResult::Type::ARR, "parent_descs", /*optional=*/true, "Only if 'category' is 'received'. List of parent descriptors for the scriptPubKey of this coin.", {
725  {RPCResult::Type::STR, "desc", "The descriptor string."},
726  }},
727  }},
728  }},
729  {RPCResult::Type::STR_HEX, "hex", "Raw data for transaction"},
730  {RPCResult::Type::OBJ, "decoded", /*optional=*/true, "The decoded transaction (only present when `verbose` is passed)",
731  {
732  {RPCResult::Type::ELISION, "", "Equivalent to the RPC decoderawtransaction method, or the RPC getrawtransaction method when `verbose` is passed."},
733  }},
735  })
736  },
737  RPCExamples{
738  HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
739  + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
740  + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" false true")
741  + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
742  },
743  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
744 {
745  const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
746  if (!pwallet) return UniValue::VNULL;
747 
748  // Make sure the results are valid at least up to the most recent block
749  // the user could have gotten from another RPC command prior to now
750  pwallet->BlockUntilSyncedToCurrentChain();
751 
752  LOCK(pwallet->cs_wallet);
753 
754  uint256 hash(ParseHashV(request.params[0], "txid"));
755 
757 
758  if (ParseIncludeWatchonly(request.params[1], *pwallet)) {
759  filter |= ISMINE_WATCH_ONLY;
760  }
761 
762  bool verbose = request.params[2].isNull() ? false : request.params[2].get_bool();
763 
764  UniValue entry(UniValue::VOBJ);
765  auto it = pwallet->mapWallet.find(hash);
766  if (it == pwallet->mapWallet.end()) {
767  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
768  }
769  const CWalletTx& wtx = it->second;
770 
771  CAmount nCredit = CachedTxGetCredit(*pwallet, wtx, filter);
772  CAmount nDebit = CachedTxGetDebit(*pwallet, wtx, filter);
773  CAmount nNet = nCredit - nDebit;
774  CAmount nFee = (CachedTxIsFromMe(*pwallet, wtx, filter) ? wtx.tx->GetValueOut() - nDebit : 0);
775 
776  entry.pushKV("amount", ValueFromAmount(nNet - nFee));
777  if (CachedTxIsFromMe(*pwallet, wtx, filter))
778  entry.pushKV("fee", ValueFromAmount(nFee));
779 
780  WalletTxToJSON(*pwallet, wtx, entry);
781 
782  UniValue details(UniValue::VARR);
783  ListTransactions(*pwallet, wtx, 0, false, details, filter, /*filter_label=*/std::nullopt);
784  entry.pushKV("details", details);
785 
786  std::string strHex = EncodeHexTx(*wtx.tx, pwallet->chain().rpcSerializationFlags());
787  entry.pushKV("hex", strHex);
788 
789  if (verbose) {
790  UniValue decoded(UniValue::VOBJ);
791  TxToUniv(*wtx.tx, /*block_hash=*/uint256(), /*entry=*/decoded, /*include_hex=*/false);
792  entry.pushKV("decoded", decoded);
793  }
794 
795  AppendLastProcessedBlock(entry, *pwallet);
796  return entry;
797 },
798  };
799 }
800 
802 {
803  return RPCHelpMan{"abandontransaction",
804  "\nMark in-wallet transaction <txid> as abandoned\n"
805  "This will mark this transaction and all its in-wallet descendants as abandoned which will allow\n"
806  "for their inputs to be respent. It can be used to replace \"stuck\" or evicted transactions.\n"
807  "It only works on transactions which are not included in a block and are not currently in the mempool.\n"
808  "It has no effect on transactions which are already abandoned.\n",
809  {
810  {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
811  },
813  RPCExamples{
814  HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
815  + HelpExampleRpc("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
816  },
817  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
818 {
819  std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
820  if (!pwallet) return UniValue::VNULL;
821 
822  // Make sure the results are valid at least up to the most recent block
823  // the user could have gotten from another RPC command prior to now
824  pwallet->BlockUntilSyncedToCurrentChain();
825 
826  LOCK(pwallet->cs_wallet);
827 
828  uint256 hash(ParseHashV(request.params[0], "txid"));
829 
830  if (!pwallet->mapWallet.count(hash)) {
831  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
832  }
833  if (!pwallet->AbandonTransaction(hash)) {
834  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not eligible for abandonment");
835  }
836 
837  return UniValue::VNULL;
838 },
839  };
840 }
841 
843 {
844  return RPCHelpMan{"rescanblockchain",
845  "\nRescan the local blockchain for wallet related transactions.\n"
846  "Note: Use \"getwalletinfo\" to query the scanning progress.\n"
847  "The rescan is significantly faster when used on a descriptor wallet\n"
848  "and block filters are available (using startup option \"-blockfilterindex=1\").\n",
849  {
850  {"start_height", RPCArg::Type::NUM, RPCArg::Default{0}, "block height where the rescan should start"},
851  {"stop_height", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "the last block height that should be scanned. If none is provided it will rescan up to the tip at return time of this call."},
852  },
853  RPCResult{
854  RPCResult::Type::OBJ, "", "",
855  {
856  {RPCResult::Type::NUM, "start_height", "The block height where the rescan started (the requested height or 0)"},
857  {RPCResult::Type::NUM, "stop_height", "The height of the last rescanned block. May be null in rare cases if there was a reorg and the call didn't scan any blocks because they were already scanned in the background."},
858  }
859  },
860  RPCExamples{
861  HelpExampleCli("rescanblockchain", "100000 120000")
862  + HelpExampleRpc("rescanblockchain", "100000, 120000")
863  },
864  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
865 {
866  std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
867  if (!pwallet) return UniValue::VNULL;
868  CWallet& wallet{*pwallet};
869 
870  // Make sure the results are valid at least up to the most recent block
871  // the user could have gotten from another RPC command prior to now
872  wallet.BlockUntilSyncedToCurrentChain();
873 
874  WalletRescanReserver reserver(*pwallet);
875  if (!reserver.reserve(/*with_passphrase=*/true)) {
876  throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
877  }
878 
879  int start_height = 0;
880  std::optional<int> stop_height;
881  uint256 start_block;
882 
883  LOCK(pwallet->m_relock_mutex);
884  {
885  LOCK(pwallet->cs_wallet);
886  EnsureWalletIsUnlocked(*pwallet);
887  int tip_height = pwallet->GetLastBlockHeight();
888 
889  if (!request.params[0].isNull()) {
890  start_height = request.params[0].getInt<int>();
891  if (start_height < 0 || start_height > tip_height) {
892  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid start_height");
893  }
894  }
895 
896  if (!request.params[1].isNull()) {
897  stop_height = request.params[1].getInt<int>();
898  if (*stop_height < 0 || *stop_height > tip_height) {
899  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid stop_height");
900  } else if (*stop_height < start_height) {
901  throw JSONRPCError(RPC_INVALID_PARAMETER, "stop_height must be greater than start_height");
902  }
903  }
904 
905  // We can't rescan beyond non-pruned blocks, stop and throw an error
906  if (!pwallet->chain().hasBlocks(pwallet->GetLastBlockHash(), start_height, stop_height)) {
907  throw JSONRPCError(RPC_MISC_ERROR, "Can't rescan beyond pruned data. Use RPC call getblockchaininfo to determine your pruned height.");
908  }
909 
910  CHECK_NONFATAL(pwallet->chain().findAncestorByHeight(pwallet->GetLastBlockHash(), start_height, FoundBlock().hash(start_block)));
911  }
912 
913  CWallet::ScanResult result =
914  pwallet->ScanForWalletTransactions(start_block, start_height, stop_height, reserver, /*fUpdate=*/true, /*save_progress=*/false);
915  switch (result.status) {
917  break;
919  throw JSONRPCError(RPC_MISC_ERROR, "Rescan failed. Potentially corrupted data files.");
921  throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted.");
922  // no default case, so the compiler can warn about missing cases
923  }
924  UniValue response(UniValue::VOBJ);
925  response.pushKV("start_height", start_height);
926  response.pushKV("stop_height", result.last_scanned_height ? *result.last_scanned_height : UniValue());
927  return response;
928 },
929  };
930 }
931 
933 {
934  return RPCHelpMan{"abortrescan",
935  "\nStops current wallet rescan triggered by an RPC call, e.g. by an importprivkey call.\n"
936  "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
937  {},
938  RPCResult{RPCResult::Type::BOOL, "", "Whether the abort was successful"},
939  RPCExamples{
940  "\nImport a private key\n"
941  + HelpExampleCli("importprivkey", "\"mykey\"") +
942  "\nAbort the running wallet rescan\n"
943  + HelpExampleCli("abortrescan", "") +
944  "\nAs a JSON-RPC call\n"
945  + HelpExampleRpc("abortrescan", "")
946  },
947  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
948 {
949  std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
950  if (!pwallet) return UniValue::VNULL;
951 
952  if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) return false;
953  pwallet->AbortRescan();
954  return true;
955 },
956  };
957 }
958 } // namespace wallet
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:421
CAmount nValue
Definition: transaction.h:160
Helper for findBlock to selectively return pieces of block data.
Definition: chain.h:52
enum wallet::CWallet::ScanResult::@17 status
void push_back(UniValue val)
Definition: univalue.cpp:104
int ret
static void WalletTxToJSON(const CWallet &wallet, const CWalletTx &wtx, UniValue &entry) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
CScript scriptPubKey
Definition: transaction.h:161
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
std::optional< int > last_scanned_height
Definition: wallet.h:614
tallyitem()=default
Required arg.
Either this tx or a mempool ancestor signals rbf.
Definition: block.h:68
bool IsValidDestinationString(const std::string &str, const CChainParams &params)
Definition: key_io.cpp:303
Unconfirmed tx that does not signal rbf and is not in the mempool.
RPCHelpMan listtransactions()
RPCHelpMan abandontransaction()
#define CHECK_NONFATAL(condition)
Identity function.
Definition: check.h:46
bool ParseIncludeWatchonly(const UniValue &include_watchonly, const CWallet &wallet)
Used by RPC commands that have an include_watchonly parameter.
Definition: util.cpp:51
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
Definition: util.cpp:26
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1043
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:477
static const RPCResult RESULT_LAST_PROCESSED_BLOCK
Definition: util.h:28
bool reserve(bool with_passphrase=false)
Definition: wallet.h:1054
State of transaction confirmed in a block.
Definition: transaction.h:26
static UniValue ListReceived(const CWallet &wallet, const UniValue &params, const bool by_label, const bool include_immature_coinbase) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
bool isAbandoned() const
Definition: transaction.h:328
Invalid, missing or duplicate parameter.
Definition: protocol.h:43
RBFTransactionState
The rbf state of unconfirmed transactions.
Definition: rbf.h:27
RPCHelpMan rescanblockchain()
void CachedTxGetAmounts(const CWallet &wallet, const CWalletTx &wtx, std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, const isminefilter &filter, bool include_change)
Definition: receive.cpp:194
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:171
std::vector< uint256 > txids
Special type that is a STR with only hex chars.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:161
std::underlying_type< isminetype >::type isminefilter
used for bitflags of isminetype
Definition: wallet.h:43
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Definition: receive.cpp:109
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:58
Special string with only hex chars.
std::string LabelFromValue(const UniValue &value)
Definition: util.cpp:134
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
Definition: addresstype.cpp:49
RPCHelpMan listsinceblock()
#define LOCK(cs)
Definition: sync.h:258
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
Definition: receive.cpp:256
RPCHelpMan listreceivedbylabel()
uint256 hashPrevBlock
Definition: block.h:26
virtual bool findBlock(const uint256 &hash, const FoundBlock &block={})=0
Return whether node has the block and optionally return block metadata or contents.
const std::string CURRENCY_UNIT
Definition: feerate.h:17
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:300
General application defined errors.
Definition: protocol.h:39
std::string DefaultHint
Hint for default value.
Definition: util.h:198
static std::vector< RPCResult > TransactionDescriptionString()
An output of a transaction.
Definition: transaction.h:157
Invalid address or key.
Definition: protocol.h:41
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:143
Special numeric to denote unix epoch time.
RPCHelpMan listreceivedbyaddress()
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: util.cpp:77
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Definition: addresstype.h:129
256-bit opaque blob.
Definition: uint256.h:106
Optional argument for which the default value is omitted from help text for one of two reasons: ...
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
std::vector< CTransactionRef > vtx
Definition: block.h:72
Special string to represent a floating point amount.
static void ListTransactions(const CWallet &wallet, const CWalletTx &wtx, int nMinDepth, bool fLong, Vec &ret, const isminefilter &filter_ismine, const std::optional< std::string > &filter_label, bool include_change=false) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
List transactions based on the given criteria.
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:122
void AppendLastProcessedBlock(UniValue &entry, const CWallet &wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
Definition: util.cpp:181
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:126
bool IsNull() const
Definition: block.h:49
RPCHelpMan gettransaction()
const uint256 & GetHash() const
Definition: transaction.h:333
std::string GetHex() const
Definition: uint256.cpp:11
UniValue ValueFromAmount(const CAmount amount)
Definition: core_write.cpp:26
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
Definition: core_write.cpp:143
FoundBlock & hash(uint256 &hash)
Definition: chain.h:55
virtual RBFTransactionState isRBFOptIn(const CTransaction &tx)=0
Check if transaction is RBF opt in.
RPCHelpMan abortrescan()
void EnsureWalletIsUnlocked(const CWallet &wallet)
Definition: util.cpp:96
static void MaybePushAddress(UniValue &entry, const CTxDestination &dest)
std::string EncodeDestination(const CTxDestination &dest)
Definition: key_io.cpp:287
Wallet errors.
Definition: protocol.h:71
bool IsCoinBase() const
Definition: transaction.h:335
Definition: receive.h:36
FoundBlock & height(int &height)
Definition: chain.h:56
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
Definition: key_io.cpp:292
void PushParentDescriptors(const CWallet &wallet, const CScript &script_pubkey, UniValue &entry)
Fetch parent descriptors of this scriptPubKey.
Definition: util.cpp:145
void TxToUniv(const CTransaction &tx, const uint256 &block_hash, UniValue &entry, bool include_hex=true, int serialize_flags=0, const CTxUndo *txundo=nullptr, TxVerbosity verbosity=TxVerbosity::SHOW_DETAILS)
Definition: core_write.cpp:171
bool CachedTxIsFromMe(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Definition: receive.cpp:251
CTransactionRef tx
Definition: transaction.h:253
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
Definition: util.cpp:72
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
Definition: util.cpp:25
Special type to denote elision (...)
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.
Definition: vector.h:34
CAmount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
Definition: receive.cpp:126