gpt4 book ai didi

node.js - 如何使用 Nodejs 绑定(bind)从 DAML 中的存档合约中获取数据?

转载 作者:太空宇宙 更新时间:2023-11-03 23:52:30 26 4
gpt4 key购买 nike

我想从 DAML 中的存档契约(Contract)中获取历史数据,以便将其用于审计目的。我读到过有关 JSON API 服务的内容,但它只能做到这一点。

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

  1. 创建
  2. 锻炼
  3. 查询有效契约(Contract)。

我正在检查 DAML 的 Nodejs 绑定(bind),并找到“Interface ArchivedEvent”,但无法理解如何利用它来获取数据。 https://digital-asset.github.io/daml-js/latest/interfaces/archivedevent.html

最佳答案

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

PackageCatalog 包含所有 templateID 的 JSON

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) {

}
}
})

关于node.js - 如何使用 Nodejs 绑定(bind)从 DAML 中的存档合约中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58820376/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com