I want to have a graph representation of the events and transactions stored on a running ledger for demo and testing.
I need something similar to what we can see in Daml Studio as the transaction view of script results, but overcoming two limitations: 1) being able to use it against a running ledger not against Daml Script 2) making it more readable by a more suitable layout and filtering the information displayed.
Also something similar to what we can see in the Daml Ledger Model chapter of Daml docs.
It seems nobody among the regular visitors of this forum has done it so far, so I set out to create my own version.
The result looks like this for the view of Alice into the ledger resulted from the setup
script in the skeleton template:
The source of the data is the transaction tree, which can be pulled from the ledger via the ledger API, using e.g. grpCurl.
The nodes of the graph represent events. The node ids have been derived from the event ids by replacing the transaction id by the offset. Events having the same prefix belong to the same transaction, so were created in an atomic manner. Event ids reflect the ordering of events.
Green nodes represent the (create events of the) active contract set at the time of pulling the transaction tree. Red nodes represent archived contracts, blue nodes represent choice exercises.
The node labels have been created by bespoke functions, reflecting the Daml model and user needs.
The edges represent three kinds of relationships: 1) the “child” relationship between top-level events and their consequences within the transaction 2) “consumed by” relationship between consuming choice exercises and the create events of the consumed contracts 3) in this graph we don’t have this, but there will be a “non-consuming exercise” relationship in the graph if the ledger also contains non-consuming exercises.
Creating a meaningful layout is always the toughest part of graph drawing. This layout was set manually, and I will think about an algorithm to produce a similar layout for more complex ledgers.
You can see the source code of the application here: Google Colab