我正在使用fabcar项目:https://github.com/IBM/blockchain-application-using-fabric-java-sdk
我想知道是否有一种方法可以获得某个键的交易历史记录(而不仅仅是查询一个简单的汽车,或者列出所有的键)。
谢谢。
发布于 2020-02-03 18:40:51
是的,您有一个名为GetHistoryForKey()的接口
你可以在这里阅读更多内容:How to fetch asset modification history in hyperledger fabric
发布于 2020-02-04 19:40:47
这是我尝试过的过程,并得到了结果。我已经在我的链代码中实现了下面的代码。
private Response getQueryHistory(ChaincodeStub chaincodeStub, List<String> args) {
// method for getting the history for key
QueryResultsIterator<KeyModification> queryResults = chaincodeStub.getHistoryForKey(args.get(0));
return newSuccessResponse(prepareJsonFromQueryResult(queryResults));
}
private String prepareJsonFromQueryResult(QueryResultsIterator<KeyModification> queryResults) {
// here build your json object from query result
return "your json object";
}有关ChaincodeStub方法的更多信息,请查看https://hyperledger.github.io/fabric-chaincode-java/release-1.4/api/org/hyperledger/fabric/shim/ChaincodeStub.html
https://stackoverflow.com/questions/60037131
复制相似问题