xchainjs-lib
xchainjs-lib copied to clipboard
[Bug] No proper check in buildTX
xchainjs-bitcoin/utils buildTX needs to check that the amount sent + fee cannot exceed the users balance, if it does then the amount sent must be equal to the users balance - fee, it should not throw an error but instead determine the new implicated amount to send (as it is maximum in this context).
@0xNegnin sorry about the long delay, looking at this now...
under the covers, we are using https://github.com/bitcoinjs/coinselect/blob/master/accumulative.js to select the inputs based on the desired outputs in the tx. if not it will error out.
I think sending the entire balance in this case is not a good idea as that's not what the caller requested.
Could a workaround be the following?
- make your call to transfer()
- if it throws Error('Insufficient Balance for transaction')
- you catch, check balances and possibly resubmit if it makes sense?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.