in 304596b3083b100df34f53ae543be50c70135ca5 wallet, rpc: Add listrawtransactions RPC
Given how small this function is and given that it is only used inside RPCMethod listrawtransactions() it can probably be a lamda function inside it.
<details>
<summary>suggested diff</summary>
$ git diff
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp
index 0602ede8e2..cdde1774f0 100644
--- a/src/wallet/rpc/transactions.cpp
+++ b/src/wallet/rpc/transactions.cpp
@@ -418,33 +418,6 @@ static void PushTxDecoded(const CWallet& wallet, const CWalletTx& wtx, UniValue&
entry.pushKV("decoded", std::move(decoded));
}
-/**
- * Append a raw transaction entry for the given wallet transaction to ret.
- *
- * [@param](/github-metadata-backup-bitcoin-bitcoin/contributor/param/) wallet The wallet.
- * [@param](/github-metadata-backup-bitcoin-bitcoin/contributor/param/) wtx The wallet transaction.
- * [@param](/github-metadata-backup-bitcoin-bitcoin/contributor/param/) ret Output vector to append the entry to.
- * [@param](/github-metadata-backup-bitcoin-bitcoin/contributor/param/) verbose If true, include a decoded transaction object.
- */
-template <class Vec>
-static void ListRawTransaction(const CWallet& wallet, const CWalletTx& wtx, Vec& ret, bool verbose)
- EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
-{
- UniValue entry(UniValue::VOBJ);
-
- PushTxAmountAndFee(wallet, wtx, entry);
-
- WalletTxToJSON(wallet, wtx, entry);
- entry.pushKV("abandoned", wtx.isAbandoned());
- entry.pushKV("hex", EncodeHexTx(*wtx.GetTx()));
-
- if (verbose) {
- PushTxDecoded(wallet, wtx, entry);
- }
-
- ret.push_back(std::move(entry));
-}
-
static std::vector<RPCResult> TransactionDescriptionString()
{
return{{RPCResult::Type::NUM, "confirmations", "The number of confirmations for the transaction. Negative confirmations means the\n"
@@ -660,12 +633,23 @@ RPCMethod listrawtransactions()
const CWallet::TxItems& tx_ordered = pwallet->wtxOrdered;
+ auto list_raw_tx = [&](const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
+ UniValue entry(UniValue::VOBJ);
+ PushTxAmountAndFee(*pwallet, wtx, entry);
+ WalletTxToJSON(*pwallet, wtx, entry);
+ entry.pushKV("abandoned", wtx.isAbandoned());
+ entry.pushKV("hex", EncodeHexTx(*wtx.GetTx()));
+ if (verbose) {
+ PushTxDecoded(*pwallet, wtx, entry);
+ }
+ ret.push_back(std::move(entry));
+ };
+
int skipped = 0;
for (CWallet::TxItems::const_reverse_iterator it = tx_ordered.rbegin(); it != tx_ordered.rend(); ++it) {
if ((int)ret.size() >= count) break;
if (skipped++ < skip) continue;
- CWalletTx* const pwtx = (*it).second;
- ListRawTransaction(*pwallet, *pwtx, ret, verbose);
+ list_raw_tx(*(*it).second);
}
}
</details>