Clean up change computation in CreateTransaction. #5924

pull domob1812 wants to merge 1 commits into bitcoin:master from domob1812:change-cleanup changing 1 files +4 −7
  1. domob1812 commented at 6:28 PM on March 18, 2015: contributor

    Compute the change directly as difference between the "requested" and the actual value returned by SelectCoins. This removes a duplication of the fee logic code.

  2. gavinandresen commented at 6:30 PM on March 18, 2015: contributor

    How did you test this?

  3. domob1812 commented at 6:55 PM on March 18, 2015: contributor

    Unit tests and wallet.py (which seems to be the relevant one).

  4. laanwj added the label Wallet on Mar 20, 2015
  5. domob1812 force-pushed on Mar 27, 2015
  6. Clean up change computation in CreateTransaction.
    Compute the change directly as difference between the "requested" and
    the actual value returned by SelectCoins.  This removes a duplication of
    the fee logic code.
    835c12291e
  7. domob1812 force-pushed on May 3, 2015
  8. in src/wallet/wallet.cpp:None in 835c12291e
    1813 | @@ -1814,10 +1814,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
    1814 |                      dPriority += (double)nCredit * age;
    1815 |                  }
    1816 |  
    1817 | -                CAmount nChange = nValueIn - nValue;
    1818 | -                if (nSubtractFeeFromAmount == 0)
    1819 | -                    nChange -= nFeeRet;
    1820 | -
    1821 | +                const CAmount nChange = nValueIn - nValueToSelect;
    


    laanwj commented at 9:09 AM on October 1, 2015:

    Before

    nChange = nValueIn - nValue - nSubtractFeeFromAmount?0:nFeeRet 
    

    After:

    nChange = nValueIn - nValueToSelect 
            = nValueIn - (nValue + nSubtractFeeFromAmount?0:nFeeRet) 
            = nValueIn - nValue - nSubtractFeeFromAmount?0:nFeeRet
    

    Looks good to me!

  9. laanwj commented at 9:12 AM on October 1, 2015: member

    ut/code review ACK

  10. laanwj merged this on Oct 1, 2015
  11. laanwj closed this on Oct 1, 2015

  12. laanwj referenced this in commit 12a7712abd on Oct 1, 2015
  13. domob1812 deleted the branch on Oct 1, 2015
  14. MarcoFalke locked this on Sep 8, 2021

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

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