@@ -16,7 +16,7 @@ import Ledger
1616 scriptCurrencySymbol ,
1717 unitDatum ,
1818 unitRedeemer ,
19- validatorHash , TxInfo (txInfoMint )
19+ validatorHash , TxInfo (txInfoMint ), TxOutRef , ChainIndexTxOut , PaymentPubKeyHash ( PaymentPubKeyHash ), pubKeyHashAddress
2020 )
2121import Ledger.Constraints qualified as Constraints
2222import Ledger.Typed.Scripts (wrapMintingPolicy )
@@ -30,12 +30,19 @@ import Plutus.V1.Ledger.Value qualified as Value
3030import PlutusTx qualified
3131import PlutusTx.Prelude qualified as PP
3232import Prelude
33+ import Control.Monad (void )
34+ import Plutus.V1.Ledger.Ada (adaValueOf )
3335
34- lockThenSpend :: Contract () EmptySchema Text ( TxId , CardanoTx )
36+ lockThenSpend :: Contract () EmptySchema Text [( TxOutRef , ChainIndexTxOut )]
3537lockThenSpend = do
36- _ <- lockAtScript
37- _ <- Contract. waitNSlots 1
38- spendFromScript
38+ _ <- lockAtScript
39+ wait 1
40+ _ <- spendFromScript
41+ wait 1
42+ pkh <- Contract. ownPaymentPubKeyHash
43+ Map. toList <$> Contract. utxosAt (pubKeyHashAddress pkh Nothing )
44+ where
45+ wait = void . Contract. waitNSlots
3946
4047lockAtScript :: Contract () EmptySchema Text (TxId , CardanoTx )
4148lockAtScript = do
@@ -63,8 +70,7 @@ spendFromScript = do
6370 ((oref1, _) : _, (oref2, _) : _) -> spendUtxo oref1 utxos1 oref2 utxos2
6471 where
6572 spendUtxo oref1 utxos1 oref2 utxos2 = do
66- let -- (JSON.Success tokenName) = JSON.fromJSON $ JSON.object ["unTokenName" .= ("ff" :: Text)]
67- token = Value. singleton currencySymbol (tokenName " ff" ) 1
73+ let token = Value. singleton currencySymbol (tokenName " ff" ) 1
6874 txc1 =
6975 Constraints. mustSpendScriptOutput oref1 unitRedeemer
7076 <> Constraints. mustMintValueWithRedeemer unitRedeemer token
@@ -74,6 +80,9 @@ spendFromScript = do
7480 <> Constraints. mintingPolicy mintingPolicy
7581
7682 let txc2 = Constraints. mustSpendScriptOutput oref2 unitRedeemer
83+ <> Constraints. mustPayToPubKey
84+ (PaymentPubKeyHash " 72cae61f85ed97fb0e7703d9fec382e4973bf47ea2ac9335cab1e3fe" )
85+ (adaValueOf 200 )
7786 lookups2 =
7887 Constraints. unspentOutputs (Map. fromList utxos2)
7988 <> Constraints. otherScript (validator2 2 )
@@ -118,11 +127,9 @@ mkValidator2 i _ _ _ =
118127 then PP. traceIfFalse " looooooooooooong" check
119128 else PP. traceIfFalse " short" check
120129 where
121- ! someWork = PP. sort $ PP. reverse [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] :: [Integer ]
130+ someWork = PP. sort $ PP. reverse [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] :: [Integer ]
122131 check = PP. length someWork PP. == 10
123132
124- -- info = scriptContextTxInfo ctx
125- -- check = PP.length (txInfoOutputs info) PP.== 1
126133
127134data TestLockSpend2
128135
@@ -150,17 +157,17 @@ mkPolicy :: () -> ScriptContext -> Bool
150157mkPolicy _ ! ctx =
151158 PP. traceIfFalse " Let me mint" check
152159 where
153- ! info = scriptContextTxInfo ctx
154- ! check =
160+ info = scriptContextTxInfo ctx
161+ check =
155162 PP. length (flattenValue PP. $ txInfoMint info) PP. == 1
156163 PP. && PP. length someWork PP. == 10
157164
158- ! someWork = PP. sort [9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 ] :: [Integer ]
165+ someWork = PP. sort [9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 ] :: [Integer ]
159166
160167mintingPolicy :: MintingPolicy
161168mintingPolicy =
162169 mkMintingPolicyScript
163170 $$ (PlutusTx. compile [|| wrapMintingPolicy mkPolicy|| ])
164171
165172currencySymbol :: CurrencySymbol
166- currencySymbol = scriptCurrencySymbol mintingPolicy
173+ currencySymbol = scriptCurrencySymbol mintingPolicy
0 commit comments