How do I get contract keys from non-verbose event streams?

We listen to our event stream and convert every contract to JSON, subsequently storing it in MongoDB.

When using the verbose setting, we’re able to get more information about each contract, in particular (1) contract keys, and (2) fully qualified type names. We get these from the DamlRecord object returned by getArguments (then use the fieldMap to convert to JSON).

When using non-verbose mode, we can get a DamlRecord of the contract using toValue, but it doesn’t have the same contents: again, it’s missing the (1) contract key and (2) fully qualified type names.

At first blush, these both seem like things that the codegen should know about. It also strikes me that converting contracts to JSON is probably a common use case; i assume we don’t support that, but wonder why.

Questions:

  1. is there a generic way to get contract keys with non-verbose?
  2. Ditto for fully qualified types?
  3. is there a best practice for converting transaction trees to JSON?
  4. is there any appetite for supporting toJSON as a first-class feature of codegen?

Please see plans and work done so far discussed starting here, and refined in further comments and linked issues/PRs from there. There is quite a lot of discussion about best approaches and what oughtn’t be done.

1 Like

is there a generic way to get contract keys with non-verbose?

One clarification on that: The contract keys are included in the CreatedEvent regardless of whether you enable verbose mode or not. The difference as you noticed i that the type & field names are omitted in non-verbose mode.

2 Likes