说我只是想得到一个涉及特定资产的所有交易的清单(假设我需要查询这个?)。我应该使用TransactionRegistry还是Historian?有什么区别?
答案 0 :(得分:2)
我们有一个当前问题可供Historian用于显示特定资产的更改/增量的历史记录 - https://github.com/hyperledger/composer/issues/991作为一种解决方法,您可以执行以下操作 - 因此对于sample network具有资产的贸易网络商品(以及交易类' Trade')您可以创建查询,例如:
query selectTransaction {description: "choose specific commodity asset"
statement: SELECT org.acme.biznet.Trade
WHERE (commodity == _$commodity ) }
关于区别:
Historian记录所有交易活动(例如创建资产,创建参与者,创建身份等等 - 以及商业网络特定的自定义交易,例如' TransferAsset' PlaceOrder'),包括(包括)有关资产/参与者的情况)改变了什么。
对于TransactionRegistry本身(即一个特定的类 - 比如说' TransferAsset'或者' PlaceOrder'),它存储在该类的Transaction注册表中 - 您可能有许多Transaction类您的业务网络。但是这里的任何内容都与其他活动无关,例如系统活动,也记录在Historian记录中。
进行查询 - 你会做这样的事情(例如在查询文件中):
query myTransactions{
description: "return all transactions made (ie system transactions)"
statement: SELECT org.acme.sample.PlaceOrder
}
即SELECT org.acme.sample.NAME_OF_TRANSACTION_CLASS
对于Historian查询 - 例如
SELECT org.hyperledger.composer.system.HistorianRecord WHERE (transactionType == 'myTranType'
在此处查看更多示例 - > https://www.ibm.com/developerworks/cloud/library/cl-create-powerful-blockchain-queries-with-hyperledger-composer/index.html
答案 1 :(得分:0)
此外,要查看您正在分区的资产ID的事务数据(增量) - 即可通过事务类的transactionInvoked
字段(例如org.acme.trading.Trade
事务类)获得。你可以使用带有环回过滤器的REST API -eg(两者都返回下面的承诺):
return this.httpClient.get('http://localhost:3000/api/Trade?filter=%7B%22include%22%3A%22resolve%22%7D', {withCredentials: true}).toPromise();`
或
return this.httpClient.get('http://localhost:3000/api/Trade?filter=%7B%22include%22%3A%22resolve%22%7D').toPromise();
具有{"include":"resolve"}
过滤器来解析事务类中的关系 - 每个已解析的事务都具有事务增量。然后,您可以查找有问题的资产ID。
示例未解析的事务类(下面,后面是已解析的txn类):
未解决:
[
{
"$class": "org.acme.mynetwork.Trade",
"commodity": "resource:org.acme.mynetwork.Commodity#1",
"newOwner": "resource:org.acme.mynetwork.Trader#2",
"transactionId": "354dca97fc6ac00aabbd923883e3ec2a3d09b8c75a54a8f536a88b6df31e8a0f",
"timestamp": "2018-03-23T12:02:11.228Z"
},
{
"$class": "org.acme.mynetwork.Trade",
"commodity": "resource:org.acme.mynetwork.Commodity#2",
"newOwner": "resource:org.acme.mynetwork.Trader#1",
"transactionId": "9da43acca718633ac8870e6ea34c3c9f481194e48bcdba42673570177091809f",
"timestamp": "2018-03-23T12:02:31.294Z"
}
]
已解决{"include":"resolve"}
作为过滤器:
[
{
"$class": "org.acme.mynetwork.Trade",
"commodity": {
"$class": "org.acme.mynetwork.Commodity",
"tradingSymbol": "1",
"description": "werwer",
"mainExchange": "wrrewer",
"quantity": 10,
"owner": {
"$class": "org.acme.mynetwork.Trader",
"tradeId": "2",
"firstName": "tes2t",
"lastName": "test"
}
},
"newOwner": {
"$class": "org.acme.mynetwork.Trader",
"tradeId": "2",
"firstName": "tes2t",
"lastName": "test"
},
"transactionId": "354dca97fc6ac00aabbd923883e3ec2a3d09b8c75a54a8f536a88b6df31e8a0f",
"timestamp": "2018-03-23T12:02:11.228Z"
},
{
"$class": "org.acme.mynetwork.Trade",
"commodity": {
"$class": "org.acme.mynetwork.Commodity",
"tradingSymbol": "2",
"description": "Ut fugiat.",
"mainExchange": "ACE2",
"quantity": 10,
"owner": {
"$class": "org.acme.mynetwork.Trader",
"tradeId": "1",
"firstName": "test",
"lastName": "test"
}
},
"newOwner": {
"$class": "org.acme.mynetwork.Trader",
"tradeId": "1",
"firstName": "test",
"lastName": "test"
},
"transactionId": "9da43acca718633ac8870e6ea34c3c9f481194e48bcdba42673570177091809f",
"timestamp": "2018-03-23T12:02:31.294Z"
}
]