mirror of
https://github.com/FiloSpaTeam/plutus-pioneer-program.git
synced 2024-12-22 05:21:59 +01:00
removed sample solution
This commit is contained in:
parent
9e0b13d96c
commit
03e6e4ca9d
2 changed files with 0 additions and 55 deletions
|
@ -15,7 +15,6 @@ library
|
|||
, Week04.Homework
|
||||
, Week04.Maybe
|
||||
, Week04.Monad
|
||||
, Week04.Solution
|
||||
, Week04.Trace
|
||||
, Week04.Writer
|
||||
other-modules: Week04.Vesting
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
|
||||
module Week04.Solution where
|
||||
|
||||
import Data.Aeson (FromJSON, ToJSON)
|
||||
import Data.Functor (void)
|
||||
import Data.Text (Text, unpack)
|
||||
import GHC.Generics (Generic)
|
||||
import Ledger
|
||||
import Ledger.Ada as Ada
|
||||
import Ledger.Constraints as Constraints
|
||||
import Plutus.Contract as Contract
|
||||
import Plutus.Trace.Emulator as Emulator
|
||||
import Wallet.Emulator.Wallet
|
||||
|
||||
data PayParams = PayParams
|
||||
{ ppRecipient :: PubKeyHash
|
||||
, ppLovelace :: Integer
|
||||
} deriving (Show, Generic, FromJSON, ToJSON)
|
||||
|
||||
type PaySchema = Endpoint "pay" PayParams
|
||||
|
||||
payContract :: Contract () PaySchema Text ()
|
||||
payContract = do
|
||||
pp <- endpoint @"pay"
|
||||
let tx = mustPayToPubKey (ppRecipient pp) $ lovelaceValueOf $ ppLovelace pp
|
||||
handleError (\err -> Contract.logInfo $ "caught error: " ++ unpack err) $ void $ submitTx tx
|
||||
payContract
|
||||
|
||||
payTrace :: Integer -> Integer -> EmulatorTrace ()
|
||||
payTrace x y = do
|
||||
h <- activateContractWallet (Wallet 1) payContract
|
||||
let pkh = pubKeyHash $ walletPubKey $ Wallet 2
|
||||
callEndpoint @"pay" h $ PayParams
|
||||
{ ppRecipient = pkh
|
||||
, ppLovelace = x
|
||||
}
|
||||
void $ Emulator.waitNSlots 1
|
||||
callEndpoint @"pay" h $ PayParams
|
||||
{ ppRecipient = pkh
|
||||
, ppLovelace = y
|
||||
}
|
||||
void $ Emulator.waitNSlots 1
|
||||
|
||||
payTest1 :: IO ()
|
||||
payTest1 = runEmulatorTraceIO $ payTrace 1000000 2000000
|
||||
|
||||
payTest2 :: IO ()
|
||||
payTest2 = runEmulatorTraceIO $ payTrace 1000000000 2000000
|
Loading…
Reference in a new issue