db

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: Apache-2.0 Imports: 9 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// prefix+hash -> Account Trie Node and Value
	KPAccountNode  = []byte("aa")
	KPAccountValue = []byte("ab")
	// prefix+hash -> Code of Account
	KPCode = []byte("ac")
	// prefix+hash -> Account Storage Trie Node
	KPAccStorageNode = []byte("ad")
	// prefix+hash -> Account Long Storage Trie Node and Value (for system contract)
	KPAccLongNode  = []byte("am")
	KPAccLongValue = []byte("an")
	// shard chain
	// prefix + hash -> AccountDelta Trie Node and Value
	KPDeltaNodeNode  = []byte("ae")
	KPDeltaNodeValue = []byte("af")
	// prefix + header.BalanceDeltaRoot -> combined trie of AccountDelta Tries
	KPDeltaTrie = []byte("ag")
	// prefix + shard.ElectChainID.Formalize() + heightOfBlock.Bytes() -> hash root of Account
	KPDeltaFromTrie = []byte("ah")
	// prefix + DeltaFromKey{ShardID, Height} -> serialization of []*AccountDelta
	KPDeltaFroms          = []byte("ai")
	KPDeltaFromMaxHeight  = []byte("aj")
	KPDeltaFromWaterline  = []byte("ak")
	KPDeltaToBeSent       = []byte("ao")
	KPDFWaterlineSnapshot = []byte("ap")

	// prefix + HistoryTree.Node.Hash -> HistoryTree.Node.Children/Leafs
	KPHistoryNode = []byte("al")

	// prefix+hash -> Transaction Trie Node and Value
	KPTxNode  = []byte("tk")
	KPTxValue = []byte("tv")
	// prefix+hash -> Transaction in block  and index of the all transactions
	KPTxIndex = []byte("ti")

	// prefix + hash -> Verifiable Cash Check Trie Node and Value
	KPVccNode  = []byte("va")
	KPVccValue = []byte("vb")
	// prefix + hash -> Cashed Verifiable Cash Check Trie Node and Value
	KPCVccNode  = []byte("vc")
	KPCVccValue = []byte("vd")
	// prefix + Vcc.Hash -> cash the check Tx.Hash
	KPCVccTxIndex = []byte("ve")

	// prefix+hash(Header) -> block/Header height
	KPBlockNumByHash = []byte("bn")
	// prefix+height -> Header hash
	KPBlockHashByNum = []byte("bh")
	// // prefix+hash(header) -> Header encoded value
	// KPBlockHeader = []byte("bv")
	// prefix+hash(header) -> block encoded value
	KPBlock = []byte("bb")
	// prefix -> current Highest block height
	KPCurrentHeight = []byte("bc")
	// prefix+hash(Header) -> Receipts
	KPReceipts = []byte("br")
	// prefix+height -> received data block (not yet processed, just persisted in the database)
	KPBlockNotVerified = []byte("bv")
	// prefix+EpochNum -> election results of the EpochNum'th committee
	// key is the elected Epoch, not the Epoch at the time of the election, starting
	// from 0. If the election result fails, continue
	KPEpochComm = []byte("bec")

	// main chain
	// prefix + FormalizedChainID -> ChainInfos Trie Node and Value
	KPChainNode  = []byte("cn")
	KPChainValue = []byte("ci")
	// prefix + ChainId + EpochNum -> Committee
	KPChainEpochCommittee = []byte("ce")
	// prefix + ChainId + Height -> Header
	KPChainHeightHeader = []byte("ch")
	// prefix + ChainId + Height -> BlockProof
	KPChainHeightProof = []byte("cp")
	// the earliest Cursor on the main chain received by the current node and has not yet
	// issued a reward, the reward can be issue from this height to process the Request
	KPRewardHeightCursor = []byte("cf")

	// prefix+ChainID -> the latest (block height + block Hash) has been reported
	KPChainReportCursor = []byte("cc")

	KPRewardBase = []byte("rb")

	KPRRNode   = []byte("ra") // Required Reserve Trie Node Prefix
	KPRRValue  = []byte("rc") // Required Reserve Trie Value Prefix
	KPRRCNode  = []byte("rd") // Required Reserve Changing Trie Node Prefix
	KPRRCValue = []byte("re") // Required Reserve Changing Trie Value Prefix
	KPRRRoot   = []byte("rf") // Required Reserve Trie Root Hash: prefix+EraNum -> RootOfRRTrie

	KPStorageEntry = []byte("se")

	ErrNotFound = errors.New("data not found")
)

Functions

func BatchWrite

func BatchWrite(dbase Database, threshold, length int,
	write func(j int, w Writer) (ok bool, err error)) (count int, err error)

func CopySlice

func CopySlice(val []byte) []byte

func GetNilError

func GetNilError(db Database, key []byte) ([]byte, error)

func NewCachedDB

func NewCachedDB(db Database, cacheSize int) (*cachedDB, error)

func PrefixKey

func PrefixKey(prefix []byte, key []byte) []byte

func PrefixKey2

func PrefixKey2(prefix1 []byte, prefix2 []byte, key []byte) []byte

func ToBlockHashKey

func ToBlockHashKey(height common.Height) []byte

func ToBlockKey

func ToBlockKey(hashOfHeader []byte) []byte

func ToBlockNotVerified

