Skip to content

Commit

Permalink
Add a few modules to the template (#20)
Browse files Browse the repository at this point in the history
Added `AuctionMintingPolicy.hs`, `GenAuctionValidatorBlueprint.hs` and
`app/GenMintingPolicyBlueprint.hs`, to make it compatible with
IntersectMBO/plutus#6477.

---------

Co-authored-by: zeme <[email protected]>
  • Loading branch information
zliu41 and zeme-wana authored Sep 16, 2024
1 parent f7601b8 commit 9431070
Show file tree
Hide file tree
Showing 10 changed files with 572 additions and 275 deletions.
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"
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

0 comments on commit 9431070

Please sign in to comment.