如何在Hyperledger Fabric中获取资产修改历史记录 [英] How to fetch asset modification history in hyperledger fabric

查看:655
本文介绍了如何在Hyperledger Fabric中获取资产修改历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 IBM bluemix区块链服务为我的资产共享演示试用一些智能合约逻辑.

仍然可以在超账结构网络中查询资产修改的历史记录.

我已经查看了Fabric 0.6和1.0版本的文档,但是只能找到 stub.pushState(key,value_json) stub.getState(key) 来交互分类帐的宽度.
但使用 stub.getState(key) ,我只能获取密钥的最新条目,但是如何获取和显示针对同一密钥编写的一系列更改/修改. 我已经使用{peeraddress}/Block/getBlock/{Block}遍历了该块,但是仅由于其安全性已启用,我才获得加密的事务有效负载.我不打算显示同一密钥的资产修改历史记录.

I am using IBM bluemix blockchain service to tryout some smart contract logic for my asset sharing demo.

Is there anyway to query the asset modified history in hyperledger fabric network.

I have checked with documentations for both fabric 0.6 and 1.0 versions, but I can find only the stub.pushState(key,value_json) and stub.getState(key) to interact width the ledger.
But using stub.getState(key), I can fetch only the latest entry of the key, but how can I fetch and display the series of changes/modification written for the same key. I have iterated through the block using {peeraddress}/Block/getBlock/{Block}, but I am getting the encrypted transaction payloads only since its security is on. I am not getting the idea to display the history of asset modifications for the same key.


请给我建议正确的方法.

预先感谢


Please suggest me the correct way to do this.

Thanks in advance

推荐答案

您可以按以下方式使用GetHistoryForKey() API:

You can use GetHistoryForKey() API as following:

    historyIter, err := stub.GetHistoryForKey(key)

    if err != nil {
        errMsg := fmt.Sprintf("[ERROR] cannot retrieve history for key <%s>, due to %s", key, err)
        fmt.Println(errMsg)
        return shim.Error(errMsg)
    }

    for historyIter.HasNext() {
        modification, err := historyIer.Next()
        if err != nil {
            errMsg := fmt.Sprintf("[ERROR] cannot read record modification for key %s, id <%s>, due to %s", key, err)
            fmt.Println(errMsg)
            return shim.Error(errMsg)
        }
        fmt.Println("Returning information about", string(modification.Value))
    }


此处是链接到具有API描述的界面:


Here is the link to the interface with API description:

// 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)

如果您不想在链代码的上下文中查看更改历史记录,则可以使用

In case you'd like to inspect history of changes not in context of chaincode you can use QSCC (Query System Chaincode), which provide following capabilities:

// These are function names from Invoke first parameter
const (
    GetChainInfo       string = "GetChainInfo"
    GetBlockByNumber   string = "GetBlockByNumber"
    GetBlockByHash     string = "GetBlockByHash"
    GetTransactionByID string = "GetTransactionByID"
    GetBlockByTxID     string = "GetBlockByTxID"
)

这篇关于如何在Hyperledger Fabric中获取资产修改历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