Skip to content

Commit 1d3126d

Browse files
committed
Merge branch 'master' into nazrhom/raw-tx
2 parents b5d2e80 + 9cf0c14 commit 1d3126d

File tree

26 files changed

+1166
-184
lines changed

26 files changed

+1166
-184
lines changed

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ Supported features:
1212
- pre balance tx (adding minimum amount of tx inputs based on fee and tx output value, balancing non ada outputs)
1313
- mint tokens, and send them to arbitrary address(es)
1414
- redeem utxos from validator scripts, using the correct datum and redeemer (scripts, datums and redeemers are persisted in files for now)
15+
- use validity time ranges
16+
- waiting for slots
1517

1618
Unsupported/In development
1719

1820
- wallet integration
19-
- chain-index integration (in progress)
20-
- handling on-chain events (utxo set change, waiting for slot, etc.)
21-
- multisig
22-
- automated tests
21+
- handling on-chain events (utxo set change, etc.)
2322

2423
## How to use this?
2524

@@ -40,6 +39,10 @@ data MyContracts
4039
2. Define a HasDefinitions instance for the endpoints
4140

4241
```haskell
42+
import BotPlutusInterface.Types (HasDefinitions (..), SomeBuiltin (..), endpointsToSchemas)
43+
import Playground.Types (FunctionSchema)
44+
import Schema (FormSchema)
45+
4346
instance HasDefinitions MyContracts where
4447
getDefinitions :: [MyContract]
4548
getDefinitions = []
@@ -62,21 +65,38 @@ instance HasDefinitions MyContracts where
6265
3. Write your main entrypoint for the application, with the preferred configurations
6366

6467
```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))
74+
6575
main :: IO ()
6676
main = do
6777
protocolParams <- JSON.decode <$> LazyByteString.readFile "protocol.json"
6878
let pabConf =
6979
PABConfig
70-
{ -- Calling the cli through ssh when set to Remote
71-
pcCliLocation = Remote "11.22.33.44"
80+
{ -- Calling the cli locally or through an ssh connection
81+
pcCliLocation = Local
7282
, pcNetwork = Testnet (NetworkMagic 42)
83+
, pcChainIndexUrl = BaseUrl Http "localhost" 9083 ""
84+
, pcPort = 9080
7385
, pcProtocolParams = protocolParams
86+
, -- | Slot configuration of the network, the default value can be used for the mainnet
87+
pcSlotConfig = def
88+
, pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
7489
, -- Directory name of the script and data files
75-
pcScriptFileDir = "result-scripts"
90+
pcScriptFileDir = "./scripts"
91+
, -- Directory for the signing key file(s)
92+
pcSigningKeyFileDir = "./signing-keys"
93+
, -- Directory where the encoded transaction files will be saved
94+
pcTxFileDir = "./txs"
7695
, -- Dry run mode will build the tx, but skip the submit step
7796
pcDryRun = False
97+
, pcLogLevel = Debug
7898
, -- Protocol params file location relative to the cardano-cli working directory (needed for the cli)
79-
pcProtocolParamsFile = "./protocol.json"
99+
, pcProtocolParamsFile = "./protocol.json"
80100
}
81101
BotPlutusInterface.runPAB @MyContracts pabConf
82102
```
@@ -107,7 +127,7 @@ The fake PAB consists of the following modules:
107127
- **BotPlutusInterface.Contract** handling contract effects by creating the necessary files and calling cardano-cli commands (a few effects are mocked)
108128
- **BotPlutusInterface.PreBalance** doing some preparations so the cli can process the rest (non-ada asset balancing, addig tx inputs, adding minimum lovelaces, add signatories)
109129
- **BotPlutusInterface.CardanoCLI** wrappers for cardano-cli commands
110-
- For development purposes, I created an ssh wrapper, so I can call relay these commands through an ssh connection. This is not nice, unsafe, and pretty slow, so I'm hoping to get rid of this pretty soon.
130+
- For development purposes, I created an ssh wrapper, so I can call relay these commands through an ssh connection. This is not nice, unsafe, and pretty slow, avoid using it if you can.
111131
- **BotPlutusInterface.UtxoParser** parse the output of the `cardano-cli query utxo` command
112132
- **BotPlutusInterface.Files** functions for handling script, datum and redeemer files
113133
- **BotPlutusInterface.Types** configuration for the fake pab

examples/plutus-game/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
### plutus-helloworld
1+
### plutus-game
22

3-
This directory contains a simple "Hello World" script. There are two versions: one using an integer literal (needed because the Plutus interpreter doesn't currently accept byte string literals) and a slighly more complicated one using a bytestring parameter.
4-
5-
``plutus-helloworld'' -- very simple numeric version
6-
7-
``plutus-helloworld-bytestring'' -- more compex version using bytestring constant
3+
Simple guessing game contract to demonstrate locking and redeeming funds with datums and redeemers

examples/plutus-game/app/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Cardano.PlutusExample.Game (
2222
import Data.Aeson qualified as JSON
2323
import Data.Aeson.TH (defaultOptions, deriveJSON)
2424
import Data.ByteString.Lazy qualified as LazyByteString
25+
import Data.Default (def)
2526
import Data.Maybe (fromMaybe)
2627
import Playground.Types (FunctionSchema)
2728
import Schema (FormSchema)
@@ -57,6 +58,7 @@ main = do
5758
, pcChainIndexUrl = BaseUrl Http "localhost" 9083 ""
5859
, pcPort = 9080
5960
, pcProtocolParams = protocolParams
61+
, pcSlotConfig = def
6062
, pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
6163
, pcScriptFileDir = "./scripts"
6264
, pcSigningKeyFileDir = "./signing-keys"

examples/plutus-game/plutus-game.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ executable plutus-game-pab
129129
, bot-plutus-interface
130130
, bytestring
131131
, cardano-api
132+
, data-default
132133
, playground-common
133134
, plutus-game
134135
, plutus-ledger

examples/plutus-nft/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
### plutus-helloworld
1+
### plutus-nft
22

3-
This directory contains a simple "Hello World" script. There are two versions: one using an integer literal (needed because the Plutus interpreter doesn't currently accept byte string literals) and a slighly more complicated one using a bytestring parameter.
4-
5-
``plutus-helloworld'' -- very simple numeric version
6-
7-
``plutus-helloworld-bytestring'' -- more compex version using bytestring constant
3+
Simple NFT schema to demonstrate token minting.

examples/plutus-nft/app/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Cardano.PlutusExample.NFT (
2020
import Data.Aeson qualified as JSON
2121
import Data.Aeson.TH (defaultOptions, deriveJSON)
2222
import Data.ByteString.Lazy qualified as LazyByteString
23+
import Data.Default (def)
2324
import Data.Maybe (fromMaybe)
2425
import Ledger.Value (TokenName)
2526
import Playground.Types (FunctionSchema)
@@ -57,6 +58,7 @@ main = do
5758
, pcChainIndexUrl = BaseUrl Http "localhost" 9083 ""
5859
, pcPort = 9080
5960
, pcProtocolParams = protocolParams
61+
, pcSlotConfig = def
6062
, pcOwnPubKeyHash = "0f45aaf1b2959db6e5ff94dbb1f823bf257680c3c723ac2d49f97546"
6163
, pcScriptFileDir = "./scripts"
6264
, pcSigningKeyFileDir = "./signing-keys"

examples/plutus-nft/plutus-nft.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ executable plutus-nft-pab
129129
, bot-plutus-interface
130130
, bytestring
131131
, cardano-api
132+
, data-default
132133
, playground-common
133134
, plutus-ledger
134135
, plutus-nft
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scripts
2+
signing-keys
3+
txs

examples/plutus-transfer/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### plutus-transfer
2+
3+
Simple value transfer from an address to multiple addresses. With the tfpOutputPerTx option,
4+
payment tx outputs can be grouped together into separate txs, the Contract waits for at least one
5+
block in between.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
CONTRACT_INST_ID=$(curl --location --request POST 'localhost:9080/api/contract/activate' \
3+
--header 'Content-Type: application/json' \
4+
--data-raw '{
5+
"caID": {
6+
"tfpOutputPerTx": 50,
7+
"tfpPayments": [
8+
[ {"getPubKeyHash": "981fc565bcf0c95c0cfa6ee6693875b60d529d87ed7082e9bf03c6a4"},
9+
{"getValue": [[{"unCurrencySymbol":""},[[{"unTokenName": ""}, 1500000]]]]}
10+
]
11+
]
12+
}
13+
}' | jq -r .unContractInstanceId )
14+
15+
echo $CONTRACT_INST_ID
16+
17+
18+
echo "{ \"tag\": \"Subscribe\", \"contents\": { \"Left\": { \"unContractInstanceId\":\"$CONTRACT_INST_ID\" } } }" | websocat -n ws://localhost:9080/ws
19+

0 commit comments

Comments
 (0)