2019-03-18 20:47:11 +04:00
|
|
|
type state is
|
2019-03-15 11:45:00 +04:00
|
|
|
record
|
|
|
|
goal : nat;
|
|
|
|
deadline : timestamp;
|
|
|
|
backers : map (address, nat);
|
|
|
|
funded : bool
|
|
|
|
end
|
|
|
|
|
2019-03-18 20:47:11 +04:00
|
|
|
entrypoint contribute (storage store : state;
|
|
|
|
const sender : address;
|
|
|
|
const amount : mutez)
|
|
|
|
: state * list (operation) is
|
|
|
|
var operations : list (operation) := ([] : list (operation)) // TODO
|
2019-03-15 11:45:00 +04:00
|
|
|
begin
|
|
|
|
if now > store.deadline then
|
|
|
|
fail "Deadline passed"
|
|
|
|
else
|
2019-03-18 20:47:11 +04:00
|
|
|
match store.backers[sender] with
|
|
|
|
None ->
|
|
|
|
store :=
|
|
|
|
copy store with
|
|
|
|
record
|
|
|
|
backers = add_binding ((sender, amount), store.backers)
|
|
|
|
end
|
2019-03-18 21:09:15 +04:00
|
|
|
| _ -> skip
|
2019-03-18 20:47:11 +04:00
|
|
|
end
|
2019-03-15 11:45:00 +04:00
|
|
|
end with (store, operations)
|
|
|
|
|
|
|
|
entrypoint get_funds (storage store : state; const sender : address)
|
2019-03-18 20:47:11 +04:00
|
|
|
: state * list (operation) is
|
|
|
|
var operations : list (operation) := ([] : list (operation)) // TODO
|
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-18 20:47:11 +04:00
|
|
|
store := copy store with record funded = True end;
|
2019-03-15 11:45:00 +04:00
|
|
|
operations := [Transfer (owner, balance)]
|
|
|
|
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)
|
|
|
|
|
|
|
|
entrypoint claim (storage store : state; const sender : address)
|
2019-03-18 20:47:11 +04:00
|
|
|
: state * list (operation) is
|
|
|
|
var operations : list (operation) := ([] : list (operation)) // TODO
|
2019-03-15 11:45:00 +04:00
|
|
|
var amount : mutez := 0
|
|
|
|
begin
|
|
|
|
if now <= store.deadline then
|
|
|
|
fail "Too soon"
|
|
|
|
else
|
2019-03-18 20:47:11 +04:00
|
|
|
match store.backers[sender] with
|
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-15 11:45:00 +04:00
|
|
|
if balance >= store.goal || store.funded then
|
|
|
|
fail "Cannot refund"
|
|
|
|
else
|
|
|
|
begin
|
2019-03-18 20:47:11 +04:00
|
|
|
amount := store.backers[sender];
|
2019-03-15 11:45:00 +04:00
|
|
|
store :=
|
|
|
|
copy store with
|
|
|
|
record
|
2019-03-18 20:47:11 +04:00
|
|
|
backers = remove_entry (sender, store.backers)
|
2019-03-15 11:45:00 +04:00
|
|
|
end;
|
|
|
|
operations := [Transfer (sender, amount)]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end with (store, operations)
|