采用超级账本结构的商业票据中没有交易数据

问题描述

我正在关注商业论文教程,以学习一些chaincode知识。在docs中说,数据库中将存储两件事。第一个是纸张的当前状态,第二个是纸张的生命周期的历史记录,即交易数据。但是,当我在运行问题,购买和兑换方法之后浏览了沙发数据库时,我只看到了纸张的当前状态,而不是纸张的历史记录,即交易数据未存储在数据库中。

在这里丢失了什么吗?我错过了哪些东西,因此我看不到交易数据?请帮助我。

解决方法

请注意,在使用合同api时,每个调用的chaincode函数都会传递一个事务上下文“ ctx”,从中可以获取chaincode存根(GetStub()),该存根具有访问分类帐的功能(例如,GetState) ())并请求更新分类帐(例如PutState())。

链接:https://hyperledger-fabric.readthedocs.io/en/release-2.2/chaincode4ade.html#fabric-contract-api

使用Go链代码的Fabric Contract API文档:

https://godoc.org/github.com/hyperledger/fabric-chaincode-go/shim#Chaincode

您也可以找到node.js文档的链接。

因此,要获取资产的历史记录,必须使用“ func(* ChaincodeStub)GetHistoryForKey” API。

// GetHistoryForKey returns a history of key values across time.
// For each historic key update,the historic value and associated
// transaction id and timestamp are returned. The timestamp is the
// timestamp provided by the client in the proposal header.
// GetHistoryForKey requires peer configuration
// core.ledger.history.enableHistoryDatabase to be true.
// The query is NOT re-executed during validation phase,phantom reads are
// not detected. That is,other committed transactions may have updated
// the key concurrently,impacting the result set,and this would not be
// detected at validation/commit time. Applications susceptible to this
// should therefore not use GetHistoryForKey as part of transactions that
// update ledger,and should limit use to read-only chaincode operations.
GetHistoryForKey(key string) (HistoryQueryIteratorInterface,error)