Skip to content
Discussions/App Development/Accessing daml template data from .dalf files in .dar file and using them in JavaForum ↗

Accessing daml template data from .dalf files in .dar file and using them in Java

App Development6 posts458 views5 likesLast activity Jan 2022
JU
Julius_WilliamOP
Dec 2021

Good day all.

I am attempting to extract daml template information from .dalf files in the generated .dar file locally and manipulate them in java.

Is there any documentation I can refer to for extracting daml template information (parameters and choices in daml templates and the template structure containing type of signatories, observers, input parameters etc) from .dalf files locally and using it in java?
Alternatively any reference repositories would be greatly appreciate as well.

I was taking a look at the daml-lf-1.14-archive-java-proto library and was wondering if template data extraction for documentation can be done by accessing local .dalf files instead of active contracts from the ledger using grpc.

Thank you!

LU
Luciano
Dec 2021

No doubt somebody will expand on this answer, but you may want to start with the LF specification linked on this page:

github.com

digital-asset/daml/blob/11e5dd37e730156b97748d67914b5e3f14a48625/daml-lf/README.md

The unified Daml-LF interpreter and engine
==========================================

This package contains the canonical in-memory LF ASTs of both the public
interface and the whole contents, decoders from on-wire LF to those, and
an interpreter for LF.

Additionally a separate package is provided for a standalone
REPL allowing loading of .dalf files and interpretation of
pure functions, updates and scenarios.

We provide both Bazel-based and Sbt-based builds for this project.  The
Sbt builds are provided solely for development purposes, to facilitate
incremental compilation and IDE integration. You can simply import the
sbt project for development, but if making changes, know that the Bazel
build is the sole source of truth for CI and releases.

Components
----------

This file has been truncated. show original
ST
stefanobaghino-da
Dec 2021
Julius_William:

I was taking a look at the daml-lf-1.14-archive-java-proto library and was wondering if template data extraction for documentation can be done by accessing local .dalf files instead of active contracts from the ledger using grpc.

daml-lf-1.14-archive-java-proto allows you to read the Daml-LF compiler output in DAR and DALF files, no need to use active contracts from the ledger using gRPC (DALF files are encoded as Protobuf but that’s it, no need to use gRPC for that).

We have a library (which is not part of the SDK and does not have access to the same stability guarantees as components in it) that we use to read and manipulate Daml-LF files (e.g. for code generation) but it’s in Scala and it’s no really easy to use in Java (https://github.com/digital-asset/daml/tree/v1.18.0/daml-lf/interface). Its main advantage is that it abstracts over the Daml-LF version (which is an important caveat to keep in mind when using libraries like daml-lf-1.14-archive-java-proto). If by any chance you can use Scala, that could be a viable choice for you (with the caveat I mentioned above about it not being part of the SDK, but rather an internal tool) and you can have a look at how it’s used to generate Java code (https://github.com/digital-asset/daml/tree/v1.18.0/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen).

For a brief example of how to use the Daml-LF Protobuf library you can have a look at how it’s used in ex-java-bindings (here the package is read from the ledger’s package service rather than a file, but the encoding is the same).

JU
Julius_William
Dec 2021

Thank you @Luciano I’ll have a shot at this!

JU
Julius_William
Dec 2021

Thank you @stefanobaghino-da for the examples, great information to know. I’ll begin with the java-proto for now!

ST
Stephen
Jan 2022

As usual, I encourage use of the interface library a little more strongly, for some reasons. It sounds like you’re on the right path, anyhow. Just keep in mind that you must develop a deeper understanding of the LF spec in order to use the java-proto directly, correctly; the protobuf definitions do not enforce all necessary rules.

← Back to Discussions