-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -- SPDX-License-Identifier: Apache-2.0 module ExerciseByKey where import Daml.Trigger exerciseByKeyTrigger : Trigger Int exerciseByKeyTrigger = Trigger { initialize = pure 3 , updateState = \msg -> case msg of MCompletion c | Failed {} <- c.status -> modify (subtract 1) _ -> pure () , rule = retryRule , registeredTemplates = AllInDar , heartbeat = None } -- Create one T template and then call a choice by key to create T_. retryRule : Party -> TriggerA Int () retryRule party = do allowedRetries <- get ts <- queryContractKey @T party t_s <- query @T_ case (ts, t_s) of (None, _) -> dedupCreate T { p = party } (Some _, []) -> dedupExerciseByKey @T party C otherwise -> pure () template T with p : Party where signatory p key p : Party maintainer key nonconsuming choice C : ContractId T_ controller p do create T_ { p } template T_ with p : Party where signatory p