Skip to content

Instantly share code, notes, and snippets.

@hurryabit
Last active May 2, 2019 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hurryabit/374ecc99ca4c70c4e10ccb828ec57888 to your computer and use it in GitHub Desktop.
Save hurryabit/374ecc99ca4c70c4e10ccb828ec57888 to your computer and use it in GitHub Desktop.
-- Copyright (c) 2019, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
daml 1.2
module Celebration where
import DA.Date qualified as Date
import DA.List
template Celebration with
participants : [Party]
date : Date
occassion : Text
where
signatory participants
template CelebrationProposal with
confirmedParticipants : [Party]
pendingParticipants : [Party]
date : Date
occassion : Text
where
signatory confirmedParticipants
ensure not (null pendingParticipants)
controller head pendingParticipants can
Confirm : ContractId CelebrationProposal
do
assert (length pendingParticipants > 1)
create this with
confirmedParticipants = head pendingParticipants :: confirmedParticipants
pendingParticipants = tail pendingParticipants
ConfirmLast : ContractId Celebration
do
assert (length pendingParticipants == 1)
create Celebration with
participants = reverse (head pendingParticipants :: confirmedParticipants)
date
occassion
test = scenario do
[alice, bob, charlie] <- mapA getParty ["Alice", "Bob", "Charlie"]
let date = Date.date 4 Date.Apr 2019
prop1 <- submit alice do
create CelebrationProposal with
confirmedParticipants = [alice]
pendingParticipants = [bob, charlie]
date
occassion = "DAML is openly available"
prop2 <- submit bob do
exercise prop1 Confirm
celebration <- submit charlie do
exercise prop2 ConfirmLast
pure ()
@neil-da
Copy link

neil-da commented Apr 23, 2019

In Confirm you should assert length pending Particpants isn't 1, otherwise you can confirm and create a contract with zero pending which is stuck. Alternative is just have one confirm, and have it do different things based on number left.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment