node.js - 超级账本结构中的商业票据中没有交易数据
问题描述
我正在关注商业票据教程来学习一些链码的东西。在文档中说,数据库中将存储两件事。第一个是纸张的当前状态,第二个是纸张生命周期的历史,即交易数据。但是当我在运行 issue、buy 和 reedem 方法后通过 couchdb 时,我只看到了纸的当前状态,而不是纸的历史,即交易数据没有存储在数据库中。
我是否在这里遗漏了什么,我遗漏了什么以至于我没有看到交易数据?请帮我。
解决方案
请注意,在使用合约 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)
推荐阅读
- python - 如何在python中实现客户端-服务器交互
- mongodb - MongoDB - 嵌套文档数组上的唯一复合索引
- javascript - 使用nodejs删除和更新mysql中的记录并使用ejs模板引擎表达
- github - 我无法推送到 GitHub
- pip - chroot 中的 Pip SSLError malloc 失败
- wordpress - 当使用添加到库存中的更多产品更新购物车时,在 woocommerce 中显示低库存通知错误
- react-native - 无法在 React-native 中的 SwitchNavigator 中导航
- python-3.x - 我可以压缩此代码以根据变量制作多个标签和条目吗?
- view - 业务中心创建新视图未显示在下拉列表中
- opencv - 级联分类器对不同颜色的对象不变?