how to access the 'eventEmitted' field in

2020-05-08 07:25发布

问题:

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

           });