兄弟连 区块链教程Fabric1.0 源代码分析blockfile区块文件存储二。
区块链教程
涉及方法如下: ```go //构造blockIndex func newBlockIndex(indexConfig *blkstorage.IndexConfig, db *leveldbhelper.DBHandle) *blockIndex //获取最后一个块索引(或编号),取key为"indexCheckpointKey"的值,即为最新的区块编号 func (index *blockIndex) getLastBlockIndexed() (uint64, error) func (index *blockIndex) indexBlock(blockIdxInfo *blockIdxInfo) error //索引区块 //根据区块哈希,获取文件区块指针 func (index *blockIndex) getBlockLocByHash(blockHash []byte) (*fileLocPointer, error) //根据区块编号,获取文件区块指针 func (index *blockIndex) getBlockLocByBlockNum(blockNum uint64) (*fileLocPointer, error) //根据交易ID,获取文件交易指针 func (index *blockIndex) getTxLoc(txID string) (*fileLocPointer, error) //根据交易ID,获取文件区块指针 func (index *blockIndex) getBlockLocByTxID(txID string) (*fileLocPointer, error) //根据区块编号和交易编号,获取文件交易指针 func (index *blockIndex) getTXLocByBlockNumTranNum(blockNum uint64, tranNum uint64) (*fileLocPointer, error) //根据交易ID,获取交易验证代码 func (index *blockIndex) getTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) //代码在common/ledger/blkstorage/fsblkstorage/blockindex.go ``` 补充blockIdxInfo结构体定义:块索引信息。 ``` type blockIdxInfo struct { blockNum uint64 //区块编号 blockHash []byte //区块哈希 flp *fileLocPointer //文件指针 txOffsets []*txindexInfo //交易索引信息 metadata *common.BlockMetadata } //代码在common/ledger/blkstorage/fsblkstorage/blockindex.go ```
|