Last active
June 13, 2022 17:56
-
-
Save ajuggler/c9b2617295112cb2f4839f4cda4a6b58 to your computer and use it in GitHub Desktop.
MPP - Bank Client agreement (homework)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Example where | |
import Language.Marlowe.Extended | |
np = 3 :: Integer -- Number of payments (positive integer) | |
am = 50 :: Integer -- Amount (in Ada) of each deposit by Client (positive integer) | |
main :: IO () | |
main = printJSON $ contract np am (TimeParam "Bank Deadline") (TimeParam "Client Deadline") | |
contract :: Integer -> Integer -> Timeout -> Timeout -> Contract | |
contract mult amount bankDeadline clientDeadline = | |
When | |
[Case | |
(Deposit | |
(Role "Bank") | |
(Role "Bank") | |
ada | |
(MulValue | |
(Constant mult) | |
amountLov | |
) | |
) | |
(deposits mult) -- The multiple deposits by Client that are expected | |
] | |
bankDeadline | |
Close | |
where | |
amountLov :: Value | |
amountLov = MulValue (Constant 1000000) (Constant amount) | |
deposit :: Action | |
deposit = Deposit (Role "Bank") (Role "Client") ada amountLov | |
deposits :: Integer -> Contract | |
deposits m = foldr addContract payClient $ replicate (fromIntegral m) True | |
where | |
addContract :: Bool -> Contract -> Contract | |
addContract x y = case x of | |
True -> (When [Case deposit y] clientDeadline Close) | |
False -> Close | |
payClient :: Contract | |
payClient = (Pay | |
(Role "Bank") | |
(Account (Role "Client")) | |
ada | |
(AvailableMoney | |
(Role "Bank") | |
ada | |
) | |
Close | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"valueParameterInfo":[],"timeParameterDescriptions":[["Bank Deadline","Deadline for Bank to make initial deposit"],["Client Deadline","Deadline for Client to finish all deposits"]],"roleDescriptions":[["Bank","The Bank"],["Client","The Client"]],"contractType":"Other","contractShortDescription":"Bank-Client agreement","contractName":"MPP - Bank Client Agreement (homework solution)","contractLongDescription":"Bank makes initial deposit, Client is expected to make multiple deposits. If Client complies, he gets all the money, otherwise the Bank gets all .","choiceInfo":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment