Skip to content

Commit f983f82

Browse files
committed
Merge branch 'master' of github.com:mlabs-haskell/bot-plutus-interface into gergely/vasil
2 parents d601900 + d882ffb commit f983f82

37 files changed

+2330
-404
lines changed

README.md

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7571
main :: IO ()
7672
main = 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+
109135
To run the fake PAB, you need to prepare a few more things:
110136

111137
4. 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

bot-plutus-interface.cabal

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,36 @@ library
8080
BotPlutusInterface.BodyBuilder
8181
BotPlutusInterface.CardanoCLI
8282
BotPlutusInterface.ChainIndex
83+
BotPlutusInterface.Config
8384
BotPlutusInterface.Contract
8485
BotPlutusInterface.Effects
8586
BotPlutusInterface.ExBudget
8687
BotPlutusInterface.Files
8788
BotPlutusInterface.Helpers
8889
BotPlutusInterface.QueryNode
8990
BotPlutusInterface.Server
91+
BotPlutusInterface.TimeSlot
9092
BotPlutusInterface.Types
9193
BotPlutusInterface.UtxoParser
94+
PlutusConfig.Base
95+
PlutusConfig.Cardano.Api
96+
PlutusConfig.Cardano.Api.Shelley
97+
PlutusConfig.Ledger
98+
PlutusConfig.Misc
99+
PlutusConfig.Types
92100

93101
build-depends:
94-
, aeson ^>=1.5.0.0
102+
, aeson
95103
, attoparsec >=0.13.2.2
96104
, bytestring ^>=0.10.12.0
97105
, cardano-api
98106
, cardano-crypto
99107
, cardano-ledger-alonzo
108+
, cardano-ledger-core
100109
, cardano-prelude
101110
, cardano-slotting
111+
, config-schema
112+
, config-value
102113
, containers
103114
, data-default
104115
, data-default-class
@@ -113,6 +124,7 @@ library
113124
, lens
114125
, memory
115126
, mtl
127+
, ouroboros-consensus
116128
, playground-common
117129
, plutus-chain-index
118130
, plutus-chain-index-core
@@ -125,22 +137,30 @@ library
125137
, plutus-script-utils
126138
, plutus-tx
127139
, plutus-tx-plugin
140+
, pretty
141+
, prettyprinter
128142
, process
129143
, QuickCheck
144+
, regex-compat
130145
, row-types
131146
, serialise
132147
, servant
133148
, servant-client
149+
, servant-client-core
134150
, servant-server
135151
, servant-websockets
136152
, split
137153
, stm
154+
, temporary
138155
, text ^>=1.2.4.0
156+
, time
157+
, tostring
139158
, transformers
140159
, transformers-either
141160
, transformers-except
142161
, unordered-containers
143162
, uuid
163+
, vector
144164
, wai
145165
, warp
146166
, websockets
@@ -154,14 +174,16 @@ test-suite bot-plutus-interface-test
154174
ghc-options: -fplugin-opt PlutusTx.Plugin:defer-errors
155175
other-modules:
156176
Spec.BotPlutusInterface.Balance
177+
Spec.BotPlutusInterface.Config
157178
Spec.BotPlutusInterface.Contract
158179
Spec.BotPlutusInterface.ContractStats
159180
Spec.BotPlutusInterface.Server
181+
Spec.BotPlutusInterface.TxStatusChange
160182
Spec.BotPlutusInterface.UtxoParser
161183
Spec.MockContract
162184

163185
build-depends:
164-
, aeson ^>=1.5.0.0
186+
, aeson
165187
, attoparsec
166188
, base
167189
, base-compat
@@ -195,6 +217,7 @@ test-suite bot-plutus-interface-test
195217
, plutus-script-utils
196218
, plutus-tx
197219
, plutus-tx-plugin
220+
, prettyprinter
198221
, QuickCheck
199222
, quickcheck-instances
200223
, row-types

cabal.project

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@ packages: ./bot-plutus-interface.cabal
77

88
tests: true
99
benchmarks: true
10-
11-
allow-newer:
12-
*:aeson
13-
, size-based:template-haskell
14-
15-
constraints:
16-
aeson >= 2
17-
, hedgehog >= 1.1

examples/plutus-game/app/Main.hs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,22 @@
33
module Main (main) where
44

