Skip to content

Commit 8e01295

Browse files
committed
remove fromJust
1 parent 77ce980 commit 8e01295

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/BotPlutusInterface/Balance.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Data.Kind (Type)
3333
import Data.List (uncons, (\\))
3434
import Data.Map (Map)
3535
import Data.Map qualified as Map
36-
import Data.Maybe (fromJust, fromMaybe, mapMaybe)
36+
import Data.Maybe (fromMaybe, mapMaybe)
3737
import Data.Set (Set)
3838
import Data.Set qualified as Set
3939
import Data.Text (Text)
@@ -144,12 +144,13 @@ balanceTxIO' pabConf ownPkh unbalancedTx balanceTxType =
144144
-- Adds required collaterals in the `Tx`, if the `Tx` is of type `BalanceTxWithScripts`.
145145
-- Also adds signatures for fee calculation
146146
preBalancedTx <-
147-
if balanceTxType == BalanceTxWithScripts
148-
then
149-
hoistEither $
150-
addSignatories ownPkh privKeys requiredSigs $
151-
addTxCollaterals (fromJust mcollateral) tx
152-
else hoistEither $ addSignatories ownPkh privKeys requiredSigs tx
147+
case balanceTxType of
148+
BalanceTxWithScripts ->
149+
maybe
150+
(throwE "Tx uses script but no collateral was provided.")
151+
(hoistEither . addSignatories ownPkh privKeys requiredSigs . flip addTxCollaterals tx)
152+
mcollateral
153+
_ -> hoistEither $ addSignatories ownPkh privKeys requiredSigs tx
153154

154155
-- Balance the tx
155156
(balancedTx, minUtxos) <- balanceTxLoop utxoIndex privKeys [] preBalancedTx

0 commit comments

Comments
 (0)