forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pending set to DAML triggers (digital-asset#3502)
fixes digital-asset#3360
- Loading branch information
1 parent
d654d75
commit 5458053
Showing
7 changed files
with
147 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
-- Copyright (c) 2019 The DAML Authors. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
daml 1.2 | ||
module PendingSet where | ||
|
||
import DA.Foldable (mapA_) | ||
import DA.Next.Map (Map) | ||
import Daml.Trigger | ||
|
||
template Foo | ||
with | ||
p : Party | ||
where | ||
signatory p | ||
|
||
template Boo | ||
with | ||
p : Party | ||
where | ||
signatory p | ||
controller p can | ||
nonconsuming ArchiveFoo: () | ||
with | ||
fooCids : [ContractId Foo] | ||
do mapA_ archive fooCids | ||
assert (length fooCids == 2) | ||
create Done with p | ||
pure () | ||
|
||
template Done | ||
with | ||
p : Party | ||
where | ||
signatory p | ||
|
||
booTrigger : Trigger () | ||
booTrigger = Trigger with | ||
initialize = \acs -> () | ||
updateState = \acs _ s -> s | ||
rule = booRule | ||
|
||
booRule : Party -> ACS -> Map CommandId [Command] -> () -> TriggerA () | ||
booRule party acs _commandsInFlight _userState = do | ||
let foos : [(ContractId Foo, Foo)] = getContracts @Foo acs | ||
let boos : [(ContractId Boo, Boo)] = getContracts @Boo acs | ||
case (boos, foos) of | ||
([], []) -> do | ||
-- initialization so we don’t have to create contracts from Scala | ||
_ <- emitCommands [createCmd (Foo party), createCmd (Foo party), createCmd (Boo party)] [] | ||
pure () | ||
(boo :: _, _ :: _) -> do | ||
let cids = map fst foos | ||
_ <- emitCommands [exerciseCmd (fst boo) ArchiveFoo with fooCids = cids] (map toAnyContractId cids) | ||
pure () | ||
_ -> pure () | ||
|
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
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
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