Skip to content

Instantly share code, notes, and snippets.

@ajuggler
Last active February 18, 2023 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajuggler/06c5a4d1f23cc89376bbe5986ab558ae to your computer and use it in GitHub Desktop.
Save ajuggler/06c5a4d1f23cc89376bbe5986ab558ae to your computer and use it in GitHub Desktop.
Plutus minting policy parametrized by TxOutRef (for minting NFT)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module SimpleMinting where
import qualified PlutusTx
import PlutusTx.Prelude as TxPrelude hiding (unless)
import qualified Plutus.Script.Utils.V2.Scripts as Scripts
import Plutus.Script.Utils.Typed (mkUntypedMintingPolicy)
import Ledger.Value
import Plutus.V2.Ledger.Api
{-# INLINABLE mkPolicy #-}
mkPolicy :: TxOutRef -> () -> ScriptContext -> Bool
mkPolicy utxo () ctx = traceIfFalse "UTxO not consumed" hasUTxO
where
info :: TxInfo
info = scriptContextTxInfo ctx
hasUTxO :: Bool
hasUTxO = any (\i -> txInInfoOutRef i == utxo) $ txInfoInputs info
policy :: TxOutRef -> MintingPolicy
policy oref = mkMintingPolicyScript $
$$(PlutusTx.compile [|| mkUntypedMintingPolicy . mkPolicy ||])
`PlutusTx.applyCode`
PlutusTx.liftCode oref
curSymbol :: TxOutRef -> CurrencySymbol
curSymbol = Scripts.scriptCurrencySymbol . policy
-- +++ Instances +++
-- Concrete instances of minting policy.
oref1_tmp :: TxOutRef
oref1_tmp = TxOutRef
{ txOutRefId = TxId "9c087132a325f6483aca8398bab1a56eda1390e762984ba054c25cafd738486c"
, txOutRefIdx = 1
}
policy_1 :: MintingPolicy
policy_1 = policy oref1_tmp
curSymbol_1 :: CurrencySymbol
curSymbol_1 = curSymbol oref1_tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment