Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions vote/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ program vote.aleo {
assert_eq(self.caller, info.proposer);

// Generate a new proposal id.
let id: field = BHP256::hash(info.title);
let id: field = BHP256::hash_to_field(info.title);

// Return a new record for the proposal.
// Finalize the proposal id.
return Proposal {
owner: self.caller,
id,
info,
} then finalize(id);
} then finalize(id, info);
}
// Create a new proposal in the "tickets" mapping.
finalize propose(public id: field) {
Mapping::set(tickets, id, 0u64);
// Create a new proposal in the `proposals` mapping.
finalize propose(public id: field, public proposal: ProposalInfo) {
// You can't amend proposal in this example
assert(!Mapping::contains(proposals, id));
Mapping::set(proposals, id, proposal);
}

// Create a new ticket to vote with.
Expand All @@ -60,10 +62,14 @@ program vote.aleo {
return Ticket {
owner: voter,
pid,
} then finalize(pid);
} then finalize(pid, self.caller);
}
// Create a new ticket on a proposal in the "tickets" mapping.
finalize new_ticket(public pid: field) {
finalize new_ticket(public pid: field, caller_core: address) {
// Only proposer can create tickets
let proposal: ProposalInfo = Mapping::get(proposals, pid);
assert_eq(caller_core, proposal.proposer);

let vote: u64 = Mapping::get_or_use(tickets, pid, 0u64);
Mapping::set(tickets, pid, vote + 1u64);
}
Expand Down