wallet, rpc: add include_change parameter to listtransactions #35009

pull alfonsoromanz wants to merge 2 commits into bitcoin:master from alfonsoromanz:wallet-listtransactions-include-change changing 3 files +33 −3
  1. alfonsoromanz commented at 11:04 PM on April 5, 2026: contributor

    Currently, listtransactions silently hides transactions whose outputs go exclusively to change addresses. This can be confusing, as reported in #34632: a user created a consolidation transaction sending funds to a change address, and the transaction disappeared from listtransactions, making it appear as though funds were lost.

    listsinceblock already supports an include_change parameter for this purpose. The internal ListTransactions helper also already accepts it. This PR simply wires the parameter through the listtransactions RPC handler for consistency.

    • Adds include_change (bool, default false) as a new argument after the existing include_watchonly
    • No behavior change for existing callers
    • Includes functional test coverage

    This approach was suggested by @mossein in #34632. A more comprehensive listrawtransactions RPC as mentioned by @achow101 could be pursued separately.

    Fixes #34632

  2. DrahtBot commented at 11:05 PM on April 5, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK achow101

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34872 (wallet: fix mixed-input transaction accounting in history RPCs by w0xlt)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • ListTransactions(*pwallet, *pwtx, 0, true, ret, filter_label, include_change) in src/wallet/rpc/transactions.cpp
    • ListTransactions(pwallet, wtx, 0, false, details, /filter_label=/std::nullopt, /include_change=*/false) in src/wallet/rpc/transactions.cpp
    • self.nodes[0].listtransactions("*", 100, 0, False, True) in test/functional/wallet_listtransactions.py

    <sup>2026-04-07 11:05:05</sup>

  3. alfonsoromanz force-pushed on Apr 5, 2026
  4. DrahtBot added the label CI failed on Apr 5, 2026
  5. DrahtBot removed the label CI failed on Apr 6, 2026
  6. bitcoin deleted a comment on Apr 6, 2026
  7. bitcoin deleted a comment on Apr 6, 2026
  8. in src/wallet/rpc/transactions.cpp:506 in 871bfa7e7a outdated
     502 | @@ -501,7 +503,7 @@ RPCMethod listtransactions()
     503 |          for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
     504 |          {
     505 |              CWalletTx *const pwtx = (*it).second;
     506 | -            ListTransactions(*pwallet, *pwtx, 0, true, ret, filter_label);
     507 | +            ListTransactions(*pwallet, *pwtx, 0, true, ret, filter_label, include_change);
    


    achow101 commented at 8:17 PM on April 6, 2026:

    In 871bfa7e7a6bd3facdb282e47a97e22c6b97b88e "wallet, rpc: add include_change parameter to listtransactions"

    There's only one other caller of ListTransactions that doesn't set include_change. This commit could remove the default value from include_change.


    alfonsoromanz commented at 11:49 AM on April 7, 2026:

    Thanks, addressed in 65fd84281a80105f5a33ff49eefb929e8a7e9ea5

  9. in test/functional/wallet_listtransactions.py:336 in 53d55d8c90 outdated
     331 | +        receive_entries = [t for t in txs if t["txid"] == txid and t["category"] == "receive"]
     332 | +        assert_equal(len(receive_entries), 0)
     333 | +
     334 | +        # With include_change=True, we get both the send (to a change address)
     335 | +        # and the actual change.
     336 | +        txs = self.nodes[0].listtransactions("*", 100, 0, False, True)
    


    achow101 commented at 8:23 PM on April 6, 2026:

    In 53d55d8c90e019276229e43cb4c1196d638383ae "test: wallet: add include_change coverage for listtransactions"

    listtransactions should also have 2 send entries for the outputs, so this test should also be checking for those.


    alfonsoromanz commented at 11:50 AM on April 7, 2026:

    Thanks, addressed in 0ef6fffda86ee8894b4694511f590eda49c9ed2a

  10. wallet, rpc: add include_change parameter to listtransactions
    listsinceblock already supports an include_change parameter, and the internal ListTransactions helper already accepts it. Wire this parameter through the listtransactions RPC handler for consistency.
    
    Since all callers of ListTransactions now pass include_change explicitly, remove the default value to ensure future callers do too.
    
    This addresses the issue reported in #34632, where transactions sending exclusively to change addresses are silently hidden from listtransactions.
    65fd84281a
  11. test: wallet: add include_change coverage for listtransactions
    Verify that listtransactions with include_change=true returns receive and send entries for change outputs. Mirrors the existing test_send_to_self test in wallet_listsinceblock.py.
    0ef6fffda8
  12. alfonsoromanz force-pushed on Apr 7, 2026
  13. alfonsoromanz commented at 11:51 AM on April 7, 2026: contributor

    Force-pushed to address @achow101's feedback.

  14. achow101 commented at 8:18 PM on April 7, 2026: member

    ACK 0ef6fffda86ee8894b4694511f590eda49c9ed2a

  15. luke-jr commented at 5:51 PM on April 8, 2026: member

    listtransactions is meant to show logical transactions, not L1 transactions. Change is by definition not a logical transaction. If you send bitcoins to a change address, I would expect it to not appear at all, rather than appearing as losing money.

  16. achow101 commented at 6:25 PM on April 8, 2026: member

    If you send bitcoins to a change address, I would expect it to not appear at all, rather than appearing as losing money.

    I agree that change should not appear at all, but if it were to be shown, they should be (and are) shown as send to self, which we show as separate send and receive transactions.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me