ldb

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2016 License: MIT Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (

	// Directory Block
	TBL_DB uint8 = iota
	TBL_DB_NUM
	TBL_DB_MR
	TBL_DB_INFO

	// Admin Block
	TBL_AB //4
	TBL_AB_NUM

	TBL_SC
	TBL_SC_NUM

	// Entry Credit Block
	TBL_CB //8
	TBL_CB_NUM
	TBL_CB_MR

	// Entry Chain
	TBL_CHAIN_HASH //11

	// The latest Block MR for chains including special chains
	TBL_CHAIN_HEAD

	// Entry Block
	TBL_EB //13
	TBL_EB_CHAIN_NUM
	TBL_EB_MR

	//Entry
	TBL_ENTRY
)

the "table" prefix

View Source
const (
	STATUS_IN_QUEUE uint8 = iota
	STATUS_PROCESSED
)

the process status in db

Variables

View Source
var CurrentDBVersion int32 = 1

Functions

func OpenLevelDB

func OpenLevelDB(dbpath string, create bool) (pbdb database.Db, err error)

Types

type LevelDb

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

func (*LevelDb) Close

func (db *LevelDb) Close() error

Close cleanly shuts down database, syncing all data.

func (*LevelDb) FetchABlockByHash added in v0.3.1

func (db *LevelDb) FetchABlockByHash(aBlockHash *common.Hash) (aBlock *common.AdminBlock, err error)

FetchABlockByHash gets an admin block by hash from the database.

func (*LevelDb) FetchAllABlocks added in v0.3.1

func (db *LevelDb) FetchAllABlocks() (aBlocks []common.AdminBlock, err error)

FetchAllABlocks gets all of the admin blocks

func (*LevelDb) FetchAllChains added in v0.3.1

func (db *LevelDb) FetchAllChains() (chains []*common.EChain, err error)

FetchAllChains get all of the cahins

func (*LevelDb) FetchAllDBlocks

func (db *LevelDb) FetchAllDBlocks() (dBlocks []common.DirectoryBlock, err error)

FetchAllDBlocks gets all of the fbInfo

func (*LevelDb) FetchAllDirBlockInfo added in v0.3.1

func (db *LevelDb) FetchAllDirBlockInfo() (dirBlockInfoMap map[string]*common.DirBlockInfo, err error)

FetchAllDirBlockInfo gets all of the dirBlockInfo

func (*LevelDb) FetchAllEBlocksByChain

func (db *LevelDb) FetchAllEBlocksByChain(chainID *common.Hash) (eBlocks *[]common.EBlock, err error)

FetchAllEBlocksByChain gets all of the blocks by chain id

func (*LevelDb) FetchAllECBlocks added in v0.3.1

func (db *LevelDb) FetchAllECBlocks() (ecBlocks []common.ECBlock, err error)

FetchAllECBlocks gets all of the entry credit blocks

func (*LevelDb) FetchAllFBlocks

func (db *LevelDb) FetchAllFBlocks() (FBlocks []block.IFBlock, err error)

FetchAllFBlocks gets all of the factoid blocks

func (*LevelDb) FetchAllUnconfirmedDirBlockInfo added in v0.3.1

func (db *LevelDb) FetchAllUnconfirmedDirBlockInfo() (dirBlockInfoMap map[string]*common.DirBlockInfo, err error)

FetchAllUnconfirmedDirBlockInfo gets all of the dirBlockInfos that have BTC Anchor confirmation

func (*LevelDb) FetchBlockHeightBySha added in v0.3.1

func (db *LevelDb) FetchBlockHeightBySha(sha *wire.ShaHash) (int64, error)

FetchBlockHeightBySha returns the block height for the given hash. This is part of the database.Db interface implementation.

func (*LevelDb) FetchBlockHeightCache added in v0.3.1

func (db *LevelDb) FetchBlockHeightCache() (sha *wire.ShaHash, height int64, err error)

FetchBlockHeightCache returns the hash and block height of the most recent

func (*LevelDb) FetchChainByHash

func (db *LevelDb) FetchChainByHash(chainID *common.Hash) (*common.EChain, error)

