Skip to content

Instantly share code, notes, and snippets.

@brunjlar
Last active January 20, 2021 20:06
Show Gist options
  • Save brunjlar/c3f5242c59e74885cd1128b33fc9f71b to your computer and use it in GitHub Desktop.
Save brunjlar/c3f5242c59e74885cd1128b33fc9f71b to your computer and use it in GitHub Desktop.
Crowd
{-# LANGUAGE OverloadedStrings #-}
module Example where
import Data.List (foldl')
import Language.Marlowe
main :: IO ()
main = print . pretty $ contract
{- Define a contract, Close is the simplest contract which just ends the contract straight away
-}
contract :: Contract
contract = crowd 1000 500 "Dora" ["Alice", "Bob", "Charlie"] 10
crowd :: Integer -- ^ campaign goal
-> Integer -- ^ individual contribution
-> Party -- ^ campaign owner
-> [Party] -- ^ contributors
-> Slot -- ^ deadline
-> Contract
crowd goal c owner contributors deadline
= go [] contributors
where
go :: [Party] -> [Party] -> Contract
go ys ns =
When
[Case (Deposit n n ada $ Constant c) $
go (n : ys) $ filter (/= n) ns | n <- ns]
deadline $ settle ys
settle :: [Party] -> Contract
settle ys
| fromIntegral (length ys) * c >= goal = foldl' pay Close ys
| otherwise = Close
pay :: Contract -> Party -> Contract
pay x p = Pay p (Party owner) ada (Constant c) x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment