ligo/Tests/crowdfunding.ligo
Christian Rinderknecht fef4337e83
Support for empty sets and maps. Alternate syntax for maps and lists:
sets, maps and lists are now homogeneous.

Lists by extension now require the "list" keyword, like sets and
maps. Semicolons needed, instead of commas.

New syntax for lists: `list [e_1; e_2; ...; e_n]`.

The empty list can now be denoted either by `list []` or `list end` or
`nil'.

Both `list` and `nil` are new keywords. Lists can also be denoted
without brackets, as sets and maps: `list e_1; e_2; ...; e_n end`.

The extension for maps follows the extension for sets: `map [b_1; b_2;
...; b_n]` or `maps b_1; ...; b_n end`.
2019-03-26 10:31:55 +01:00

64 lines
1.9 KiB
Plaintext

type store is
record
goal : nat;
deadline : timestamp;
backers : map (address, nat);
funded : bool;
end
entrypoint contribute (storage store : store;
const sender : address;
const amount : mutez)
: store * list (operation) is
var operations : list (operation) := nil
const s : list (int) = list [1; 2; 3]
const t : set (int) = set []
block {
if now > store.deadline then
fail "Deadline passed";
else
case store.backers[sender] of
None -> store.backers[sender] := Some (amount)
// None -> patch store.backers with map sender -> amount end
| _ -> skip
end
} with (store, operations)
entrypoint withdraw (storage store : store; const sender : address)
: store * list (operation) is
var operations : list (operation) := list end
begin
if sender = owner then
if now (Unit) >= store.deadline then
if balance >= store.goal then {
store.funded := True;
// patch store with record funded = True end;
operations := list [Transfer (owner, balance)];
};
else fail "Below target"
else { fail "Too soon"; }
else skip
end with (store, operations)
entrypoint claim (storage store : store; const sender : address)
: store * list (operation) is
var operations : list (operation) := list []
var amount : mutez := 0
begin
if now <= store.deadline then
fail "Too soon"
else
case store.backers[sender] of
None ->
fail "Not a backer"
| Some (amount) ->
if balance >= store.goal or store.funded then
fail "Cannot refund"
else
begin
operations := list [Transfer (sender, amount)];
remove sender from map store.backers
end
end
end with (store, operations)