Module Daml.Trigger¶
Data Types¶
data Trigger s
This is the type of your trigger.
s
is 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 -> Time -> Map CommandId [Command] -> s -> TriggerA () The rule defines the main logic of your trigger. It can send commands to the ledger using emitCommands
to change the ACS. The rule depends on the following arguments: * The party your trigger is running as. * The current state of the ACS. * The current time (UTC in wallclock mode, Unix epoch in static mode) * The commands in flight. * The user-defined state.registeredTemplates RegisteredTemplates The templates the trigger will receive events for. heartbeat Optional RelTime Send a heartbeat message at the given interval. instance HasField “heartbeat” (Trigger s) (Optional RelTime)
instance HasField “initialize” (Trigger s) (ACS -> s)
instance HasField “registeredTemplates” (Trigger s) RegisteredTemplates
instance HasField “rule” (Trigger s) (Party -> ACS -> Time -> Map CommandId [Command] -> s -> TriggerA ())
instance HasField “updateState” (Trigger s) (ACS -> Message -> s -> s)
Functions¶
- getTemplates
- : Template a => ACS -> [(ContractId a, a)]
- getContracts
: Template a => ACS -> [(ContractId a, a)]
Extract the contracts of a given template from the ACS.
- emitCommands
: [Command] -> [AnyContractId] -> TriggerA CommandId
Send a transaction consisting of the given commands to the ledger. The second argument can be used to mark a list of contract ids as pending. These contracts will automatically be filtered from getContracts until we either get the corresponding transaction event for this command or a failing completion.
- dedupCreate
: (Eq t, Template t) => t -> TriggerA ()
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
emitCommands
withcreateCmd
and handle filtering yourself.
- dedupCreateAndExercise
: (Eq t, Eq c, Template t, Choice t c r) => t -> c -> TriggerA ()
Create the template and exercise a choice on it 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 and exercise as a single-command transaction. If you need to send multiple commands in one transaction, use
emitCommands
withcreateAndExerciseCmd
and handle filtering yourself.
- dedupExercise
: (Eq c, Choice t c r) => ContractId t -> c -> TriggerA ()
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
emitCommands
withexerciseCmd
and handle filtering yourself.If you are calling a consuming choice, you might be better off by using
emitCommands
and adding the contract id to the pending set.
- dedupExerciseByKey
: (Eq c, Eq k, Choice t c r, TemplateKey t k) => k -> c -> TriggerA ()
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
emitCommands
withexerciseCmd
and handle filtering yourself.
- runTrigger
: Trigger s -> Trigger (TriggerState s)
Transform the high-level trigger type into the one from
Daml.Trigger.LowLevel
.