|
1 | 1 | {-# LANGUAGE AllowAmbiguousTypes #-} |
2 | 2 |
|
3 | | -module BotInterface.Run (execute, runWrapped) where |
| 3 | +module BotInterface.Run (runContract, runContract_) where |
4 | 4 |
|
5 | 5 | import BotInterface.Setup qualified as BIS |
6 | 6 | import BotInterface.Wallet (BpiWallet, ledgerPkh) |
7 | | -import BotPlutusInterface.Contract (runContract) |
| 7 | +import BotPlutusInterface.Contract qualified as BIC |
8 | 8 | import BotPlutusInterface.Types ( |
9 | 9 | CLILocation (Local), |
10 | 10 | ContractEnvironment (ContractEnvironment), |
@@ -32,39 +32,27 @@ import BotPlutusInterface.Types ( |
32 | 32 | ) |
33 | 33 | import Cardano.Api.ProtocolParameters (ProtocolParameters) |
34 | 34 | import Control.Concurrent.STM (newTVarIO, readTVarIO) |
| 35 | +import Control.Monad (void) |
35 | 36 | import Control.Monad.Catch (MonadCatch, handleAll) |
36 | 37 | import Control.Monad.IO.Class (MonadIO, liftIO) |
37 | | -import Control.Monad.Reader (MonadReader (ask), ReaderT (runReaderT)) |
| 38 | +import Control.Monad.Reader (MonadReader (ask), ReaderT) |
38 | 39 | import Data.Aeson (ToJSON, eitherDecodeFileStrict') |
39 | 40 | import Data.Kind (Type) |
40 | 41 | import Data.Row (Row) |
41 | | -import Data.Text (Text, pack) |
| 42 | +import Data.Text (pack) |
42 | 43 | import Data.UUID.V4 qualified as UUID |
43 | | -import LocalCluster.Types (ClusterEnv (chainIndexUrl, networkId)) |
| 44 | +import LocalCluster.Types (ClusterEnv (chainIndexUrl, networkId), FailReason (ContractErr, OtherErr), RunResult (RunFailed, RunSuccess)) |
44 | 45 | import Plutus.Contract (Contract) |
45 | 46 | import Plutus.PAB.Core.ContractInstance.STM (Activity (Active)) |
46 | 47 | import Wallet.Types (ContractInstanceId (ContractInstanceId)) |
47 | 48 |
|
48 | | -data FailReason e |
49 | | - = ContractErr e |
50 | | - | OtherErr Text |
51 | | - deriving stock (Show) |
52 | | - |
53 | | -data RunResult w e a |
54 | | - = RunSuccess |
55 | | - { contractResult :: a |
56 | | - , contractState :: ContractState w |
57 | | - } |
58 | | - | RunFailed {reason :: FailReason e} |
59 | | - deriving stock (Show) |
60 | | - |
61 | | -execute :: |
| 49 | +runContract :: |
62 | 50 | forall (w :: Type) (s :: Row Type) (e :: Type) (a :: Type) (m :: Type -> Type). |
63 | 51 | (ToJSON w, Monoid w, MonadIO m, MonadCatch m) => |
64 | 52 | BpiWallet -> |
65 | 53 | Contract w s e a -> |
66 | 54 | ReaderT ClusterEnv m (RunResult w e a) |
67 | | -execute bpiWallet contract = |
| 55 | +runContract bpiWallet contract = |
68 | 56 | ask |
69 | 57 | >>= readProtocolParams |
70 | 58 | >>= either |
@@ -101,15 +89,15 @@ execute bpiWallet contract = |
101 | 89 | , ceWallet = playGroundWallet |
102 | 90 | , ceContractInstanceId = contractInstanceID |
103 | 91 | } |
104 | | - res <- liftIO $ runContract contractEnv playGroundWallet contract |
| 92 | + res <- liftIO $ BIC.runContract contractEnv playGroundWallet contract |
105 | 93 | case res of |
106 | 94 | Left e -> return $ RunFailed (ContractErr e) |
107 | 95 | Right a -> RunSuccess a <$> liftIO (readTVarIO contractState) |
108 | 96 |
|
109 | | -runWrapped :: |
| 97 | +runContract_ :: |
| 98 | + forall (w :: Type) (s :: Row Type) (e :: Type) (a :: Type) (m :: Type -> Type). |
110 | 99 | (ToJSON w, Monoid w, MonadIO m, MonadCatch m) => |
111 | | - ClusterEnv -> |
112 | 100 | BpiWallet -> |
113 | 101 | Contract w s e a -> |
114 | | - m (RunResult w e a) |
115 | | -runWrapped cEnv bpiWallet contract = runReaderT (execute bpiWallet contract) cEnv |
| 102 | + ReaderT ClusterEnv m () |
| 103 | +runContract_ bpiWallet contract = void $ runContract bpiWallet contract |
0 commit comments