1

I wanted to get the history data from the archived contracts in DAML so that it can be used for audit purpose. I read about JSON API services but it is only able to.

https://docs.daml.com/json-api/index.html

  1. Create
  2. Exercise
  3. Query Active Contracts.

I was going through nodejs binding of DAML and found "Interface ArchivedEvent" but was not able to understand how to leverage it for getting the data. https://digital-asset.github.io/daml-js/latest/interfaces/archivedevent.html

Shalabh Negi
  • 621
  • 7
  • 18

2 Answers2

1

This is the sample piece of code through which i was able to fetch all the template data.

PackageCatalog contains the JSON of all the templateID

templateId: { packageId: 'my-package-id', moduleName: 'SomeModule', entityName: 'SomeTemplate' },

const ledger = require('@digitalasset/daml-ledger'); 
const templateIds = require('../config/PackageCatalog.json')


const connect = util.promisify(ledger.DamlLedgerClient.connect.bind(ledger.DamlLedgerClient))
const client = await connect({ host: ' host id of your like localhost or some ip', port: 'your sandbox port number' })
const tmplt_Test = templateIds['Main.Test.Testuno:Testtemp']
const filtersByParty = {}
filtersByParty['Party Data you want to fetch'] = { inclusive: { templateIds: [tmplt_Test] } };
const GetTransactionsRequest = {
  begin: { offsetType: 'boundary', boundary: ledger.LedgerOffsetBoundaryValue.BEGIN },
  filter: { filtersByParty: filtersByParty }
};
let getAllTransactionData = client.transactionClient.getTransactions(GetTransactionsRequest);

getAllTransactionData.on('data', response => {
  console.log(" \n\n response :::: " + JSON.stringify(response))
  for (let transaction of response.transactions) {
    let events = transaction.eventsById;
    for (let eventId in events) {

    }
  }
})
Shalabh Negi
  • 621
  • 7
  • 18
0

The ArchivedEvent doesn't expose the argument with which the contract was initially created.

There are two possible approaches that you can take for auditing:

  1. you can have a look at the Extractor, which dumps contracts on a RDBMS where you can query for archived contracts, or
  2. write your app where you replay the transaction stream from the very beginning with TransactionService#getTransactions, save the contracts coming in as CreatedEvents and then mark them as archived whenever you see an ArchivedEvent, using the contract identifier as reference.

Please note though that the Node.js bindings are currently a community-driven project so they may lag behind the latest releases.

stefanobaghino
  • 11,253
  • 4
  • 35
  • 63