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

Restore CI checks for doc site code #6376

Merged
merged 1 commit into from
Aug 5, 2024
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
22 changes: 22 additions & 0 deletions doc/docusaurus/docusaurus-examples.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ common ghc-version-support
if (impl(ghc <9.6) || impl(ghc >=9.7))
buildable: False

library docusaurus-code
import: lang, ghc-version-support
hs-source-dirs: static/code

if (impl(ghcjs) || os(windows))
buildable: False

other-modules:
AuctionValidator
BasicPlutusTx
BasicPolicies
BasicValidators

build-depends:
, base >=4.9 && <5
, plutus-core ^>=1.31
, plutus-ledger-api ^>=1.31
, plutus-tx ^>=1.31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the release script know that these need to be updated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I don't think so. I'll remove these bounds

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I was wrong, it actually does know.


if !(impl(ghcjs) || os(ghcjs))
build-depends: plutus-tx-plugin

executable example-cip57
import: lang, ghc-version-support
main-is: Example/Cip57/Blueprint/Main.hs
Expand Down
30 changes: 18 additions & 12 deletions doc/docusaurus/static/code/AuctionValidator.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}

{-# OPTIONS_GHC -fno-ignore-interface-pragmas #-}
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
Expand Down Expand Up @@ -192,7 +193,12 @@ auctionTypedValidator params (AuctionDatum highestBid) redeemer ctx@(ScriptConte
Nothing -> PlutusTx.traceError ("Not found: Output paid to highest bidder")
-- BLOCK8
{-# INLINEABLE auctionUntypedValidator #-}
auctionUntypedValidator :: AuctionParams -> BuiltinData -> BuiltinData -> BuiltinData -> ()
auctionUntypedValidator ::
AuctionParams ->
BuiltinData ->
BuiltinData ->
BuiltinData ->
PlutusTx.BuiltinUnit
auctionUntypedValidator params datum redeemer ctx =
PlutusTx.check
( auctionTypedValidator
Expand All @@ -204,7 +210,7 @@ auctionUntypedValidator params datum redeemer ctx =

auctionValidatorScript ::
AuctionParams ->
CompiledCode (BuiltinData -> BuiltinData -> BuiltinData -> ())
CompiledCode (BuiltinData -> BuiltinData -> BuiltinData -> PlutusTx.BuiltinUnit)
auctionValidatorScript params =
$$(PlutusTx.compile [||auctionUntypedValidator||])
`PlutusTx.unsafeApplyCode` PlutusTx.liftCode plcVersion100 params
Expand Down
12 changes: 5 additions & 7 deletions doc/docusaurus/static/code/BasicPlutusTx.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
-- BLOCK1
-- Necessary language extensions for the Plutus Tx compiler to work.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 #-}

module BasicPlutusTx where

import PlutusCore.Default qualified as PLC
import PlutusCore.Version (plcVersion100)
-- Main Plutus Tx module.
import PlutusTx
-- Additional support for lifting.
import PlutusTx.Lift
-- Builtin functions.
import PlutusTx.Builtins
-- The Plutus Tx Prelude, discussed further below.
Expand Down
8 changes: 3 additions & 5 deletions doc/docusaurus/static/code/BasicPolicies.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module BasicPolicies where

import PlutusCore.Default qualified as PLC
import PlutusTx
import PlutusTx.Lift
import PlutusTx.Prelude

import PlutusLedgerApi.V1.Contexts
import PlutusLedgerApi.V1.Crypto
import PlutusLedgerApi.V1.Scripts
import PlutusLedgerApi.V1.Value
import PlutusTx.AssocMap qualified as Map

Expand Down Expand Up @@ -42,14 +40,14 @@ currencyValueOf (Value m) c = case Map.lookup c m of
-- BLOCK2
-- The 'plutus-ledger' package from 'plutus-apps' provides helper functions to automate
-- some of this boilerplate.
oneAtATimePolicyUntyped :: BuiltinData -> BuiltinData -> ()
oneAtATimePolicyUntyped :: BuiltinData -> BuiltinData -> BuiltinUnit
-- 'check' fails with 'error' if the argument is not 'True'.
oneAtATimePolicyUntyped r c =
check $ oneAtATimePolicy (unsafeFromBuiltinData r) (unsafeFromBuiltinData c)

-- We can use 'compile' to turn a minting policy into a compiled Plutus Core program,
-- just as for validator scripts.
oneAtATimeCompiled :: CompiledCode (BuiltinData -> BuiltinData -> ())
oneAtATimeCompiled :: CompiledCode (BuiltinData -> BuiltinData -> BuiltinUnit)
oneAtATimeCompiled = $$(compile [|| oneAtATimePolicyUntyped ||])
-- BLOCK3
singleSignerPolicy :: () -> ScriptContext -> Bool
Expand Down
20 changes: 6 additions & 14 deletions doc/docusaurus/static/code/BasicValidators.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand All @@ -8,24 +9,15 @@
{-# LANGUAGE ViewPatterns #-}
module BasicValidators where

import PlutusCore.Default qualified as PLC
import PlutusTx
import PlutusTx.Lift
import PlutusTx.Prelude

import PlutusLedgerApi.Common
import PlutusLedgerApi.V1.Contexts
import PlutusLedgerApi.V1.Crypto
import PlutusLedgerApi.V1.Scripts
import PlutusLedgerApi.V1.Value

import Data.ByteString qualified as BS
import Data.ByteString.Lazy qualified as BSL

import Codec.Serialise
import Flat qualified

import Prelude (IO, print, show)
import Prelude (IO, print)
import Prelude qualified as Haskell

myKeyHash :: PubKeyHash
Expand Down Expand Up @@ -61,16 +53,16 @@ beforeEnd (Date d) (Fixed e) = d <= e
beforeEnd (Date _) Never = True

-- | Check that the date in the redeemer is before the limit in the datum.
validateDate :: BuiltinData -> BuiltinData -> BuiltinData -> ()
validateDate :: BuiltinData -> BuiltinData -> BuiltinData -> BuiltinUnit
-- The 'check' function takes a 'Bool' and fails if it is false.
-- This is handy since it's more natural to talk about booleans.
validateDate datum redeemer _ =
check $ beforeEnd (unsafeFromBuiltinData datum) (unsafeFromBuiltinData redeemer)

dateValidator :: CompiledCode (BuiltinData -> BuiltinData -> BuiltinData -> ())
dateValidator :: CompiledCode (BuiltinData -> BuiltinData -> BuiltinData -> BuiltinUnit)
dateValidator = $$(compile [|| validateDate ||])
-- BLOCK4
validatePayment :: BuiltinData -> BuiltinData -> BuiltinData -> ()
validatePayment :: BuiltinData -> BuiltinData -> BuiltinData -> BuiltinUnit
validatePayment _ _ ctx =
let valCtx = unsafeFromBuiltinData ctx
-- The 'TxInfo' in the validation context is the representation of the
Expand All @@ -94,5 +86,5 @@ showSerialised = print serialisedDateValidator
-- The 'loadFromFile' function is a drop-in replacement for 'compile', but
-- takes the file path instead of the code to compile.
validatorCodeFromFile :: CompiledCode (() -> () -> ScriptContext -> Bool)
validatorCodeFromFile = $$(loadFromFile "howtos/myscript.uplc")
validatorCodeFromFile = $$(loadFromFile "static/code/myscript.uplc")
-- BLOCK7
Empty file.