Skip to content

Commit a509e2b

Browse files
author
euonymos
committed
chore: how to generate diagrams
1 parent 222a69a commit a509e2b

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

.ghci

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
:set -Wunused-binds -Wunused-imports -Worphans
2-
:set -isrc -itest

docs/getting-started.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ See the reference section for a full reference of `TxConstraint`.
106106
- `script` is a phantom type parameter, just like in `TxConstraint`.
107107
- `value` is the type of what this expression will resolve during runtime.
108108

109-
`ConstraintDSL` allows us to reference parts of the state machine's parameters,
109+
`ConstraintDSL` allows us to reference parts of the state machine's parameters,
110110
the current state, the transition arguments, and so forth.
111111

112112
It also lets us perform checks (like equality) and apply transformations (like lifting a Plutarch function).
@@ -452,14 +452,14 @@ The following are lifted versions of Plutarch operators
452452

453453
#### Setup: The Types
454454

455-
First, we define a type to denote our script. Its an uninhabited type, it cant be constructed.
455+
First, we define a type to denote our script. Its an uninhabited type, it cant be constructed.
456456
Its only used as a tag for connecting all instances of type classes together.
457457

458458
```haskell
459459
data SimpleAuction
460460
```
461461

462-
We define a type for the read-only state of our script. This state cant be modified once created.
462+
We define a type for the read-only state of our script. This state cant be modified once created.
463463
This becomes the `Params` associated type of the `CEMScript` type class.
464464

465465
```haskell
@@ -507,8 +507,8 @@ data SimpleAuctionTransition
507507
```
508508

509509
We can now define an instance of the `CEMScriptTypes` for `SimpleAuction`.
510-
`CEMScriptTypes` is a superclass of `CEMScript`, which just includes the associated types.
511-
By defining the associated types separately, we can use the `deriveCEMAssociatedTypes`
510+
`CEMScriptTypes` is a superclass of `CEMScript`, which just includes the associated types.
511+
By defining the associated types separately, we can use the `deriveCEMAssociatedTypes`
512512
Template Haskell function to generate some boilerplate.
513513

514514
```haskell
@@ -520,8 +520,8 @@ instance CEMScriptTypes SimpleAuction where
520520
$(deriveCEMAssociatedTypes False ''SimpleAuction)
521521
```
522522

523-
`deriveCEMAssociatedTypes` just executes `derivePlutusSpine` for all three of the associated types.
524-
But it can only do that if all the members of a type have a `HasPlutusSpine` implementation.
523+
`deriveCEMAssociatedTypes` just executes `derivePlutusSpine` for all three of the associated types.
524+
But it can only do that if all the members of a type have a `HasPlutusSpine` implementation.
525525
This is why we need to do `derivePlutusSpine` for the `Bid` type ourselves.
526526

527527
The boolean argument to `deriveCEMAssociatedTypes` is unused for now, and it is recommended to use a value of `False`.
@@ -534,7 +534,7 @@ To implement the logic of our script, we define an instance of `CEMScript` for o
534534
instance CEMScript SimpleAuction where
535535
```
536536

537-
We provide a value for `compilationConfig`, which at the moment contains
537+
We provide a value for `compilationConfig`, which at the moment contains
538538
only a prefix for error codes to tell errors from different programs apart.
539539

540540
```haskell
@@ -661,3 +661,14 @@ Let’s examine each of the entries in the map in detail.
661661
]
662662
)
663663
```
664+
665+
### Generating state diagram
666+
667+
Use `genCemGraph` function from `Cardano.CEM.Documentation` module
668+
to produce `graphviz` definition:
669+
670+
```bash
671+
$ cabal repl cem-script-example
672+
ghci> :m +System.IO Cardano.CEM CEM.Example.Auction Data.Proxy
673+
ghci> withFile "auction_diagram.dot" WriteMode (\h -> hPutStrLn h (genCemGraph "CEM Simple Acutoin" (Proxy :: Proxy SimpleAuction)))
674+
```

src/Cardano/CEM.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Cardano.CEM.Address as X (
88
cemScriptPlutusCredential,
99
)
1010
import Cardano.CEM.Compile as X
11+
import Cardano.CEM.Documentation as X (genCemGraph)
1112
import Cardano.CEM.DSL as X (
1213
CEMScript (..),
1314
CEMScriptDatum,

0 commit comments

Comments
 (0)