Giter VIP home page Giter VIP logo

plutus-personal-playground's Introduction

Personal Playground

Playground for my own personal experiments.

Note: Heavily relies on source code in/from

Sitenote: Just in case you are still looking for a stake pool, BNR is our.

Setup nix-shell Env

Simple

Naively, call nix-shell with path to shell.nix in plutus repo.

plutus-pioneer-program/code/week08 $ nix-shell ../../plutus/shell.nix

Advanced: Automatic loading on entering project directory

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
  • Note (maybe good or bad):
    • Installs pre-commit hooks
    • Like formatting nix files

Setup:

  • Add shell.nix to project dir (like plutus-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
  • Load nix-shell automatically with direnv
    • 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)

Test Cases

Test Case: Parallel Auction

Source code: src/ParallelAuction.hs.

Details and Learnings.

Await Tx Confirmed

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 Slots)
    • And either throws and error, withTimeoutThrowError, or
    • just logs the timeout, withTimeoutLogging.
    • Usage example:
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

Tx Input Datum in Validator / On Chain

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 the txInfoData in the ScriptContext
  • Datum of inputs are only references via their DatumHash but not availabe in txInfoData per default.
  • Any Datum can be added via mustIncludeDatum to txInfoData and be found via foundDatum
  • I.e. also the missing Datum of the inputs

Official:

  • Datums of inputs must be automatically available
  • Added issue, which is already solved

Test Case: Payback

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.

plutus-personal-playground's People

Contributors

mputz86 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.