Created
November 4, 2020 21:44
-
-
Save entzik/d70956d6a3c911ee703031db5b37627f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preconsuming choice CastVote: ContractId Doodle | |
with | |
voter: Party | |
option: Text | |
inviteId: ContractId DoodleInvite | |
controller voter | |
do | |
invite <- fetch inviteId | |
assertMsg "this invite was issued for a different doodle" (invite.doodleName == name) | |
assertMsg "the voter casting the vote does not match the voter who received the invite" (invite.voter == voter) | |
assertMsg "the organizer who issued the invite is not the one who created this doodle" (invite.organizer == organizer) | |
assertMsg "this doodle not is open" open | |
assertMsg "voters is not one of the invited voters" (elem voter voters) | |
assertMsg "this is not a valid option " (elem option options) | |
let | |
crtVotes = fromOptional (VotingSlot with count = 0, voted = []) (DA.TextMap.lookup option this.votes) | |
updatedVotes = DA.TextMap.insert option (VotingSlot with count = crtVotes.count + 1, voted = voter :: crtVotes.voted) this.votes | |
assertMsg "each voter is only allowed to cast one vote per option" (notElem voter crtVotes.voted) | |
create this with votes = updatedVotes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment