-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.aleo
113 lines (93 loc) · 2.59 KB
/
main.aleo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// The 'vote.aleo' program.
program vote.aleo;
// Proposal details
interface ProposalInfo:
title as field;
content as field;
// todo: wait bug-fix, https://github.com/AleoHQ/aleo/issues/334
// title as string;
// content as string;
proposer as address;
// Proposal record records proposal info publicly
// Delete this if mapping is more convenient to access
record Proposal:
owner as address.private;
gates as u64.private;
id as field.public;
info as ProposalInfo.public;
// Save proposal info in public storage
// Delete this if record is more convenient to access
mapping proposals:
key id as field.public;
value info as ProposalInfo.public;
// Privacy tickets to vote
record Ticket:
owner as address.private;
gates as u64.private;
pid as field.public;
// Count the total tickets issued for each proposal
mapping tickets:
key pid as field.public;
value count as u64.public;
// Count votes of agreement
mapping agree_votes:
key pid as field.public;
value count as u64.public;
// Count votes of disagreement
mapping disagree_votes:
key pid as field.public;
value count as u64.public;
// Propose a new proposal
// propose(proposal: ProposalInfo)
function propose:
// proposal
input r0 as ProposalInfo.public;
// check proposer
assert.eq self.caller r0.proposer;
// generate proposal id
hash.bhp256 r0 into r1;
// create record
cast self.caller 0u64 r1 r0 into r2 as Proposal.record;
output r2 as Proposal.record;
// finalize r1 r0;
finalize r1;
finalize propose:
// id
input r0 as field.public;
// proposal
// input r1 as ProposalInfo.public;
// todo: delete below, save to proposals mapping
increment tickets[r0] by 0u64;
// new_ticket(pid: field, voter: address)
function new_ticket:
// pid
input r0 as field.public;
// voter
input r1 as address.public;
// todo: check caller to be the proposer
// create record
cast r1 0u64 r0 into r2 as Ticket.record;
output r2 as Ticket.record;
finalize r0;
finalize new_ticket:
// pid
input r0 as field.public;
// count tickets
increment tickets[r0] by 1u64;
// agree(ticket: Ticket.record)
function agree:
// ticket
input r0 as Ticket.record;
finalize r0.pid;
finalize agree:
input r0 as field.public;
increment agree_votes[r0] by 1u64;
// disagree(ticket: Ticket.record)
function disagree:
// ticket
input r0 as Ticket.record;
finalize r0.pid;
// disagree(pid: field)
finalize disagree:
input r0 as field.public;
increment disagree_votes[r0] by 1u64;