Module Daml.Trigger¶
Typeclasses¶
class ActionTriggerAny m where
Features possible in
initialize
,updateState
, andrule
.
- queryContractId
: Template a => ContractId a -> m (Optional a)
Find the contract with the given
id
in the ACS, if present.instance ActionTriggerAny (TriggerA s)
instance ActionTriggerAny TriggerInitializeA
instance ActionTriggerAny (TriggerUpdateA s)
class ActionTriggerAny m => ActionTriggerUpdate m where
Features possible in
updateState
andrule
.
- getCommandsInFlight
Retrieve command submissions made by this trigger that have not yet completed. If the trigger has restarted, it will not contain commands from before the restart; therefore, this should be treated as an optimization rather than an absolute authority on ledger state.
instance ActionTriggerUpdate (TriggerA s)
instance ActionTriggerUpdate (TriggerUpdateA s)
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 TriggerInitializeA s Initialize the user-defined state based on the ACS. updateState Message -> TriggerUpdateA s () Update the user-defined state based on a transaction or completion message. It can manipulate the state with get
,put
, andmodify
, or query the ACS withquery
.rule Party -> TriggerA s () 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 user-defined state. and can retrieve other data with functions inTriggerA
: * The current state of the ACS. * The current time (UTC in wallclock mode, Unix epoch in static mode) * The commands in flight.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) (TriggerInitializeA s)
instance HasField “registeredTemplates” (Trigger s) RegisteredTemplates
instance HasField “rule” (Trigger s) (Party -> TriggerA s ())
instance HasField “updateState” (Trigger s) (Message -> TriggerUpdateA s ())
data TriggerA s a
TriggerA is the type used in the
rule
of a Daml trigger. Its main feature is that you can callemitCommands
to send commands to the ledger.instance ActionTriggerAny (TriggerA s)
instance ActionTriggerUpdate (TriggerA s)
instance Functor (TriggerA s)
instance ActionState s (TriggerA s)
instance HasTime (TriggerA s)
instance Action (TriggerA s)
instance Applicative (TriggerA s)
instance HasField “rule” (Trigger s) (Party -> TriggerA s ())
instance HasField “runTriggerA” (TriggerA s a) (ACS -> TriggerRule (TriggerAState s) a)
data TriggerInitializeA a
TriggerInitializeA is the type used in the
initialize
of a Daml trigger. It can query, but not emit commands or update the state.instance ActionTriggerAny TriggerInitializeA
instance Functor TriggerInitializeA
instance Action TriggerInitializeA
instance Applicative TriggerInitializeA
instance HasField “initialize” (Trigger s) (TriggerInitializeA s)
instance HasField “runTriggerInitializeA” (TriggerInitializeA a) (ACS -> a)
data TriggerUpdateA s a
TriggerUpdateA is the type used in the
updateState
of a Daml trigger. It has similar actions in common withTriggerA
, but cannot useemitCommands
orgetTime
.instance ActionTriggerAny (TriggerUpdateA s)
instance ActionTriggerUpdate (TriggerUpdateA s)
instance Functor (TriggerUpdateA s)
instance ActionState s (TriggerUpdateA s)
instance Action (TriggerUpdateA s)
instance Applicative (TriggerUpdateA s)
instance HasField “runTriggerUpdateA” (TriggerUpdateA s a) ((Map CommandId [Command], ACS) -> State s a)
instance HasField “updateState” (Trigger s) (Message -> TriggerUpdateA s ())
Functions¶
- query
: (Template a, ActionTriggerAny m) => m [(ContractId a, a)]
Extract the contracts of a given template from the ACS.
- queryContractKey
: (Template a, HasKey a k, Eq k, ActionTriggerAny m, Functor m) => k -> m (Optional (ContractId a, a))
Find the contract with the given
key
in the ACS, if present.
- emitCommands
: [Command] -> [AnyContractId] -> TriggerA s 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 s ()
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 s ()
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 s ()
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 s ()
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
.