Skip to content

Commit

Permalink
Check fee amount compared to inputs for subtractFee style transactions
Browse files Browse the repository at this point in the history
It was the only utxo picker without a path to check for insufficient funds
  • Loading branch information
peachbits committed Jan 24, 2024
1 parent d5ee729 commit f848dc4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- changed: Add insufficient funds check `subtractFee` style transactions

## 2.5.2 (2024-01-23)

- removed: Disable `accelerate` for bip32 (Airbitz) wallets
Expand Down
4 changes: 4 additions & 0 deletions src/common/utxobased/keymanager/utxopicker/subtractFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ export function subtractFee(args: UtxoPickerArgs): UtxoPickerResult {
const fee = Math.ceil(feeRate * utils.transactionBytes(utxos, outputs))
targets[0].value -= fee
outputs[0].value -= fee

const targetValue = utils.sumOrNaN(targets)
if (fee > targetValue) return { inputs: utxos, fee, changeUsed: false }

return { inputs: utxos, outputs, fee, changeUsed: false }
}

0 comments on commit f848dc4

Please sign in to comment.