@@ -62,50 +62,76 @@ 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+ d601900dab2e364aea1084bcb8281116e4724309
69+ import Prelude
7470
7571main :: IO ()
7672main = 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 = Just 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- , pcOwnStakePubKeyHash = Nothing
91- , -- Directory name of the script and data files
92- pcScriptFileDir = " ./scripts"
93- , -- Directory for the signing key file(s)
94- pcSigningKeyFileDir = " ./signing-keys"
95- , -- Directory where the encoded transaction files will be saved
96- pcTxFileDir = " ./txs"
97- , -- Dry run mode will build the tx, but skip the submit step
98- pcDryRun = False
99- , pcLogLevel = Debug
100- , -- Protocol params file location relative to the cardano-cli working directory (needed for the cli)
101- , pcProtocolParamsFile = " ./protocol.json"
102- , pcEnableTxEndpoint = True
103- -- Save some stats during contract run (only transactions execution budgets supported atm)
104- , pcCollectStats = False
105- }
73+ pabConf <-
74+ either error id
75+ <$> BotPlutusInterface. loadPABConfig " ./pabConfig.value"
10676 BotPlutusInterface. runPAB @ MyContracts pabConf
10777```
10878
79+ Configuration format (example: <examples/plutus-game/pabConfig.value>):
80+
81+ ``` console
82+ $ cabal repl --disable-optimisation --repl-options -Wwarn
83+ ...
84+ BotPlutusInterface> :m Prelude
85+ ...
86+ Prelude> :l BotPlutusInterface.Config
87+ ...
88+ Prelude BotPlutusInterface.Config> putStrLn docPABConfig
89+ Top-level configuration file fields:
90+ cliLocation: `local` or destination text
91+ calling the cli through ssh when set to destination (default:
92+ local)
93+ chainIndexUrl: url text
94+ (default: "http://localhost:9083")
95+ networkId: case insensitive `mainnet` atom or 32-bit unsigned integral number
96+ (default: 42)
97+ scriptFileDir: path text
98+ Directory name of the script and data files (default:
99+ "./result-scripts")
100+ signingKeyFileDir: path text
101+ Directory name of the signing key files (default: "./signing-keys")
102+ txFileDir: path text
103+ Directory name of the transaction files (default: "./txs")
104+ metadataDir: path text
105+ Directory name of metadata files (default: "/metadata")
106+ protocolParamsFile: filepath text
107+ Protocol params file location relative to the cardano-cli working
108+ directory (needed for the cli) in JSON format. (default:
109+ "./protocol.json")
110+ dryRun: `true` or `false`
111+ Dry run mode will build the tx, but skip the submit step (default:
112+ true)
113+ logLevel: `error` or `warn` or `notice` or `info` or `debug`
114+ (default: info)
115+ ownPubKeyHash: PubKeyHash text
116+ (default: "")
117+ ownStakePubKeyHash: case insensitive `nothing` atom or StakePubKeyHash text
118+ (default: nothing)
119+ tipPollingInterval: non-negative integral number
120+ (default: 10000000)
121+ port: port non-negative integral number
122+ (default: 9080)
123+ enableTxEndpoint: `true` or `false`
124+ (default: false)
125+ collectStats: `true` or `false`
126+ Save some stats during contract run (only transactions execution
127+ budgets supported atm) (default: false)
128+ collectLogs: `true` or `false`
129+ Save logs from contract execution: pab request logs and contract
130+ logs (default: false)
131+ budgetMultiplier: rational multiplier in form `1` or `1 % 2`
132+ (default: 1)
133+ ```
134+
109135To run the fake PAB, you need to prepare a few more things:
110136
1111374 . Save the protocol params file to the root folder of your project using the cardano-cli
@@ -129,6 +155,7 @@ The fake PAB consists of the following modules:
129155
130156- ** BotPlutusInterface** main entry point
131157- ** BotPlutusInterface.Server** Servant server, handling http endpoint calls and websockets
158+ - ** BotPlutusInterface.Config** load/save PAB configuration file
132159- ** BotPlutusInterface.Contract** handling contract effects by creating the necessary files and calling cardano-cli commands (a few effects are mocked)
133160- ** BotPlutusInterface.Balance** doing some preparations so the cli can process the rest (non-ada asset balancing, addig tx inputs, adding minimum lovelaces, add signatories)
134161- ** BotPlutusInterface.CardanoCLI** wrappers for cardano-cli commands
0 commit comments