首页 > 解决方案 > 超级账本结构中的商业票据中没有交易数据

问题描述

我正在关注商业票据教程来学习一些链码的东西。在文档中说,数据库中将存储两件事。第一个是纸张的当前状态,第二个是纸张生命周期的历史,即交易数据。但是当我在运行 issue、buy 和 reedem 方法后通过 couchdb 时,我只看到了纸的当前状态,而不是纸的历史,即交易数据没有存储在数据库中。

我是否在这里遗漏了什么,我遗漏了什么以至于我没有看到交易数据?请帮我。

标签: node.jshyperledger-fabricblockchainhyperledgersmartcontracts

解决方案


请注意,在使用合约 api 时,每个被调用的链码函数都会传递一个事务上下文“ctx”,您可以从中获取链码存根(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)

推荐阅读