db

package
v0.0.0-...-77b6ffe Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyLastHeader = "LastHeader"
	KeyLastBlock  = "LastBlock"
)

Variables

This section is empty.

Functions

func CommitBatch

func CommitBatch(db Database, height uint64) error

Types

type Batch

type Batch interface {
	Put(key, value []byte) error
	Delete(key []byte) error
	Write() error
	Len() int
}

func GetBatch

func GetBatch(db Database, height uint64) Batch

type BatchMgr

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

BatchMgr manages db write batch

type Database

type Database interface {
	Put(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	Delete(key []byte) error
	Close()
	NewBatch() Batch
	NewIterator(prefix []byte) iterator.Iterator
}

type LDBDatabase

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

the Database for LevelDB LDBDatabase implements the DataBase interface

func NewLDBDataBase

func NewLDBDataBase(filepath string) (*LDBDatabase, error)

NewLDBDataBase new a LDBDatabase instance require a data filepath return *LDBDataBase and will return an error with type of ErrCorrupted if corruption detected in the DB.

func (*LDBDatabase) Close

func (self *LDBDatabase) Close()

Close close the LDBDataBase

func (*LDBDatabase) Delete

func (self *LDBDatabase) Delete(key []byte) error

Delete deletes the value for the given key

func (*LDBDatabase) Destroy

func (self *LDBDatabase) Destroy() error

Destroy, clean the whole database, warning: bad performance if to many data in the db

func (*LDBDatabase) DestroyByRange

func (self *LDBDatabase) DestroyByRange(start, end []byte) error

DestroyByRange, clean data which key in range [start, end)

func (*LDBDatabase) Get

func (self *LDBDatabase) Get(key []byte) ([]byte, error)

Get gets value for the given key, it returns ErrNotFound if the Database does not contains the key

func (*LDBDatabase) LDB

func (self *LDBDatabase) LDB() *leveldb.DB

LDB returns *leveldb.DB instance

func (*LDBDatabase) NewBatch

func (db *LDBDatabase) NewBatch() Batch

NewBatch returns a Batch instance it allows batch-operation

func (*LDBDatabase) NewIterator

func (self *LDBDatabase) NewIterator(prefix []byte) iterator.Iterator

NewIterator returns a Iterator for traversing the database

func (*LDBDatabase) NewIteratorWithPrefix

func (self *LDBDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator

func (*LDBDatabase) Put

func (self *LDBDatabase) Put(key []byte, value []byte) error

Put sets value for the given key, if the key exists, it will overwrite the value

type TinyDB

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

TinyDB stores and manages blockchain data

func NewTinyDB

func NewTinyDB(db Database) *TinyDB

func (*TinyDB) GetBlock

func (tdb *TinyDB) GetBlock(height uint64, hash common.Hash) (*types.Block, error)

func (*TinyDB) GetHash

func (tdb *TinyDB) GetHash(height uint64) (common.Hash, error)

func (*TinyDB) GetHeader

func (tdb *TinyDB) GetHeader(height uint64, hash common.Hash) (*types.Header, error)

func (*TinyDB) GetHeight

func (tdb *TinyDB) GetHeight(hash common.Hash) (uint64, error)

func (*TinyDB) GetLastBlock

func (tdb *TinyDB) GetLastBlock() (common.Hash, error)

func (*TinyDB) GetLastHeader

func (tdb *TinyDB) GetLastHeader() (common.Hash, error)

func (*TinyDB) GetReceipt

func (tdb *TinyDB) GetReceipt(txHash common.Hash) (*types.Receipt, error)

func (*TinyDB) GetTxMeta

func (tdb *TinyDB) GetTxMeta(txHash common.Hash) (*types.TxMeta, error)

func (*TinyDB) LDB

func (tdb *TinyDB) LDB() Database

func (*TinyDB) PutBlock

func (tdb *TinyDB) PutBlock(batch Batch, block *types.Block, sync, flush bool) error

func (*TinyDB) PutHash

func (tdb *TinyDB) PutHash(batch Batch, height uint64, hash common.Hash, sync, flush bool) error

func (*TinyDB) PutHeader

func (tdb *TinyDB) PutHeader(batch Batch, header *types.Header, sync, flush bool) error

func (*TinyDB) PutHeight

func (tdb *TinyDB) PutHeight(batch Batch, hash common.Hash, height uint64, sync, flush bool) error

func (*TinyDB) PutLastBlock

func (tdb *TinyDB) PutLastBlock(batch Batch, hash common.Hash, sync, flush bool) error

func (*TinyDB) PutLastHeader

func (tdb *TinyDB) PutLastHeader(batch Batch, hash common.Hash, sync, flush bool) error

func (*TinyDB) PutReceipt

func (tdb *TinyDB) PutReceipt(batch Batch, txHash common.Hash, receipt *types.Receipt, sync, flush bool) error

func (*TinyDB) PutTxMetas

func (tdb *TinyDB) PutTxMetas(batch Batch, txs types.Transactions, hash common.Hash, height uint64, sync, flush bool) error

PutTxMetas put transactions' meta to db in batch

Jump to

Keyboard shortcuts

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