Skip to content

Instantly share code, notes, and snippets.

@ajuggler
Last active June 13, 2022 17:56
Show Gist options
  • Save ajuggler/c9b2617295112cb2f4839f4cda4a6b58 to your computer and use it in GitHub Desktop.
Save ajuggler/c9b2617295112cb2f4839f4cda4a6b58 to your computer and use it in GitHub Desktop.
MPP - Bank Client agreement (homework)
{-# 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
)
{"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":[]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment