Last active
January 20, 2021 20:06
-
-
Save brunjlar/c3f5242c59e74885cd1128b33fc9f71b to your computer and use it in GitHub Desktop.
Crowd
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 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 |
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