55
import BotPlutusInterface qualified
6+
import BotPlutusInterface.Config qualified as BotPlutusInterface
67
import BotPlutusInterface.Types (
7-
CLILocation (Local),
88
HasDefinitions (..),
9-
LogLevel (Debug),
10-
PABConfig (..),
119
SomeBuiltin (..),
1210
endpointsToSchemas,
1311
)
14-
import Cardano.Api (NetworkId (Testnet), NetworkMagic (..))
1512
import Cardano.PlutusExample.Game (
1613
GameSchema,
1714
GuessParams,
1815
LockParams,
1916
guess,
2017
lock,
2118
)
22-
import Data.Aeson qualified as JSON
2319
import Data.Aeson.TH (defaultOptions, deriveJSON)
24-
import Data.ByteString.Lazy qualified as LazyByteString
25-
import Data.Default (def)
26-
import Data.Maybe (fromMaybe)
2720
import Playground.Types (FunctionSchema)
2821
import Schema (FormSchema)
29-
import Servant.Client.Core (BaseUrl (BaseUrl), Scheme (Http))
3022
import Prelude
3123

3224
instance HasDefinitions GameContracts where
@@ -48,28 +40,7 @@ $(deriveJSON defaultOptions ''GameContracts)
4840

4941
main :: IO ()
5042
main = do
51-
protocolParams <-
52-
fromMaybe (error "protocol.json file not found") . JSON.decode
53-
<$> LazyByteString.readFile "protocol.json"
54-
let pabConf =
55-
PABConfig
56-
{ pcCliLocation = Local
57-
, pcNetwork = Testnet (NetworkMagic 9)
58-
, pcChainIndexUrl = BaseUrl Http "localhost" 9083 ""
59-
, pcPort = 9080
60-
, pcProtocolParams = protocolParams
61-
, pcTipPollingInterval = 10_000_000
62-
, pcSlotConfig = def
63-
, pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
64-
, pcOwnStakePubKeyHash = Nothing
65-
, pcScriptFileDir = "./scripts"
66-
, pcSigningKeyFileDir = "./signing-keys"
67-
, pcTxFileDir = "./txs"
68-
, pcDryRun = True
69-
, pcLogLevel = Debug
70-
, pcProtocolParamsFile = "./protocol.json"
71-
, pcEnableTxEndpoint = True
72-
, pcMetadataDir = "./metadata"
73-
, pcCollectStats = False
74-
}
43+
pabConf <-
44+
either error id
45+
<$> BotPlutusInterface.loadPABConfig "./pabConfig.value"
7546
BotPlutusInterface.runPAB @GameContracts pabConf

examples/plutus-game/cabal.project

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,3 @@ write-ghc-environment-files: never
1111
-- Always build tests and benchmarks.
1212
tests: true
1313
benchmarks: true
14-
15-
allow-newer:
16-
*:aeson
17-
, size-based:template-haskell
18-
19-
constraints:
20-
aeson >= 2
21-
, hedgehog >= 1.1
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- Calling the cli locally or through an ssh connection
2+
cliLocation: local
3+
chainIndexUrl: "http://localhost:9083"
4+
networkId: 9
5+
6+
-- Directory name of the script and data files
7+
scriptFileDir: "./scripts"
8+
9+
-- Directory for the signing key file(s)
10+
signingKeyFileDir: "./signing-keys"
11+
12+
-- Directory where the encoded transaction files will be saved
13+
txFileDir: "./txs"
14+
15+
-- Directory name of metadata files
16+
metadataDir: "./metadata"
17+
18+
-- Protocol params file location relative to the cardano-cli working directory (needed for the cli)
19+
protocolParamsFile: "./protocol.json"
20+
21+
-- Dry run mode will build the tx, but skip the submit step
22+
dryRun: true
23+
logLevel: debug
24+
ownPubKeyHash: "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
25+
ownStakePubKeyHash: nothing
26+
tipPollingInterval: 10000000
27+
port: 9080
28+
enableTxEndpoint: true
29+
30+
-- Save some stats during contract run (only transactions execution budgets supported atm)
31+
collectStats: false
32+
33+
-- Save logs from contract execution: pab request logs and contract logs
34+
collectLogs: false

examples/plutus-game/plutus-game.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ library
7474
import: common-lang
7575
exposed-modules: Cardano.PlutusExample.Game
7676
build-depends:
77-
, aeson ^>=1.5.0.0
77+
, aeson
7878
, attoparsec >=0.13.2.2
7979
, bot-plutus-interface
8080
, bytestring ^>=0.10.12.0
@@ -126,7 +126,7 @@ library
126126
executable plutus-game-pab
127127
import: common-lang
128128
build-depends:
129-
, aeson ^>=1.5.0.0
129+
, aeson
130130
, bot-plutus-interface
131131
, bytestring
132132
, cardano-api

0 commit comments

Comments
 (0)