Skip to content

Commit

Permalink
pass down withdrawal value to 'handleCannotCoverFee' to prevent under…
Browse files Browse the repository at this point in the history
…flow in fee calculation.
  • Loading branch information
KtorZ committed Aug 27, 2020
1 parent f6e74dc commit 3d4469c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ estimateFeeForPayment ctx wid recipients withdrawal = do
guardCoinSelection minUtxo cs

estimateFeeForCoinSelection $ (Fee . feeBalance <$> selectCoins)
`catchE` handleCannotCover utxo recipients
`catchE` handleCannotCover utxo withdrawal recipients

-- | When estimating fee, it is rather cumbersome to return "cannot cover fee"
-- whereas clients are just asking for an estimation. Therefore, we convert
Expand All @@ -1468,13 +1468,19 @@ estimateFeeForPayment ctx wid recipients withdrawal = do
handleCannotCover
:: Monad m
=> UTxO
-> Quantity "lovelace" Word64
-> NonEmpty TxOut
-> ErrSelectForPayment e
-> ExceptT (ErrSelectForPayment e) m Fee
handleCannotCover utxo outs = \case
handleCannotCover utxo (Quantity withdrawal) outs = \case
ErrSelectForPaymentFee (ErrCannotCoverFee missing) -> do
let available = fromIntegral (W.balance utxo) - sum (getCoin . coin <$> outs)
pure $ Fee $ available + missing
let available
= fromIntegral (W.balance utxo)
+ fromIntegral withdrawal
let payment
= sum (getCoin . coin <$> outs)
pure $ Fee $
available + missing - payment
e ->
throwE e

Expand Down

0 comments on commit 3d4469c

Please sign in to comment.