This is a follow up to my question about nested maps in a Trigger in this post Nested MapA for Triggers to Exercise a choice - #2 by bernhard
My terminal keeps flickering with
13:40:57.112 [TriggerRunner-akka.actor.default-dispatcher-9] WARN com.daml.lf.engine.trigger.Runner - Command failed: DAML_AUTHORIZATION_ERROR(8,887fc896): Interpretation error: Error: node NodeId(1) (b0dd5a2d0e56041ea6673a0d0634ae85439f3259b53d7ac1ea5b2ad22026953f:Account:AssetHoldingAccount) requires authorizers b, but only a,d were given, code: 3 , context: {triggerDefinition: "b0dd5a2d0e56041ea6673a0d0634ae85439f3259b53d7ac1ea5b2ad22026953f:Trigger:autoSendExampleAssetAccountProposal"}
13:40:57.112 [TriggerRunner-akka.actor.default-dispatcher-9] DEBUG daml.tracelog - [unknown source]: "TRIGGERED"
^C13:40:57.117 [TriggerRunner-akka.actor.default-dispatcher-10] WARN com.daml.lf.engine.trigger.Runner - Command failed: Channel shutdownNow invoked, code: 14 , context: {triggerDefinition: "b0dd5a2d0e56041ea6673a0d0634ae85439f3259b53d7ac1ea5b2ad22026953f:Trigger:autoSendExampleAssetAccountProposal"}
13:40:57.118 [TriggerRunner-akka.actor.default-dispatcher-10] DEBUG daml.tracelog - [unknown source]: "TRIGGERED"
13:40:57.118 [TriggerRunner-akka.actor.default-dispatcher-10] WARN com.daml.lf.engine.trigger.Runner - Command failed: Channel shutdownNow invoked, code: 14 , context: {triggerDefinition: "b0dd5a2d0e56041ea6673a0d0634ae85439f3259b53d7ac1ea5b2ad22026953f:Trigger:autoSendExampleAssetAccountProposal"}
13:40:57.119 [TriggerRunner-akka.actor.default-dispatcher-10] DEBUG daml.tracelog - [unknown source]: "TRIGGERED"
The trigger is below. My goal is here is create an AssetHoldingAccountRequest
for each new user (this is done on the frontend) , and I only want the trigger to run when there is a non-empty list of AssetHoldingAccountRequests
, because I map through these requests, exercising the Accept
choice. At the moment, it seems that the trigger is run in a loop.
Per the below, this template should be archived once “Accept” is exercised by the owner/admin party.
template AssetHoldingAccountRequest with
recipient: Party
owner: Party
where
signatory recipient
observer owner
choice Accept: ContractId AssetHoldingAccountProposal
with assetHoldingAccount: ContractId AssetHoldingAccount
controller owner
do
exercise assetHoldingAccount Invite_New_Asset_Holder with
recipient = recipient
Trigger here
module Trigger where
import Account
import qualified Daml.Trigger as T
import DA.Foldable
import DA.Next.Map (Map)
import DA.Optional (whenSome)
import DA.Action
import qualified DA.List.Total as List
autoSendExampleAssetAccountProposal: T.Trigger ()
autoSendExampleAssetAccountProposal = T.Trigger
{ initialize = pure (),
updateState = \_ -> pure (),
registeredTemplates = T.AllInDar,
rule = \p -> do
asset_holding_account_requests <- T.query @Account.AssetHoldingAccountRequest
let isNotMe = (\requests -> requests.recipient /= p)
let notMeList = filter (\(_, contract) -> isNotMe contract) asset_holding_account_requests
let requests = map fst notMeList
assetAccounts <- T.query @Account.AssetHoldingAccount
let isET = (\account -> account.assetType.symbol == "ET")
let etAccounts = filter (\(_, contract) -> isET contract) assetAccounts
let cids = map fst etAccounts
let commands = map(\request -> map(\cid -> T.exerciseCmd request Accept with assetHoldingAccount = cid) cids ) requests
T.emitCommands ( DA.Foldable.concat commands)[]
debug $ "TRIGGERED",
heartbeat = None
}
(some additional context)
The lines below is actually a work around, what I actually want to do is grab 1 account with a key
let isET = (\account -> account.assetType.symbol == "ET")
let etAccounts = filter (\(_, contract) -> isET contract) assetAccounts
I suspect it’s triggering non stop due to the line
let commands = map(\request -> map(\cid -> T.exerciseCmd request Accept with assetHoldingAccount = cid) cids ) requests
Any ideas? I previously was mapping over the list of Cids (the length should be always 1), and that’s why I was thinking perhaps since it was always non-empty, the trigger would keep firing.
But I since reversed the mapping, so we are mapping the requests in the outer map. So technically if all the requests were archived through “Accept” It shouldn’t keep firing right?