From the description of Bitcoin Core, subtractfeefrom
is a parameter to define which recipient address would opt-in to receive less and contribute to pay the fee
Here is a usecase:
Alex has one UTXO which contains 10 BTC and he sends Mary and Bob each 1 BTC. The transaction fee is 0.5 BTC, so the change to Alex is 10 - 2 - 0.5 = 7.5 BTC.
How does subtractfeefrom
apply to above case in DETAIL?
My high level assumption is
- Get the required fee for the txn
- Deduct this amount evenly from every optin output destination, except the change output, e.g 0.5 BTC / 2 destinations
- First optin output destination also deduct by the non divisible amount - e.g 0.5BTC % 2 destinations
- check if the deducted output is dust, else continue
- adding the total deducted amount to change address
Additionally, what if there is no change output, do we need to create one in this case?
sendmany
, since it has thesubtractfeefrom
parameter, but there is alsosubtract_fee_from_outputs
onsend
, andsubtractfeefromamount
onsendtoaddress
.