blocks[block.Hash()] = block
}
- cache := newBlockCache(func(hash *bc.Hash) (*types.Block, error) {
+ cache := newBlockCache(func(hash *bc.Hash, height uint64) (*types.Block, error) {
return blocks[*hash], nil
})
for i := 0; i < maxCachedBlocks+10; i++ {
block := newBlock(uint64(i))
hash := block.Hash()
- cache.lookup(&hash)
+ cache.lookup(&hash, block.Height)
}
for i := 0; i < 10; i++ {
// GetBlock return the block by given hash and height
func GetBlock(db dbm.DB, hash *bc.Hash, height uint64) (*types.Block, error) {
- bytez := db.Get(calcBlockKey(hash))
- if bytez == nil {
+ /*
+ bytez := db.Get(calcBlockKey(hash))
+ if bytez == nil {
+ return nil, nil
+ }
+ */
+
+ block := &types.Block{}
+ //err := block.UnmarshalText(bytez)
+
+ binaryBlockHeader := db.Get(calcBlockHeaderKey(height, hash))
+ if binaryBlockHeader == nil {
return nil, nil
}
- block := &types.Block{}
- err := block.UnmarshalText(bytez)
- return block, err
+ binaryBlockTxs := db.Get(calcBlockTransactionsKey(hash))
+ if binaryBlockTxs == nil {
+ return nil, nil
+ }
+
+ if err := block.BlockHeader.UnmarshalText(binaryBlockHeader); err != nil {
+ return nil, err
+ }
+
+ if err := block.UnmarshalTextForTransactions(binaryBlockTxs); err != nil {
+ return nil, err
+ }
+
+ return block, nil
}
// NewStore creates and returns a new Store object.
}
blockHash := block.Hash()
- gotBlock, err := store.GetBlock(&blockHash)
+ gotBlock, err := store.GetBlock(&blockHash, block.Height)
if err != nil {
t.Fatal(err)
}
func (s *mockStore) BlockExist(hash *bc.Hash, height uint64) bool { return false }
func (s *mockStore) GetBlock(*bc.Hash, uint64) (*types.Block, error) { return nil, nil }
+func (s *mockStore) GetBlockHeader(*bc.Hash, uint64) (*types.BlockHeader, error) { return nil, nil }
func (s *mockStore) GetStoreStatus() *BlockStoreState { return nil }
func (s *mockStore) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) { return nil, nil }
func (s *mockStore) GetTransactionsUtxo(*state.UtxoViewpoint, []*bc.Tx) error { return nil }
func (s *mockStore1) BlockExist(hash *bc.Hash, height uint64) bool { return false }
func (s *mockStore1) GetBlock(*bc.Hash, uint64) (*types.Block, error) { return nil, nil }
+func (s *mockStore1) GetBlockHeader(*bc.Hash, uint64) (*types.BlockHeader, error) { return nil, nil }
func (s *mockStore1) GetStoreStatus() *BlockStoreState { return nil }
func (s *mockStore1) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) { return nil, nil }
func (s *mockStore1) GetTransactionsUtxo(utxoView *state.UtxoViewpoint, tx []*bc.Tx) error {