From 1d41352d61a52ab94237e12c6a4efd29fe19a447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jann=20M=C3=BCller?= Date: Fri, 11 Aug 2023 09:39:34 +0200 Subject: [PATCH] mockchain: instance MonadTrans MockchainT --- changelog.md | 1 + src/mockchain/convex-mockchain.cabal | 1 + src/mockchain/lib/Convex/MockChain.hs | 12 ++++++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 37ec0779..16359cad 100644 --- a/changelog.md +++ b/changelog.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `convex-mockchain`: - `Convex.MockChain`: Support for profiling plutus scripts. `evaluateTx` returns the script contexts for a transaction. These can be turned into a fully applied script with `fullyAppliedScript`. - `Convex.MockChain`: Export `fromLedgerUTxO` + - `Convex.MockChain`: `MonadTrans` instance for `MockchainT`, export constructor * Add `querySlotNo` to `MonadBlockchain` typeclass and update both blockchain and mockchain implementations. * Add `utcTimeToPosixTime` in `Convex.Utils`. * Considering explicit error type `MonadBlockchainError` for `MonadBlockchainCardanoNodeT` to enable proper error handling by caller. diff --git a/src/mockchain/convex-mockchain.cabal b/src/mockchain/convex-mockchain.cabal index f5c1017d..a0ef66b9 100644 --- a/src/mockchain/convex-mockchain.cabal +++ b/src/mockchain/convex-mockchain.cabal @@ -42,6 +42,7 @@ library time, data-default, mtl, + transformers, HUnit, bytestring diff --git a/src/mockchain/lib/Convex/MockChain.hs b/src/mockchain/lib/Convex/MockChain.hs index 47b13836..6aea23aa 100644 --- a/src/mockchain/lib/Convex/MockChain.hs +++ b/src/mockchain/lib/Convex/MockChain.hs @@ -38,7 +38,7 @@ module Convex.MockChain( fullyAppliedScript, -- * Mockchain implementation MockchainError(..), - MockchainT, + MockchainT(..), Mockchain, runMockchainT, runMockchain, @@ -95,6 +95,7 @@ import Control.Monad.Reader (ReaderT, ask, asks, runReaderT) import Control.Monad.State (StateT, get, gets, modify, put, runStateT) +import Control.Monad.Trans.Class (MonadTrans (..)) import Convex.Class (MonadBlockchain (..), MonadMockchain (..)) import Convex.Era (ERA) @@ -277,15 +278,15 @@ constructValidated pv globals (UtxoEnv _ pp _ _) st tx = AlonzoTx (body tx) (wits tx) -- (getField @"wits" tx) - (IsValid (lift scriptEvalResult)) + (IsValid (lift_ scriptEvalResult)) (auxiliaryData tx) -- (getField @"auxiliaryData" tx) in pure (vTx, sLst) where utxo = utxosUtxo st sysS = systemStart globals ei = epochInfo globals - lift (Passes _) = True - lift (Fails _ _) = False + lift_ (Passes _) = True + lift_ (Fails _ _) = False applyTx :: NodeParams -> @@ -300,6 +301,9 @@ applyTx params oldState@MockChainState{mcsEnv, mcsPoolState} tx context = do newtype MockchainT m a = MockchainT (ReaderT NodeParams (StateT MockChainState (ExceptT MockchainError m)) a) deriving newtype (Functor, Applicative, Monad) +instance MonadTrans MockchainT where + lift = MockchainT . lift . lift . lift + data MockchainError = MockchainValidationFailed ValidationError | FailWith String