aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAntoine Poinsot <darosior@protonmail.com>2022-07-07 14:06:27 +0200
committerAntoine Poinsot <darosior@protonmail.com>2022-08-16 18:33:05 +0200
commit0fd2d144540b720626fc065a3cef5188831b5ee2 (patch)
tree59dd67fd3cf748fbd829cad0421f0192cce12b29 /src/wallet
parent55f98d087efd2609d808c082d5770306cc489409 (diff)
downloadbitcoin-0fd2d144540b720626fc065a3cef5188831b5ee2.tar.xz
rpc: add an include_change parameter to listsinceblock
It's useful for an external application tracking coins to not be limited by our change detection. For instance, for a watchonly wallet with two descriptors a transaction from one to the other would be considered a change output and not be included in the result (if the address was not generated by this wallet).
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/receive.cpp6
-rw-r--r--src/wallet/receive.h3
-rw-r--r--src/wallet/rpc/transactions.cpp13
3 files changed, 14 insertions, 8 deletions
diff --git a/src/wallet/receive.cpp b/src/wallet/receive.cpp
index 8de4017371..c3aeef4209 100644
--- a/src/wallet/receive.cpp
+++ b/src/wallet/receive.cpp
@@ -223,7 +223,8 @@ CAmount CachedTxGetAvailableCredit(const CWallet& wallet, const CWalletTx& wtx,
void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
std::list<COutputEntry>& listReceived,
- std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter)
+ std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter,
+ bool include_change)
{
nFee = 0;
listReceived.clear();
@@ -248,8 +249,7 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
// 2) the output is to us (received)
if (nDebit > 0)
{
- // Don't report 'change' txouts
- if (OutputIsChange(wallet, txout))
+ if (!include_change && OutputIsChange(wallet, txout))
continue;
}
else if (!(fIsMine & filter))
diff --git a/src/wallet/receive.h b/src/wallet/receive.h
index 1caef293f2..36759059b8 100644
--- a/src/wallet/receive.h
+++ b/src/wallet/receive.h
@@ -44,7 +44,8 @@ struct COutputEntry
void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
std::list<COutputEntry>& listReceived,
std::list<COutputEntry>& listSent,
- CAmount& nFee, const isminefilter& filter);
+ CAmount& nFee, const isminefilter& filter,
+ bool include_change);
bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter);
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<uint256>& trusted_parents) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx);
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp
index db44ee7a4c..aed9f0d5c1 100644
--- a/src/wallet/rpc/transactions.cpp
+++ b/src/wallet/rpc/transactions.cpp
@@ -315,13 +315,16 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
* @param filter_label Optional label string to filter incoming transactions.
*/
template <class Vec>
-static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nMinDepth, bool fLong, Vec& ret, const isminefilter& filter_ismine, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
+static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nMinDepth, bool fLong,
+ Vec& ret, const isminefilter& filter_ismine, const std::string* filter_label,
+ bool include_change = false)
+ EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
{
CAmount nFee;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
- CachedTxGetAmounts(wallet, wtx, listReceived, listSent, nFee, filter_ismine);
+ CachedTxGetAmounts(wallet, wtx, listReceived, listSent, nFee, filter_ismine, include_change);
bool involvesWatchonly = CachedTxIsFromMe(wallet, wtx, ISMINE_WATCH_ONLY);
@@ -548,6 +551,7 @@ RPCHelpMan listsinceblock()
{"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Include transactions to watch-only addresses (see 'importaddress')"},
{"include_removed", RPCArg::Type::BOOL, RPCArg::Default{true}, "Show transactions that were removed due to a reorg in the \"removed\" array\n"
"(not guaranteed to work on pruned nodes)"},
+ {"include_change", RPCArg::Type::BOOL, RPCArg::Default{false}, "Also add entries for change outputs.\n"},
},
RPCResult{
RPCResult::Type::OBJ, "", "",
@@ -628,6 +632,7 @@ RPCHelpMan listsinceblock()
}
bool include_removed = (request.params[3].isNull() || request.params[3].get_bool());
+ bool include_change = (!request.params[4].isNull() && request.params[4].get_bool());
int depth = height ? wallet.GetLastBlockHeight() + 1 - *height : -1;
@@ -637,7 +642,7 @@ RPCHelpMan listsinceblock()
const CWalletTx& tx = pairWtx.second;
if (depth == -1 || abs(wallet.GetTxDepthInMainChain(tx)) < depth) {
- ListTransactions(wallet, tx, 0, true, transactions, filter, nullptr /* filter_label */);
+ ListTransactions(wallet, tx, 0, true, transactions, filter, nullptr /* filter_label */, /*include_change=*/include_change);
}
}
@@ -654,7 +659,7 @@ RPCHelpMan listsinceblock()
if (it != wallet.mapWallet.end()) {
// We want all transactions regardless of confirmation count to appear here,
// even negative confirmation ones, hence the big negative.
- ListTransactions(wallet, it->second, -100000000, true, removed, filter, nullptr /* filter_label */);
+ ListTransactions(wallet, it->second, -100000000, true, removed, filter, nullptr /* filter_label */, /*include_change=*/include_change);
}
}
blockId = block.hashPrevBlock;