Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Tezos-Developer-Resources/Examples/Crowdfund/Basic.ml
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
41 lines (36 sloc)
1.17 KB
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
[%%version 0.3] | |
(* Basic Tezos crowdfunding contract *) | |
(* Author - Postables *) | |
type storage = { | |
owner : key_hash; | |
funding_goal : tez; | |
amount_raised : tez; | |
soft_cap : tez; | |
} | |
let%init storage = { | |
owner = tz1YLtLqD1fWHthSVHPD116oYvsd4PTAHUoc; | |
funding_goal = 100tz; | |
amount_raised = 0tz; | |
soft_cap = 75tz; | |
} | |
let%entry main | |
(parameter : key_hash) | |
(storage : storage) = | |
if storage.amount_raised >= storage.funding_goal then | |
if (Current.amount()) > 0tz then | |
Current.failwith "funding goal already reached" | |
else | |
let owner_typed = Account.default storage.owner in | |
let owner_refund_op = Contract.call owner_typed storage.funding_goal () in | |
( [owner_refund_op], storage) | |
else | |
let amount = Current.amount() in | |
let new_raise = amount + storage.amount_raised in | |
if new_raise > storage.funding_goal then | |
let difference = new_raise - storage.funding_goal in | |
let key_typed = Account.default parameter in | |
let sender_refund_op = Contract.call key_typed difference () in | |
( [sender_refund_op], storage) | |
else | |
let storage = storage.amount_raised <- amount in | |
( ([] : operation list), storage) |