how to access the 'eventEmitted' field in transaction history of hyperledger fabric

只谈情不闲聊 提交于 2019-12-02 16:21:19

问题


I am working on hyperledger fabric.I want to access the 'eventEmitted' field in transaction history of hyperledger fabric.

 /*transaction history*/
  "transactionType": "com.acn.hps.aops.ims.addingEvidence",
 "eventsEmitted": [
  {
    "$class": "com.acn.hps.aops.ims.BasicEvent",
    "evidenceId": "100",
    "eventId": 
    "b66fd1c38754519339172905d916497376029ad9620ba5f19999fb73cf1d8b58#0",
    "timestamp": "2018-03-01T08:36:41.164Z"
  }
]

I was able to query the Transaction type and got the result, but now to access the evidence id field in eventEmitted how the query will be if i pass _$evidenceId and it matches with the field evidenceId in eventEmitted

query showEvidenceAllHistorians {
description: "get all assetDoc transactions"
statement: SELECT org.hyperledger.composer.system.HistorianRecord
WHERE (transactionType == 'com.acn.hps.aops.ims.addingEvidence')
  }

回答1:


I do not know CONTAINS is not the answer you want? But you can give it a try




回答2:


something like: (this is based on the trade-network as a sample from our sample-networks on Github:

 return query('History') // eg. just a standard Historian query where emittedEvents are recorded
         .then(function (results) {

             for (var n = 0; n < results.length; n++) {

                var element = results[n];
                if (element.eventsEmitted[0] == 'Resource {id=org.acme.trading.TradeNotification#ee730e99-ba77-48b4-83a1-480e7218b7ff#0}') {
                     console.log('Historical record # ' + (n+1) + ', object is : ' +  element);
                     console.log('eventEmitted:  ' + element.eventsEmitted[0]);
                      var firsteventElement = element.eventsEmitted[0];
                      console.log('New var is ' + firsteventElement);
                      var fieldVal = element.eventsEmitted[0].commodity; // field defined in my Event in the model
                      console.log('New var is ' + firsteventElement + 'commodity id in the event Emitted is ' + fieldVal);
                }
              } /// for

           });  


来源:https://stackoverflow.com/questions/49104387/how-to-access-the-eventemitted-field-in-transaction-history-of-hyperledger-fab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!