FetchChainByHash gets a chain by chainID

func (*LevelDb) FetchDBHashByHeight added in v0.3.1

func (db *LevelDb) FetchDBHashByHeight(dBlockHeight uint32) (*common.Hash, error)

FetchDBHashByHeight gets a dBlockHash from the database.

func (*LevelDb) FetchDBHashByMR added in v0.3.1

func (db *LevelDb) FetchDBHashByMR(dBMR *common.Hash) (*common.Hash, error)

FetchDBHashByMR gets a DBHash by MR from the database.

func (*LevelDb) FetchDBlockByHash

func (db *LevelDb) FetchDBlockByHash(dBlockHash *common.Hash) (*common.DirectoryBlock, error)

FetchDBlock gets an entry by hash from the database.

func (*LevelDb) FetchDBlockByHeight added in v0.3.1

func (db *LevelDb) FetchDBlockByHeight(dBlockHeight uint32) (dBlock *common.DirectoryBlock, err error)

FetchDBlockByHeight gets an directory block by height from the database.

func (*LevelDb) FetchDBlockByMR added in v0.3.1

func (db *LevelDb) FetchDBlockByMR(dBMR *common.Hash) (*common.DirectoryBlock, error)

FetchDBlockByMR gets a directory block by merkle root from the database.

func (*LevelDb) FetchDirBlockInfoByHash added in v0.3.1

func (db *LevelDb) FetchDirBlockInfoByHash(dbHash *common.Hash) (dirBlockInfo *common.DirBlockInfo, err error)

FetchDirBlockInfoByHash gets an DirBlockInfo obj

func (*LevelDb) FetchEBHashByMR

func (db *LevelDb) FetchEBHashByMR(eBMR *common.Hash) (*common.Hash, error)

FetchEBHashByMR gets an entry by hash from the database.

func (*LevelDb) FetchEBlockByHash

func (db *LevelDb) FetchEBlockByHash(eBlockHash *common.Hash) (*common.EBlock, error)

FetchEntryBlock gets an entry by hash from the database.

func (*LevelDb) FetchEBlockByMR

func (db *LevelDb) FetchEBlockByMR(eBMR *common.Hash) (eBlock *common.EBlock, err error)

FetchEBlockByMR gets an entry block by merkle root from the database.

func (*LevelDb) FetchECBlockByHash added in v0.3.1

func (db *LevelDb) FetchECBlockByHash(ecBlockHash *common.Hash) (ecBlock *common.ECBlock, err error)

FetchECBlockByHash gets an Entry Credit block by hash from the database.

func (*LevelDb) FetchEntryByHash

func (db *LevelDb) FetchEntryByHash(entrySha *common.Hash) (entry *common.Entry, err error)

FetchEntry gets an entry by hash from the database.

func (*LevelDb) FetchFBlockByHash

func (db *LevelDb) FetchFBlockByHash(hash *common.Hash) (FBlock block.IFBlock, err error)

FetchFBlockByHash gets an factoid block by hash from the database.

func (*LevelDb) FetchHeadMRByChainID added in v0.3.1

func (db *LevelDb) FetchHeadMRByChainID(chainID *common.Hash) (blkMR *common.Hash, err error)

FetchHeadMRByChainID gets a MR of the highest block from the database.

func (*LevelDb) FetchHeightRange added in v0.3.1

func (db *LevelDb) FetchHeightRange(startHeight, endHeight int64) (rshalist []wire.ShaHash, err error)

