daml/triggers/service/test-model/TestTrigger.daml
Gary Verhaegen a925f0174c
update copyright notices for 2021 (#8257)
* update copyright notices for 2021

To be merged on 2021-01-01.

CHANGELOG_BEGIN
CHANGELOG_END

* patch-bazel-windows & da-ghc-lib
2021-01-01 19:49:51 +01:00

79 lines
1.4 KiB
Haskell

-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
module TestTrigger where
import DA.Action
import DA.Foldable
import Daml.Trigger
import Daml.Script (script)
template A
with
p : Party
v : Int
where
signatory p
template B
with
p : Party
v : Int
where
signatory p
trigger : Trigger ()
trigger = Trigger with
initialize = pure ()
updateState = \_ -> pure ()
rule = triggerRule
registeredTemplates = AllInDar
heartbeat = None
triggerRule : Party -> TriggerA () ()
triggerRule p = do
as <- filter (\(_, a) -> a.p == p) <$> query @A
bs <- map (\(_, B x y) -> (x,y)) . filter (\(_, b) -> b.p == p) <$> query @B
forA_ as $ \(aCid, A x y) ->
when ((x,y) `notElem` bs) $
void $ emitCommands [createCmd (B x y)] [toAnyContractId aCid]
pure ()
-- This is a dummy definition to make sure
-- that we blow the default protobuf recursion limit
-- and thereby test that we decode using the raised limit.
_protobufrecursionlimit y = script do
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
pure ()
y