简体   繁体   English

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

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

I'm working on the latest rev of hyperledger-composer (V0.13) and have built a network with multiple roles, each of which can invoke selected transactions within the blockchain. 我正在研究hyperledger-composer(V0.13)的最新版本,并构建了一个具有多个角色的网络,每个角色都可以调用区块链中的选定事务。 I would now like to query the blockchain (?Historian?) for all transactions which have been executed against a specific Order (defined type of asset). 我现在想查询区块链(?Historian?),查看针对特定订单(已定义的资产类型)执行的所有交易。

I've used two different appoaches to pulling Historian data, once through direct API access historian.getall() and the other through a defined query: 我曾使用两种不同的方法来提取Historian数据,一次通过直接API访问historian.getall() ,另一种通过定义的查询:

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

}

Both queries succeed in that they return all transactions within the system. 两个查询都成功,因为它们返回系统内的所有事务。 per ex: 每个例子:

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 }

What I can't find, and need, is a way to query the history of transactions against a single Order. 我无法找到和需要的是一种根据单个订单查询交易历史的方法。 An Order is defined (partial listing) as follows: 订单定义(部分列表)如下:

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 

What I'm looking for is a mechanism that will allow me to query the blockchain to get every record pertaining to an Order with orderNumber = '009' . 我正在寻找的是一种机制,它允许我查询区块链以获得Order with orderNumber = '009'Order with orderNumber = '009'相关的每条记录。 I can, and have, easily found the current state of Order # 009, but am now looking for the history of transactions against that order. 我可以而且很容易找到订单#009的当前状态,但现在正在寻找针对该订单的交易历史。 How to I tell Historian, or another service in the hyperledger-composer system, to give me that information? 如何告诉Historian或hyperledger-composer系统中的其他服务给我这些信息?

What you are trying to do makes total sense, however the Historian doesn't yet support it. 你想要做的事情完全有道理,但是历史学家还没有支持它。 This requirement is being tracked here: https://github.com/hyperledger/composer/issues/991 这个要求在这里被跟踪: https//github.com/hyperledger/composer/issues/991

The plan is to add metadata into the HistorianRecord to capture the IDs of the assets and participants that where impacted by the transaction along with the operation performed (delete, update, create, read?). 计划是在HistorianRecord添加元数据,以捕获受事务影响的资产和参与者的ID以及执行的操作(删除,更新,创建,读取?)。

Once that is in place you will be able to query for HistorianRecord s that reference a given asset/participant id. 一旦到位,您将能够查询引用给定资产/参与者ID的HistorianRecord

My work around is to have the transaction emit the results as event and have a query to then fetch the transaction by id from HistorianRecords which will contains the results emitted as event before. 我的工作是让事务将结果作为事件发出,然后有一个查询,然后从HistorianRecords中获取id来获取事务,该事件将包含之前作为事件发出的结果。

I've posted the detailed answer here: https://github.com/hyperledger/composer/issues/2458#issuecomment-383377837 我在这里发布了详细的答案: https//github.com/hyperledger/composer/issues/2458#issuecomment-383377837

A good workaround would be write a script function to update asset , emit the results as an event . 一个好的解决方法是编写脚本函数来更新资产,将结果作为事件发出。 And filter it from the rest endpoint in transactions tab . 并在“事务”选项卡中从其余端点过滤它。

One workaround solution is to emit an Event for your transaction. 一种解决方法是为您的事务发出一个事件。 Mention ASSET as a field of the event. 提及ASSET作为活动的一个领域。 Please experiment with the following code. 请试用以下代码。

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.

相关问题 如何解决#hyperledger-Composer V0.14解组错误 - How to resolve #hyperledger-Composer V0.14 unmarshalling error hyperledger-composer nodejs sdk ping失败 - hyperledger-composer nodejs sdk ping fails Hyperledger Composer中的多个事务 - Multiple Transactions in Hyperledger Composer Hyperledger Fabric 中的资产历史记录 - History of asset in Hyperledger Fabric Hyperledger-Composer:为什么使用 Node.js 而不是 Angular? - Hyperledger-Composer: Why use Node.js instead of Angular? 寻找一个端到端教程,以使用Hyperledger Fabric和Composer REST SERVER开发NodeJs区块链应用程序 - Looking for a End-to-End tutorial to develop a NodeJs Blockchain Appliation using Hyperledger Fabric and Composer REST SERVER 如何为应用程序使用区块链创建公共分类帐? - How do i create a public ledger using blockchain for my application? 如何使用Hyperledger Fabric Node SDK获取事务列表 - How to fetch list of transactions using hyperledger fabric node sdk Hyperledger Composer - 找不到交易错误 - Hyperledger Composer - can't find transaction error 尝试使用npm start启动Hyperledger Composer应用程序会出现“找不到名称%participant%”错误 - Attempt to launch Hyperledger Composer app using npm start gives “Cannot find name %participant%” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM