Created
August 4, 2023 20:53
-
-
Save da-blog/b72b4a4583302b37d89f279d0e9666da to your computer and use it in GitHub Desktop.
This file contains 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. | |
-- SPDX-License-Identifier: Apache-2.0 | |
daml 1.2 | |
module FlexibleControllers where | |
template FeatureAssignment with | |
employee : Party | |
sponsor : Party | |
description : Text | |
where | |
signatory [employee, sponsor] | |
template FeatureSuggestion with | |
employee : Party | |
founders : [Party] | |
description : Text | |
where | |
signatory employee | |
observer founders | |
choice AcceptFeature: ContractId FeatureAssignment with | |
sponsor : Party | |
controller sponsor | |
do | |
assert $ elem sponsor founders | |
create FeatureAssignment with employee, description, sponsor | |
test = scenario do | |
drWho <- getParty "Dr Who" | |
founders@[eric, shaul, yuval] <- mapA getParty ["Eric", "Shaul", "Yuval"] | |
suggestion <- submit drWho do | |
create FeatureSuggestion with | |
employee = drWho | |
description = "Implement a bill splitting app in DAML" | |
founders | |
-- Despite being the CEO, Yuval can't exercise on Shaul's behalf | |
-- due to a missing authorization. | |
submitMustFail yuval do | |
exercise suggestion AcceptFeature with sponsor = shaul | |
-- Dr. Who can't make themselves the sponsor of their own suggestion | |
-- because they are not a founder. | |
submitMustFail drWho do | |
exercise suggestion AcceptFeature with sponsor = drWho | |
submit eric do | |
exercise suggestion AcceptFeature with sponsor = eric |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment