@@ -138,6 +138,7 @@ data TxBodyErrorAutoBalance era
138138 -- ^ Total deposits
139139 L. MaryValue
140140 -- ^ Balance
141+ | TxBodyErrorMakeUnsignedTx MakeUnsignedTxError
141142
142143deriving instance Show (TxBodyErrorAutoBalance era )
143144
@@ -203,6 +204,8 @@ instance Error (TxBodyErrorAutoBalance era) where
203204 , " \n Balance (UTxO value - deposits): "
204205 , pshow balance
205206 ]
207+ TxBodyErrorMakeUnsignedTx err ->
208+ prettyError err
206209
207210-- | Use when you do not have access to the UTxOs you intend to spend
208211estimateBalancedTxBody
@@ -254,12 +257,14 @@ estimateBalancedTxBody
254257data TxFeeEstimationError era
255258 = TxFeeEstimationScriptExecutionError (TxBodyErrorAutoBalance (LedgerEra era ))
256259 | TxFeeEstimationBalanceError (TxBodyErrorAutoBalance (LedgerEra era ))
260+ | TxFeeEstimationMakeUnsignedTxError MakeUnsignedTxError
257261 deriving Show
258262
259263instance Error (TxFeeEstimationError era ) where
260264 prettyError = \ case
261265 TxFeeEstimationScriptExecutionError e -> prettyError e
262266 TxFeeEstimationBalanceError e -> prettyError e
267+ TxFeeEstimationMakeUnsignedTxError e -> prettyError e
263268
264269-- | Use when you do not have access to the UTxOs you intend to spend
265270estimateBalancedTxBody'
@@ -365,17 +370,18 @@ estimateBalancedTxBody'
365370 -- Step 3. Create a tx body with out max lovelace fee. This is strictly for
366371 -- calculating our fee with evaluateTransactionFee.
367372 let maxLovelaceFee = L. Coin (2 ^ (32 :: Integer ) - 1 )
368- let txbody1ForFeeEstimateOnly =
369- makeUnsignedTx
370- useEra
371- txbodycontent1
372- { txFee = maxLovelaceFee
373- , txOuts =
374- obtainCommonConstraints (useEra @ era ) (TxOut changeTxOut)
375- : txOuts txbodycontent
376- , txReturnCollateral = mDummyReturnCollateral
377- , txTotalCollateral = mDummyTotalCollateral
378- }
373+ txbody1ForFeeEstimateOnly <-
374+ first TxFeeEstimationMakeUnsignedTxError $
375+ makeUnsignedTx
376+ useEra
377+ txbodycontent1
378+ { txFee = maxLovelaceFee
379+ , txOuts =
380+ obtainCommonConstraints (useEra @ era ) (TxOut changeTxOut)
381+ : txOuts txbodycontent
382+ , txReturnCollateral = mDummyReturnCollateral
383+ , txTotalCollateral = mDummyTotalCollateral
384+ }
379385 let fee =
380386 evaluateTransactionFee
381387 pparams
@@ -400,8 +406,8 @@ estimateBalancedTxBody'
400406 -- 1. The original outputs
401407 -- 2. Tx fee
402408 -- 3. Return and total collateral
403- let
404- txbody2 =
409+ txbody2 <-
410+ first TxFeeEstimationMakeUnsignedTxError $
405411 makeUnsignedTx
406412 useEra
407413 txbodycontent1
@@ -1420,10 +1426,11 @@ makeTransactionBodyAutoBalance
14201426 -- 3. update tx with fees
14211427 -- 4. balance the transaction and update tx change output
14221428
1423- let txbodyForChange =
1424- makeUnsignedTx
1425- useEra
1426- txbodycontent
1429+ txbodyForChange <-
1430+ first TxBodyErrorMakeUnsignedTx $
1431+ makeUnsignedTx
1432+ useEra
1433+ txbodycontent
14271434
14281435 let initialChangeTxOutValue :: Ledger. Value (LedgerEra era ) =
14291436 evaluateTransactionBalance pp poolids stakeDelegDeposits drepDelegDeposits utxo txbodyForChange
@@ -1441,13 +1448,14 @@ makeTransactionBodyAutoBalance
14411448 -- scripts execution costs.
14421449 -- TODO: The txbody is made (leder tx) so this
14431450 -- is where the execution units map is made
1444- let UnsignedTx txbody =
1445- makeUnsignedTx
1446- useEra
1447- ( txbodycontent
1448- & modTxOuts
1449- (<> [initialChangeTxOut])
1450- )
1451+ UnsignedTx txbody <-
1452+ first TxBodyErrorMakeUnsignedTx $
1453+ makeUnsignedTx
1454+ useEra
1455+ ( txbodycontent
1456+ & modTxOuts
1457+ (<> [initialChangeTxOut])
1458+ )
14511459 let exUnitsMapWithLogs =
14521460 evaluateTransactionExecutionUnits
14531461 systemstart
@@ -1479,17 +1487,18 @@ makeTransactionBodyAutoBalance
14791487 let maxLovelaceFee = L. Coin (2 ^ (32 :: Integer ) - 1 )
14801488 -- Make a txbody that we will use for calculating the fees.
14811489 let (maybeDummyReturnTxCollateral, maybeDummyTotalTxCollateral) = maybeDummyTotalCollAndCollReturnOutput txbodycontent changeaddr
1482- let txbody1 =
1483- makeUnsignedTx
1484- useEra
1485- txbodycontent1
1486- { txFee = maxLovelaceFee
1487- , txReturnCollateral = maybeDummyReturnTxCollateral
1488- , txTotalCollateral = maybeDummyTotalTxCollateral
1489- , txOuts =
1490- txOuts txbodycontent
1491- <> [initialChangeTxOut]
1492- }
1490+ txbody1 <-
1491+ first TxBodyErrorMakeUnsignedTx $
1492+ makeUnsignedTx
1493+ useEra
1494+ txbodycontent1
1495+ { txFee = maxLovelaceFee
1496+ , txReturnCollateral = maybeDummyReturnTxCollateral
1497+ , txTotalCollateral = maybeDummyTotalTxCollateral
1498+ , txOuts =
1499+ txOuts txbodycontent
1500+ <> [initialChangeTxOut]
1501+ }
14931502
14941503 -- NB: This has the potential to over estimate the fees because estimateTransactionKeyWitnessCount
14951504 -- makes the conservative assumption that all inputs are from distinct
@@ -1521,14 +1530,15 @@ makeTransactionBodyAutoBalance
15211530 -- does not matter, instead it's just the values of the fee and outputs.
15221531 -- Here we do not want to start with any change output, since that's what
15231532 -- we need to calculate.
1524- let txbody2 =
1525- makeUnsignedTx
1526- useEra
1527- txbodycontent1
1528- { txFee = fee
1529- , txReturnCollateral = maybeReturnTxCollateral
1530- , txTotalCollateral = maybeTotalTxCollateral
1531- }
1533+ txbody2 <-
1534+ first TxBodyErrorMakeUnsignedTx $
1535+ makeUnsignedTx
1536+ useEra
1537+ txbodycontent1
1538+ { txFee = fee
1539+ , txReturnCollateral = maybeReturnTxCollateral
1540+ , txTotalCollateral = maybeTotalTxCollateral
1541+ }
15321542
15331543 case useEra @ era of
15341544 DijkstraEra -> error " makeTransactionBodyAutoBalance: DijkstraEra not supported"
@@ -1566,10 +1576,11 @@ makeTransactionBodyAutoBalance
15661576 , txReturnCollateral = maybeReturnTxCollateral
15671577 , txTotalCollateral = maybeTotalTxCollateral
15681578 }
1569- let txbody3 =
1570- makeUnsignedTx
1571- useEra
1572- finalTxBodyContent
1579+ txbody3 <-
1580+ first TxBodyErrorMakeUnsignedTx $
1581+ makeUnsignedTx
1582+ useEra
1583+ finalTxBodyContent
15731584 return
15741585 (txbody3, finalTxBodyContent)
15751586
0 commit comments