func ToBlockNotVerified(height common.Height) []byte

func ToBlockNumberKey

func ToBlockNumberKey(hashOfHeader []byte) []byte

func ToBlockReceiptsKey

func ToBlockReceiptsKey(hashOfHeader []byte) []byte

func ToBlockTXIndexKey

func ToBlockTXIndexKey(hashOfTransacion []byte) []byte

func ToChainCommitteeKey

func ToChainCommitteeKey(chainId common.ChainID, epochNum common.EpochNum) []byte

func ToChainHeightHeaderKey

func ToChainHeightHeaderKey(chainId common.ChainID, height common.Height) []byte

func ToChainHeightProofKey

func ToChainHeightProofKey(chainId common.ChainID, height common.Height) []byte

func ToChainReportCursorKey

func ToChainReportCursorKey(chainId common.ChainID) []byte

func ToCurrentHeightKey

func ToCurrentHeightKey() []byte

func ToDFWaterlineSnapshotKey

func ToDFWaterlineSnapshotKey(hashOfWaterlines []byte) []byte

func ToDeltaFromKey

func ToDeltaFromKey(fromID common.ChainID, height common.Height) []byte

func ToDeltaFromMaxHeightKey

func ToDeltaFromMaxHeightKey(fromID common.ChainID) []byte

func ToDeltaFromWaterlineKey

func ToDeltaFromWaterlineKey(fromID common.ChainID) []byte

func ToDeltaToBeSentKey

func ToDeltaToBeSentKey() []byte

func ToEpochCommKey

func ToEpochCommKey(chainId common.ChainID, epoch common.EpochNum) []byte

func ToFirstRewardCursorKey

func ToFirstRewardCursorKey() []byte

func ToRRKey

func ToRRKey(era common.EraNum) []byte

func ToRewardBaseKey

func ToRewardBaseKey(chainId common.ChainID) []byte

func ToStorageEntryKey

func ToStorageEntryKey(root []byte, num int) []byte

Types

type Batch

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

type DataAdapter

type DataAdapter interface {
	Load(key []byte) (value []byte, err error)
	Save(key []byte, value []byte) error
}

func NewKeyPrefixedDataAdapter

func NewKeyPrefixedDataAdapter(database Database, keyPrefix []byte) DataAdapter

func NewTransparentDataAdapter

func NewTransparentDataAdapter() DataAdapter

type Database

type Database interface {
	Put(key, value []byte) error
	Has(key []byte) (bool, error)
	Get(key []byte) ([]byte, error)
	Delete(key []byte) error
	NewBatch() Batch
	Batch(batch Batch) error
	Close() error
}

func NewCachedDBWithPath

func NewCachedDBWithPath(path string, cacheSize int) (Database, error)

func NewMemDB

func NewMemDB() Database

type DummyAdapter

type DummyAdapter struct{}

func (DummyAdapter) Load

func (d DummyAdapter) Load(key []byte) (value []byte, err error)

func (DummyAdapter) Save

func (d DummyAdapter) Save(key []byte, value []byte) error

type KeyBatch

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

func (*KeyBatch) Delete

func (k *KeyBatch) Delete(key []byte) error

func (*KeyBatch) Put

func (k *KeyBatch) Put(key, value []byte) error

func (*KeyBatch) Size

func (k *KeyBatch) Size() int

type KeyDatabase

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

func (*KeyDatabase) Batch

func (d *KeyDatabase) Batch(batch Batch) error

func (*KeyDatabase) Close

func (d *KeyDatabase) Close() error

func (*KeyDatabase) Delete

func (d *KeyDatabase) Delete(key []byte) error

func (*KeyDatabase) Get

func (d *KeyDatabase) Get(key []byte) ([]byte, error)

func (*KeyDatabase) Has

func (d *KeyDatabase) Has(key []byte) (bool, error)

func (*KeyDatabase) NewBatch

func (d *KeyDatabase) NewBatch() Batch

func (*KeyDatabase) Put

func (d *KeyDatabase) Put(key, value []byte) error

type LDB

type LDB struct {
	common.AbstractService
	// contains filtered or unexported fields
}

func NewLDB

func NewLDB(path string) (*LDB, error)

func (*LDB) Batch

func (db *LDB) Batch(batch Batch) error

func (*LDB) Delete

func (db *LDB) Delete(key []byte) error

func (*LDB) Get

func (db *LDB) Get(key []byte) ([]byte, error)

func (*LDB) Has

func (db *LDB) Has(key []byte) (bool, error)

func (*LDB) NewBatch

func (db *LDB) NewBatch() Batch

func (*LDB) Path

func (db *LDB) Path() string

func (*LDB) Put

func (db *LDB) Put(key, value []byte) error

type MemDB

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

func (*MemDB) Batch

func (m *MemDB) Batch(batch Batch) error

func (*MemDB) Close

func (m *MemDB) Close() error

func (*MemDB) Delete

func (m *MemDB) Delete(key []byte) error

func (*MemDB) Get

func (m *MemDB) Get(key []byte) ([]byte, error)

func (*MemDB) Has

func (m *MemDB) Has(key []byte) (bool, error)

func (*MemDB) NewBatch

func (m *MemDB) NewBatch() Batch

func (*MemDB) Put

func (m *MemDB) Put(key, value []byte) error

type Writer

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

Jump to

Keyboard shortcuts

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