Playground for my own personal experiments.
Note: Heavily relies on source code in/from
- plutus repository
- Especially the use-cases project
- Some code from plutus-pioneer-program was copied for easy reference (in
src/WeekXX
folders like in original repo)
Sitenote: Just in case you are still looking for a stake pool, BNR is our.
Naively, call nix-shell
with path to shell.nix
in plutus
repo.
plutus-pioneer-program/code/week08 $ nix-shell ../../plutus/shell.nix
Advantages:
- Automatically sets up
nix-shell
when you enter any project directory- Especially whenever you enter a sub-directory
- Like
cd plutus-pioneer-program/code/week08
- Preserves your shell (like
zsh
)- Instead of
nix-shell
's default shell,bash
- Instead of
- Note (maybe good or bad):
- Installs pre-commit hooks
- Like formatting nix files
Setup:
- Add
shell.nix
to project dir (likeplutus-pioneer-program
){ }: let # Import shell from plutus repo # Makes tools like haskell-language-server available shell = import ./../plutus/shell.nix {}; in shell
- Assumes
plutus
repo is on same level, like> tree -L 1 . ├── plutus ├── plutus-pioneer-program ├── plutus-personal-playground
- Assumes
- Load
nix-shell
automatically withdirenv
- Install
direnv
- Install
nix-direnv
- Probably the most complicated step
- Easy for everbody who is using
home-manager
- For everybody else: Easiest method is probably the
.envrc
method
- Automatically load env by adding
use nix
to.envrc
in project folder> cd plutus-pioneer-program > echo "use nix" >> .envrc > direnv allow
- Test by exiting, re-entering and trying to use
haskell-language-server
> cd > cd - > haskell-language-server --version haskell-language-server version: 1.1.0.0 (GHC: 8.10.4.20210212) (PATH: /nix/store/ygfxr40id5jsyg2g3yb0drqj0fspp322-haskell-language-server-exe-haskell-language-server-1.1.0.0/bin/haskell-language-server)
- Install
Source code: src/ParallelAuction.hs.
Source code: src/Issues/AwaitTxConfirmedIssue.hs.
Issue brought up by @dino in discord.
awaitTxConfirmed
loops forever if validation fails- I.e. contract is blocked for further requests
- Same as what happened in lecture 02
Solution:
-
Add a timeout to the
awaitTxConfirmed
-
Added helper functions for
- Waiting for timeout (in
Slot
s) - And either throws and error,
withTimeoutThrowError
, or - just logs the timeout,
withTimeoutLogging
. - Usage example:
- Waiting for timeout (in
mint :: Integer -> Contract w SignedSchema Text ()
mint amt = do
let val = Value.singleton curSymbol "ABC" amt
lookups = Constraints.monetaryPolicy policy
tx = Constraints.mustForgeValue val
ledgerTx <- submitTxConstraintsWith @Void lookups tx
withTimeoutLogging 2 $ do
Contract.logInfo @String $ printf "Awaiting confirmation"
awaitTxConfirmed $ txId ledgerTx
Contract.logInfo @String $ printf "forged %s" (show val)
- Note: Transaction confirmation handling will change in future, so probably not worth to contribute
Source code: src/InputTxDatumsIssue.hs.
Assumed that a validator has access to Datum
of the UTxOs spent by the transaction. Since there is a DatumHash
given, it is Just ...
. But the hash can nowhere used.
Solution: mustIncludeDatum
actually solves the issue. So in essence it just adds the Datum
with the hash to txInfoData
and then I can pick them up with findDatum
🎉
Summing it up:
Datum
of outputs seem to be automatically added to thetxInfoData
in theScriptContext
Datum
of inputs are only references via theirDatumHash
but not availabe intxInfoData
per default.- Any
Datum
can be added viamustIncludeDatum
totxInfoData
and be found viafoundDatum
- I.e. also the missing
Datum
of the inputs
Official:
Datum
s of inputs must be automatically available- Added issue, which is already solved
See src/PayBackIssue.hs for the implementation.
Somehow paying back an UTxO with a token attached resulted in the transaction submitter "payed the payback". Problem was the missing split of the value of the UTxO into the native (ADA) amount and the token before using the value.