Skip to content

Instantly share code, notes, and snippets.

where
...
key (organizer, name): (Party, Text)
maintainer (fst key)
where
signatory organizer
observer voters
ensure (unique voters) && (unique options)
@entzik
entzik / lists.hs
Last active October 11, 2020 19:58
choice AddVoter : ContractId Doodle
with
voter: Party
controller organizer
do
assertMsg "this doodle has been opened for voting, cannot add voters" (not open)
create this with voters = voter::voters
choice RemoveVoter : ContractId Doodle
with
do
create this with voters = voter::voters
do
create this with voters = DA.List.delete voter voters
create this with voters = DA.List.delete elementToDelete voters
preconsuming choice IssueInvites : ContractId Doodle
controller organizer
do
assertMsg "this doodle has been opened for voting, cannot issue any more invites" (not open)
DA.Traversable.mapA
(\voter -> create DoodleInvite
with doodleName = this.name, organizer = this.organizer, voter = voter)
voters
-- archive self
create this with open = True
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());
}
template DoodleInvite
with
doodleName: Text
organizer: Party
voter: Party
where
signatory organizer
observer voter
key (organizer, voter, doodleName) : (Party, Party, Text)
maintainer key._1
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