Last active
May 2, 2019 13:05
-
-
Save hurryabit/374ecc99ca4c70c4e10ccb828ec57888 to your computer and use it in GitHub Desktop.
A DAML model showcasing unbounded signatories https://medium.com/daml-driven/removing-the-limits-on-signatories-6f947ab19361
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
-- 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 () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.