How do I find the history of transactions for an A

2019-04-29 10:47发布

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. I would now like to query the blockchain (?Historian?) for all transactions which have been executed against a specific Order (defined type of asset).

I've used two different appoaches to pulling Historian data, once through direct API access historian.getall() and the other through a defined query:

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'. I can, and have, easily found the current state of Order # 009, but am now looking for the history of transactions against that order. How to I tell Historian, or another service in the hyperledger-composer system, to give me that information?

3条回答
唯我独甜
2楼-- · 2019-04-29 11:10

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

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?).

Once that is in place you will be able to query for HistorianRecords that reference a given asset/participant id.

查看更多
甜甜的少女心
3楼-- · 2019-04-29 11:11

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 .

查看更多
看我几分像从前
4楼-- · 2019-04-29 11:14

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.

I've posted the detailed answer here: https://github.com/hyperledger/composer/issues/2458#issuecomment-383377837

查看更多
登录 后发表回答