0

I'm building a use case where a person can buy a token and depending on the amount of ADA spent, he gets X tokens and a Special NFT.

Each Validator represent the policy Id of these native tokens I'm creating.

Now I must prevent anyone from minting without paying and off course check if the ADA is the value of the mint

mintWithFriend :: MintParams -> Contract w FreeSchema Text ()
mintWithFriend mp = do 
        let  destinations       = paymentTo mp
             referralAddr       = pubKeyHashAddress (referral destinations) Nothing
        now                     <- currentTime
        utxosReferral           <- utxosAt referralAddr         
        let
            vals                =  (_ciTxOutValue <$> (snd <$> Map.toList utxosReferral))            
            referralOk          =  extractLevel (getTot vals []) 0

            yacada              = Value.singleton yacadaSymbol (U.yacadaName) (U.calculateYacada $ mpAdaAmount mp) -- coins for customer
            yacadaNft           = Value.singleton yacadaNFTSymbol  (U.giveReferralNFTName (mpAdaAmount mp) now)  1 -- NFT for is base referral
            yacadaReferralNft   = Value.singleton yacadaNFTSymbol  (U.upgradeReferralNFTName (referralOk+1) now)  1 -- upgrade for the referral account
            treasuryAdas        = Ada.lovelaceValueOf $ U.treasuryAda (mpAdaAmount mp) referralOk 
            referralAdas        = Ada.lovelaceValueOf $ U.referralAda (mpAdaAmount mp) referralOk            
            lookups             = Constraints.mintingPolicy policy 
                                    <> Constraints.mintingPolicy levelPolicy 
            payment             = Constraints.mustPayToPubKey (treasury destinations) treasuryAdas 
                                    <> Constraints.mustPayToPubKey (referral destinations) (referralAdas <>  yacadaReferralNft)                             
            mint                = Constraints.mustMintValue (yacada <> yacadaNft <> yacadaReferralNft)                              
            tx                  = mint <> payment
                                                             
        ledgerTx <- submitTxConstraintsWith @Void lookups tx
        void $ awaitTxConfirmed $ getCardanoTxId ledgerTx

On this Off-chain contract, I'm building such transaction.

The policy and LevelPolicy are my 2 validators. the only utxo sent are the payment.

being that I have 2 validators can I define what utxo goes for each?

{-# INLINABLE yacadaPolicy #-}
yacadaPolicy ::  () -> PlutusV1.ScriptContext -> Bool
yacadaPolicy _ ctx  =  
    traceIfFalse "not ok" True
       
    where        
        allOk :: Bool
        allOk = True
        
        info :: TxInfo
        info = scriptContextTxInfo ctx

        minted :: Value
        minted = txInfoMint info

        mintedValue :: [(CurrencySymbol, TokenName, Integer)]
        mintedValue = flattenValue (minted)

        -- ?? Paied amount ?? --
        -- ?? amount of yacada == minted amount ??
        -- ?? name of yacadaNFT == level given by amount of ADA && quantity == 1
        -- ?? did the treasury account received the ADA
        -- ?? did the referral NFT name correct quantity = 1??
        -- ?? did the referral received ADA and new NFT
      

The full source is https://github.com/cmorgado/yacada_learning

Many thanks in advancednat

1 Answer 1

0

being that I have 2 validators can I define what utxo goes for each?

No, both scripts have visibility of all inputs and outputs of the transaction.

You can try ensuring that unique outputs are checked for each script.

2
  • I have distinct outputs how do I see them in the validator? Oct 7, 2022 at 11:55
  • Your can access transaction outputs with txInfoOutputs info
    – james
    Oct 8, 2022 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.