go谈话区块链教程fabric1.0源代码领会ledger(账本)二

  伯仲连go谈话+区块链教程fabric1.0源代码领会ledger(账本)二区块链伯仲。。  # fabric 1.0源代码条记 之 led...

go谈话区块链教程fabric1.0源代码领会ledger(账本)二

  伯仲连go谈话+区块链教程fabric1.0源代码领会ledger(账本)二区块链伯仲。

  # fabric 1.0源代码条记 之 ledger(账本)

币小哥资源讯息:

  ```go

  type ledger interface {

  getblockchaininfo() (*common.blockchaininfo, error) //获得blockchain基础消息

  getblockbynumber(blocknumber uint64) (*common.block, error) //按给定莫大获得block区块链伯仲,给定math.maxuint64将获得最新block

  getblocksiterator(startblocknumber uint64) (resultsiterator, error) //获得从startblocknumber发端的迭代器(包括startblocknumber)区块链伯仲,迭代器是阻碍迭代,直到ledger中下一个block可用

  close() //封闭ledger

  commit(block *common.block) error //提交新block

  //代码在common/ledger/ledger_interface.go

  validatedledger接口暂不决义本领,从peerledger挑选出失效买卖后,validatedledger表白最后账本区块链伯仲。姑且忽视。

币小哥资源讯息:用来实行查问区块链伯仲。

  个中get*本领用来扶助kv-based数据模子,executequery本领用来扶助更充分的数据和查问扶助区块链伯仲。

  ```go

  type queryexecutor interface {

  getstate(namespace string, key string) ([]byte, error) //按namespace和key获得value区块链伯仲,对于chaincode,chaincodeid即为namespace

  getstatemultiplekeys(namespace string, keys []string) ([][]byte, error) //一次挪用获得多个key的值

  //获得迭代器区块链伯仲,归来囊括startkey、但不囊括endkeyd的之间一切值

  getstaterangescaniterator(namespace string, startkey string, endkey string) (commonledger.resultsiterator, error)

  executequery(namespace, query string) (commonledger.resultsiterator, error) //实行查问并归来迭代器区块链伯仲,仅用来查问statedb

  done() //开释queryexecutor占用的资源

  //代码在core/ledger/ledger_interface.go

币小哥资源讯息:实行汗青记载查问区块链伯仲。

  ```go

  type historyqueryexecutor interface {

  gethistoryforkey(namespace string, key string) (commonledger.resultsiterator, error) //按key查汗青记载

  //代码在core/ledger/ledger_interface.go

币小哥资源讯息:在"尽大概"最新状况的普遍快速照相上模仿买卖区块链伯仲。

  个中set*本领用来扶助kv-based数据模子,executeupdate本领用来扶助更充分的数据和查问扶助区块链伯仲。

  ```go

  type txsimulator interface {

  queryexecutor //嵌入queryexecutor接口

  setstate(namespace string, key string, value []byte) error //按namespace和key写入value

  deletestate(namespace string, key string) error //按namespace和key简略

  setstatemultiplekeys(namespace string, kvs map[string][]byte) error //一次挪用树立多个key的值

  executeupdate(query string) error //executeupdate用来扶助充分的数据模子

  gettxsimulationresults() ([]byte, error) //获得模仿买卖的截止

  //代码在core/ledger/ledger_interface.go

  ## 4、kvledger.kvledger构造体及本领(实行peerledger接口)

币小哥资源讯息:

  ```go

  type kvledger struct {

  ledgerid string //ledgerid

  blockstore blkstorage.blockstore //blkstorage

  txtmgmt txmgr.txmgr //txmgr

  historydb historydb.historydb //historydb

  //代码在core/ledger/kvledger/kv_ledger.go

币小哥资源讯息:

  ```go

  //结构kvledger

  func newkvledger(ledgerid string, blockstore blkstorage.blockstore,versioneddb statedb.versioneddb, historydb historydb.historydb) (*kvledger, error)

  //按结果一个灵验块回复statedb和historydb

  func (l *kvledger) recoverdbs() error

  //检索指定范畴内的块, 并将写入集提交给状况 db 或汗青数据库, 或同声

  func (l *kvledger) recommitlostblocks(firstblocknum uint64, lastblocknum uint64, recoverables ...recoverable) error

  //按买卖id获得买卖

  func (l *kvledger) gettransactionbyid(txid string) (*peer.processedtransaction, error)

  //获得blockchaininfo

  func (l *kvledger) getblockchaininfo() (*common.blockchaininfo, error)

  //按区块编号获得块

  func (l *kvledger) getblockbynumber(blocknumber uint64) (*common.block, error)

  //按开始块获得块迭代器

  func (l *kvledger) getblocksiterator(startblocknumber uint64) (commonledger.resultsiterator, error)

  //获得块哈希

  func (l *kvledger) getblockbyhash(blockhash []byte) (*common.block, error)

  //按买卖id获得块

  func (l *kvledger) getblockbytxid(txid string) (*common.block, error)

  //按买卖id获得买卖考证代码

  func (l *kvledger) gettxvalidationcodebytxid(txid string) (peer.txvalidationcode, error)

  func (l *kvledger) prune(policy commonledger.prunepolicy) error //暂未实行

  //创造买卖模仿器

  func (l *kvledger) newtxsimulator() (ledger.txsimulator, error)

  //创造查问实行器

  func (l *kvledger) newqueryexecutor() (ledger.queryexecutor, error)

  func (l *kvledger) newhistoryqueryexecutor() (ledger.historyqueryexecutor, error)

  //提交灵验块区块链伯仲,块写入blkstorage,块中写集介入批处置并革新statedb,写集自己入historydb

  func (l *kvledger) commit(block *common.block) error

  //创造汗青记载查问实行器

  func (l *kvledger) close() //封闭

  //代码在core/ledger/kvledger/kv_ledger.go

  ## 5、kvledger.provider构造体及本领(实行peerledgerprovider接口)

币小哥资源讯息:

  ```go

  type provider struct {

  idstore *idstore //idstore

  blockstoreprovider blkstorage.blockstoreprovider //blkstorage

  vdbprovider statedb.versioneddbprovider //statedb

  historydbprovider historydb.historydbprovider //historydb

  //代码在core/ledger/kvledger/kv_ledger_provider.go

币小哥资源讯息:[fabric 1.0源代码条记 之 ledger #idstore(ledgerid数据库)](idstore.md)

币小哥资源讯息:[fabric 1.0源代码条记 之 ledger #blkstorage(block文献保存)](blkstorage.md)

币小哥资源讯息:[fabric 1.0源代码条记 之 ledger #statedb(状况数据库)](statedb.md)

币小哥资源讯息:[fabric 1.0源代码条记 之 ledger #historydb(汗青数据库)](historydb.md)

币小哥资源讯息:

  ```go

  //辨别结构idstore、blockstoreprovider、vdbprovider和historydbprovider区块链伯仲,并用来结构provider,并回复之前未实行创造的ledger

  func newprovider() (ledger.peerledgerprovider, error)

  //按创世区块创造并翻开ledger区块链伯仲,提交创世区块(块入blkstorage,写集革新statedb,写集自己写入historydb),创造ledgerid

  func (provider *provider) create(genesisblock *common.block) (ledger.peerledger, error)

  //挪用provider.openinternal(ledgerid)区块链伯仲,翻开ledger

  func (provider *provider) open(ledgerid string) (ledger.peerledger, error)

  //按ledgerid翻开blkstorage、statedb和historydb区块链伯仲,并创造kvledger

  func (provider *provider) openinternal(ledgerid string) (ledger.peerledger, error)

  //ledgerid能否生存

  func (provider *provider) exists(ledgerid string) (bool, error)

  //获得ledgerid列表区块链伯仲,调取provider.idstore.getallledgerids()

  func (provider *provider) list() ([]string, error)

  //封闭idstore、blkstorage、statedb、historydb

  func (provider *provider) close()

  //查看能否有之前未实行创造的ledger区块链伯仲,并回复

  func (provider *provider) recoverunderconstructionledger()

  func (provider *provider) runcleanup(ledgerid string) error //姑且没有实行

  func paniconerr(err error, mgsformat string, args ...interface{}) //paniconerr

  //代码在core/ledger/kvledger/kv_ledger_provider.go

  ## 6、ledgermgmt(ledger处置因变量)

币小哥资源讯息:

  ```go

  var openedledgers map[string]ledger.peerledger //ledger map区块链伯仲,key为chainid(即channelid或ledgerid)

  var ledgerprovider ledger.peerledgerprovider //ledgerprovider

  //代码在core/ledger/ledgermgmt/ledger_mgmt.go

币小哥资源讯息:

  ```go

  func initialize() //ledger初始化区块链伯仲,挪用initialize(),once.do保证仅挪用一次

  func initialize() //ledger初始化区块链伯仲,囊括初始化openedledgers及ledgerprovider

  //挪用ledgerprovider.create(genesisblock)创造ledger区块链伯仲,并介入openedledgers

  func createledger(genesisblock *common.block) (ledger.peerledger, error)

  //按id取ledger区块链伯仲,并挪用ledgerprovider.open(id)翻开ledger

  func openledger(id string) (ledger.peerledger, error)

  //获得ledgerid列表区块链伯仲,调取ledgerprovider.list()

  func getledgerids() ([]string, error)

  //封闭ledgerprovider

  func close()

  //结构closableledger

  func wrapledger(id string, l ledger.peerledger) ledger.peerledger

  //代码在core/ledger/ledgermgmt/ledger_mgmt.go

币小哥资源讯息:

  ```go

  type closableledger struct {

  id string

  ledger.peerledger

  func (l *closableledger) close() //调取l.closewithoutlock()

  func (l *closableledger) closewithoutlock() //delete(openedledgers, l.id)

  //代码在core/ledger/ledgermgmt/ledger_mgmt.go

本文转载自互联网,如有侵权,联系删除

相关推荐

评论列表
  • 这个DeFi智能合约金融池,真是厉害,哈哈哈,趁现在知道的还不多,赶紧领取HT,梭哈

    2021-11-04 21:57:51 回复该评论
  • 投资币圈,投资BTC.ETH,投资DeFi不应后悔当时没有投资,而应学会现在买

    2021-11-04 21:57:51 回复该评论
  • 币圈就是自由市场,也许会被打压,但是绝对不会消亡

    2021-11-17 22:36:49 回复该评论
  • 亏不会亏就是大家白忙活赚得少

    2021-11-17 22:36:49 回复该评论
  • 我亏了,1万美金了

    2021-11-18 05:09:45 回复该评论
  • 嫩模都被收割走了

    2021-11-18 05:09:45 回复该评论