Skip to content

Commit

Permalink
mockchain: instance MonadTrans MockchainT
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed Aug 11, 2023
1 parent 16abc34 commit 1d41352
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/mockchain/convex-mockchain.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ library
time,
data-default,
mtl,
transformers,
HUnit,
bytestring

Expand Down
12 changes: 8 additions & 4 deletions src/mockchain/lib/Convex/MockChain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Convex.MockChain(
fullyAppliedScript,
-- * Mockchain implementation
MockchainError(..),
MockchainT,
MockchainT(..),
Mockchain,
runMockchainT,
runMockchain,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 ->
Expand All @@ -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
Expand Down

0 comments on commit 1d41352

Please sign in to comment.