From 50ee6b0394e9febeeb43e84ec590c2a97ad4691c Mon Sep 17 00:00:00 2001 From: George Flerovsky Date: Sat, 24 Apr 2021 22:16:11 -0400 Subject: [PATCH 1/2] Update Week 1 and 2 files to Week 3 env. --- code/week01/cabal.project | 3 ++- code/week01/src/Week01/EnglishAuction.hs | 30 ++++++++++++------------ code/week02/cabal.project | 3 ++- code/week02/src/Week02/FortyTwo.hs | 2 +- code/week02/src/Week02/Gift.hs | 2 +- code/week02/src/Week02/Homework1.hs | 2 +- code/week02/src/Week02/Homework2.hs | 2 +- code/week02/src/Week02/IsData.hs | 4 ++-- code/week02/src/Week02/Solution1.hs | 4 ++-- code/week02/src/Week02/Solution2.hs | 4 ++-- code/week02/src/Week02/Typed.hs | 4 ++-- 11 files changed, 31 insertions(+), 29 deletions(-) diff --git a/code/week01/cabal.project b/code/week01/cabal.project index 399beef..b74979b 100644 --- a/code/week01/cabal.project +++ b/code/week01/cabal.project @@ -22,7 +22,8 @@ source-repository-package plutus-tx plutus-tx-plugin prettyprinter-configurable - tag: 3746610e53654a1167aeb4c6294c6096d16b0502 + quickcheck-dynamic + tag: 3aa86304e9bfc425667051a8a94db73fcdc38878 -- The following sections are copied from the 'plutus' repository cabal.project at the revision -- given above. diff --git a/code/week01/src/Week01/EnglishAuction.hs b/code/week01/src/Week01/EnglishAuction.hs index 7b41070..765dad0 100644 --- a/code/week01/src/Week01/EnglishAuction.hs +++ b/code/week01/src/Week01/EnglishAuction.hs @@ -110,7 +110,7 @@ minBid AuctionDatum{..} = case adHighestBid of Just Bid{..} -> bBid + 1 {-# INLINABLE mkAuctionValidator #-} -mkAuctionValidator :: AuctionDatum -> AuctionAction -> ValidatorCtx -> Bool +mkAuctionValidator :: AuctionDatum -> AuctionAction -> ScriptContext -> Bool mkAuctionValidator ad redeemer ctx = traceIfFalse "wrong input value" correctInputValue && case redeemer of @@ -131,12 +131,12 @@ mkAuctionValidator ad redeemer ctx = where info :: TxInfo - info = valCtxTxInfo ctx + info = scriptContextTxInfo ctx input :: TxInInfo input = let - isScriptInput i = case txInInfoWitness i of + isScriptInput i = case (txOutDatumHash . txInInfoResolved) i of Nothing -> False Just _ -> True xs = [i | i <- txInfoInputs info, isScriptInput i] @@ -146,7 +146,7 @@ mkAuctionValidator ad redeemer ctx = _ -> traceError "expected exactly one script input" inVal :: Value - inVal = txInInfoValue input + inVal = txOutValue . txInInfoResolved $ input auction :: Auction auction = adAuction ad @@ -162,12 +162,12 @@ mkAuctionValidator ad redeemer ctx = sufficientBid :: Integer -> Bool sufficientBid amount = amount >= minBid ad - ownOutput :: TxOutInfo + ownOutput :: TxOut outputDatum :: AuctionDatum (ownOutput, outputDatum) = case getContinuingOutputs ctx of - [o] -> case txOutType o of - PayToPubKey -> traceError "wrong output type" - PayToScript h -> case findDatum h info of + [o] -> case txOutDatumHash o of + Nothing -> traceError "wrong output type" + Just h -> case findDatum h info of Nothing -> traceError "datum not found" Just (Datum d) -> case PlutusTx.fromData d of Just ad' -> (o, ad') @@ -189,7 +189,7 @@ mkAuctionValidator ad redeemer ctx = let os = [ o | o <- txInfoOutputs info - , txOutAddress o == PubKeyAddress bBidder + , txOutAddress o == pubKeyHashAddress bBidder ] in case os of @@ -210,7 +210,7 @@ mkAuctionValidator ad redeemer ctx = , txOutValue o' == v ] in - txOutAddress o == PubKeyAddress h + txOutAddress o == pubKeyHashAddress h auctionInstance :: Scripts.ScriptInstance Auctioning auctionInstance = Scripts.validator @Auctioning @@ -226,7 +226,7 @@ auctionHash :: Ledger.ValidatorHash auctionHash = Scripts.validatorHash auctionValidator auctionAddress :: Ledger.Address -auctionAddress = ScriptAddress auctionHash +auctionAddress = scriptHashAddress auctionHash data StartParams = StartParams { spDeadline :: !Slot @@ -336,15 +336,15 @@ findAuction :: HasBlockchainActions s -> TokenName -> Contract w s Text (TxOutRef, TxOutTx, AuctionDatum) findAuction cs tn = do - utxos <- utxoAt $ ScriptAddress auctionHash + utxos <- utxoAt $ scriptHashAddress auctionHash let xs = [ (oref, o) | (oref, o) <- Map.toList utxos , Value.valueOf (txOutValue $ txOutTxOut o) cs tn == 1 ] case xs of - [(oref, o)] -> case txOutType $ txOutTxOut o of - PayToPubKey -> throwError "unexpected out type" - PayToScript h -> case Map.lookup h $ txData $ txOutTxTx o of + [(oref, o)] -> case txOutDatumHash $ txOutTxOut o of + Nothing -> throwError "unexpected out type" + Just h -> case Map.lookup h $ txData $ txOutTxTx o of Nothing -> throwError "datum not found" Just (Datum e) -> case PlutusTx.fromData e of Nothing -> throwError "datum has wrong type" diff --git a/code/week02/cabal.project b/code/week02/cabal.project index 399beef..b74979b 100644 --- a/code/week02/cabal.project +++ b/code/week02/cabal.project @@ -22,7 +22,8 @@ source-repository-package plutus-tx plutus-tx-plugin prettyprinter-configurable - tag: 3746610e53654a1167aeb4c6294c6096d16b0502 + quickcheck-dynamic + tag: 3aa86304e9bfc425667051a8a94db73fcdc38878 -- The following sections are copied from the 'plutus' repository cabal.project at the revision -- given above. diff --git a/code/week02/src/Week02/FortyTwo.hs b/code/week02/src/Week02/FortyTwo.hs index 691bd78..bd9e6e0 100644 --- a/code/week02/src/Week02/FortyTwo.hs +++ b/code/week02/src/Week02/FortyTwo.hs @@ -41,7 +41,7 @@ valHash :: Ledger.ValidatorHash valHash = Scripts.validatorHash validator scrAddress :: Ledger.Address -scrAddress = ScriptAddress valHash +scrAddress = scriptHashAddress valHash type GiftSchema = BlockchainActions diff --git a/code/week02/src/Week02/Gift.hs b/code/week02/src/Week02/Gift.hs index 73221e0..9676eaa 100644 --- a/code/week02/src/Week02/Gift.hs +++ b/code/week02/src/Week02/Gift.hs @@ -38,7 +38,7 @@ valHash :: Ledger.ValidatorHash valHash = Scripts.validatorHash validator scrAddress :: Ledger.Address -scrAddress = ScriptAddress valHash +scrAddress = scriptHashAddress valHash type GiftSchema = BlockchainActions diff --git a/code/week02/src/Week02/Homework1.hs b/code/week02/src/Week02/Homework1.hs index 72bfaf5..99dd70f 100644 --- a/code/week02/src/Week02/Homework1.hs +++ b/code/week02/src/Week02/Homework1.hs @@ -31,7 +31,7 @@ import Text.Printf (printf) {-# INLINABLE mkValidator #-} -- This should validate if and only if the two Booleans in the redeemer are equal! -mkValidator :: () -> (Bool, Bool) -> ValidatorCtx -> Bool +mkValidator :: () -> (Bool, Bool) -> ScriptContext -> Bool mkValidator _ _ _ = True -- FIX ME! data Typed diff --git a/code/week02/src/Week02/Homework2.hs b/code/week02/src/Week02/Homework2.hs index 7a3acb9..94f62c2 100644 --- a/code/week02/src/Week02/Homework2.hs +++ b/code/week02/src/Week02/Homework2.hs @@ -42,7 +42,7 @@ PlutusTx.unstableMakeIsData ''MyRedeemer {-# INLINABLE mkValidator #-} -- This should validate if and only if the two Booleans in the redeemer are equal! -mkValidator :: () -> MyRedeemer -> ValidatorCtx -> Bool +mkValidator :: () -> MyRedeemer -> ScriptContext -> Bool mkValidator _ _ _ = True -- FIX ME! data Typed diff --git a/code/week02/src/Week02/IsData.hs b/code/week02/src/Week02/IsData.hs index a0152ee..cf26e92 100644 --- a/code/week02/src/Week02/IsData.hs +++ b/code/week02/src/Week02/IsData.hs @@ -35,7 +35,7 @@ newtype MySillyRedeemer = MySillyRedeemer Integer PlutusTx.unstableMakeIsData ''MySillyRedeemer {-# INLINABLE mkValidator #-} -mkValidator :: () -> MySillyRedeemer -> ValidatorCtx -> Bool +mkValidator :: () -> MySillyRedeemer -> ScriptContext -> Bool mkValidator () (MySillyRedeemer r) _ = traceIfFalse "wrong redeemer" $ r == 42 data Typed @@ -57,7 +57,7 @@ valHash :: Ledger.ValidatorHash valHash = Scripts.validatorHash validator scrAddress :: Ledger.Address -scrAddress = ScriptAddress valHash +scrAddress = scriptHashAddress valHash type GiftSchema = BlockchainActions diff --git a/code/week02/src/Week02/Solution1.hs b/code/week02/src/Week02/Solution1.hs index 5031a0d..7b7b624 100644 --- a/code/week02/src/Week02/Solution1.hs +++ b/code/week02/src/Week02/Solution1.hs @@ -31,7 +31,7 @@ import Text.Printf (printf) {-# INLINABLE mkValidator #-} -- This should validate if and only if the two Booleans in the redeemer are equal! -mkValidator :: () -> (Bool, Bool) -> ValidatorCtx -> Bool +mkValidator :: () -> (Bool, Bool) -> ScriptContext -> Bool mkValidator () (b, c) _ = traceIfFalse "wrong redeemer" $ b == c data Typed @@ -53,7 +53,7 @@ valHash :: Ledger.ValidatorHash valHash = Scripts.validatorHash validator scrAddress :: Ledger.Address -scrAddress = ScriptAddress valHash +scrAddress = scriptHashAddress valHash type GiftSchema = BlockchainActions diff --git a/code/week02/src/Week02/Solution2.hs b/code/week02/src/Week02/Solution2.hs index 006a6a4..a349ad2 100644 --- a/code/week02/src/Week02/Solution2.hs +++ b/code/week02/src/Week02/Solution2.hs @@ -42,7 +42,7 @@ PlutusTx.unstableMakeIsData ''MyRedeemer {-# INLINABLE mkValidator #-} -- This should validate if and only if the two Booleans in the redeemer are equal! -mkValidator :: () -> MyRedeemer -> ValidatorCtx -> Bool +mkValidator :: () -> MyRedeemer -> ScriptContext -> Bool mkValidator () (MyRedeemer b c) _ = traceIfFalse "wrong redeemer" $ b == c data Typed @@ -64,7 +64,7 @@ valHash :: Ledger.ValidatorHash valHash = Scripts.validatorHash validator scrAddress :: Ledger.Address -scrAddress = ScriptAddress valHash +scrAddress = scriptHashAddress valHash type GiftSchema = BlockchainActions diff --git a/code/week02/src/Week02/Typed.hs b/code/week02/src/Week02/Typed.hs index 8dbf0a5..72db7e7 100644 --- a/code/week02/src/Week02/Typed.hs +++ b/code/week02/src/Week02/Typed.hs @@ -30,7 +30,7 @@ import Prelude (Semigroup (..)) import Text.Printf (printf) {-# INLINABLE mkValidator #-} -mkValidator :: () -> Integer -> ValidatorCtx -> Bool +mkValidator :: () -> Integer -> ScriptContext -> Bool mkValidator () r _ | r == 42 = True | otherwise = False @@ -54,7 +54,7 @@ valHash :: Ledger.ValidatorHash valHash = Scripts.validatorHash validator scrAddress :: Ledger.Address -scrAddress = ScriptAddress valHash +scrAddress = scriptHashAddress valHash type GiftSchema = BlockchainActions From 66dac083b112380c3e539a308aca2ff8fc710472 Mon Sep 17 00:00:00 2001 From: Thomas Diesler Date: Wed, 28 Apr 2021 20:39:35 +0200 Subject: [PATCH 2/2] Update plutus to what is used by week04 --- code/week01/cabal.project | 2 +- code/week02/cabal.project | 2 +- code/week02/src/Week02/Burn.hs | 2 +- code/week03/cabal.project | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/week01/cabal.project b/code/week01/cabal.project index b74979b..30ca08b 100644 --- a/code/week01/cabal.project +++ b/code/week01/cabal.project @@ -23,7 +23,7 @@ source-repository-package plutus-tx-plugin prettyprinter-configurable quickcheck-dynamic - tag: 3aa86304e9bfc425667051a8a94db73fcdc38878 + tag: 47bee0d683857655d60c230a8b25ab7058c54d55 -- The following sections are copied from the 'plutus' repository cabal.project at the revision -- given above. diff --git a/code/week02/cabal.project b/code/week02/cabal.project index b74979b..30ca08b 100644 --- a/code/week02/cabal.project +++ b/code/week02/cabal.project @@ -23,7 +23,7 @@ source-repository-package plutus-tx-plugin prettyprinter-configurable quickcheck-dynamic - tag: 3aa86304e9bfc425667051a8a94db73fcdc38878 + tag: 47bee0d683857655d60c230a8b25ab7058c54d55 -- The following sections are copied from the 'plutus' repository cabal.project at the revision -- given above. diff --git a/code/week02/src/Week02/Burn.hs b/code/week02/src/Week02/Burn.hs index 2b38b5f..13c5b51 100644 --- a/code/week02/src/Week02/Burn.hs +++ b/code/week02/src/Week02/Burn.hs @@ -39,7 +39,7 @@ valHash :: Ledger.ValidatorHash valHash = Scripts.validatorHash validator scrAddress :: Ledger.Address -scrAddress = ScriptAddress valHash +scrAddress = scriptHashAddress valHash type GiftSchema = BlockchainActions diff --git a/code/week03/cabal.project b/code/week03/cabal.project index b74979b..30ca08b 100644 --- a/code/week03/cabal.project +++ b/code/week03/cabal.project @@ -23,7 +23,7 @@ source-repository-package plutus-tx-plugin prettyprinter-configurable quickcheck-dynamic - tag: 3aa86304e9bfc425667051a8a94db73fcdc38878 + tag: 47bee0d683857655d60c230a8b25ab7058c54d55 -- The following sections are copied from the 'plutus' repository cabal.project at the revision -- given above.