const logModule = "leveldb"
var (
- blockStoreKey = []byte("blockStore")
- blockPrefix = []byte("B:")
- blockHeaderPrefix = []byte("BH:")
- txStatusPrefix = []byte("BTS:")
+ BlockStoreKey = []byte("blockStore")
+ BlockPrefix = []byte("B:")
+ BlockHeaderPrefix = []byte("BH:")
+ TxStatusPrefix = []byte("BTS:")
)
func loadBlockStoreStateJSON(db dbm.DB) *protocol.BlockStoreState {
- bytes := db.Get(blockStoreKey)
+ bytes := db.Get(BlockStoreKey)
if bytes == nil {
return nil
}
cache blockCache
}
-func calcBlockKey(hash *bc.Hash) []byte {
- return append(blockPrefix, hash.Bytes()...)
+func CalcBlockKey(hash *bc.Hash) []byte {
+ return append(BlockPrefix, hash.Bytes()...)
}
-func calcBlockHeaderKey(height uint64, hash *bc.Hash) []byte {
+func CalcBlockHeaderKey(height uint64, hash *bc.Hash) []byte {
buf := [8]byte{}
binary.BigEndian.PutUint64(buf[:], height)
- key := append(blockHeaderPrefix, buf[:]...)
+ key := append(BlockHeaderPrefix, buf[:]...)
return append(key, hash.Bytes()...)
}
-func calcTxStatusKey(hash *bc.Hash) []byte {
- return append(txStatusPrefix, hash.Bytes()...)
+func CalcTxStatusKey(hash *bc.Hash) []byte {
+ return append(TxStatusPrefix, hash.Bytes()...)
}
// GetBlock return the block by given hash
func GetBlock(db dbm.DB, hash *bc.Hash) (*types.Block, error) {
- bytez := db.Get(calcBlockKey(hash))
+ bytez := db.Get(CalcBlockKey(hash))
if bytez == nil {
return nil, nil
}
// GetTransactionStatus will return the utxo that related to the block hash
func (s *Store) GetTransactionStatus(hash *bc.Hash) (*bc.TransactionStatus, error) {
- data := s.db.Get(calcTxStatusKey(hash))
+ data := s.db.Get(CalcTxStatusKey(hash))
if data == nil {
return nil, errors.New("can't find the transaction status by given hash")
}
func (s *Store) LoadBlockIndex(stateBestHeight uint64) (*state.BlockIndex, error) {
startTime := time.Now()
blockIndex := state.NewBlockIndex()
- bhIter := s.db.IteratorPrefix(blockHeaderPrefix)
+ bhIter := s.db.IteratorPrefix(BlockHeaderPrefix)
defer bhIter.Release()
var lastNode *state.BlockNode
blockHash := block.Hash()
batch := s.db.NewBatch()
- batch.Set(calcBlockKey(&blockHash), binaryBlock)
- batch.Set(calcBlockHeaderKey(block.Height, &blockHash), binaryBlockHeader)
- batch.Set(calcTxStatusKey(&blockHash), binaryTxStatus)
+ batch.Set(CalcBlockKey(&blockHash), binaryBlock)
+ batch.Set(CalcBlockHeaderKey(block.Height, &blockHash), binaryBlockHeader)
+ batch.Set(CalcTxStatusKey(&blockHash), binaryTxStatus)
batch.Write()
log.WithFields(log.Fields{
return err
}
- batch.Set(blockStoreKey, bytes)
+ batch.Set(BlockStoreKey, bytes)
batch.Write()
return nil
}