Converting GetPackageResponse to local dar file

Hi team,

So I’m interacting with a remote ledger and wish to download all the deployed packages on the remote node. Then I wish to run Java Codegen locally using the downloaded package. Then I wish to be able to upload that package again and interact with it using my Java Codegen/Bindings.

I’ve used the PackageClient to receive the GetPackageResponse. However, I’m unsure as to how I can convert this to a local dar file. I tried writing the GetPackageResponse.archivePayload byte array to a local file in the form ‘xxxx.dar’, however, when I ran daml damlc inspect-dar on the file, I got the error:

daml damlc inspect-dar 2264eb088eb6fc740e11241b2bf06.dar
damlc: Data.Binary.Get.runGet at position 4: Did not find end of central directory signature
CallStack (from HasCallStack):
  error, called at libraries\\binary\\src\\Data\\Binary\\Get.hs:351:5 in binary-

I guess this means that I must also be writing the GetPackageResponse.hashFunction and GetPackageResponse.hash, however, I’m unsure as to the appropriate way to convert these to bytes and write these to the local file.

Thank you!


ps. don’t forget my badges <3 @anthony

1 Like

I recommend using the daml ledger fetch-dar command for this which should do exactly what you’re asking.

Writing your own DAR is definitely possible but it is a bit of a challenge. You have to track dependencies of the Dalf you start with since DARs include all of their dependencies. You also have to wrap the response that you get from the ledger in the daml-lf container. What you get from the ledger is the payload. Which you then need to wrap in an Archive response.