Is it possible to resuse custom function script in trigger

I wanted something like this myself but once you look into the details, the cases where this actually makes sense unfortunately mostly disappear.

The two main differences between Script & Triggers that matter here are the following:

  1. A trigger always runs as a single party whereas a Daml Script can submit commands as many different parties.
  2. A trigger submits commands asynchronously. One of the many consequences of that is that you do not get access to the result. A Script on the other hand submits synchronously so you get access to the result and you know that the command has succeeded before moving on to the next one.

So porting an arbitrary script to triggers just does not work. There is a subset of single-party scripts that could be ported in theory but even for those you need to worry about pending sets for triggers which just don’t exist in scripts.

So in practice, the cases where this work are relatively tiny and usually triggers just do different things than your daml scripts.

What can sometimes be helpful if putting some shared logic in a choice that you call via createAndExerciseCmd.

1 Like