繁体   English   中英

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

[英]How do I find the history of transactions for an Asset in a blockchain implemented using hyperledger-composer?

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

我曾使用两种不同的方法来提取Historian数据,一次通过直接API访问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 

我正在寻找的是一种机制,它允许我查询区块链以获得Order with orderNumber = '009'Order with orderNumber = '009'相关的每条记录。 我可以而且很容易找到订单#009的当前状态,但现在正在寻找针对该订单的交易历史。 如何告诉Historian或hyperledger-composer系统中的其他服务给我这些信息?

你想要做的事情完全有道理,但是历史学家还没有支持它。 这个要求在这里被跟踪: https//github.com/hyperledger/composer/issues/991

计划是在HistorianRecord添加元数据,以捕获受事务影响的资产和参与者的ID以及执行的操作(删除,更新,创建,读取?)。

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

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

我在这里发布了详细的答案: https//github.com/hyperledger/composer/issues/2458#issuecomment-383377837

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

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

let historian = await businessNetworkConnection.getHistorian(); let historianRecords = await historian.getAll(); for(let i=0; i< historianRecords.length;i++) {console.log(historianRecords[i].transactionId+ "-----> " + historianRecords[i].eventsEmitted[0].YOUR_ASSET_NAME);}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM