ligo/src/parser/pascaligo/Tests/crowdfunding.ligo
Christian Rinderknecht 10469818c1 Removed entrypoint and storage as keywords.
Bug fix: `n-1` was scanned as `n` and `-1`, which was rejected by
a style constraint.

I removed useless style constraints in the lexer.

I removed dead code in `pascaligo.ml`.

I added my first draft for the reference manual of PascaLIGO: DO
NOT EDIT. Edit the website instead.

About the bug fix: This was an awkward attempt at rejecting at
lexing time negative integer literals whose sign is separated
from the digits, like `- 1`. The fix was simple: remove the
`integer` regular expression and use `natural`.
2019-09-26 16:35:16 +02:00

56 lines
1.6 KiB
Plaintext

type store is
record [
goal : mutez;
deadline : timestamp;
backers : map (address, nat);
funded : bool;
]
function back (var store : store) : list (operation) * store is
var operations : list (operation) := list []
begin
if now > store.deadline then
fail "Deadline passed";
else
case store.backers[sender] of [
None -> store.backers[sender] := amount
// or: None -> patch store.backers with map sender -> amount end
| _ -> skip
]
end with (operations, store)
function claim (var store : store) : list (operation) * store is
var operations : list (operation) := nil
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 "Goal reached: no refund."
else
begin
operations := list [transaction (unit, sender, amount)];
remove sender from map store.backers
end
end
end with (operations, store)
function withdraw (var store : store) : list (operation) * store is
var operations : list (operation) := list end
begin
if sender = owner then
if now >= store.deadline then
if balance >= store.goal then {
store.funded := True;
// or: patch store with record funded = True end;
operations := list [Transfer (owner, balance)];
};
else fail "Below target."
else fail "Too soon.";
else skip
end with (operations, store)