Skip to content

Instantly share code, notes, and snippets.

@j-mueller
j-mueller / Contract.hs
Created November 14, 2019 15:44
Vesting (new playground)
{-# LANGUAGE FlexibleContexts #-}
-- A game with two players. Player 1 thinks of a secret word
-- and uses its hash, and the game validator script, to lock
-- some funds (the prize) in a pay-to-script transaction output.
-- Player 2 guesses the word by attempting to spend the transaction
-- output. If the guess is correct, the validator script releases the funds.
-- If it isn't, the funds stay locked.
import Control.Applicative ((<|>), Applicative(..))
import Control.Lens
import Control.Monad (when, void)
@j-mueller
j-mueller / Sample event log
Last active October 29, 2019 09:37
Sample event log
Events for W2:
• {contribute: (PubKey {getPubKey = fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025},Value {getValue = Map {unMap = [(,Map {unMap = [(,10)]})]}})}
• {tx: WriteTxSuccess: TxIdOf {getTxId = 380fbc4c5efc421c4c6759c1cd07910cc83451f6adbbd1b08341a2679a55f34b}}
• {address: ( 9f0318d20018a8181e18e018fe18ac18e818fb1884185e185e18c9185018a618f918ad18d81837091824184f187b1881131846185413189f184118a4ff
, Tx TxId: 9f18380f18bc184c185e18fc1842181c184c1867185918c118cd0718910c18c81834185118f618ad18bb18d118b01883184118a21867189a185518f3184bff:
{inputs: TxInOf {txInRef = TxOutRefOf {txOutRefId = TxIdOf {getTxId = 60ea4aabc8bee7b68555c4655e3a0e76f734b8f8725a13158157f6c97eafe284}, txOutRefIdx = 8}, txInType = ConsumePublicKeyAddress (PubKey {getPubKey = fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025})}
outputs: PayToPubKey: PubKey: fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025, PayToScript: "\252Q\20
@j-mueller
j-mueller / Playground.hs
Last active September 19, 2019 23:16
Plutus Playground Smart Contract
-- Vesting scheme as a PLC contract
import qualified Prelude as Haskell
import Language.PlutusTx.Prelude
import qualified Data.Map as Map
import qualified Data.Set as Set
import IOTS
import qualified Language.PlutusTx as PlutusTx
import Ledger (Address, DataScript(..),
@j-mueller
j-mueller / Alt.hs
Last active July 22, 2019 10:29
Lift & NDet
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Safe #-}
-- A game with two players. Player 1 thinks of a secret word
-- and uses its hash, and the game validator script, to lock
-- some funds (the prize) in a pay-to-script transaction output.
-- Player 2 guesses the word by attempting to spend the transaction
-- output. If the guess is correct, the validator script releases the funds.
-- If it isn't, the funds stay locked.
import qualified Language.PlutusTx as PlutusTx
import Language.PlutusTx.Prelude
import Ledger
@j-mueller
j-mueller / Multisig.hs
Last active May 14, 2019 11:16
Multisig PLC
validate :: MultiSig -> () -> () -> PendingTx -> ()
validate =
let
validate (MultiSig keys num) () () p =
let
present = $$(P.length) ($$(P.filter) ($$(V.txSignedBy) p) keys)
in
if $$(P.geq) present num
then ()
else $$(P.error) ($$(P.traceH) "WRONG!" ())
@j-mueller
j-mueller / Playground.hs
Created April 18, 2019 13:39
Plutus Playground Smart Contract
-- | Crowdfunding contract implemented using the [[Plutus]] interface.
-- This is the fully parallel version that collects all contributions
-- in a single transaction.
--
-- Note [Transactions in the crowdfunding campaign] explains the structure of
-- this contract on the blockchain.
import qualified Language.PlutusTx as PlutusTx
import qualified Ledger.Interval as Interval
import Ledger.Slot (SlotRange)
import qualified Ledger.Slot as Slot
@j-mueller
j-mueller / Playground.hs
Created April 17, 2019 19:35
Plutus Playground Smart Contract
-- | A game with two players. Player 1 thinks of a secret word
-- and uses its hash, and the game validator script, to lock
-- some funds (the prize) in a pay-to-script transaction output.
-- Player 2 guesses the word by attempting to spend the transaction
-- output. If the guess is correct, the validator script releases the funds.
-- If it isn't, the funds stay locked.
import qualified Language.PlutusTx as PlutusTx
import qualified Language.PlutusTx.Prelude as P
import Ledger
import qualified Ledger.Value as Value
@j-mueller
j-mueller / Playground.hs
Last active September 19, 2019 23:20
Plutus Playground Smart Contract
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-ignore-interface-pragmas #-}
-- | A guessing game that
--
-- * Uses a state machine to keep track of the current secret word
@j-mueller
j-mueller / Playground.hs
Last active April 12, 2019 06:52
Plutus Playground Smart Contract
-- | Vesting scheme as a PLC contract
import Control.Monad (void)
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Language.PlutusTx as P
import Ledger (Address, DataScript(..), RedeemerScript(..), Signature, Slot, TxOutRef, TxIn, ValidatorScript(..))
import qualified Ledger as L
import Ledger.Ada (Ada)