-
Notifications
You must be signed in to change notification settings - Fork 756
Expand file tree
/
Copy pathAction.hs
More file actions
77 lines (67 loc) · 3.06 KB
/
Copy pathAction.hs
File metadata and controls
77 lines (67 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{-# LANGUAGE GADTs #-}
{-|
Module : Cardano.Benchmarking.Script.Action
Description : Convert an 'Action' to a monadic 'ActionM'.
This is just exporting 'action', and 'liftToAction' is tough
to use because of the risk of circular imports.
-}
module Cardano.Benchmarking.Script.Action
( action
, liftToAction
)
where
import Cardano.Benchmarking.OuroborosImports as Core (protocolToNetworkId)
import Cardano.Benchmarking.Script.Core
import Cardano.Benchmarking.Script.Env
import Cardano.Benchmarking.Script.Types
import Cardano.Benchmarking.Tracer
import Cardano.TxGenerator.Setup.NodeConfig
import Cardano.TxGenerator.Types (TxGenError)
import Control.Monad.IO.Class
import Control.Monad.Trans.Except.Extra
import qualified Data.Text as Text (unpack)
-- | 'action' has as its sole callers
-- 'Cardano.Benchmark.Script.runScript' from "Cardano.Benchmark.Script"
-- and 'Cardano.Benchmark.Script.Selftest' from
-- "Cardano.Benchmark.Script.Selftest".
-- It translates the various cases of the 'Action' to monadic values
-- which execute the specified actions when evaluated. It passes all
-- the cases' fields to functions with very similar names to the
-- constructors.
action :: Action -> ActionM ()
action a = case a of
SetNetworkId val -> setEnvNetworkId val
SetSocketPath val -> setEnvSocketPath val
InitWallet name -> initWallet name
SetProtocolParameters p -> setProtocolParameters p
StartProtocol configFile cardanoTracerSocket -> startProtocol configFile cardanoTracerSocket
ReadSigningKey name filePath -> readSigningKey name filePath
DefineSigningKey name descr -> defineSigningKey name descr
AddFund era wallet txIn lovelace keyName -> addFund era wallet txIn lovelace keyName
Delay t -> delay t
Submit era submitMode txParams generator -> submitAction era submitMode generator txParams
WaitBenchmark -> waitBenchmark
CancelBenchmark -> cancelBenchmark
WaitForEra era -> waitForEra era
LogMsg txt -> traceDebug $ Text.unpack txt
Reserved options -> reserved options
-- | 'liftToAction' first lifts from IO, then converts an 'Either'
-- to an 'Control.Monad.Trans.Except.ExceptT' and then transforms
-- the error type to 'Cardano.Benchmarking.Script.Env.Error'.
liftToAction :: IO (Either TxGenError a) -> ActionM a
liftToAction = firstExceptT TxGenError . newExceptT . liftIO
-- | 'startProtocol' sets up the protocol for the transaction
-- generator from the first argument, @configFile@ and optionally
-- traces to the second, @tracerSocket@.
startProtocol :: FilePath -> Maybe FilePath -> ActionM ()
startProtocol configFile tracerSocket = do
nodeConfig <- liftToAction $ mkNodeConfig configFile
protocol <- liftToAction $ mkConsensusProtocol nodeConfig
setEnvProtocol protocol
setEnvGenesis $ getGenesis protocol
iomgr <- askIOManager
networkId <- liftIO $ protocolToNetworkId protocol
let
tracerSocket' = (,,) iomgr networkId `fmap` tracerSocket
setEnvNetworkId networkId
liftIO (initTxGenTracers tracerSocket') >>= setBenchTracers