Skip to content

Instantly share code, notes, and snippets.

@ajuggler
Last active June 11, 2022 05:36
Show Gist options
  • Save ajuggler/55037fe45c588ed7e1c2f219ff53af52 to your computer and use it in GitHub Desktop.
Save ajuggler/55037fe45c588ed7e1c2f219ff53af52 to your computer and use it in GitHub Desktop.
Double Pay (Haskell)
{-# LANGUAGE OverloadedStrings #-}
module Example where
import Language.Marlowe.Extended
main :: IO ()
main = printJSON $ contract (Role "Giver1") (Role "Giver2") (Role "Receiver") (ConstantParam "Deposit") (TimeParam "Deadline")
contract :: Party -> Party -> Party -> Value -> Timeout -> Contract
contract giver1 giver2 receiver amount deadline =
When
[deposits giver1 giver2, deposits giver2 giver1]
deadline
Close
where
pay :: Contract
pay =
(Pay
giver1
(Party receiver)
ada
(AvailableMoney
giver1
ada
)
(Pay
giver2
(Party receiver)
ada
(AvailableMoney
giver2
ada
)
Close
)
)
deposit :: Party -> Action
deposit p = Deposit p p ada $ amount
deposits :: Party -> Party -> Case
deposits p1 p2 = Case
(deposit p1)
(When
[Case (deposit p2) pay]
deadline
Close
)
{"valueParameterInfo":[["Deposit",{"valueParameterFormat":{"contents":[6,""],"tag":"DecimalFormat"},"valueParameterDescription":""}]],"timeParameterDescriptions":[],"roleDescriptions":[],"contractType":"Other","contractShortDescription":"Two payers give to a single recipient.","contractName":"Double pay (haskell)","contractLongDescription":"Two payers give to a single recipient. Exercise in using Haskell.","choiceInfo":[]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment