kvstore

package module
v0.0.0-...-046b1b1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2022 License: Apache-2.0 Imports: 14 Imported by: 1

README

chain5j-kvstore

简介

chain5j-kvstore chain5j链KV数据库处理模块。

功能

证书

chain5j-kvstore 的源码允许用户在遵循 Apache 2.0 开源证书 规则的前提下使用。

版权

Copyright@2022 chain5j

chain5j

Documentation

Overview

Package kvstore

@author: xwc1125

Package kvstore

@author: xwc1125

Package kvstore

@author: xwc1125

Package kvstore

@author: xwc1125

Package kvstore

@author: xwc1125

Package kvstore

@author: xwc1125

Index

Constants

View Source
const (
	DefaultTxStorePath    = "txdata"
	DefaultBlockStorePath = "chaindata"
	DefaultCrudStorePath  = "cruddata"
)

Variables

This section is empty.

Functions

func DeleteBlock

func DeleteBlock(db ChainDbDeleter, hash types.Hash, number uint64)

DeleteBlock removes all block data associated with a hash.

func DeleteBody

func DeleteBody(db ChainDbDeleter, hash types.Hash, number uint64)

DeleteBody removes all block body data associated with a hash.

func DeleteCanonicalHash

func DeleteCanonicalHash(db ChainDbDeleter, number uint64)

DeleteCanonicalHash 移除区块高度到hash的键值映射。

func DeleteHeader

func DeleteHeader(db ChainDbDeleter, hash types.Hash, number uint64)

DeleteHeader removes all block header data associated with a hash.

func HasBody

func HasBody(db ChainDbReader, hash types.Hash, number uint64) bool

HasBody verifies the existence of a block body corresponding to the hash.

func HasHeader

func HasHeader(db ChainDbReader, hash types.Hash, number uint64) bool

HasHeader 检查区块头是否存在

func NewKvStore

func NewKvStore(rootCtx context.Context, opts ...option) (protocol.Database, error)

func ReadBlock

func ReadBlock(db ChainDbReader, hash types.Hash, number uint64) *models.Block

ReadBlock retrieves an entire block corresponding to the hash, assembling it back from the stored header and body. If either the header or body could not be retrieved nil is returned.

Note, due to concurrent download of header and block body the header and thus canonical hash can be stored in the database but the body data not (yet).

func ReadBody

func ReadBody(db ChainDbReader, hash types.Hash, number uint64) *models.Body

ReadBody retrieves the block body corresponding to the hash.

func ReadBodyRLP

func ReadBodyRLP(db ChainDbReader, hash types.Hash, number uint64) rlp.RawValue

ReadBodyRLP retrieves the block body (transactions and uncles) in RLP encoding.

func ReadCanonicalHash

func ReadCanonicalHash(db ChainDbReader, number uint64) types.Hash

ReadCanonicalHash 读取规范区块头hash

func ReadChainConfigByHash

func ReadChainConfigByHash(db ChainDbReader, bHash types.Hash) (*models.ChainConfig, error)

ReadChainConfigByHash 读取区块链配置,hash为创世区块hash

func ReadChainConfigByHeight

func ReadChainConfigByHeight(db ChainDbReader, height uint64) (*models.ChainConfig, error)

func ReadChainConfigLatest

func ReadChainConfigLatest(db ChainDbReader) (*models.ChainConfig, error)

ReadChainConfigLatest 读取最新的区块链配置

func ReadHeadBlockHash

func ReadHeadBlockHash(db ChainDbReader) types.Hash

ReadHeadBlockHash 读取当前区块hash

func ReadHeadHeaderHash

func ReadHeadHeaderHash(db ChainDbReader) types.Hash

ReadHeadHeaderHash 读取当前区块头hash

func ReadHeader

func ReadHeader(db ChainDbReader, hash types.Hash, number uint64) *models.Header

ReadHeader 读取header

func ReadHeaderNumber

func ReadHeaderNumber(db ChainDbReader, hash types.Hash) *uint64

ReadHeaderNumber 根据区块hash检索区块高度值

func ReadHeaderRLP

func ReadHeaderRLP(db ChainDbReader, hash types.Hash, number uint64) rlp.RawValue

ReadHeaderRLP retrieves a block header in its raw RLP database encoding.

func ReadReceipts

func ReadReceipts(db ChainDbReader, hash types.Hash, number uint64) statetype.Receipts

ReadReceipts retrieves all the transaction receipts belonging to a block.

func ReadTransaction

func ReadTransaction(db ChainDbReader, hash types.Hash) (models.Transaction, types.Hash, uint64, uint64)

ReadTransaction retrieves a specific transaction from the database, along with its added positional metadata.

func ReadTxLookupEntry

func ReadTxLookupEntry(db ChainDbReader, hash types.Hash) (blockHash types.Hash, blockIndex uint64, txType types.TxType, txIndex uint64)

ReadTxLookupEntry retrieves the positional metadata associated with a transaction hash to allow retrieving the transaction or receipt by hash.

func WithDB

func WithDB(db kvstore.Database) option

WithDB kv数据库

func WriteBlock

func WriteBlock(db ChainDbWriter, block *models.Block)

WriteBlock serializes a block into the database, header and body separately.

func WriteBody

func WriteBody(db ChainDbWriter, hash types.Hash, number uint64, body *models.Body)

WriteBody store a block body into the database.

func WriteBodyRLP

func WriteBodyRLP(db ChainDbWriter, hash types.Hash, number uint64, rlp rlp.RawValue)

WriteBodyRLP stores an RLP encoded block body into the database.

func WriteCanonicalHash

func WriteCanonicalHash(db ChainDbWriter, hash types.Hash, number uint64)

WriteCanonicalHash 写入规范区块头hash。

func WriteChainConfig

func WriteChainConfig(db ChainDbWriter, bHash types.Hash, height uint64, cfg *models.ChainConfig) error

WriteChainConfig 写入链配置

func WriteHeadBlockHash

func WriteHeadBlockHash(db ChainDbWriter, hash types.Hash)

WriteHeadBlockHash 写入当前区块hash

func WriteHeadHeaderHash

func WriteHeadHeaderHash(db ChainDbWriter, hash types.Hash)

WriteHeadHeaderHash 写入当前区块头hash

func WriteHeader

func WriteHeader(db ChainDbWriter, header *models.Header)

WriteHeader 写入区块头

func WriteReceipts

func WriteReceipts(db ChainDbWriter, hash types.Hash, number uint64, receipts statetype.Receipts)

WriteReceipts stores all the transaction receipts belonging to a block.

func WriteTxLookupEntries

func WriteTxLookupEntries(db ChainDbWriter, block *models.Block)

WriteTxLookupEntries stores a positional metadata for every transaction from a block, enabling hash based transaction and receipt lookups.

Types

type ChainDbDeleter

type ChainDbDeleter interface {
	Delete(key []byte) error
}

ChainDbDeleter wraps the Delete method of a backing data store.

type ChainDbReader

type ChainDbReader interface {
	Has(key []byte) (bool, error)
	Get(key []byte) ([]byte, error)
}

ChainDbReader wraps the Has and Get method of a backing data store.

type ChainDbWriter

type ChainDbWriter interface {
	Put(key []byte, value []byte) error
}

ChainDbWriter wraps the Put method of a backing data store.

type TxLookupEntry

type TxLookupEntry struct {
	BlockHash  types.Hash   // 区块Hash
	BlockIndex uint64       // 区块Index
	TxType     types.TxType // 交易类型
	TxIndex    uint64       // 交易index
}

TxLookupEntry is a positional metadata to help looking up the data content of a transaction or receipt given only its hash.

Directories

Path Synopsis
Package block_store
Package block_store
Package crud_store
Package crud_store
Package tx_store
Package tx_store

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL