Skip to content

Instantly share code, notes, and snippets.

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
create this with voters = DA.List.delete elementToDelete voters
do
create this with voters = DA.List.delete voter voters
do
create this with voters = voter::voters
@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
where
signatory organizer
observer voters
ensure (unique voters) && (unique options)
where
...
key (organizer, name): (Party, Text)
maintainer (fst key)
template Doodle
with
name: Text
organizer: Party
voters: [Party]
options: [Text]
votes: TextMap VotingSlot
open: Bool
where
signatory organizer
data VotingSlot = VotingSlot
with
count : Int
voted : [Party]
deriving (Eq, Show)
test = scenario do
user1 <- getParty "User One"
user2 <- getParty "User Two"
user3 <- getParty "User Three"
userContract1 <- user1 `submit` do
create User with username = user1, following = []
userContract2 <- user2 `submit` do
create User with username = user2, following = []