0

I have an asset that I have created in hyperledger composer and I want to get the transaction history of the asset using the asset id.

one of the work around as suggested in a similar question is to emit an event to every transaction that makes changes to the asset and then query the historian record based on the events emitted.

This is what I mean

// transaction that is going to make changes to the asset
transaction ModifyAsset{
 o String assetId
}

// event
event ModifyAssetEvent {
 o Asset asset
 o String assetId
}

// queries  the historian record
query searchProductHistory {
  description: "search product by serial number"
  statement: 
    SELECT org.hyperledger.composer.system.HistorianRecord
    WHERE (eventsEmitted[0].assetId == $assetId)
} 

This is could have been ideal but unfortunately Hyperledger composer cannot allow such a query.

Any other solution that I can use to achieve my goal will be highly appreciated

thanks in advance.

Ivan
  • 759
  • 1
  • 10
  • 19

2 Answers2

0

Maybe if you make a query to return only transactions with the specific asset id works.

Something like:

let q1 = businessNetworkConnection.buildQuery(
'SELECT org.hyperledger.composer.system.HistorianRecord'
 + 'WHERE (transactionId == assetId)'
);   
  • the transaction ids are different from the asset ids and therefore it returns an empty list. – Ivan Apr 02 '19 at 22:39
0

My bad, but maybe something like

transaction.transactionInvoked.eventsemitted.asset == assetName

maybe Works.

  • unfortunately Hyperledger composer seems not to allow such type of queries, otherwise thank you. – Ivan Apr 03 '19 at 15:29