bitcoin/bitcoin — pull request #4331 by cozz (2014-06-11 23:04:58+00:00)
Title: Subtract fee from amount

Fixes #2724 and #1570.

Adds the automatically-subtract-the-fee-from-the-amount-and-send-whats-left feature to the GUI and rpc (sendtoaddres,sendfrom,sendmany).

The checkbox is only shown for the first recipient. This is to avoid confusion and to make the implementation
as simple as possible: We deduct the fee from the first recipient, if its not enough -> fail

-----------
There is an edge case to consider: Instead of moving dust change to fees, we raise the change
until no dust and deduct from the recipient.
Example:
Amount: 10000 satoshis
Fee: 300 satoshis
Selected unspent output: 10001 satoshis

Now normally:
Recipient receives: 9700
Fee: 300
Change: 1
To pay: 10000

But 1 satoshi is dust, so instead we do:
Recipient receives: 9155 (9700 - 545)
Fee: 300
Change: 546 (1 + 545)
To pay: 9455

So you end up paying less than 10000 in this edge case. But if we would move dust-change to fees (or recipient) you would pay 10001 which would be totally unexpected if you enter 10000 and say "please just deduct the fee from the 10000 and send whats left".

![subtractfeefromamount7](https://cloud.githubusercontent.com/assets/2814559/3252143/f67cf112-f1bb-11e3-88f0-e30a1573c80d.png)

Without checkbox
![subtractfeefromamount4](https://cloud.githubusercontent.com/assets/2814559/3252150/0eab2c18-f1bc-11e3-95b7-417f85a0d642.png)

With checkbox
![subtractfeefromamount3](https://cloud.githubusercontent.com/assets/2814559/3252154/166c5468-f1bc-11e3-9b47-17b3cc0787b4.png)

Dust edge case
![subtractfeefromamount5](https://cloud.githubusercontent.com/assets/2814559/3252158/1f515790-f1bc-11e3-91cc-75b242912050.png)

rpc
![subtractfeefromamount6](https://cloud.githubusercontent.com/assets/2814559/3252160/244fe5cc-f1bc-11e3-9a18-48acc6e080c2.png)