I want to have a minting policy that checks some conditions of another input-utxo of the transaction. Fetching all transaction inputs and iterating over them is possible using txInfoInputs
(see plutus-docs). But how do I check which redeemer is handed over to these utxos?
I have the below code. It checks that there is an input utxo with a defined nft. Now I try to check that the redeemer of this storeUtxO
is of type BuyTickets
. How do I do this?
-- What are we doing here ? We are just checking that the transaction
-- includes a utxo-input with the defined store nft and that the redeemer
-- of the store utxo is 'BuyTickets'. We want that the store takes care
-- of validating the ticket purchase.
{-# INLINABLE mkTicketPolicy #-}
mkTicketPolicy :: Store -> () -> ScriptContext -> Bool
mkTicketPolicy st () ctx =
traceIfFalse "store nft not found" hasStoreNft
&& traceIfFalse "wrong redeemer" hasCorrectRedeemer
where
let (c, t) = storeNft st -- storeNFT :: Store -> AssetClass
storeUtxO :: TxInInfo
storeUtxO = find
(\i -> (valueOf (txOutValue $ txInInfoResolved $ i) c t) == 1)
(txInfoInputs $ scriptContextTxInfo $ ctx)
hasStoreNft :: Bool
hasStoreNft = case storeUtxO of
Nothing -> False
Just _ -> True
hasCorrectRedeemer :: Bool
-- TODO