ngblocks

package
v0.0.0-...-571fd38 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ngblocks is a store for blocks which contains txs

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlockHeightConflict = errors.New("already has a block on the same height")
	ErrPrevBlockNotExist   = errors.New("prev block does not exist")
)
View Source
var ErrNoTxInHash = errors.New("cannot find tx by the hash")
View Source
var ErrPutEmptyBlock = errors.New("putting empty block into the db")

Functions

func GetBlockByHash

func GetBlockByHash(txn *badger.Txn, hash []byte) (*ngtypes.Block, error)

func GetBlockByHeight

func GetBlockByHeight(txn *badger.Txn, height uint64) (*ngtypes.Block, error)

func GetLatestBlock

func GetLatestBlock(txn *badger.Txn) (*ngtypes.Block, error)

func GetLatestHash

func GetLatestHash(txn *badger.Txn) ([]byte, error)

func GetLatestHeight

func GetLatestHeight(txn *badger.Txn) (uint64, error)

func GetOriginBlock

func GetOriginBlock(txn *badger.Txn) (*ngtypes.Block, error)

func GetOriginHash

func GetOriginHash(txn *badger.Txn) ([]byte, error)

func GetOriginHeight

func GetOriginHeight(txn *badger.Txn) (uint64, error)

func GetTxByHash

func GetTxByHash(txn *badger.Txn, hash []byte) (*ngtypes.Tx, error)

func PutNewBlock

func PutNewBlock(txn *badger.Txn, block *ngtypes.Block) error

PutNewBlock puts a new block into db and updates the tags. should check block before putting dev should continue upgrading the state after PutNewBlock

Types

type BlockStore

type BlockStore struct {
	*badger.DB
	Network ngtypes.Network
}

BlockStore managers a badger DB, which stores vaults and blocks and some helper tags for managing. TODO: Add DAG support to extend the capacity of store initialize with genesis blocks first, then load the origin in bootstrap process

func Init

func Init(db *badger.DB, network ngtypes.Network) *BlockStore

Init will do all initialization for the block store.

func (*BlockStore) ForcePutNewBlock

func (store *BlockStore) ForcePutNewBlock(txn *badger.Txn, block *ngtypes.Block) error

ForcePutNewBlock puts a block into db regardless of local store check should check block self before putting

func (*BlockStore) InitFromCheckpoint

func (store *BlockStore) InitFromCheckpoint(block *ngtypes.Block) error

Jump to

Keyboard shortcuts

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