2019-03-19 17:32:43 +04:00
|
|
|
type store is
|
2019-03-15 11:45:00 +04:00
|
|
|
record
|
|
|
|
goal : nat;
|
|
|
|
deadline : timestamp;
|
|
|
|
backers : map (address, nat);
|
2019-03-22 00:34:22 +04:00
|
|
|
funded : bool;
|
2019-03-15 11:45:00 +04:00
|
|
|
end
|
|
|
|
|
2019-03-20 13:06:33 +04:00
|
|
|
const foo : store = map "X" -> 10; "Y" -> 11 end
|
|
|
|
|
2019-03-19 17:32:43 +04:00
|
|
|
entrypoint contribute (storage store : store;
|
2019-03-18 20:47:11 +04:00
|
|
|
const sender : address;
|
|
|
|
const amount : mutez)
|
2019-03-19 17:32:43 +04:00
|
|
|
: store * list (operation) is
|
2019-03-19 13:52:47 +04:00
|
|
|
var operations : list (operation) := []
|
2019-03-15 11:45:00 +04:00
|
|
|
begin
|
|
|
|
if now > store.deadline then
|
|
|
|
fail "Deadline passed"
|
|
|
|
else
|
2019-03-19 14:54:23 +04:00
|
|
|
case store.backers[sender] of
|
2019-03-20 17:57:55 +04:00
|
|
|
None -> store.backers[sender] := Some (amount)
|
2019-03-20 19:31:33 +04:00
|
|
|
// None -> patch store.backers with map sender -> amount end
|
2019-03-20 12:45:32 +04:00
|
|
|
| _ -> skip
|
2019-03-18 20:47:11 +04:00
|
|
|
end
|
2019-03-15 11:45:00 +04:00
|
|
|
end with (store, operations)
|
|
|
|
|
2019-03-19 17:32:43 +04:00
|
|
|
entrypoint withdraw (storage store : store; const sender : address)
|
|
|
|
: store * list (operation) is
|
2019-03-19 13:52:47 +04:00
|
|
|
var operations : list (operation) := []
|
2019-03-15 11:45:00 +04:00
|
|
|
begin
|
|
|
|
if sender = owner then
|
|
|
|
if now >= store.deadline then
|
|
|
|
if balance >= store.goal then
|
|
|
|
begin
|
2019-03-20 16:27:55 +04:00
|
|
|
store.funded := True;
|
2019-03-20 19:31:33 +04:00
|
|
|
// patch store with record funded = True end;
|
2019-03-20 12:45:32 +04:00
|
|
|
operations := [Transfer (owner, balance)]
|
2019-03-15 11:45:00 +04:00
|
|
|
end
|
|
|
|
else fail "Below target"
|
|
|
|
else fail "Too soon"
|
2019-03-18 21:09:15 +04:00
|
|
|
else skip
|
2019-03-15 11:45:00 +04:00
|
|
|
end with (store, operations)
|
|
|
|
|
2019-03-19 17:32:43 +04:00
|
|
|
entrypoint claim (storage store : store; const sender : address)
|
|
|
|
: store * list (operation) is
|
2019-03-19 13:52:47 +04:00
|
|
|
var operations : list (operation) := []
|
2019-03-15 11:45:00 +04:00
|
|
|
var amount : mutez := 0
|
|
|
|
begin
|
|
|
|
if now <= store.deadline then
|
|
|
|
fail "Too soon"
|
|
|
|
else
|
2019-03-19 14:54:23 +04:00
|
|
|
case store.backers[sender] of
|
2019-03-15 11:45:00 +04:00
|
|
|
None ->
|
|
|
|
fail "Not a backer"
|
2019-03-18 20:47:11 +04:00
|
|
|
| Some (amount) ->
|
2019-03-20 15:28:25 +04:00
|
|
|
if balance >= store.goal or store.funded then
|
2019-03-15 11:45:00 +04:00
|
|
|
fail "Cannot refund"
|
|
|
|
else
|
|
|
|
begin
|
2019-03-20 12:45:32 +04:00
|
|
|
operations := [Transfer (sender, amount)];
|
2019-03-20 19:16:30 +04:00
|
|
|
store.backers[sender] := None
|
2019-03-15 11:45:00 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end with (store, operations)
|