-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmart_contract_example
46 lines (38 loc) · 1.68 KB
/
Smart_contract_example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
module DeliveryContractWithOracle where
import Language.Marlowe.Extended.V1
main :: IO ()
main = printJSON deliveryContract
-- Define the number of slots in two weeks as an Integer and convert to Timeout
slotsInTwoWeeks :: Timeout
slotsInTwoWeeks = let
slots = (60 * 60 * 24 * 14) `div` 20 -- Calculate as Integer
in fromInteger slots -- Convert to Timeout
-- Define parties involved in the contract
seller, buyer, oracle :: Party
seller = Role "Seller"
buyer = Role "Buyer"
oracle = Role "USPS_Oracle"
-- Define deposits from each party
sellerDeposit, buyerDeposit :: Value
sellerDeposit = Constant 100_000_000 -- 100 ADA in Lovelaces
buyerDeposit = Constant 100_000_000 -- 100 ADA in Lovelaces
-- Define the choice for the oracle
deliveryConfirmation :: ChoiceId
deliveryConfirmation = ChoiceId "Package Delivered" oracle
-- Define the contract
deliveryContract :: Contract
deliveryContract =
When [Case (Deposit seller seller ada sellerDeposit)
(When [Case (Deposit buyer buyer ada buyerDeposit)
(When [Case (Choice deliveryConfirmation [Bound 1 1])
(Pay seller (Party buyer) ada sellerDeposit
$ Pay buyer (Party seller) ada buyerDeposit
Close)]
(slotsInTwoWeeks) -- Waiting for oracle's confirmation
Close)] -- Buyer's deposit
(slotsInTwoWeeks) -- Waiting for seller's deposit
Close)]
(slotsInTwoWeeks) -- Initial timeout
Close -- Contract closure in case of timeout