通过gRPC客户端在DA Ledger上执行CRUD [英] Doing CRUD on the DA Ledger through a gRPC client
问题描述
我正在编写DA Ledger客户端应用程序.之所以进展缓慢,是因为API文档没有说明如何组合提供的服务以在账本上执行简单的创建,读取,更新和删除操作.
例如,没有简单的服务允许客户直接读取给定方的所有联系人.首先,客户需要获得分类帐ID,然后(我认为)包裹ID.等等.有一项服务可以读取有效合约,但是无效合约又如何呢?
拥有一些文档来解释和演示如何组合对各种服务的调用将对您有所帮助,例如:
I am in the process of writing a DA Ledger client application. It's going slow because the API documentation does not explain how to combine the provided services to do simple Create, read, update, and delete on the Ledger.
For example there is no simple service that allows the client to read all contacts from a given party directly. First the client needs to get the ledger id, and then (I think) the package id. etc. There is a service to read active contracts, but what about inactive contracts?
It would be helpful to have some documentation that explains and demonstrates how to combine calls to the various services to (for example):
- 阅读给定方的所有合同
- 在给定合同上行使选择权
- 创建新合同
我的应用程序是用php编写的.我不一定需要使用php中的示例,但我只想知道如何使用提供的服务来完成简单的任务.
My application is being written in php. I don't necessarily need examples in php but I just want to know how do use the provided services to accomplish simple tasks.
推荐答案
阅读给定方的所有合同
DAML分类帐本质上是事件驱动的系统.因此,它不像传统数据库那样提供查询访问.相反,您的应用程序订阅了 TransactionService 使用 GetTransactionsRequest 指定 LEDGER_BEGIN 作为begin
偏移量.这将为您提供自分类帐启动以来发生的所有Created
和Archived
事件.在您的应用程序中,您可以使用这些事件来建立分类帐的表示形式(内存中或持久性),然后可以方便地进行查询.例如,您可以按合同类型填充字典,为每个Created
事件添加一个条目,并在收到Archived
事件时再次将其删除.
A DAML Ledger is an inherently event-driven system. As such it doesn't provide query access like a traditional database. Instead, your application subscribes to the TransactionService using the GetTransactionsRequest and specifying LEDGER_BEGIN as the begin
offset. This will deliver you all Created
and Archived
events that happened since the ledger was started. In your application you can consume these events to build up a representation (in-memory or persisted) of the ledger, which you can then query conveniently. For example, you could populate a dictionary by contract type, adding an entry for each Created
event and removing it again when an Archived
event is received.
创建合同或行使选择权
有两种方法可以做到这一点:
There are two ways to do this:
-
通过
Submit
在 CommandCompletionService .注意,接收到这样的命令完成消息仅确认分类帐可以成功接收到该命令.它不会包含该命令的任何效果(创建和存档事件).您将在上述TransactionService
上再次收到这些邮件.
Submit a create or exercise command via
Submit
on the CommandSubmissionService and wait for a success or error message on the CommandCompletionService. Note that receiving such command completion message only confirms that the command could be successfully received by the ledger. It will not contain any effects (create and archive events) from that command. These you will again receive on theTransactionService
mentioned above.
Submit a create or exercise command via SubmitAndWait
on the CommandService. This service combines command submission and completion in a synchronous call to the server-side, and will therefore only return once the command has been accepted or rejected by the server. It is usually more convenient to use this way of command submission as it takes care of some of the asynchronous event handling required in the previous method.
请注意,您可以从使用上述TransactionService
建立的分类帐表示中获得行使选择权所需的合约ID.
Note that you can obtain the contract id required to exercise choices from your ledger representation built up using the TransactionService
mentioned above.
这篇关于通过gRPC客户端在DA Ledger上执行CRUD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!