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

Add a few modules to the template #20

Merged
merged 3 commits into from
Sep 16, 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
2 changes: 1 addition & 1 deletion .github/workflows/build-devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
-v ./.:/workspaces/plutus-tx-template \
-w /workspaces/plutus-tx-template \
-i ghcr.io/input-output-hk/devx-devcontainer:x86_64-linux.ghc96-iog \
bash -ic "cabal update && cabal run plutus-tx-template && test -e validator.uplc"
bash -ic "cabal update && cabal build all"
zliu41 marked this conversation as resolved.
Show resolved Hide resolved
237 changes: 0 additions & 237 deletions app/AuctionValidator.hs

This file was deleted.

90 changes: 90 additions & 0 deletions app/GenAuctionValidatorBlueprint.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}

module Main where

import AuctionValidator
import Data.ByteString.Short qualified as Short
import Data.Set qualified as Set
import PlutusLedgerApi.Common (serialiseCompiledCode)
import PlutusTx.Blueprint
import System.Environment (getArgs)

auctionParams :: AuctionParams
auctionParams =
AuctionParams
{ apSeller = error "Replace with seller public key hash"
, apCurrencySymbol = error "Replace with currency symbol"
, apTokenName = "TokenToBeAuctioned"
, apMinBid = 100
, apEndTime = error "Replace with the auction's end time"
}

myContractBlueprint :: ContractBlueprint
myContractBlueprint =
MkContractBlueprint
{ contractId = Just "auction-validator"
, contractPreamble = myPreamble
, contractValidators = Set.singleton myValidator
, contractDefinitions = deriveDefinitions @[AuctionParams, AuctionDatum, AuctionRedeemer]
}

myPreamble :: Preamble
myPreamble =
MkPreamble
{ preambleTitle = "Auction Validator"
, preambleDescription = Just "Blueprint for a Plutus script validating auction transactions"
, preambleVersion = "1.0.0"
, preamblePlutusVersion = PlutusV2
, preambleLicense = Just "MIT"
}

myValidator :: ValidatorBlueprint referencedTypes
myValidator =
MkValidatorBlueprint
{ validatorTitle = "Auction Validator"
, validatorDescription = Just "Plutus script validating auction transactions"
, validatorParameters =
[ MkParameterBlueprint
{ parameterTitle = Just "Parameters"
, parameterDescription = Just "Compile-time validator parameters"
, parameterPurpose = Set.singleton Spend
, parameterSchema = definitionRef @AuctionParams
}
]
, validatorRedeemer =
MkArgumentBlueprint
{ argumentTitle = Just "Redeemer"
, argumentDescription = Just "Redeemer for the auction validator"
, argumentPurpose = Set.fromList [Spend]
, argumentSchema = definitionRef @()
}
, validatorDatum = Nothing
, validatorCompiledCode =
Just . Short.fromShort . serialiseCompiledCode $
auctionValidatorScript auctionParams
}

writeBlueprintToFile :: FilePath -> IO ()
writeBlueprintToFile path = writeBlueprint path myContractBlueprint

main :: IO ()
main =
getArgs >>= \case
[arg] -> writeBlueprintToFile arg
args -> fail $ "Expects one argument, got " <> show (length args)
Loading