piledb

package
v0.0.0-...-24e5678 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChunkUnit       = uint32(172800 * 30)
	ChunkMetaSize   = int64(256)
	ChunkHeaderSize = int64(int64(ChunkUnit)*8 + ChunkMetaSize)
)

consts

Variables

View Source
var (
	ErrInvalidChunkBeginHeight     = errors.New("invalid chunk begin height")
	ErrInvalidChunkEndHeight       = errors.New("invalid chunk end height")
	ErrInvalidAppendHeight         = errors.New("invalid append height")
	ErrInvalidHeight               = errors.New("invalid height")
	ErrInvalidInitHeigth           = errors.New("invalid init height")
	ErrInvalidFileSize             = errors.New("invalid file size")
	ErrInvalidGenesisHash          = errors.New("invalid genesis hash")
	ErrInvalidInitialHash          = errors.New("invalid initial hash")
	ErrInvalidDataIndex            = errors.New("invalid data index")
	ErrMissingPile                 = errors.New("invalid missing pile")
	ErrAlreadyInitialized          = errors.New("already initialized")
	ErrExeedMaximumDataArrayLength = errors.New("exceed maximum data array length")
	ErrHeightCrashed               = errors.New("height crashed")
	ErrUnderInitHeight             = errors.New("under init height")
)

errors

View Source
var EvmHeight uint32

Functions

func SetEvmHeight

func SetEvmHeight(h uint32)

Types

type DB

type DB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DB provides stack like value store using piles

func Open

func Open(path string, initHash hash.Hash256, InitHeight uint32, InitTimestamp uint64) (*DB, error)

Open creates a DB that includes loaded piles

func (*DB) AppendData

func (db *DB) AppendData(Height uint32, DataHash hash.Hash256, Datas [][]byte) error

AppendData pushes data to top of the pile in piles

func (*DB) Close

func (db *DB) Close()

Close closes pile DB

func (*DB) GetData

func (db *DB) GetData(Height uint32, index int) ([]byte, error)

GetData returns a data at the index of the height

func (*DB) GetDatas

func (db *DB) GetDatas(Height uint32, from int, count int) ([]byte, error)

GetDatas returns datas of the height between from and from + count

func (*DB) GetHash

func (db *DB) GetHash(Height uint32) (hash.Hash256, error)

GetHash returns a hash value of the height

func (*DB) Init

func (db *DB) Init(genHash hash.Hash256, initHash hash.Hash256, initHeight uint32, initTimestamp uint64) error

Init initialize database when not initialized

func (*DB) InitHeight

func (db *DB) InitHeight() uint32

InitHeight returns init height

func (*DB) InitTimestamp

func (db *DB) InitTimestamp() uint64

InitTimestamp returns init timestamp

func (*DB) SetSyncMode

func (db *DB) SetSyncMode(sync bool)

SetSyncMode changes sync mode(sync every second when disabled)

type Pile

type Pile struct {
	sync.Mutex

	HeadHeight    uint32
	BeginHeight   uint32
	InitHeight    uint32
	GenHash       hash.Hash256
	InitHash      hash.Hash256
	InitTimestamp uint64
	// contains filtered or unexported fields
}

Pile proivdes a part of stack like store

func LoadPile

func LoadPile(path string) (*Pile, error)

LoadPile loads a pile from the file

func NewPile

func NewPile(path string, GenHash hash.Hash256, InitHash hash.Hash256, InitHeight uint32, InitTimestamp uint64, BaseHeight uint32) (*Pile, error)

NewPile returns a Pile

func (*Pile) AppendData

func (p *Pile) AppendData(Sync bool, Height uint32, DataHash hash.Hash256, Datas [][]byte) error

AppendData pushes data to the top of the pile

func (*Pile) Close

func (p *Pile) Close()

Close closes a pile

func (*Pile) GetData

func (p *Pile) GetData(Height uint32, index int) ([]byte, error)

GetData returns a data at the index of the height

func (*Pile) GetDatas

func (p *Pile) GetDatas(Height uint32, from int, count int) ([]byte, error)

GetDatas returns datas of the height between from and from + count

func (*Pile) GetHash

func (p *Pile) GetHash(Height uint32) (hash.Hash256, error)

GetHash returns a hash value of the height

Jump to

Keyboard shortcuts

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