Skip to content

Commit 6df1da9

Browse files
Merge branch 'master' into node-update
2 parents 330c134 + dc7b54a commit 6df1da9

File tree

27 files changed

+1822
-198
lines changed

27 files changed

+1822
-198
lines changed

README.md

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,50 +62,77 @@ 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

7572
main :: IO ()
7673
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 = 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-
}
74+
pabConf <-
75+
either error id
76+
<$> BotPlutusInterface.loadPABConfig "./pabConfig.value"
10677
BotPlutusInterface.runPAB @MyContracts pabConf
10778
```
10879

80+
Configuration format (example: <examples/plutus-game/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: case insensitive `mainnet` atom or 32-bit unsigned integral number
97+
(default: 42)
98+
scriptFileDir: path text
99+
Directory name of the script and data files (default:
100+
"./result-scripts")
101+
signingKeyFileDir: path text
102+
Directory name of the signing key files (default: "./signing-keys")
103+
txFileDir: path text
104+
Directory name of the transaction files (default: "./txs")
105+
metadataDir: path text
106+
Directory name of metadata files (default: "/metadata")
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: case insensitive `nothing` atom or StakePubKeyHash text
119+
(default: nothing)
120+
tipPollingInterval: non-negative integral number
121+
(default: 10000000)
122+
port: port non-negative integral number
123+
(default: 9080)
124+
enableTxEndpoint: `true` or `false`
125+
(default: false)
126+
collectStats: `true` or `false`
127+
Save some stats during contract run (only transactions execution
128+
budgets supported atm) (default: false)
129+
collectLogs: `true` or `false`
130+
Save logs from contract execution: pab request logs and contract
131+
logs (default: false)
132+
budgetMultiplier: rational multiplier in form `1` or `1 % 2`
133+
(default: 1)
134+
```
135+
109136
To run the fake PAB, you need to prepare a few more things:
110137

111138
4. Save the protocol params file to the root folder of your project using the cardano-cli
@@ -129,6 +156,7 @@ The fake PAB consists of the following modules:
129156

130157
- **BotPlutusInterface** main entry point
131158
- **BotPlutusInterface.Server** Servant server, handling http endpoint calls and websockets
159+
- **BotPlutusInterface.Config** load/save PAB configuration file
132160
- **BotPlutusInterface.Contract** handling contract effects by creating the necessary files and calling cardano-cli commands (a few effects are mocked)
133161
- **BotPlutusInterface.Balance** doing some preparations so the cli can process the rest (non-ada asset balancing, addig tx inputs, adding minimum lovelaces, add signatories)
134162
- **BotPlutusInterface.CardanoCLI** wrappers for cardano-cli commands

bot-plutus-interface.cabal

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,23 @@ 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:
94102
, aeson ^>=1.5.0.0
@@ -97,8 +105,11 @@ library
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
@@ -124,18 +136,24 @@ library
124136
, plutus-pab
125137
, plutus-tx
126138
, plutus-tx-plugin
139+
, pretty
127140
, prettyprinter
128141
, process
129142
, QuickCheck
143+
, regex-compat
130144
, row-types
131145
, serialise
132146
, servant
133147
, servant-client
148+
, servant-client-core
134149
, servant-server
135150
, servant-websockets
136151
, split
137152
, stm
153+
, temporary
138154
, text ^>=1.2.4.0
155+
, time
156+
, tostring
139157
, transformers
140158
, transformers-either
141159
, transformers-except
@@ -155,6 +173,7 @@ test-suite bot-plutus-interface-test
155173
ghc-options: -fplugin-opt PlutusTx.Plugin:defer-errors
156174
other-modules:
157175
Spec.BotPlutusInterface.Balance
176+
Spec.BotPlutusInterface.Config
158177
Spec.BotPlutusInterface.Contract
159178
Spec.BotPlutusInterface.ContractStats
160179
Spec.BotPlutusInterface.Server

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 1097911063)
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
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: 1097911063
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-nft/app/Main.hs

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

66
import BotPlutusInterface qualified
7+
import BotPlutusInterface.Config qualified as BotPlutusInterface
78
import BotPlutusInterface.Types (
8-
CLILocation (Local),
99
HasDefinitions (..),
10-
LogLevel (Debug),
11-
PABConfig (..),
1210
SomeBuiltin (..),
1311
endpointsToSchemas,
1412
)
15-
import Cardano.Api (NetworkId (Testnet), NetworkMagic (..))
1613
import Cardano.PlutusExample.NFT
17-
import Data.Aeson qualified as JSON
1814
import Data.Aeson.TH (defaultOptions, deriveJSON)
19-
import Data.ByteString.Lazy qualified as LazyByteString
20-
import Data.Default (def)
21-
import Data.Maybe (fromMaybe)
2215
import Playground.Types (FunctionSchema)
2316
import Schema (FormSchema)
24-
import Servant.Client.Core (BaseUrl (BaseUrl), Scheme (Http))
2517
import Prelude
2618

2719
instance HasDefinitions MintNFTContracts where
@@ -44,28 +36,7 @@ $(deriveJSON defaultOptions ''MintNFTContracts)
4436

4537
main :: IO ()
4638
main = do
47-
protocolParams <-
48-
fromMaybe (error "protocol.json file not found") . JSON.decode
49-
<$> LazyByteString.readFile "protocol.json"
50-
let pabConf =
51-
PABConfig
52-
{ pcCliLocation = Local
53-
, pcNetwork = Testnet (NetworkMagic 1097911063)
54-
, pcChainIndexUrl = BaseUrl Http "localhost" 9083 ""
55-
, pcPort = 9080
56-
, pcProtocolParams = protocolParams
57-
, pcTipPollingInterval = 10_000_000
58-
, pcSlotConfig = def
59-
, pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
60-
, pcOwnStakePubKeyHash = Nothing
61-
, pcScriptFileDir = "./scripts"
62-
, pcSigningKeyFileDir = "./signing-keys"
63-
, pcTxFileDir = "./txs"
64-
, pcDryRun = False
65-
, pcLogLevel = Debug
66-
, pcProtocolParamsFile = "./protocol.json"
67-
, pcEnableTxEndpoint = True
68-
, pcMetadataDir = "./metadata"
69-
, pcCollectStats = False
70-
}
39+
pabConf <-
40+
either error id
41+
<$> BotPlutusInterface.loadPABConfig "./pabConfig.value"
7142
BotPlutusInterface.runPAB @MintNFTContracts pabConf
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: 1097911063
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

0 commit comments

Comments
 (0)