mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 09:17:43 +03:00
d2e2c21684
New year, new copyright, new expected unknown issues with various files that won't be covered by the script and/or will be but shouldn't change. I'll do the details on Jan 1, but would appreciate this being preapproved so I can actually get it merged by then. CHANGELOG_BEGIN CHANGELOG_END
123 lines
3.5 KiB
Haskell
123 lines
3.5 KiB
Haskell
-- Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
-- SPDX-License-Identifier: Apache-2.0
|
|
|
|
-- The `demo` scenario below demonstrates
|
|
-- (1) a successful exercise of a choice with two controllers (necessarily in
|
|
-- the body of another choice),
|
|
-- (2) a failing attempt to exercise a choice with two controllers by the
|
|
-- wrong two actors,
|
|
-- (3) a failing attempt to exercise a choice with two controllers by just one
|
|
-- of them,
|
|
-- (4) a successful exercise of a choice with two controllers that actually
|
|
-- coincide through a direct commit.
|
|
--
|
|
-- There's a blog post about this example as well:
|
|
-- https://digitalasset.atlassian.net/wiki/spaces/DEL/blog/2018/06/14/595427344/Introducing+Conjunction+Choices
|
|
|
|
module ConjunctionChoices where
|
|
|
|
template PaintHouse
|
|
with
|
|
owner : Party
|
|
painter : Party
|
|
cleaner : Party
|
|
price : Decimal
|
|
where
|
|
signatory owner
|
|
signatory painter
|
|
signatory cleaner
|
|
|
|
|
|
template PaintHouseProposal
|
|
with
|
|
owner : Party
|
|
painter : Party
|
|
cleaner : Party
|
|
price : Decimal
|
|
where
|
|
signatory owner
|
|
observer [painter, cleaner]
|
|
|
|
choice PaintHouseProposal_Accept : ContractId PaintHouse
|
|
controller [painter, cleaner]
|
|
do create PaintHouse with owner; painter; cleaner; price
|
|
|
|
|
|
template PainterCleanerRelationship
|
|
with
|
|
painter : Party
|
|
cleaner : Party
|
|
threshold : Decimal
|
|
where
|
|
signatory painter
|
|
signatory cleaner
|
|
|
|
nonconsuming choice AcceptPaintHouse : ContractId PaintHouse
|
|
with cid : ContractId PaintHouseProposal
|
|
controller painter
|
|
do paintHouseProposal <- fetch cid
|
|
assert (paintHouseProposal.painter == painter)
|
|
assert (paintHouseProposal.cleaner == cleaner)
|
|
assert (paintHouseProposal.price >= threshold)
|
|
exercise cid PaintHouseProposal_Accept
|
|
|
|
|
|
template PainterCleanerProposal
|
|
with
|
|
painter : Party
|
|
cleaner : Party
|
|
threshold : Decimal
|
|
where
|
|
signatory painter
|
|
observer cleaner
|
|
|
|
choice PainterCleanerProposal_Accept : ContractId PainterCleanerRelationship
|
|
controller cleaner
|
|
do create PainterCleanerRelationship with painter; cleaner; threshold
|
|
|
|
|
|
demo = scenario do
|
|
alice <- getParty "Alice"
|
|
bob <- getParty "Bob"
|
|
charlie <- getParty "Charlie"
|
|
donald <- getParty "Donald"
|
|
eric <- getParty "Eric"
|
|
painterCleanerProposal <- submit bob do
|
|
create PainterCleanerProposal with
|
|
painter = bob
|
|
cleaner = charlie
|
|
threshold = 500.0
|
|
painterCleanerRelationship <- submit charlie do
|
|
exercise painterCleanerProposal PainterCleanerProposal_Accept
|
|
|
|
paintAlicesHouseProposal <- submit alice do
|
|
create PaintHouseProposal with
|
|
owner = alice
|
|
painter = bob
|
|
cleaner = charlie
|
|
price = 1000.0
|
|
submit bob do
|
|
exercise painterCleanerRelationship AcceptPaintHouse with
|
|
cid = paintAlicesHouseProposal
|
|
|
|
paintDonaldsTowerProposal1 <- submit donald do
|
|
create PaintHouseProposal with
|
|
owner = donald
|
|
painter = bob
|
|
cleaner = eric
|
|
price = 1000000.0
|
|
submitMustFail bob do
|
|
exercise painterCleanerRelationship AcceptPaintHouse with
|
|
cid = paintDonaldsTowerProposal1
|
|
submitMustFail bob do
|
|
exercise paintDonaldsTowerProposal1 PaintHouseProposal_Accept
|
|
|
|
paintDonaldsTowerProposal2 <- submit donald do
|
|
create PaintHouseProposal with
|
|
owner = donald
|
|
painter = bob
|
|
cleaner = bob
|
|
price = 1500000.0
|
|
submit bob do
|
|
exercise paintDonaldsTowerProposal2 PaintHouseProposal_Accept
|