Skip to content

Instantly share code, notes, and snippets.

@brunjlar
Last active January 12, 2021 21:00
Show Gist options
  • Save brunjlar/43ede88e93a3848a7859b3c5ae8f6261 to your computer and use it in GitHub Desktop.
Save brunjlar/43ede88e93a3848a7859b3c5ae8f6261 to your computer and use it in GitHub Desktop.
joint payment
{-# LANGUAGE OverloadedStrings #-}
module Example where
import Language.Marlowe
main :: IO ()
main = print . pretty $ contract "Alice" "Bob" "Charlie" 100
{- Define a contract, Close is the simplest contract which just ends the contract straight away
-}
contract :: Party -> Party -> Party -> Integer -> Contract
contract alice bob charlie amount =
When
[ Case (deposit alice) $
When
[ Case (deposit bob) pay
] 2 Close
, Case (deposit bob) $
When
[ Case (deposit alice) pay
] 2 Close
] 1 Close
where
a :: Value Observation
a = Constant amount
deposit :: Party -> Action
deposit p = Deposit p p ada a
pay :: Contract
pay = Pay alice (Party charlie) ada a $
Pay bob (Party charlie) ada a
Close
When
[Case
(Deposit
(Role "Alice")
(Role "Alice")
(Token "" "")
(Constant 100)
)
(When
[Case
(Deposit
(Role "Bob")
(Role "Bob")
(Token "" "")
(Constant 100)
)
(Pay
(Role "Alice")
(Party (Role "Charlie"))
(Token "" "")
(Constant 100)
(Pay
(Role "Bob")
(Party (Role "Charlie"))
(Token "" "")
(Constant 100)
Close
)
)]
2 Close
), Case
(Deposit
(Role "Bob")
(Role "Bob")
(Token "" "")
(Constant 100)
)
(When
[Case
(Deposit
(Role "Alice")
(Role "Alice")
(Token "" "")
(Constant 100)
)
(Pay
(Role "Alice")
(Party (Role "Charlie"))
(Token "" "")
(Constant 100)
(Pay
(Role "Bob")
(Party (Role "Charlie"))
(Token "" "")
(Constant 100)
Close
)
)]
2 Close
)]
1 Close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment