Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating cheatsheet #453

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 47 additions & 27 deletions doc/CHEATSHEET.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
initDist :: InitialDistribution
initDist = InitialDistribution
[ paysPK (wallet 3) (ada 6)
, paysScript fooTypedValidator FooTypedDatum (ada 6)
, paysScript fooTypedValidator FooTypedDatum (ada 6)
, paysPK (wallet 2) (ada 2) `withDatum` fooDatum
, paysPK (wallet 1) (ada 2) `withReferenceScript` fooValidator
]
Expand Down Expand Up @@ -118,9 +118,7 @@ foo = do
validateTxSkel $
txSkelTemplate
{ txSkelIns = ...,
txSkelOuts = ...,
txSkelMints = ...,
txSkelSigners = ...
...
}
...
```
Expand All @@ -133,12 +131,22 @@ foo = do
validateTxSkel' $
txSkelTemplate
{ txSkelIns = ...,
txSkelOuts = ...,
txSkelMints = ...,
txSkelSigners = ...
...
}
...
```
* ... ignore any returned value
```haskell
foo :: MonadBlockChain m => m ()
foo = do
...
validateTxSkel_ $
txSkelTemplate
{ txSkelIns = ...,
...
}
...
```

### Use wallets

Expand Down Expand Up @@ -171,19 +179,29 @@ txSkelTemplate

### Spend some UTxOs

* No redeemer: `txSkelEmptyRedeemer`
* With a given redeemer: `txSkelSomeRedeemer`
* A redeemer and a reference script: `txSkelSomeRedeemerAndReferenceScript`
* No redeemer but a reference script: `txSkelEmptyRedeemerAndReferenceScript`
* No redeemer: `emptyTxSkelRedeemer`
* With a given redeemer: `someTxSkelRedeemer myRedeemer`
* Attach a reference input (with a reference script): ``redeemer `withReferenceInput` txOutRef``

```haskell
txSkelTemplate
{ ...
txSkelIns = Map.fromList [(txOutRef1, myRedeemer1), (txOutRef2, myRedeemer2]
txSkelIns = Map.fromList [(txOutRef1, myRedeemer1), (txOutRef2, myRedeemer2 `withReferenceInput` txOutRef)]
...
}
```

* Allow automatic attachment of reference scripts:
```
txSkelTemplate
{ ...
txSkelIns = Map.fromList [(txOutRef1, myRedeemer1), (txOutRef2, myRedeemer2)],
txSkelOpts = def { txOptAutoReferenceScript = True },
...
}
```


### Return `TxOutRef`s from transaction outputs from...

* ... the Cardano transaction
Expand All @@ -194,7 +212,7 @@ txSkelTemplate
let (txOutRef1, _) : (txOutRef2, _) : _ = utxosFromCardanoTx cTx
return (txOutRef1, txOutRef2)
```
* ... the returns `TxOutRef`s
* ... the returned `TxOutRef`s
```haskell
endpointFoo :: MonadBlockChain m => m (Api.TxOutRef, Api.TxOutRef)
endpointFoo = do
Expand Down Expand Up @@ -225,10 +243,10 @@ foo txOutRef = do
* Mint tokens: positive amount
* Burn tokens: negative amount

* No redeemer: `(Script.Versioned fooPolicy Script.PlutusV3, txSkelEmptyRedeemer, "fooName", 3)`
* With redeemer: `(Script.Versioned barPolicy Script.PlutusV3, txSkelSomeRedeemer typedRedeemer, "barName", -3)`
* With a redeemer and reference script: `(Script.Versioned barPolicy Script.PlutusV3, txSkelSomeRedeemerAndReferenceScript txOutRef typedRedeemer, "barName", 12)`
* With no redeemer but a reference scrip: `(Script.Versioned barPolicy Script.PlutusV3, txSkelEmptyRedeemerAndReferenceScript txOutRef, "fooName", -6)`
* No redeemer: `(Script.Versioned fooPolicy Script.PlutusV3, emptyTxSkelRedeemer, "fooName", 3)`
* With redeemer: `(Script.Versioned barPolicy Script.PlutusV3, someTxSkelRedeemer typedRedeemer, "barName", -3)`
* With a redeemer and explicit reference script: ``(Script.Versioned barPolicy Script.PlutusV3, someTxSkelRedeemer typedRedeemer `withReferenceInput` oRef, "barName", 12)``
* With a redeemer and implicit reference script: `(Script.Versioned barPolicy Script.PlutusV3, someTxSkelRedeemer typedRedeemer, "fooName", -6)`, and turn on option `txOptAutoReferenceScript`

```haskell
txSkelTemplate
Expand Down Expand Up @@ -295,16 +313,6 @@ txSkelTemplate
* ``paysPK ... `withStakingCredential` ...``
* ``paysScript... ... `withStakingCredential` ...``

### Spend a referenced script output

```haskell
txSkelTemplate
{ ...
txSkelIns = Map.fromList [(scriptTxOutRefToSpend, txSkelSomeRedeemerForReferencedScript txOutRefCarryingReferenceScript redeemer), ...],
...
}
```

## Balancing

### Choose which wallet provides UTxOs to balance a transaction
Expand Down Expand Up @@ -542,3 +550,15 @@ txSkelTemplate
{ txOptAnchorResolution = AnchorResolutionHttp
}
```

## Withdrawals

Withdrawals allow to execute scripts with the "rewarding" purpose but do not
work properly in terms of withdrawn values.

```haskell
txSkelTemplate
{ txSkelWithdrawals = scriptWithdrawal withdrawalScript someRedeemer someAdaValue,
...
}
```