xchainjs-lib icon indicating copy to clipboard operation
xchainjs-lib copied to clipboard

[Bug] No proper check in buildTX

Open 0xNegnin opened this issue 2 years ago • 1 comments

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 avatar Mar 18 '22 05:03 0xNegnin

@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?

  1. make your call to transfer()
  2. if it throws Error('Insufficient Balance for transaction')
  3. you catch, check balances and possibly resubmit if it makes sense?

mikewyszinski avatar May 17 '22 23:05 mikewyszinski

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Sep 21 '23 02:09 github-actions[bot]