I am trying to use trigger to pass information from one DAML contract to another, like this:
template Bar
with
owner: Party
someInfo: Int
state: Bar_State
where
signatory owner
controller owner can
Bar_Accept : ContractId Bar
do
create BarTrigger with info=someInfo
create this with state=BarState_Accepted
Bar_Reject : ContractId Bar
do
create this with state=BarState_Rejected
template BarTrigger
with
owner: Party
info: Int
where
signatory owner
controller owner can
BarTrigger_Consume: ()
do pure()
The state transition of Bar will trigger the execution of DoSomething, which is defined as a choice of some other contract in another file.
triggerRule : Party -> TriggerA () ()
triggerRule _party = do
triggers <- query @BarTrigger
forA_ triggers $ \(cid, c) -> do
if (c.owner == _party)
then do
debug ((show c.owner) <> " do something with " <> "info=" <> (show c.info))
dedupExercise someCid DoSomething with info=c.info
dedupExercise cid BarTrigger_Consume
else pure()
The code works if I only have one trigger generated. If I have multiple triggers (from multiple contracts generated from the template Bar), I get this error:
Trigger is running as alice (context: {triggerDefinition=75c51e68bcce2f98be4ce858be6ad37b26b7bb55277440fa07b61a6295434ec7:Keplaax.Triggers.SellerTrigger:trigger})
[unknown source]: "'alice' do something with info=2"
[unknown source]: "'alice' do something with info=1"
[unknown source]: "'alice' do something with info=1"
Command failed: Inconsistent: DuplicateKey: Contract Key not unique, code: 3 (context: {triggerDefinition=75c51e68bcce2f98be4ce858be6ad37b26b7bb55277440fa07b61a6295434ec7:Keplaax.Triggers.SellerTrigger:trigger})
I guess I am doing something stupid in DoSomething.
I am seeking for advice on how to debug DoSomething with Daml navigator (I guess I have to because I am using trigger?)… I added debug into DoSomething but I am not sure where the trace go.