Skip to content

Commit

Permalink
Map ErrScriptExecutionFailed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Aug 6, 2024
1 parent ec5e666 commit b5d5e3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions hydra-node/src/Hydra/Chain/Direct/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ finalizeTx TinyWallet{sign, coverFee} ctx utxo userUTxO partialTx = do
throwIO (NoFuelUTXOFound :: PostTxError Tx)
Left ErrNotEnoughFunds{} ->
throwIO (NotEnoughFuel :: PostTxError Tx)
Left ErrScriptExecutionFailed{scriptFailure = (redeemerPtr, scriptFailure)} ->
Left ErrScriptExecutionFailed{redeemerPointer, scriptFailure} ->
throwIO
( ScriptFailedInWallet
{ redeemerPtr = show redeemerPtr
, failureReason = show scriptFailure
{ redeemerPtr = redeemerPointer
, failureReason = scriptFailure
} ::
PostTxError Tx
)
Expand Down
14 changes: 11 additions & 3 deletions hydra-node/src/Hydra/Chain/Direct/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import Cardano.Ledger.Shelley.API qualified as Ledger
import Cardano.Ledger.Val (invert)
import Cardano.Slotting.EpochInfo (EpochInfo)
import Cardano.Slotting.Time (SystemStart (..))
import Control.Arrow (left)
import Control.Concurrent.Class.MonadSTM (check, newTVarIO, readTVarIO, writeTVar)
import Control.Lens (view, (%~), (.~), (^.))
import Data.List qualified as List
Expand Down Expand Up @@ -242,7 +241,7 @@ data ErrCoverFee
= ErrNotEnoughFunds ChangeError
| ErrNoFuelUTxOFound
| ErrUnknownInput {input :: TxIn}
| ErrScriptExecutionFailed {scriptFailure :: Text} -- FIXME: try to avoid Text
| ErrScriptExecutionFailed {redeemerPointer :: Text, scriptFailure :: Text} -- FIXME: try to avoid Text
| ErrTranslationError (ContextError LedgerEra)
deriving stock (Show)

Expand Down Expand Up @@ -428,13 +427,22 @@ estimateScriptsCost ::
Tx era ->
Either ErrCoverFee (Map (PlutusPurpose AsIx era) ExUnits)
estimateScriptsCost pparams systemStart epochInfo utxo tx = do
Map.traverseWithKey (\ptr -> left $ ErrScriptExecutionFailed . show) $
Map.traverseWithKey convertResult $
evalTxExUnits
pparams
tx
(Ledger.UTxO utxo)
epochInfo
systemStart
where
convertResult ptr = \case
Right exUnits -> Right exUnits
Left failure ->
Left $
ErrScriptExecutionFailed
{ redeemerPointer = show ptr
, scriptFailure = show failure
}

--
-- Logs
Expand Down

0 comments on commit b5d5e3c

Please sign in to comment.