Skip to content

Commit

Permalink
evaluateTransactionExecutionUnitsShelley: return logs
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jun 14, 2024
1 parent 833e8c0 commit 8baad9b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import qualified Ouroboros.Consensus.HardFork.History as Consensus
import qualified PlutusLedgerApi.V1 as Plutus

import Control.Monad (forM_)
import Data.Bifunctor (bimap, first)
import Data.Bifunctor (bimap, first, second)
import Data.ByteString.Short (ShortByteString)
import Data.Foldable (toList)
import Data.Function ((&))
Expand Down Expand Up @@ -618,7 +618,7 @@ evaluateTransactionExecutionUnits :: forall era. ()
-> UTxO era
-> TxBody era
-> Either (TransactionValidityError era)
(Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
(Map ScriptWitnessIndex (Either ScriptExecutionError ([Text.Text], ExecutionUnits)))
evaluateTransactionExecutionUnits era systemstart epochInfo pp utxo txbody =
case makeSignedTransaction' era [] txbody of
ShelleyTx sbe tx' -> evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo pp utxo tx'
Expand All @@ -631,11 +631,11 @@ evaluateTransactionExecutionUnitsShelley :: forall era. ()
-> UTxO era
-> L.Tx (ShelleyLedgerEra era)
-> Either (TransactionValidityError era)
(Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
(Map ScriptWitnessIndex (Either ScriptExecutionError ([Text.Text], ExecutionUnits)))
evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo (LedgerProtocolParameters pp) utxo tx =
caseShelleyToMaryOrAlonzoEraOnwards
(const (Right Map.empty))
(\w -> case alonzoEraOnwardsConstraints w $ L.evalTxExUnits pp tx (toLedgerUTxO sbe utxo) ledgerEpochInfo systemstart of
(\w -> case alonzoEraOnwardsConstraints w $ L.evalTxExUnitsWithLogs pp tx (toLedgerUTxO sbe utxo) ledgerEpochInfo systemstart of
Left err -> Left $ alonzoEraOnwardsConstraints w
$ TransactionValidityTranslationError err
Right exmap -> Right (fromLedgerScriptExUnitsMap w exmap)
Expand All @@ -648,12 +648,12 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo (LedgerProtoc
:: Alonzo.AlonzoEraScript (ShelleyLedgerEra era)
=> AlonzoEraOnwards era
-> Map (L.PlutusPurpose L.AsIx (ShelleyLedgerEra era))
(Either (L.TransactionScriptFailure (ShelleyLedgerEra era)) Alonzo.ExUnits)
-> Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)
(Either (L.TransactionScriptFailure (ShelleyLedgerEra era)) ([Text.Text], Alonzo.ExUnits))
-> Map ScriptWitnessIndex (Either ScriptExecutionError ([Text.Text], ExecutionUnits))
fromLedgerScriptExUnitsMap aOnwards exmap =
Map.fromList
[ (toScriptIndex aOnwards rdmrptr,
bimap (fromAlonzoScriptExecutionError aOnwards) fromAlonzoExUnits exunitsOrFailure)
bimap (fromAlonzoScriptExecutionError aOnwards) (second fromAlonzoExUnits) exunitsOrFailure)
| (rdmrptr, exunitsOrFailure) <- Map.toList exmap ]

fromAlonzoScriptExecutionError
Expand Down Expand Up @@ -980,13 +980,14 @@ makeTransactionBodyAutoBalance sbe systemstart history lpp@(LedgerProtocolParame
-- 1,2,4 or 8 bytes?
}

exUnitsMap <- first TxBodyErrorValidityInterval $
evaluateTransactionExecutionUnits
era
systemstart history
lpp
utxo
txbody0
exUnitsMapWithLogs <- first TxBodyErrorValidityInterval $
evaluateTransactionExecutionUnits
era
systemstart history
lpp
utxo
txbody0
let exUnitsMap = Map.map (fmap snd) exUnitsMapWithLogs

exUnitsMap' <-
case Map.mapEither id exUnitsMap of
Expand Down

0 comments on commit 8baad9b

Please sign in to comment.