FetchHeightRange looks up a range of blocks by the start and ending heights. Fetch is inclusive of the start height and exclusive of the ending height. To fetch all hashes from the start height until no more are present, use the special id `AllShas'.

func (*LevelDb) FetchNextBlockHeightCache added in v0.3.1

func (db *LevelDb) FetchNextBlockHeightCache() (height int64)

FetchNextBlockHeightCache returns the next block height from server

func (*LevelDb) InitializeExternalIDMap

func (db *LevelDb) InitializeExternalIDMap() (extIDMap map[string]bool, err error)

Initialize External ID map for explorer search

func (*LevelDb) InsertChain

func (db *LevelDb) InsertChain(chain *common.EChain) (err error)

InsertChain inserts the newly created chain into db

func (*LevelDb) InsertDirBlockInfo added in v0.3.1

func (db *LevelDb) InsertDirBlockInfo(dirBlockInfo *common.DirBlockInfo) (err error)

Insert the Directory Block meta data into db

func (*LevelDb) InsertEntry added in v0.3.1

func (db *LevelDb) InsertEntry(entry *common.Entry) error

InsertEntry inserts an entry

func (*LevelDb) ProcessABlockBatch added in v0.3.1

func (db *LevelDb) ProcessABlockBatch(block *common.AdminBlock) error

ProcessABlockBatch inserts the AdminBlock

func (*LevelDb) ProcessDBlockBatch

func (db *LevelDb) ProcessDBlockBatch(dblock *common.DirectoryBlock) error

FetchDBEntriesFromQueue gets all of the dbentries that have not been processed

func (db *LevelDb) FetchDBEntriesFromQueue(startTime *[]byte) (dbentries []*common.DBEntry, err error) {
	db.dbLock.Lock()
	defer db.dbLock.Unlock()

	var fromkey []byte = []byte{byte(TBL_EB_QUEUE)} // Table Name (1 bytes)
	fromkey = append(fromkey, *startTime...)        // Timestamp  (8 bytes)

	var tokey []byte = []byte{byte(TBL_EB_QUEUE)} // Table Name (4 bytes)
	binaryTimestamp := make([]byte, 8)
	binary.BigEndian.PutUint64(binaryTimestamp, uint64(time.Now().Unix()))
	tokey = append(tokey, binaryTimestamp...) // Timestamp  (8 bytes)

	fbEntrySlice := make([]*common.DBEntry, 0, 10)

	iter := db.lDb.NewIterator(&util.Range{Start: fromkey, Limit: tokey}, db.ro)

	for iter.Next() {
		if bytes.Equal(iter.Value(), []byte{byte(STATUS_IN_QUEUE)}) {
			key := make([]byte, len(iter.Key()))
			copy(key, iter.Key())
			dbEntry := new(common.DBEntry)

			dbEntry.SetTimestamp(key[1:9]) // Timestamp (8 bytes)
			cid := key[9:41]
			dbEntry.ChainID = new(common.Hash)
			dbEntry.ChainID.Bytes = cid // Chain id (32 bytes)
			dbEntry.SetHash(key[41:73]) // Entry Hash (32 bytes)

			fbEntrySlice = append(fbEntrySlice, dbEntry)
		}
	}
	iter.Release()
	err = iter.Error()

	return fbEntrySlice, nil
}

ProcessDBlockBatche inserts the DBlock and update all it's dbentries in DB

func (*LevelDb) ProcessEBlockBatch

func (db *LevelDb) ProcessEBlockBatch(eblock *common.EBlock) error

ProcessEBlockBatche inserts the EBlock and update all it's ebentries in DB

func (*LevelDb) ProcessECBlockBatch added in v0.3.1

func (db *LevelDb) ProcessECBlockBatch(block *common.ECBlock) error

ProcessECBlockBatche inserts the ECBlock and update all it's cbentries in DB

func (*LevelDb) ProcessFBlockBatch

func (db *LevelDb) ProcessFBlockBatch(block block.IFBlock) error

ProcessFBlockBatch inserts the factoid block

func (*LevelDb) RollbackClose

func (db *LevelDb) RollbackClose() error

func (*LevelDb) Sync

func (db *LevelDb) Sync() error

Sync verifies that the database is coherent on disk, and no outstanding transactions are in flight.

func (*LevelDb) UpdateBlockHeightCache added in v0.3.1

func (db *LevelDb) UpdateBlockHeightCache(dirBlkHeigh uint32, dirBlkHash *common.Hash) error

UpdateBlockHeightCache updates the dir block height cache in db

func (*LevelDb) UpdateNextBlockHeightCache added in v0.3.1

func (db *LevelDb) UpdateNextBlockHeightCache(dirBlkHeigh uint32) error

UpdateNextBlockHeightCache updates the next dir block height cache (from server) in db

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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