blockstore

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: Apache-2.0 Imports: 14 Imported by: 5

README

blockstore

An implemention of blockstore which support customization by config file.

Build Status codecov

Getting started

Running it then should be as simple as:

$ make all
Testing
$ make test

Documentation

Index

Constants

View Source
const (
	// DB plugin
	PLUGIN_LEVELDB = "leveldb"
	// memory plugin
	PLUGIN_MEMDB = "memorydb"
	// block height before genesis block
	INIT_BLOCK_HEIGHT = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockStore

type BlockStore struct {
	// contains filtered or unexported fields
}

Block store save the data of block & transaction

func NewBlockStore

func NewBlockStore(config *config.BlockStoreConfig) (*BlockStore, error)

NewBlockStore return the block store instance

func (*BlockStore) Delete added in v1.1.0

func (blockStore *BlockStore) Delete(key []byte) error

Delete removes the key from the key-value data store.

func (*BlockStore) Get added in v1.0.0

func (blockStore *BlockStore) Get(key []byte) ([]byte, error)

Get get a record by key

func (*BlockStore) GetBlockByHash

func (blockStore *BlockStore) GetBlockByHash(hash types.Hash) (*types.Block, error)

GetBlockByHash get block by block hash.

func (*BlockStore) GetBlockByHeight

func (blockStore *BlockStore) GetBlockByHeight(height uint64) (*types.Block, error)

GetBlockByHeight get block by height.

func (*BlockStore) GetCurrentBlock

func (blockStore *BlockStore) GetCurrentBlock() *types.Block

GetCurrentBlock get current block.

func (*BlockStore) GetCurrentBlockHeight

func (blockStore *BlockStore) GetCurrentBlockHeight() uint64

GetCurrentBlockHeight get current block height.

func (*BlockStore) GetReceiptByBlockHash added in v1.0.0

func (blockStore *BlockStore) GetReceiptByBlockHash(blockHash types.Hash) []*types.Receipt

GetReceiptByHash get receipt by relative block's hash

func (*BlockStore) GetReceiptByTxHash

func (blockStore *BlockStore) GetReceiptByTxHash(txHash types.Hash) (*types.Receipt, types.Hash, uint64, uint64, error)

GetReceiptByHash get receipt by relative tx's hash

func (*BlockStore) GetTransactionByHash

func (blockStore *BlockStore) GetTransactionByHash(hash types.Hash) (*types.Transaction, types.Hash, uint64, uint64, error)

GetTransactionByHash get transaction by hash

func (*BlockStore) Put added in v1.0.0

func (blockStore *BlockStore) Put(key []byte, value []byte) error

Put add a record to database

func (*BlockStore) WriteBlock

func (blockStore *BlockStore) WriteBlock(block *types.Block) error

WriteBlock write the block to database. return error if write failed.

func (*BlockStore) WriteBlockWithReceipts

func (blockStore *BlockStore) WriteBlockWithReceipts(block *types.Block, receipts []*types.Receipt) error

WriteBlock write the block and relative receipts to database. return error if write failed.

type BlockStoreAPI

type BlockStoreAPI interface {
	dbstore.DBPutter

	// Get get from db
	Get(key []byte) ([]byte, error)

	// WriteBlock write the block to database. return error if write failed.
	WriteBlock(block *types.Block) error

	// GetBlockByHash get block by block hash.
	GetBlockByHash(hash types.Hash) (*types.Block, error)

	// GetBlockByHeight get block by height.
	GetBlockByHeight(height uint64) (*types.Block, error)

	// GetCurrentBlock get current block.
	GetCurrentBlock() *types.Block

	// GetCurrentBlockHeight get current block height.
	GetCurrentBlockHeight() uint64

	// GetTransactionByHash get transaction by hash
	GetTransactionByHash(hash types.Hash) (*types.Transaction, types.Hash, uint64, uint64, error)

	// WriteBlock write the block and relative receipts to database. return error if write failed.
	WriteBlockWithReceipts(block *types.Block, receipts []*types.Receipt) error

	// GetReceiptByHash get receipt by relative tx's hash
	GetReceiptByTxHash(txHash types.Hash) (*types.Receipt, types.Hash, uint64, uint64, error)

	// GetReceiptByHash get receipt by relative block's hash
	GetReceiptByBlockHash(txHash types.Hash) []*types.Receipt

	// Delete removes the key from the key-value data store.
	Delete(key []byte) error
}

BlockStoreAPI block-store module public api.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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