user2537: 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


user3990: if I got you right, what you want to do is not possible.
The spending transaction sends the reedemer for each UTXO the transaction wants to spend.
The spending transaction is created by your offline code and the redeemers for the specific scripts send together with that transaction. The redeemer is not carried on the UTXO, so the UTXO holding the NFT does not have that information, just the datumHash (Datum).
You can use the redeemer with the script validating the NFTs UTXO, e.g. if it is allowed to spend it (as for an oracle). If the validator decline, the UTXO is not spend, which leads to a missing input for "mkTicketPolicy".
So you have to check in your "mkTicketPolicy" if the NFTs UTXO will be spend. But you cannot check out of another validator script the redeemer backwards.
By submitting your transaction for your "mkTicketPolicy" validator you have to attach another constraint which triggers the validator script for the NFTs UTXO. A good example how to do that is the oracle script from the Plutus Pioneer course.
I hope I could explain it in an understandable way.
Edit:
let v       = txOutValue (txOutTxOut o) <> lovelaceValueOf (oFee oracle)
                        p       = assetClassValue (oAsset oracle) $ price (lovelaces $ txOutValue $ txOutTxOut o') x
                        lookups = Constraints.otherScript (swapValidator oracle)                     <>
                                  Constraints.otherScript (oracleValidator oracle)                   <>
                                  Constraints.unspentOutputs (Map.fromList [(oref, o), (oref', o')])
                        tx      = Constraints.mustSpendScriptOutput oref  (Redeemer $ PlutusTx.toBuiltinData Use) <>
                                  Constraints.mustSpendScriptOutput oref' (Redeemer $ PlutusTx.toBuiltinData ())  <>
                                  Constraints.mustPayToOtherScript
                                    (validatorHash $ oracleValidator oracle)
                                    (Datum $ PlutusTx.toBuiltinData x)
                                    v                                                                             <>
                                  Constraints.mustPayToPubKey pkh' p
                    ledgerTx <- submitTxConstraintsWith @Swapping lookups tx
                    awaitTxConfirmed $ txId ledgerTx

This is copied from the Swap.hs of the oracle example from the pioneers course. You see that two scripts with two reedemers are part of the transaction. Maybe this clarifies a bit better.
Here is the link to the complete example:
https://github.com/input-output-hk/plutus-pioneer-program/tree/main/code/week06/src/Week06/Oracle

2537: <p>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 <code>txInfoInputs</code> (see <a href="https://alpha.marlowe.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Contexts.html" rel="nofollow noreferrer">plutus-docs</a>). But how do I check which redeemer is handed over to these utxos?</p>
<p>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 <code>storeUtxO</code> is of type <code>BuyTickets</code>. How do I do this?</p>
<pre><code>-- 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 -&gt; () -&gt; ScriptContext -&gt; Bool
mkTicketPolicy st () ctx =
    traceIfFalse &quot;store nft not found&quot; hasStoreNft
    &amp;&amp; traceIfFalse &quot;wrong redeemer&quot; hasCorrectRedeemer
  where
    let (c, t) = storeNft st -- storeNFT :: Store -&gt; AssetClass

    storeUtxO :: TxInInfo
    storeUtxO = find
        (\i -&gt; (valueOf (txOutValue $ txInInfoResolved $ i) c t) == 1)
        (txInfoInputs $ scriptContextTxInfo $ ctx)

    hasStoreNft :: Bool
    hasStoreNft = case storeUtxO of
        Nothing -&gt; False
        Just _ -&gt; True

    hasCorrectRedeemer :: Bool
    -- TODO
</code></pre>
 3990: <p>if I got you right, what you want to do is not possible.
The spending transaction sends the reedemer for each UTXO the transaction wants to spend.
The spending transaction is created by your offline code and the redeemers for the specific scripts send together with that transaction. The redeemer is not carried on the UTXO, so the UTXO holding the NFT does not have that information, just the datumHash (Datum).</p>
<p>You can use the redeemer with the script validating the NFTs UTXO, e.g. if it is allowed to spend it (as for an oracle). If the validator decline, the UTXO is not spend, which leads to a missing input for &quot;mkTicketPolicy&quot;.</p>
<p>So you have to check in your &quot;mkTicketPolicy&quot; if the NFTs UTXO will be spend. But you cannot check out of another validator script the redeemer backwards.
By submitting your transaction for your &quot;mkTicketPolicy&quot; validator you have to attach another constraint which triggers the validator script for the NFTs UTXO. A good example how to do that is the oracle script from the Plutus Pioneer course.
I hope I could explain it in an understandable way.</p>
<p>Edit:</p>
<pre><code>let v       = txOutValue (txOutTxOut o) &lt;&gt; lovelaceValueOf (oFee oracle)
                        p       = assetClassValue (oAsset oracle) $ price (lovelaces $ txOutValue $ txOutTxOut o') x
                        lookups = Constraints.otherScript (swapValidator oracle)                     &lt;&gt;
                                  Constraints.otherScript (oracleValidator oracle)                   &lt;&gt;
                                  Constraints.unspentOutputs (Map.fromList [(oref, o), (oref', o')])
                        tx      = Constraints.mustSpendScriptOutput oref  (Redeemer $ PlutusTx.toBuiltinData Use) &lt;&gt;
                                  Constraints.mustSpendScriptOutput oref' (Redeemer $ PlutusTx.toBuiltinData ())  &lt;&gt;
                                  Constraints.mustPayToOtherScript
                                    (validatorHash $ oracleValidator oracle)
                                    (Datum $ PlutusTx.toBuiltinData x)
                                    v                                                                             &lt;&gt;
                                  Constraints.mustPayToPubKey pkh' p
                    ledgerTx &lt;- submitTxConstraintsWith @Swapping lookups tx
                    awaitTxConfirmed $ txId ledgerTx
</code></pre>
<p>This is copied from the Swap.hs of the oracle example from the pioneers course. You see that two scripts with two reedemers are part of the transaction. Maybe this clarifies a bit better.</p>
<p>Here is the link to the complete example:
<a href="https://github.com/input-output-hk/plutus-pioneer-program/tree/main/code/week06/src/Week06/Oracle" rel="nofollow noreferrer">https://github.com/input-output-hk/plutus-pioneer-program/tree/main/code/week06/src/Week06/Oracle</a></p>
