首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Hyper-ledger Fabric中查询台账和历史数据

如何在Hyper-ledger Fabric中查询台账和历史数据
EN

Stack Overflow用户
提问于 2017-07-10 17:38:39
回答 2查看 6K关注 0票数 7

由于账本包含一系列的业务,如何从账本中查询账本的当前状态和历史数据。

EN

回答 2

Stack Overflow用户

发布于 2017-07-10 20:45:06

如果你对链码上下文中的历史数据感兴趣,你可以使用ChaincodeStubInterface应用编程接口,例如

代码语言:javascript
复制
// 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)

它能够检索给定键的整个历史记录,您将收到返回迭代器,它将为您提供对给定键的历史更改的洞察,例如:

代码语言:javascript
复制
historyIer, err := stub.GetHistoryForKey(yourKeyIsHere)

if err != nil {
    fmt.Println(errMsg)
    return shim.Error(errMsg)
}

if historyIer.HasNext() {
    modification, err := historyIer.Next()
    if err != nil {
        fmt.Println(errMsg)
        return shim.Error(errMsg)
    }
    fmt.Println("Returning information about", string(modification.Value))
}

另请注意,您需要确保在分类帐部分的core.yaml文件部分中启用了历史数据库:

代码语言:javascript
复制
ledger:

  history:
    # enableHistoryDatabase - options are true or false
    # Indicates if the history of key updates should be stored.
    # All history 'index' will be stored in goleveldb, regardless if using
    # CouchDB or alternate database for the state.
    enableHistoryDatabase: true
票数 3
EN

Stack Overflow用户

发布于 2017-07-10 18:21:24

您可以使用QSCC查询分类账。它是用来查询对等体的系统链码。它有各种各样的查询,比如get block by number等。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45008607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档