Skip to content

Instantly share code, notes, and snippets.

@entzik
Created November 4, 2020 21:44
Show Gist options
  • Save entzik/d70956d6a3c911ee703031db5b37627f to your computer and use it in GitHub Desktop.
Save entzik/d70956d6a3c911ee703031db5b37627f to your computer and use it in GitHub Desktop.
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