Description
Currently, when changeIndex is not null, the change in satoshis is returned to:
changeAddress, if changeAddress is not null.
This works fine for single addresses but seems a bit odd when dealing with mixed address UTXOs.
Example Scenario
Let's illustrate with a real-world example:
- You need to pay 50 units.
- You only have 30 units.
- You borrow 20 units from me.
- I lend you a 50-unit note.
- You should return 30 units back to me as change.
Problem
In the context of UTXOs, if the borrowed 50-unit note is from a different address (mixed address UTXO), the system should be able to handle this by correctly returning the change to the lender’s address.
Proposal
To handle this scenario effectively, we suggest discussing whether to remove the restriction on changeAddress. This would allow the system to dynamically allocate the change to the appropriate address based on the UTXOs involved.
This adjustment will ensure that the returned change correctly reflects the source addresses, thereby improving the handling of mixed address UTXOs.