New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up change computation in CreateTransaction. #5924

Merged
merged 1 commit into from Oct 1, 2015

Conversation

Projects
None yet
3 participants
@domob1812
Contributor

domob1812 commented Mar 18, 2015

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.

@gavinandresen

This comment has been minimized.

Show comment
Hide comment
@gavinandresen

gavinandresen Mar 18, 2015

Contributor

How did you test this?

Contributor

gavinandresen commented Mar 18, 2015

How did you test this?

@domob1812

This comment has been minimized.

Show comment
Hide comment
@domob1812

domob1812 Mar 18, 2015

Contributor

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

Contributor

domob1812 commented Mar 18, 2015

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

@laanwj laanwj added the Wallet label Mar 20, 2015

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.
if (nSubtractFeeFromAmount == 0)
nChange -= nFeeRet;
const CAmount nChange = nValueIn - nValueToSelect;

This comment has been minimized.

@laanwj

laanwj Oct 1, 2015

Member

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!

@laanwj

laanwj Oct 1, 2015

Member

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!

@laanwj

This comment has been minimized.

Show comment
Hide comment
@laanwj

laanwj Oct 1, 2015

Member

ut/code review ACK

Member

laanwj commented Oct 1, 2015

ut/code review ACK

@laanwj laanwj merged commit 835c122 into bitcoin:master Oct 1, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

laanwj added a commit that referenced this pull request Oct 1, 2015

Merge pull request #5924
835c122 Clean up change computation in CreateTransaction. (Daniel Kraft)

@domob1812 domob1812 deleted the domob1812:change-cleanup branch Oct 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment