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