@@ -62,49 +62,85 @@ instance HasDefinitions MyContracts where
6262 MyContract. contract params
6363```
6464
65- 3 . Write your main entrypoint for the application, with the preferred configurations
65+ 3 . Write your main entrypoint for the application and the configuration file
6666
6767``` haskell
68- import BotPlutusInterface.Types (CLILocation (Local ), LogLevel (Debug ), PABConfig (.. ))
69- import Cardano.Api (NetworkId (Testnet ), NetworkMagic (.. ))
70- import Data.Aeson qualified as JSON
71- import Data.ByteString.Lazy qualified as LazyByteString
72- import Data.Default (def )
73- import Servant.Client.Core (BaseUrl (BaseUrl ), Scheme (Http ))
68+ import BotPlutusInterface qualified
69+ import BotPlutusInterface.Config qualified as BotPlutusInterface
70+ import Prelude
7471
7572main :: IO ()
7673main = do
77- protocolParams <- JSON. decode <$> LazyByteString. readFile " protocol.json"
78- let pabConf =
79- PABConfig
80- { -- Calling the cli locally or through an ssh connection
81- pcCliLocation = Local
82- , pcNetwork = Testnet (NetworkMagic 42 )
83- , pcChainIndexUrl = BaseUrl Http " localhost" 9083 " "
84- , pcPort = 9080
85- , pcProtocolParams = protocolParams
86- , pcTipPollingInterval = 10_000_000
87- , -- | Slot configuration of the network, the default value can be used for the mainnet
88- pcSlotConfig = def
89- , pcOwnPubKeyHash = " 0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
90- , -- Directory name of the script and data files
91- pcScriptFileDir = " ./scripts"
92- , -- Directory for the signing key file(s)
93- pcSigningKeyFileDir = " ./signing-keys"
94- , -- Directory where the encoded transaction files will be saved
95- pcTxFileDir = " ./txs"
96- , -- Dry run mode will build the tx, but skip the submit step
97- pcDryRun = False
98- , pcLogLevel = Debug
99- , -- | Forced budget for scripts, as optional (CPU Steps, Memory Units)
100- pcForceBudget = Nothing
101- , -- Protocol params file location relative to the cardano-cli working directory (needed for the cli)
102- , pcProtocolParamsFile = " ./protocol.json"
103- , pcEnableTxEndpoint = True
104- }
74+ pabConf <-
75+ either error id
76+ <$> BotPlutusInterface. loadPABConfig " config/pabConfig.value"
10577 BotPlutusInterface. runPAB @ MyContracts pabConf
10678```
10779
80+ Configuration format (example: <examples/plutus-game/config/pabConfig.value>):
81+
82+ ``` console
83+ $ cabal repl --disable-optimisation --repl-options -Wwarn
84+ ...
85+ BotPlutusInterface> :m Prelude
86+ ...
87+ Prelude> :l BotPlutusInterface.Config
88+ ...
89+ Prelude BotPlutusInterface.Config> putStrLn docPABConfig
90+ Top-level configuration file fields:
91+ cliLocation: `local` or destination text
92+ calling the cli through ssh when set to destination (default:
93+ local)
94+ chainIndexUrl: url text
95+ (default: "http://localhost:9083")
96+ networkId: `mainnet` or 32-bit unsigned integral number
97+ (default: 42)
98+ slotConfig: SlotConfig configuration
99+ (see default in example)
100+ scriptFileDir: path text
101+ Directory name of the script and data files (default:
102+ "./result-scripts")
103+ signingKeyFileDir: path text
104+ Directory name of the signing key files (default: "./signing-keys")
105+ txFileDir: path text
106+ Directory name of the transaction files (default: "./txs")
107+ protocolParamsFile: filepath text
108+ Protocol params file location relative to the cardano-cli working
109+ directory (needed for the cli) in JSON format. (default:
110+ "./protocol.json")
111+ dryRun: `true` or `false`
112+ Dry run mode will build the tx, but skip the submit step (default:
113+ true)
114+ logLevel: `error` or `warn` or `notice` or `info` or `debug`
115+ (default: info)
116+ ownPubKeyHash: PubKeyHash text
117+ (default: "")
118+ ownStakePubKeyHash: `nothing` or StakePubKeyHash text
119+ (default: nothing)
120+ tipPollingInterval: non-negative integral number
121+ (default: 10000000)
122+ forceBudget: `nothing` or ExecutionUnits configuration
123+ Forced budget for scripts, as optional (CPU Steps, Memory Units)
124+ (default: nothing)
125+ port: port non-negative integral number
126+ (default: 9080)
127+ enableTxEndpoint: `true` or `false`
128+ (default: false)
129+
130+ ExecutionUnits configuration
131+ steps: REQUIRED non-negative integral number
132+ This corresponds roughly to the time to execute a script.
133+ memory: REQUIRED non-negative integral number
134+ This corresponds roughly to the peak memory used during script
135+ execution.
136+
137+ SlotConfig configuration
138+ length: REQUIRED integral number
139+ Length (number of milliseconds) of one slot
140+ zeroTime: REQUIRED integral number
141+ Beginning of slot 0 (in milliseconds)
142+ ```
143+
108144To run the fake PAB, you need to prepare a few more things:
109145
1101464 . Save the protocol params file to the root folder of your project using the cardano-cli
@@ -128,6 +164,7 @@ The fake PAB consists of the following modules:
128164
129165- ** BotPlutusInterface** main entry point
130166- ** BotPlutusInterface.Server** Servant server, handling http endpoint calls and websockets
167+ - ** BotPlutusInterface.Config** load/save PAB configuration file
131168- ** BotPlutusInterface.Contract** handling contract effects by creating the necessary files and calling cardano-cli commands (a few effects are mocked)
132169- ** BotPlutusInterface.Balance** doing some preparations so the cli can process the rest (non-ada asset balancing, addig tx inputs, adding minimum lovelaces, add signatories)
133170- ** BotPlutusInterface.CardanoCLI** wrappers for cardano-cli commands
0 commit comments