如何在使用hyperledger-composer实现的区块链中查找资产的交易历史记录?

问题描述 投票:6回答:4

我正在研究hyperledger-composer(V0.13)的最新版本,并构建了一个具有多个角色的网络,每个角色都可以调用区块链中的选定事务。我现在想查询区块链(?Historian?),查看针对特定订单(已定义的资产类型)执行的所有交易。

我曾经使用两种不同的方法来提取历史数据,一次是通过直接API访问qazxsw poi,另一种是通过定义的查询:

historian.getall()

两个查询都成功,因为它们返回系统内的所有事务。每个例子:

query getHistorianRecords {
  description: "get all Historian records"
  statement: SELECT org.hyperledger.composer.system.HistorianRecord

}

我无法找到和需要的是一种根据单个订单查询交易历史的方法。订单定义(部分列表)如下:

ValidatedResource {
    '$modelManager': ModelManager { modelFiles: [Object] },
    '$namespace': 'org.hyperledger.composer.system',
    '$type': 'HistorianRecord',
    '$identifier': '0c3274475fed3703692bb7344453ab0910686905451b41d5d08ff1b032732aa1',
    '$validator': ResourceValidator { options: {} },
    transactionId: '0c3274475fed3703692bb7344453ab0910686905451b41d5d08ff1b032732aa1',
    transactionType: 'org.acme.Z2BTestNetwork.CreateOrder',
    transactionInvoked: 
     Relationship {
       '$modelManager': [Object],
       '$namespace': 'org.acme.Z2BTestNetwork',
       '$type': 'CreateOrder',
       '$identifier': '0c3274475fed3703692bb7344453ab0910686905451b41d5d08ff1b032732aa1',
       '$class': 'Relationship' },
    eventsEmitted: [],
    transactionTimestamp: 2017-09-22T19:32:48.182Z }

我正在寻找的是一种机制,它允许我查询区块链以获得与asset Order identified by orderNumber { o String orderNumber o String[] items o String status ... o String approved o String paid --> Provider provider --> Shipper shipper --> Buyer buyer --> Seller seller --> FinanceCo financeCo 相关的每条记录。我可以而且很容易找到订单#009的当前状态,但现在正在寻找针对该订单的交易历史。如何告诉Historian或hyperledger-composer系统中的其他服务给我这些信息?

node.js hyperledger-composer historian
4个回答
6
投票

你想要做的事情完全有道理,但是历史学家还没有支持它。这个要求正在跟踪:Order with orderNumber = '009'

计划是将元数据添加到https://github.com/hyperledger/composer/issues/991中,以捕获受事务影响的资产和参与者的ID以及执行的操作(删除,更新,创建,读取?)。

一旦到位,您将能够查询引用给定资产/参与者ID的HistorianRecords。


1
投票

我的工作是让事务将结果作为事件发出,然后有一个查询,然后从HistorianRecords中获取id来获取事务,该事件将包含之前作为事件发出的结果。

我在这里发布了详细的答案:HistorianRecord


0
投票

一个好的解决方法是编写脚本函数来更新资产,将结果作为事件发出。并在“事务”选项卡中从其余端点过滤它。


0
投票

一种解决方法是为您的事务发出一个事件。提及ASSET作为活动的一个领域。请试用以下代码。

https://github.com/hyperledger/composer/issues/2458#issuecomment-383377837

© www.soinside.com 2019 - 2024. All rights reserved.