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
assertMsg "each voter is only allowed to cast one vote per option" (notElem voter crtVotes.voted) | |
create this with votes = updatedVotes |
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
VotingSlot with count = crtVotes.count + 1, voted = voter :: crtVotes.voted |
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
updatedVotes = DA.TextMap.insert option (VotingSlot with count = crtVotes.count + 1, voted = voter :: crtVotes.voted) this.votes |
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
crtVotes = fromOptional (VotingSlot with count = 0, voted = []) (DA.TextMap.lookup option this.votes) |
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
do | |
invite <- fetch inviteId | |
... | |
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 |
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) |
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
nonconsuming choice Vote : ContractId Doodle | |
with | |
option: Text | |
controller voter | |
do | |
doodleContractId <- lookupByKey @Doodle (organizer, doodleName) | |
doodleContract <- fetch (fromSome doodleContractId) | |
assertMsg "this party does not own the doodle " (organizer == doodleContract.organizer) | |
exercise (fromSome doodleContractId) CastVote with voter = this.voter, option = option, inviteId = self |
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
nonconsuming choice Vote : ContractId Doodle | |
with | |
option: Text | |
controller voter | |
do | |
doodleContractId <- lookupByKey @Doodle (organizer, doodleName) | |
doodleContract <- fetch (fromSome doodleContractId) | |
assertMsg "this party does not own the doodle " (organizer == doodleContract.organizer) | |
exercise (fromSome doodleContractId) CastVote with voter = this.voter, option = option, inviteId = self |
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
template DoodleInvite | |
with | |
doodleName: Text | |
organizer: Party | |
voter: Party | |
where | |
signatory organizer | |
observer voter | |
key (organizer, voter, doodleName) : (Party, Party, Text) | |
maintainer key._1 |
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
public static <T, R> List<R> mapA(Function<T,R> function, List<T> list) { | |
return list.stream().map(t -> function.apply(t)).collect(Collectors.toList()); | |
} |
NewerOlder