rpc/wallet: add optional transaction(s) to getbalances #22776

pull kallewoof wants to merge 1 commits into bitcoin:master from kallewoof:202108-getbalances-tx changing 4 files +139 −2
  1. kallewoof commented at 4:13 AM on August 23, 2021: member

    Optional transactions provided to getbalances iterates over the inputs and outputs, and tallies up the balance change for the given wallet. This can be useful e.g. when verifying that a coin join like transaction doesn't contain unexpected inputs that the wallet will then sign for unintentionally.

    This is an alternative to #22751.

  2. fanquake added the label RPC/REST/ZMQ on Aug 23, 2021
  3. kallewoof force-pushed on Aug 23, 2021
  4. ghost commented at 5:49 AM on August 23, 2021: none

    Concept ACK. Will try today.

  5. kallewoof force-pushed on Aug 23, 2021
  6. meshcollider commented at 6:14 AM on August 23, 2021: contributor

    Approach ACK, definitely prefer this over #22751 👍

  7. MarcoFalke commented at 6:33 AM on August 23, 2021: member

    How is the user going to use this? Call the RPC thrice and compare the results?

    • Fist time to get the balances before
    • Second time to get the balances with the tx included
    • Third time to verify no other thread added a wallet tx in-between, which would invalidate the result
  8. kallewoof commented at 7:23 AM on August 23, 2021: member

    @MarcoFalke The transaction is supposedly not yet broadcasted. They'd only need to call getbalances once. The existing output would give the wallet's balance as it is (excluding the transaction), and the added "changes" would show how the balance would change, if the transaction was broadcasted.

    I.e. I get a coin-join with 100 other inputs and a bunch of outputs. I call getbalances [hex], and the "changes" column tells me how much I gain/lose from broadcasting the transaction.

  9. MarcoFalke commented at 7:31 AM on August 23, 2021: member

    Oh I didn't see the changed result, because the documentation wasn't updated.

  10. kallewoof force-pushed on Aug 23, 2021
  11. kallewoof commented at 7:38 AM on August 23, 2021: member

    Good point, documentation updated.

  12. DrahtBot commented at 1:32 PM on August 23, 2021: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #23813 (Add test and docs for getblockfrompeer by fjahr)
    • #23706 (rpc: getblockfrompeer followups by Sjors)
    • #23532 (test: add functional test for -startupnotify by brunoerg)
    • #22751 (rpc/wallet: add simulaterawtransaction RPC by kallewoof)

    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.

  13. unknown approved
  14. unknown commented at 4:40 PM on August 23, 2021: none

    tACK https://github.com/bitcoin/bitcoin/pull/22776/commits/67ff5ae4b092c3284da7481e13518dbbd3d945f5

    Tested with different transactions (input from wallet, input not belonging to wallet, outputs from wallet, outputs outside wallet)

    Example:

    Request:
    
    POST /wallet/W2 HTTP/1.1
    Host: 127.0.0.1:18333
    Authorization: Basic dXNlcjMzOnBhc3N3b3JkMzM=
    Content-Type: text/plain
    Content-Length: 521
    
    {"jsonrpc": "1.0", "id": "curltest", "method": "getbalances", "params": ["02000000000101fff8d9d39105eeec162fb45bd2a3e796b255866469a2cc7de93e438f3722c1490000000000fdffffff02801a0600000000001600145b497cfd64324fb0c4f7317472ca591cd7eb3bbfe093040000000000160014b1348ec3acd422b7c84f97f8757a0a5c3db9e32d02473044022020c3a9d7d06429008de82f13de672aac7886c5d6557a7c330bcb8cbc20b8cf4f02203890042ed8bf331e92f07df5d2a7bf5d8ade12cbb216f14493a98d0a188c4918012103c65a6e4a66a4a6b4af981c5e81632bb2d7336bc75d7ccf83e055006a2693050f00000000"]}
    
    Response:
    
    {
        "result": {
            "mine": {
                "trusted": 5051.31588006,
                "untrusted_pending": 0.00000000,
                "immature": 0.00000000
            },
            "tx": {
                "changes": 0.00000000
            }
        },
        "error": null,
        "id": "curltest"
    }
    

    Everything looks good to me. Also tested by fuzzing this argument for getbalances with random strings. No issues.

  15. meshcollider added the label Wallet on Aug 24, 2021
  16. achow101 commented at 11:54 PM on August 25, 2021: member

    -0 on this.

    As I commented in #22751 (comment), I would prefer a broader "see how transactions modify the wallet without actually modifying it" RPC rather than trying to jam that functionality into an existing one.

    But if this is the approach that others prefer, then I would also prefer this to accept multiple transactions (as an array) rather than a single transaction. It is conceivable that a user would want to see how multiple transactions would modify their wallet at the same time, e.g. when broadcasting a package.

  17. kallewoof force-pushed on Aug 26, 2021
  18. kallewoof commented at 5:32 AM on August 26, 2021: member

    Switched to array of raw transactions.

    I am neutral on whether to add this here or create a new simulaterawtransaction as in #22751.

  19. kallewoof force-pushed on Aug 26, 2021
  20. kallewoof renamed this:
    rpc/wallet: add optional transaction to getbalances
    rpc/wallet: add optional transaction(s) to getbalances
    on Aug 26, 2021
  21. luke-jr commented at 1:45 AM on September 20, 2021: member

    #22751 seems to make more sense IMO

    If users need both pieces of information, they can just batch them.

  22. in src/wallet/rpcwallet.cpp:2413 in 2c4e77ed3b outdated
    2343 | @@ -2344,8 +2344,14 @@ static RPCHelpMan getbalances()
    2344 |  {
    2345 |      return RPCHelpMan{
    2346 |          "getbalances",
    2347 | -        "Returns an object with all balances in " + CURRENCY_UNIT + ".\n",
    2348 | -        {},
    2349 | +        "Returns an object with all balances in " + CURRENCY_UNIT + ", optionally including the balance change given one or more specified transactions.\n",
    2350 | +        {
    2351 | +            {"rawtxs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "An array of hex strings of raw transactions.\n",
    


    luke-jr commented at 1:46 AM on September 20, 2021:

    It seems weird to have an array of raw transactions as a positional argument here.

  23. luke-jr changes_requested
  24. kallewoof commented at 10:54 AM on September 21, 2021: member

    I think #22751 is emerging as the superior option here. Ping if you disagree and I'll reopen this.

  25. kallewoof closed this on Sep 21, 2021

  26. kallewoof commented at 11:53 PM on September 21, 2021: member

    Some prefer this over #22751, so reopening this for now.

  27. kallewoof reopened this on Sep 21, 2021

  28. in test/functional/wallet_balance_getbalances.py:39 in 2c4e77ed3b outdated
      34 | +        node0.createwallet(wallet_name='w0')
      35 | +        w0 = node0.get_wallet_rpc('w0')
      36 | +        node1.createwallet(wallet_name='w1')
      37 | +        w1 = node1.get_wallet_rpc('w1')
      38 | +
      39 | +        node0.generatetoaddress(nblocks=COINBASE_MATURITY + 1, address=w0.getnewaddress())
    


    MarcoFalke commented at 11:30 AM on November 9, 2021:
            self.generatetoaddress(...
    

    MarcoFalke commented at 11:31 AM on November 9, 2021:

    after a rebase, that is


    kallewoof commented at 12:06 PM on November 14, 2021:

    Thanks!

  29. kallewoof force-pushed on Nov 14, 2021
  30. DrahtBot added the label Needs rebase on Dec 8, 2021
  31. rpc/wallet: add optional transactions array to getbalances
    One or several optional transactions provided to getbalances iterates over the inputs and outputs, and tallies up the balance change for the given wallet. This can be useful e.g. when verifying that a coin join like transaction doesn't contain unexpected inputs that the wallet will then sign for unintentionally.
    e63ec4c651
  32. kallewoof force-pushed on Dec 9, 2021
  33. DrahtBot removed the label Needs rebase on Dec 9, 2021
  34. laanwj commented at 3:02 PM on December 17, 2021: member

    I would prefer a broader "see how transactions modify the wallet without actually modifying it" RPC rather than trying to jam that functionality into an existing one.

    I tend to agree here. It is useful functionality but I think it's cleaner to have it separated as a seperate RPC.

  35. DrahtBot added the label Needs rebase on Jan 3, 2022
  36. DrahtBot commented at 8:40 AM on January 3, 2022: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

    <sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>

  37. kallewoof marked this as a draft on Feb 1, 2022
  38. DrahtBot commented at 7:03 AM on July 25, 2022: contributor

    <!--13523179cfe9479db18ec6c5d236f789-->There hasn't been much activity lately and the patch still needs rebase. What is the status here?

    • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
    • Is it no longer relevant? ➡️ Please close.
    • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.
  39. kallewoof closed this on Jul 25, 2022

  40. achow101 referenced this in commit 35305c759a on Aug 5, 2022
  41. sidhujag referenced this in commit 3cdbdce312 on Aug 6, 2022
  42. bitcoin locked this on Jul 25, 2023

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-13 15:14 UTC

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