Documentation ¶
Index ¶
- Constants
- Variables
- func OpenLevelDB(dbpath string, create bool) (pbdb database.Db, err error)
- type LevelDb
- func (db *LevelDb) Close() error
- func (db *LevelDb) FetchABlockByHash(aBlockHash *common.Hash) (aBlock *common.AdminBlock, err error)
- func (db *LevelDb) FetchAllABlocks() (aBlocks []common.AdminBlock, err error)
- func (db *LevelDb) FetchAllChains() (chains []*common.EChain, err error)
- func (db *LevelDb) FetchAllDBlocks() (dBlocks []common.DirectoryBlock, err error)
- func (db *LevelDb) FetchAllDirBlockInfo() (dirBlockInfoMap map[string]*common.DirBlockInfo, err error)
- func (db *LevelDb) FetchAllEBlocksByChain(chainID *common.Hash) (eBlocks *[]common.EBlock, err error)
- func (db *LevelDb) FetchAllECBlocks() (ecBlocks []common.ECBlock, err error)
- func (db *LevelDb) FetchAllFBlocks() (FBlocks []block.IFBlock, err error)
- func (db *LevelDb) FetchAllUnconfirmedDirBlockInfo() (dirBlockInfoMap map[string]*common.DirBlockInfo, err error)
- func (db *LevelDb) FetchBlockHeightBySha(sha *wire.ShaHash) (int64, error)
- func (db *LevelDb) FetchBlockHeightCache() (sha *wire.ShaHash, height int64, err error)
- func (db *LevelDb) FetchChainByHash(chainID *common.Hash) (*common.EChain, error)
- func (db *LevelDb) FetchDBHashByHeight(dBlockHeight uint32) (*common.Hash, error)
- func (db *LevelDb) FetchDBHashByMR(dBMR *common.Hash) (*common.Hash, error)
- func (db *LevelDb) FetchDBlockByHash(dBlockHash *common.Hash) (*common.DirectoryBlock, error)
- func (db *LevelDb) FetchDBlockByHeight(dBlockHeight uint32) (dBlock *common.DirectoryBlock, err error)
- func (db *LevelDb) FetchDBlockByMR(dBMR *common.Hash) (*common.DirectoryBlock, error)
- func (db *LevelDb) FetchDirBlockInfoByHash(dbHash *common.Hash) (dirBlockInfo *common.DirBlockInfo, err error)
- func (db *LevelDb) FetchEBHashByMR(eBMR *common.Hash) (*common.Hash, error)
- func (db *LevelDb) FetchEBlockByHash(eBlockHash *common.Hash) (*common.EBlock, error)
- func (db *LevelDb) FetchEBlockByMR(eBMR *common.Hash) (eBlock *common.EBlock, err error)
- func (db *LevelDb) FetchECBlockByHash(ecBlockHash *common.Hash) (ecBlock *common.ECBlock, err error)
- func (db *LevelDb) FetchEntryByHash(entrySha *common.Hash) (entry *common.Entry, err error)
- func (db *LevelDb) FetchFBlockByHash(hash *common.Hash) (FBlock block.IFBlock, err error)
- func (db *LevelDb) FetchHeadMRByChainID(chainID *common.Hash) (blkMR *common.Hash, err error)
- func (db *LevelDb) FetchHeightRange(startHeight, endHeight int64) (rshalist []wire.ShaHash, err error)
- func (db *LevelDb) FetchNextBlockHeightCache() (height int64)
- func (db *LevelDb) InitializeExternalIDMap() (extIDMap map[string]bool, err error)
- func (db *LevelDb) InsertChain(chain *common.EChain) (err error)
- func (db *LevelDb) InsertDirBlockInfo(dirBlockInfo *common.DirBlockInfo) (err error)
- func (db *LevelDb) InsertEntry(entry *common.Entry) error
- func (db *LevelDb) ProcessABlockBatch(block *common.AdminBlock) error
- func (db *LevelDb) ProcessDBlockBatch(dblock *common.DirectoryBlock) error
- func (db *LevelDb) ProcessEBlockBatch(eblock *common.EBlock) error
- func (db *LevelDb) ProcessECBlockBatch(block *common.ECBlock) error
- func (db *LevelDb) ProcessFBlockBatch(block block.IFBlock) error
- func (db *LevelDb) RollbackClose() error
- func (db *LevelDb) Sync() error
- func (db *LevelDb) UpdateBlockHeightCache(dirBlkHeigh uint32, dirBlkHash *common.Hash) error
- func (db *LevelDb) UpdateNextBlockHeightCache(dirBlkHeigh uint32) error
Constants ¶
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
const ( STATUS_IN_QUEUE uint8 = iota STATUS_PROCESSED )
the process status in db
Variables ¶
var CurrentDBVersion int32 = 1
Functions ¶
Types ¶
type LevelDb ¶
type LevelDb struct {
// contains filtered or unexported fields
}
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
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
FetchAllECBlocks gets all of the entry credit blocks
func (*LevelDb) FetchAllFBlocks ¶
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
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
FetchBlockHeightCache returns the hash and block height of the most recent
func (*LevelDb) FetchChainByHash ¶
FetchChainByHash gets a chain by chainID
func (*LevelDb) FetchDBHashByHeight ¶ added in v0.3.1
FetchDBHashByHeight gets a dBlockHash from the database.
func (*LevelDb) FetchDBHashByMR ¶ added in v0.3.1
FetchDBHashByMR gets a DBHash by MR from the database.
func (*LevelDb) FetchDBlockByHash ¶
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
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 ¶
FetchEBHashByMR gets an entry by hash from the database.
func (*LevelDb) FetchEBlockByHash ¶
FetchEntryBlock gets an entry by hash from the database.
func (*LevelDb) FetchEBlockByMR ¶
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 ¶
FetchEntry gets an entry by hash from the database.
func (*LevelDb) FetchFBlockByHash ¶
FetchFBlockByHash gets an factoid block by hash from the database.
func (*LevelDb) FetchHeadMRByChainID ¶ added in v0.3.1
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
FetchNextBlockHeightCache returns the next block height from server
func (*LevelDb) InitializeExternalIDMap ¶
Initialize External ID map for explorer search
func (*LevelDb) InsertChain ¶
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
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 ¶
ProcessEBlockBatche inserts the EBlock and update all it's ebentries in DB
func (*LevelDb) ProcessECBlockBatch ¶ added in v0.3.1
ProcessECBlockBatche inserts the ECBlock and update all it's cbentries in DB
func (*LevelDb) ProcessFBlockBatch ¶
ProcessFBlockBatch inserts the factoid block
func (*LevelDb) RollbackClose ¶
func (*LevelDb) Sync ¶
Sync verifies that the database is coherent on disk, and no outstanding transactions are in flight.
func (*LevelDb) UpdateBlockHeightCache ¶ added in v0.3.1
UpdateBlockHeightCache updates the dir block height cache in db
func (*LevelDb) UpdateNextBlockHeightCache ¶ added in v0.3.1
UpdateNextBlockHeightCache updates the next dir block height cache (from server) in db