How to trigger an action once a specific date & time reached

G-d willing

Hello,
I am implementing a bid system for purchasing bonds. The bid has a time limit where the investors cannot submit their offers anymore. And once the time reaches, the system should review the offers, and decide which offers to accept, and which one to reject.
How can I trigger this action on the ledger which will happen automatically?

Thanks,

Hi @cohen.avraham,

The Daml ledger itself is “just” a system of record; it doesn’t take action. If you want something to happen, you need to have a client that talks to the ledger through its gRPC API, and that client needs to be properly authenticated.

The simplest way to achieve what you’re after here is probably to use the Trigger Service. The Trigger Service is a ledger client written by DA and distributed as part of the SDK. It allows you to write triggers in Daml that will maintain some invariants on the ledger.

I’ll refer you to the documentation for details, but as a very high level view, here are a couple important points to keep in mind:

  • The Trigger Service is not “special” in that it is ultimately just a Scala application that talks to the ledger through the gRPC API. If it doesn’t fit your use-cases, you may want to consider building your own application that talks to the gRPC API; there’s nothing the Trigger Service does that you couldn’t do (though obviously you’d have to replicate a substantial amount of effort).
  • “Triggers” are a bit of an unfortunate name; it’s better to think of them as rules, or invariants. It’s a subtle change in perspective that will help you write them in a much more robust way.

The overall approach I’d suggest is that the initial “bid-accepting” contract embeds a “deadline: Time” parameter, and:

  • The choice to add a bid checks for that time.
  • You run a Trigger “often enough” (there’s a tradeoff with performance here) to collect all expired open bids and close them appropriately.

I’d recommend putting as much of the logic in the templates themselves rather than in the trigger code, i.e. the trigger code should ideally just be calling choices on templates rather than have complex logic itself.

Hope that helped.

4 Likes

Thank you @Gary_Verhaegen.
This is exactly what I was looking for :+1: