Skip to content

Demo adjustments and storing the autogen files #79

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

Merged
merged 2 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions experimental/ctl-env/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake ../..#dev-ctl-env
10 changes: 2 additions & 8 deletions experimental/ctl-env/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
demo:
all:
rm -fr .work-dir
mkdir .work-dir
lbf compile --debug --compiler `which lbc` -w .work-dir -i lbf-base -i api/ -f api/Demo.lbf
lbg gen-purescript --debug -i .work-dir/compiler-input.textproto -o .work-dir/codegen-output.textproto -p autogen

coop:
rm -fr .work-dir
mkdir .work-dir
lbf compile --debug --compiler `which lbc` -w .work-dir -i lbf-base -i api/ -f api/Coop.lbf
lbf compile --debug --compiler `which lbc` -w .work-dir -i lbf-base -i api/ -f api/Citizen.lbf
lbg gen-purescript --debug -i .work-dir/compiler-input.textproto -o .work-dir/codegen-output.textproto -p autogen
38 changes: 38 additions & 0 deletions experimental/ctl-env/api/Citizen.lbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Citizen

import Prelude
import qualified Plutus.V1 as Plutus (Bytes)
import Plutus

-- What is a Citizen?
record Citizen = {
firstName : Name,
lastName : Name,
id : NationalId
}
-- Citizens can be compared for equality!
derive Eq Citizen
-- Citizens can be stored in a Cardano UTXO as a Datum!
derive PlutusData Citizen

prod Name = Plutus.Bytes
derive Eq Name
derive PlutusData Name

sum NationalId = CroatianPassport CroatianOIB Picture
| CroatianIdCard CroatianOIB
| SwissVisa SwissVisaType
derive Eq NationalId
derive PlutusData NationalId

prod CroatianOIB = Integer
derive Eq CroatianOIB
derive PlutusData CroatianOIB

prod Picture = Plutus.Bytes
derive Eq Picture
derive PlutusData Picture

sum SwissVisaType = L | B | C
derive Eq SwissVisaType
derive PlutusData SwissVisaType
46 changes: 0 additions & 46 deletions experimental/ctl-env/api/Coop.lbf

This file was deleted.

22 changes: 0 additions & 22 deletions experimental/ctl-env/api/Demo.lbf

This file was deleted.

91 changes: 91 additions & 0 deletions experimental/ctl-env/autogen/LambdaBuffers/Citizen.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module LambdaBuffers.Citizen (Citizen(..)
, CroatianOIB(..)
, Name(..)
, NationalId(..)
, Picture(..)
, SwissVisaType(..)) where

import LambdaBuffers.Plutus as LambdaBuffers.Plutus
import LambdaBuffers.Plutus.V1 as LambdaBuffers.Plutus.V1
import LambdaBuffers.Prelude as LambdaBuffers.Prelude
import Ctl.Internal.ToData as Ctl.Internal.ToData
import Ctl.Internal.Types.PlutusData as Ctl.Internal.Types.PlutusData
import Data.BigInt as Data.BigInt
import Data.Newtype as Data.Newtype
import LambdaBuffers.Runtime.PlutusLedgerApi as LambdaBuffers.Runtime.PlutusLedgerApi
import Prelude as Prelude

newtype Citizen = MkCitizen { firstName :: Name
, lastName :: Name
, id :: NationalId}
derive instance Data.Newtype.Newtype Citizen _
newtype CroatianOIB = MkCroatianOIB LambdaBuffers.Prelude.Integer
derive instance Data.Newtype.Newtype CroatianOIB _
newtype Name = MkName LambdaBuffers.Plutus.V1.Bytes
derive instance Data.Newtype.Newtype Name _
data NationalId = NationalId'CroatianPassport CroatianOIB Picture
| NationalId'CroatianIdCard CroatianOIB
| NationalId'SwissVisa SwissVisaType

newtype Picture = MkPicture LambdaBuffers.Plutus.V1.Bytes
derive instance Data.Newtype.Newtype Picture _
data SwissVisaType = SwissVisaType'L | SwissVisaType'B | SwissVisaType'C


