DAML Trigger Library¶
The DAML Trigger library defines the API used to declare a DAML trigger. See DAML Triggers - Off-Ledger Automation in DAML:: for more information on DAML triggers.
Active contract set, you can use
getTemplatesto access the templates of a given type.
instance HasField “acs” (TriggerState s) ACS
data Trigger s
This is the type of your trigger.
sis the user-defined state type which you can often leave at
Field Type Description initialize ACS -> s Initialize the user-defined state based on the ACS. updateState ACS -> Message -> s -> s Update the user-defined state based on the ACS and a transaction or completion message. rule Party -> ACS -> Map CommandId [Command] -> s -> TriggerA () The rule defines the main logic of your trigger. Given the party your trigger is running as, the ACS, the commands in flight and the user-defined state, you can send commands to the ledger using
emitCommandsto change the ACS.
data TriggerA a
: Template a => ACS -> [(ContractId a, a)]
Extract the templates of a given type from the ACS.
Send a transaction consisting of the given commands to the ledger.
Create the template if it’s not already in the list of commands in flight (it will still be created if it is in the ACS).
Note that this will send the create as a single-command transaction. If you need to send multiple commands in one transaction, use
createCmdand handle filtering yourself.
Exercise the choice on the given contract if it is not already in flight.
Note that this will send the exercise as a single-command transaction. If you need to send multiple commands in one transaction, use
exerciseCmdand handle filtering yourself.
This type represents the contract id of an unknown template. You can use
fromAnyContractIdto check which template it corresponds to.
instance HasField “contractId” AnyContractId (ContractId ())
instance HasField “templateId” AnyContractId TemplateTypeRep
A ledger API command. To construct a command use
Field Type Description templateArg AnyTemplate
Field Type Description contractId AnyContractId choiceArg AnyChoice
instance HasField “choiceArg” Command AnyChoice
instance HasField “templateArg” Command AnyTemplate
instance MapKey CommandId
A set of commands that are submitted as a single transaction.
instance HasField “emittedCommands” TriggerAState [Commands]
A completion message. Note that you will only get completions for commands emitted from the trigger. Contrary to the ledger API completion stream, this also includes synchronous failures.
Field Type Description transactionId TransactionId
The data in a
instance HasField “argument” Created AnyTemplate
We implicitly assume that the package id corresponds to the package the trigger is part of. This type is temporary until we have a builtin in LF for identifiers.
data Trigger s
Trigger is (approximately) a left-fold over
Messagewith an accumulator of type
: Template t => AnyContractId -> Optional (ContractId t)
Check if a
AnyContractIdcorresponds to the given template or return
Check if a
Createdevent corresponds to the given template.
Check if an
Archivedevent corresponds to the given template.
: Template t => Command -> Optional t
Check if the command corresponds to a create command for the given template.