Converting GetPackageResponse to local dar file
- zoraizmahmoodOP 1
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.archivePayloadbyte array to a local file in the form ‘xxxx.dar’, however, when I randaml damlc inspect-daron 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-0.8.8.0:Data.Binary.GetI guess this means that I must also be writing the
GetPackageResponse.hashFunctionandGetPackageResponse.hash, however, I’m unsure as to the appropriate way to convert these to bytes and write these to the local file.Thank you!
Regards,
Zoraizps. don’t forget my badges <3 @anthony
- cocreature 3
I recommend using the
daml ledger fetch-darcommand 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
Archiveresponse.