instance Prelude.Eq Citizen where
eq = (\x0 -> (\x1 -> ((Prelude.(&&) ((Prelude.(&&) ((Prelude.(&&) true) ((Prelude.(==) (Data.Newtype.unwrap x0).firstName) (Data.Newtype.unwrap x1).firstName))) ((Prelude.(==) (Data.Newtype.unwrap x0).lastName) (Data.Newtype.unwrap x1).lastName))) ((Prelude.(==) (Data.Newtype.unwrap x0).id) (Data.Newtype.unwrap x1).id)) ) )
instance Ctl.Internal.ToData.ToData Citizen where
toData = (\x0 -> (Ctl.Internal.Types.PlutusData.List [(Ctl.Internal.ToData.toData (Data.Newtype.unwrap x0).firstName)
,(Ctl.Internal.ToData.toData (Data.Newtype.unwrap x0).lastName)
,(Ctl.Internal.ToData.toData (Data.Newtype.unwrap x0).id)]) )
instance Prelude.Eq Name where
eq = (\x0 -> (\x1 -> let MkName x2 = x0 in let MkName x3 = x1 in ((Prelude.(&&) true) ((Prelude.(==) x2) x3)) ) )
instance Ctl.Internal.ToData.ToData Name where
toData = (\x0 -> let MkName x1 = x0 in (Ctl.Internal.ToData.toData x1) )
instance Prelude.Eq NationalId where
eq = (\x0 -> (\x1 -> case x0 of
NationalId'CroatianPassport x2 x3 -> case x1 of
NationalId'CroatianPassport x4 x5 -> ((Prelude.(&&) ((Prelude.(&&) true) ((Prelude.(==) x2) x4))) ((Prelude.(==) x3) x5))
NationalId'CroatianIdCard x6 -> false
NationalId'SwissVisa x7 -> false
NationalId'CroatianIdCard x8 -> case x1 of
NationalId'CroatianPassport x9 x10 -> false
NationalId'CroatianIdCard x11 -> ((Prelude.(&&) true) ((Prelude.(==) x8) x11))
NationalId'SwissVisa x12 -> false
NationalId'SwissVisa x13 -> case x1 of
NationalId'CroatianPassport x14 x15 -> false
NationalId'CroatianIdCard x16 -> false
NationalId'SwissVisa x17 -> ((Prelude.(&&) true) ((Prelude.(==) x13) x17)) ) )
instance Ctl.Internal.ToData.ToData NationalId where
toData = (\x0 -> case x0 of
NationalId'CroatianPassport x1 x2 -> ((LambdaBuffers.Runtime.PlutusLedgerApi.pdConstr (Data.BigInt.fromInt 0)) [(Ctl.Internal.ToData.toData x1)
,(Ctl.Internal.ToData.toData x2)])
NationalId'CroatianIdCard x3 -> ((LambdaBuffers.Runtime.PlutusLedgerApi.pdConstr (Data.BigInt.fromInt 1)) [(Ctl.Internal.ToData.toData x3)])
NationalId'SwissVisa x4 -> ((LambdaBuffers.Runtime.PlutusLedgerApi.pdConstr (Data.BigInt.fromInt 2)) [(Ctl.Internal.ToData.toData x4)]) )
instance Prelude.Eq CroatianOIB where
eq = (\x0 -> (\x1 -> let MkCroatianOIB x2 = x0 in let MkCroatianOIB x3 = x1 in ((Prelude.(&&) true) ((Prelude.(==) x2) x3)) ) )
instance Ctl.Internal.ToData.ToData CroatianOIB where
toData = (\x0 -> let MkCroatianOIB x1 = x0 in (Ctl.Internal.ToData.toData x1) )
instance Prelude.Eq Picture where
eq = (\x0 -> (\x1 -> let MkPicture x2 = x0 in let MkPicture x3 = x1 in ((Prelude.(&&) true) ((Prelude.(==) x2) x3)) ) )
instance Ctl.Internal.ToData.ToData Picture where
toData = (\x0 -> let MkPicture x1 = x0 in (Ctl.Internal.ToData.toData x1) )
instance Prelude.Eq SwissVisaType where
eq = (\x0 -> (\x1 -> case x0 of
SwissVisaType'L -> case x1 of
SwissVisaType'L -> true
SwissVisaType'B -> false
SwissVisaType'C -> false
SwissVisaType'B -> case x1 of
SwissVisaType'L -> false
SwissVisaType'B -> true
SwissVisaType'C -> false
SwissVisaType'C -> case x1 of
SwissVisaType'L -> false
SwissVisaType'B -> false
SwissVisaType'C -> true ) )
instance Ctl.Internal.ToData.ToData SwissVisaType where
toData = (\x0 -> case x0 of
SwissVisaType'L -> (Ctl.Internal.Types.PlutusData.Integer (Data.BigInt.fromInt 0))
SwissVisaType'B -> (Ctl.Internal.Types.PlutusData.Integer (Data.BigInt.fromInt 1))
SwissVisaType'C -> (Ctl.Internal.Types.PlutusData.Integer (Data.BigInt.fromInt 2)) )
12 changes: 12 additions & 0 deletions experimental/ctl-env/autogen/LambdaBuffers/Plutus.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module LambdaBuffers.Plutus (PlutusData(..)) where

import LambdaBuffers.Prelude as LambdaBuffers.Prelude
import Ctl.Internal.ToData as Ctl.Internal.ToData
import Ctl.Internal.Types.PlutusData as Ctl.Internal.Types.PlutusData
import Data.BigInt as Data.BigInt
import Data.Newtype as Data.Newtype
import Prelude as Prelude

type PlutusData = Ctl.Internal.Types.PlutusData.PlutusData


92 changes: 92 additions & 0 deletions experimental/ctl-env/autogen/LambdaBuffers/Plutus/V1.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module LambdaBuffers.Plutus.V1 (Address(..)
, AssetClass(..)
, Bytes(..)
, Credential(..)
, CurrencySymbol(..)
, Datum(..)
, DatumHash(..)
, Extended(..)
, Interval(..)
, LowerBound(..)
, Map(..)
, POSIXTime(..)
, POSIXTimeRange(..)
, PubKeyHash(..)
, Redeemer(..)
, RedeemerHash(..)
, ScriptHash(..)
, StakingCredential(..)
, TokenName(..)
, TxId(..)
, TxOutRef(..)
, UpperBound(..)
, Value(..)) where

import LambdaBuffers.Plutus as LambdaBuffers.Plutus
import LambdaBuffers.Prelude as LambdaBuffers.Prelude
import Ctl.Internal.Plutus.Types.Address as Ctl.Internal.Plutus.Types.Address
import Ctl.Internal.Plutus.Types.AssocMap as Ctl.Internal.Plutus.Types.AssocMap
import Ctl.Internal.Plutus.Types.Credential as Ctl.Internal.Plutus.Types.Credential
import Ctl.Internal.Plutus.Types.CurrencySymbol as Ctl.Internal.Plutus.Types.CurrencySymbol
import Ctl.Internal.Plutus.Types.Value as Ctl.Internal.Plutus.Types.Value
import Ctl.Internal.Serialization.Hash as Ctl.Internal.Serialization.Hash
import Ctl.Internal.ToData as Ctl.Internal.ToData
import Ctl.Internal.Types.Datum as Ctl.Internal.Types.Datum
import Ctl.Internal.Types.Interval as Ctl.Internal.Types.Interval
import Ctl.Internal.Types.PubKeyHash as Ctl.Internal.Types.PubKeyHash
import Ctl.Internal.Types.RawBytes as Ctl.Internal.Types.RawBytes
import Ctl.Internal.Types.Redeemer as Ctl.Internal.Types.Redeemer
import Ctl.Internal.Types.TokenName as Ctl.Internal.Types.TokenName
import Ctl.Internal.Types.Transaction as Ctl.Internal.Types.Transaction
import Data.BigInt as Data.BigInt
import Data.Newtype as Data.Newtype
import LambdaBuffers.Runtime.PlutusLedgerApi as LambdaBuffers.Runtime.PlutusLedgerApi
import Prelude as Prelude

type Address = Ctl.Internal.Plutus.Types.Address.Address

type AssetClass = LambdaBuffers.Runtime.PlutusLedgerApi.AssetClass

type Bytes = Ctl.Internal.Types.RawBytes.RawBytes

type Credential = Ctl.Internal.Plutus.Types.Credential.Credential

type CurrencySymbol = Ctl.Internal.Plutus.Types.CurrencySymbol.CurrencySymbol

type Datum = Ctl.Internal.Types.Datum.Datum

type DatumHash = Ctl.Internal.Types.Datum.DataHash

type Extended a = Ctl.Internal.Types.Interval.Extended a

type Interval a = Ctl.Internal.Types.Interval.Interval a

type LowerBound a = Ctl.Internal.Types.Interval.LowerBound a

type Map k v = Ctl.Internal.Plutus.Types.AssocMap.Map k v

type POSIXTime = Ctl.Internal.Types.Interval.POSIXTime

type POSIXTimeRange = Ctl.Internal.Types.Interval.OnchainPOSIXTimeRange

type PubKeyHash = Ctl.Internal.Types.PubKeyHash.PubKeyHash

type Redeemer = Ctl.Internal.Types.Redeemer.Redeemer

type RedeemerHash = Ctl.Internal.Types.Redeemer.RedeemerHash

type ScriptHash = Ctl.Internal.Serialization.Hash.ScriptHash

type StakingCredential = Ctl.Internal.Plutus.Types.Credential.StakingCredential

type TokenName = Ctl.Internal.Types.TokenName.TokenName

type TxId = Ctl.Internal.Types.Transaction.TransactionHash

type TxOutRef = Ctl.Internal.Types.Transaction.TransactionInput

type UpperBound a = Ctl.Internal.Types.Interval.UpperBound a

type Value = Ctl.Internal.Plutus.Types.Value.Value


45 changes: 45 additions & 0 deletions experimental/ctl-env/autogen/LambdaBuffers/Prelude.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module LambdaBuffers.Prelude (Bool(..)
, Bytes(..)
, Char(..)
, Either(..)
, Int32(..)
, Integer(..)
, List(..)
, Map(..)
, Maybe(..)
, Set(..)
, Text(..)) where

import Ctl.Internal.Types.ByteArray as Ctl.Internal.Types.ByteArray
import Data.BigInt as Data.BigInt
import Data.Either as Data.Either
import Data.Map as Data.Map
import Data.Maybe as Data.Maybe
import Data.Newtype as Data.Newtype
import Data.Set as Data.Set
import Prelude as Prelude
import Prim as Prim

type Bool = Prim.Boolean

type Bytes = Ctl.Internal.Types.ByteArray.ByteArray

type Char = Prim.Char

type Either a b = Data.Either.Either a b

type Int32 = Prim.Int

type Integer = Data.BigInt.BigInt

type List a = Prim.Array a

type Map a b = Data.Map.Map a b

type Maybe a = Data.Maybe.Maybe a

type Set a = Data.Set.Set a

type Text = Prim.String


Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module LambdaBuffers.Runtime.PlutusLedgerApi (AssetClass) where
module LambdaBuffers.Runtime.PlutusLedgerApi (pdConstr, AssetClass) where

import Ctl.Internal.Plutus.Types.CurrencySymbol (CurrencySymbol)
import Ctl.Internal.Types.TokenName (TokenName)
import Data.Tuple.Nested (type (/\))
import Ctl.Internal.Types.BigNum (fromBigInt, zero)
import Data.BigInt (BigInt)
import Ctl.Internal.Types.PlutusData (PlutusData(Constr))
import Data.Maybe (Maybe(Nothing, Just))

type AssetClass = CurrencySymbol /\ TokenName

-- | TODO(bladyjoker): Whaaai https://github.com/Plutonomicon/cardano-transaction-lib/blob/b565f4b1ec877c671ec4ffc13b1b89dbe498bceb/src/Internal/Types/PlutusData.purs#L36
pdConstr :: BigInt -> Array PlutusData -> PlutusData
pdConstr bi pds = case fromBigInt bi of
Nothing -> Constr zero pds
Just bn -> Constr bn pds
Loading