From 528928c8fb0f5408d59d4ab3fe7b244bc2795b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Br=C3=BCnjes?= Date: Sun, 25 Jul 2021 22:47:30 +0200 Subject: [PATCH] fixed Homework1 & Solution1 --- code/week05/src/Week05/Homework1.hs | 6 ++++-- code/week05/src/Week05/Solution1.hs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/code/week05/src/Week05/Homework1.hs b/code/week05/src/Week05/Homework1.hs index bca27e5..2660b0f 100644 --- a/code/week05/src/Week05/Homework1.hs +++ b/code/week05/src/Week05/Homework1.hs @@ -15,6 +15,7 @@ module Week05.Homework1 where import Control.Monad hiding (fmap) import Control.Monad.Freer.Extras as Extras import Data.Aeson (ToJSON, FromJSON) +import Data.Default (Default (..)) import Data.Text (Text) import Data.Void (Void) import GHC.Generics (Generic) @@ -24,6 +25,7 @@ import qualified PlutusTx import PlutusTx.Prelude hiding (Semigroup(..), unless) import Ledger hiding (mint, singleton) import Ledger.Constraints as Constraints +import Ledger.TimeSlot import qualified Ledger.Typed.Scripts as Scripts import Ledger.Value as Value import Playground.Contract (printJson, printSchemas, ensureKnownCurrencies, stage, ToSchema) @@ -63,7 +65,7 @@ mint mp = do else do let val = Value.singleton (curSymbol pkh deadline) (mpTokenName mp) (mpAmount mp) lookups = Constraints.mintingPolicy $ policy pkh deadline - tx = Constraints.mustMintValue val <> Constraints.mustValidateIn (to deadline) + tx = Constraints.mustMintValue val <> Constraints.mustValidatlIn (to $ now + 5000) ledgerTx <- submitTxConstraintsWith @Void lookups tx void $ awaitTxConfirmed $ txId ledgerTx Contract.logInfo @String $ printf "forged %s" (show val) @@ -80,7 +82,7 @@ mkKnownCurrencies [] test :: IO () test = runEmulatorTraceIO $ do let tn = "ABC" - deadline = 10 + deadline = slotToBeginPOSIXTime def 10 h <- activateContractWallet (Wallet 1) endpoints callEndpoint @"mint" h $ MintParams { mpTokenName = tn diff --git a/code/week05/src/Week05/Solution1.hs b/code/week05/src/Week05/Solution1.hs index 8a42970..9fc6cf3 100644 --- a/code/week05/src/Week05/Solution1.hs +++ b/code/week05/src/Week05/Solution1.hs @@ -14,6 +14,7 @@ module Week05.Solution1 where import Control.Monad hiding (fmap) import Data.Aeson (ToJSON, FromJSON) +import Data.Default (Default (..)) import Data.Text (Text) import Data.Void (Void) import GHC.Generics (Generic) @@ -23,6 +24,7 @@ import qualified PlutusTx import PlutusTx.Prelude hiding (Semigroup(..), unless) import Ledger hiding (mint, singleton) import Ledger.Constraints as Constraints +import Ledger.TimeSlot import qualified Ledger.Typed.Scripts as Scripts import Ledger.Value as Value import Playground.Contract (printJson, printSchemas, ensureKnownCurrencies, stage, ToSchema) @@ -69,7 +71,7 @@ mint mp = do else do let val = Value.singleton (curSymbol pkh deadline) (mpTokenName mp) (mpAmount mp) lookups = Constraints.mintingPolicy $ policy pkh deadline - tx = Constraints.mustMintValue val <> Constraints.mustValidateIn (to deadline) + tx = Constraints.mustMintValue val <> Constraints.mustValidateIn (to $ now + 5000) ledgerTx <- submitTxConstraintsWith @Void lookups tx void $ awaitTxConfirmed $ txId ledgerTx Contract.logInfo @String $ printf "forged %s" (show val) @@ -86,7 +88,7 @@ mkKnownCurrencies [] test :: IO () test = runEmulatorTraceIO $ do let tn = "ABC" - deadline = 10 + deadline = slotToBeginPOSIXTime def 10 h <- activateContractWallet (Wallet 1) endpoints callEndpoint @"mint" h $ MintParams { mpTokenName = tn