Skip to content

Commit 6fe064d

Browse files
committed
Updating the README
1 parent 4161311 commit 6fe064d

File tree

2 files changed

+131
-69
lines changed

2 files changed

+131
-69
lines changed

README.md

Lines changed: 131 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,38 @@ to [UPLC](https://plutonomicon.github.io/plutonomicon/uplc), such as
5353

5454
## How to integrate `cooked-validators` in a project
5555

56-
1. `cooked-validators` depends on
57-
[cardano-haskell-packages](https://github.com/input-output-hk/cardano-haskell-packages)
58-
to get cardano-related packages and on
59-
[cardano-node-emulator](https://github.com/tweag/cardano-node-emulator-forked)
60-
directly. If you have no constraint on the version of this package, copy the
61-
file [`cabal.project`](./cabal.project) to your project and
62-
[adapt](https://cabal.readthedocs.io/en/stable/cabal-project-description-file.html#specifying-the-local-packages)
63-
the `packages` stanza.
56+
There are two ways for this integration:
57+
58+
1. `cooked-validators`, and all its dependencies, are available on
59+
[cardano-haskel-packages
60+
(CHaP)](https://github.com/IntersectMBO/cardano-haskell-packages). To rely
61+
on a release available there, add the following stanza to your
62+
`cabal.project`:
63+
64+
```cabal.project
65+
repository cardano-haskell-packages
66+
url: https://chap.intersectmbo.org/
67+
secure: True
68+
root-keys:
69+
3e0cce471cf09815f930210f7827266fd09045445d65923e6d0238a6cd15126f
70+
443abb7fb497a134c343faf52f0b659bd7999bc06b7f63fa76dc99d631f9bea1
71+
a86a1f6ce86c449c46666bda44268677abf29b5b2d2eb5ec7af903ec2f117a82
72+
bcec67e8e99cabfa7764d75ad9b158d72bfacf70ca1d0ec8bc6b4406d1bf8413
73+
c00aae8461a256275598500ea0e187588c35a5d5d7454fb57eac18d9edb86a56
74+
d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee
75+
76+
index-state:
77+
, cardano-haskell-packages 2026-02-13T00:00:02Z
78+
```
6479

65-
2. Add the following stanza to the file `cabal.project`
80+
To find the appropriate index state to fill above, look for
81+
`cooked-validators` on [CHaP's packages
82+
list](https://chap.intersectmbo.org/all-packages/).
83+
84+
2. Alternatively, if you want to rely on a specific commit or branch not
85+
available on CHaP, you can import `cooked-validators` directly from GitHub
86+
with the following stanza:
87+
6688
```cabal.project
6789
source-repository-package
6890
type: git
@@ -71,86 +93,129 @@ the `packages` stanza.
7193
subdir:
7294
.
7395
```
96+
7497
where `myTag` is either a commit hash in the repo, or a tag, such as v8.0.0
7598
(see [available
7699
releases](https://github.com/tweag/cooked-validators/releases)).
100+
101+
Note that, should you do that, you would likely still need CHaP for all the
102+
other dependencies.
77103

78-
3. Each release of `cooked-validators` is pinned to a specific version of
79-
[`cardano-api`](https://github.com/IntersectMBO/cardano-api) which in turn
80-
pins the versions of all other Cardano-related dependencies (including
81-
Plutus). Make sure your project relies on the same version.
104+
Each release of `cooked-validators` is pinned to a specific version of
105+
[`cardano-api`](https://github.com/IntersectMBO/cardano-api) which in turn pins
106+
the versions of all other Cardano-related dependencies (including Plutus). Make
107+
sure your project relies on the same version.
82108

83109
## Example
84110

85111
This example shows how to create and validate a simple transaction that
86-
transfers 10 Ada from wallet 1 to wallet 2, without manually handling fees or
87-
balancing.
112+
transfers 10 Ada from Alice (wallet 1) to Bob (wallet 2), without manually
113+
handling fees or balancing.
88114

89-
1. Enter a Cabal read-eval-print-loop (with `cabal repl`)
115+
1. Create a new Haskell module, for example `Demo.hs`
90116

91117
2. Import your required dependencies
92118
``` haskell
93119
> import Cooked
94-
> import qualified Plutus.Script.Utils.Value as Script
120+
> import Plutus.Script.Utils.Value qualified as Script
95121
```
96122

97-
3. Define a transaction which transfers 10 Ada from wallet 1 to wallet 2
123+
3. Start the definition of a `MockChain` run:
124+
``` haskell
125+
> myDemoRun :: StagedMockChain ()
126+
> myDemoRun = do
127+
```
128+
129+
4. Define aliases for Alice and Bob:
98130
``` haskell
99-
let myTransaction = txSkelTemplate {txSkelOuts = [wallet 2 `receives` Value (Script.ada 10)], txSkelSignatories = txSkelSignatoriesFromList [wallet 1]}
131+
> alice <- define "Alice" $ wallet 1
132+
> bob <- define "Bob" $ wallet 2
133+
```
134+
135+
5. Give some initial funds to Alice:
136+
``` haskell
137+
> forceOutputs_ $ replicate 3 $ alice `receives` Value (Script.ada 10)
138+
```
139+
140+
5. Take some notes:
141+
``` haskell
142+
> noteS "Alice is sending 10 ADA to Bob"
143+
> noteS "I let cooked-validators do the heavy lifting for me"
100144
```
101145

102-
4. Send the transaction for validation, and request the printing of the run
146+
6. Submit the transaction:
103147
``` haskell
104-
printCooked . runMockChain . validateTxSkel_ $ myTransaction
148+
> validateTxSkel_
149+
> txSkelTemplate
150+
> { txSkelOuts = [bob `receives` Value (Script.ada 10)],
151+
> txSkelSignatories = txSkelSignatoriesFromList [wallet 1]
152+
> }
105153
```
106154

107-
5. Observe the log of the run, including:
108-
- The original skeleton, and its balanced counterpart
109-
- The associated fee and collaterals
110-
- The final mockchain state, with every wallet's assets (notice the 10 ADA
111-
payment owned by wallet 2)
112-
- The value returned by the run (here `()` as we used `validateTxSkel_`)
113-
```haskell
114-
📖 MockChain run log:
115-
New raw skeleton submitted to the adjustment pipeline:
116-
- Validity interval: (-∞ , +∞)
117-
- Signatories:
118-
- wallet 1 [balancing]
119-
- Outputs:
120-
- Pays to pubkey wallet 2
121-
- Lovelace: 10_000_000
122-
New adjusted skeleton submitted for validation:
123-
- Validity interval: (-∞ , +∞)
124-
- Signatories:
125-
- wallet 1 [balancing]
126-
- Inputs:
127-
- Spends #4480b35!3 from pubkey wallet 1
128-
- Redeemer ()
129-
- Lovelace: 100_000_000
130-
- Outputs:
131-
- Pays to pubkey wallet 2
132-
- Lovelace: 10_000_000
133-
- Pays to pubkey wallet 1
134-
- Lovelace: 89_828_383
135-
- Fee: Lovelace: 171_617
136-
- No collateral required
137-
New transaction successfully validated:
138-
- Transaction id: #c095342
139-
- Number of new outputs: 2
140-
UTxO state:
141-
pubkey wallet 1
142-
- Lovelace: 89_828_383
143-
- (×3) Lovelace: 100_000_000
144-
pubkey wallet 2
145-
- Lovelace: 10_000_000
146-
- (×4) Lovelace: 100_000_000
147-
pubkey wallet 3
148-
- (×4) Lovelace: 100_000_000
149-
pubkey wallet 4
150-
- (×4) Lovelace: 100_000_000
151-
🟢 Returned value: ()
155+
7. Lookup for the UTxOs now owned by Bob, and assert that he indeed possesses 1:
156+
``` haskell
157+
> bobUtxos <- utxosAt bob
158+
> assert "Bob now has 1 utxo" $ length bobUtxos == 1
152159
```
153160

161+
8. Enter a `cabal repl`, run and print the trace:
162+
``` haskell
163+
printCooked $ runMockChainDef myDemoRun
164+
```
165+
166+
5. Observe the output of printing the run, including:
167+
- The notes you've taken
168+
- The log produced by cooked, with, the original submitted skeleton as well
169+
as the adjusted and balanced skeletong with computed fee and collaterals.
170+
- The assertions you've made and their evaluation.
171+
- The final mockchain state, with every peer's assets (notice the 10 ADA
172+
payment owned by Bob).
173+
- The value returned by the run (here `()`).
174+
175+
```
176+
📔 Notes:
177+
- Alice is going to send 10 ADA to Bob
178+
- I let cooked-validators do the heavy lifting for me
179+
📖 MockChain run log:
180+
⁍ New raw skeleton submitted to the adjustment pipeline:
181+
- Validity interval: (-∞ , +∞)
182+
- Signatories:
183+
- Alice [balancing]
184+
- Outputs:
185+
- Pays to pubkey Bob
186+
- Lovelace: 10_000_000
187+
⁍ New adjusted skeleton submitted for validation:
188+
- Validity interval: (-∞ , +∞)
189+
- Signatories:
190+
- Alice [balancing]
191+
- Inputs:
192+
- Spends #d769532!1 from pubkey Alice
193+
- Redeemer ()
194+
- Lovelace: 10_000_000
195+
- Spends #d769532!2 from pubkey Alice
196+
- Redeemer ()
197+
- Lovelace: 10_000_000
198+
- Outputs:
199+
- Pays to pubkey Bob
200+
- Lovelace: 10_000_000
201+
- Pays to pubkey Alice
202+
- Lovelace: 9_826_799
203+
- Fee: Lovelace: 173_201
204+
- No collateral required
205+
⁍ New transaction successfully validated:
206+
- Transaction id: #bff7a56
207+
- Number of new outputs: 2
208+
✅ Assertions:
209+
- ✔ Bob now has 1 utxo
210+
💰 UTxO state:
211+
• pubkey Alice
212+
- Lovelace: 9_826_799
213+
- Lovelace: 10_000_000
214+
• pubkey Bob
215+
- Lovelace: 10_000_000
216+
🟢 Success with returned value: ()
217+
```
218+
154219
## Documentation
155220

156221
- The rendered Haddock for the current `main` branch can be found

cabal.project

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,4 @@ package cardano-crypto-praos
4646
flags: -external-libsodium-vrf
4747

4848
constraints:
49-
, cardano-api == 10.18.1.0
5049
, cardano-node-emulator == 1.4.1.0
51-
, polysemy == 1.9.2.0
52-
, polysemy-plugin == 0.4.5.3

0 commit comments

Comments
 (0)