Commit 001b8e3e authored by manish's avatar manish
Browse files

[FAB-3673] remove blockhoder interface/struct



This CR removes Blockholder interface/struct and uses common.Block
everywhere in common ledger.

Change-Id: I66de25a603c61c4c8131c6fb53b5545f5717fb4c
Signed-off-by: default avatarmanish <manish.sethi@gmail.com>
parent add0af39
...@@ -124,7 +124,7 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr, ...@@ -124,7 +124,7 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr,
for { for {
block, err := itr.Next() block, err := itr.Next()
testutil.AssertNoError(t, err, fmt.Sprintf("Error while getting block number [%d] from iterator", numBlocksItrated)) testutil.AssertNoError(t, err, fmt.Sprintf("Error while getting block number [%d] from iterator", numBlocksItrated))
testutil.AssertEquals(t, block.(*blockHolder).GetBlock(), expectedBlocks[numBlocksItrated]) testutil.AssertEquals(t, block, expectedBlocks[numBlocksItrated])
numBlocksItrated++ numBlocksItrated++
if numBlocksItrated == lastBlockNum-firstBlockNum+1 { if numBlocksItrated == lastBlockNum-firstBlockNum+1 {
break break
......
...@@ -17,33 +17,11 @@ limitations under the License. ...@@ -17,33 +17,11 @@ limitations under the License.
package fsblkstorage package fsblkstorage
import ( import (
"fmt"
"sync" "sync"
"github.com/hyperledger/fabric/common/ledger" "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/protos/common"
) )
// blockHolder holds block bytes
type blockHolder struct {
blockBytes []byte
}
// GetBlock serializes Block from block bytes
func (bh *blockHolder) GetBlock() *common.Block {
block, err := deserializeBlock(bh.blockBytes)
if err != nil {
panic(fmt.Errorf("Problem in deserialzing block: %s", err))
}
return block
}
// GetBlockBytes returns block bytes
func (bh *blockHolder) GetBlockBytes() []byte {
return bh.blockBytes
}
// blocksItr - an iterator for iterating over a sequence of blocks // blocksItr - an iterator for iterating over a sequence of blocks
type blocksItr struct { type blocksItr struct {
mgr *blockfileMgr mgr *blockfileMgr
...@@ -108,7 +86,7 @@ func (itr *blocksItr) Next() (ledger.QueryResult, error) { ...@@ -108,7 +86,7 @@ func (itr *blocksItr) Next() (ledger.QueryResult, error) {
return nil, err return nil, err
} }
itr.blockNumToRetrieve++ itr.blockNumToRetrieve++
return &blockHolder{nextBlockBytes}, nil return deserializeBlock(nextBlockBytes)
} }
// Close releases any resources held by the iterator // Close releases any resources held by the iterator
......
...@@ -78,9 +78,9 @@ func testIterateAndVerify(t *testing.T, itr *blocksItr, blocks []*common.Block, ...@@ -78,9 +78,9 @@ func testIterateAndVerify(t *testing.T, itr *blocksItr, blocks []*common.Block,
blocksIterated := 0 blocksIterated := 0
for { for {
t.Logf("blocksIterated: %v", blocksIterated) t.Logf("blocksIterated: %v", blocksIterated)
bh, err := itr.Next() block, err := itr.Next()
testutil.AssertNoError(t, err, "") testutil.AssertNoError(t, err, "")
testutil.AssertEquals(t, bh.(*blockHolder).GetBlock(), blocks[blocksIterated]) testutil.AssertEquals(t, block, blocks[blocksIterated])
blocksIterated++ blocksIterated++
if blocksIterated == len(blocks) { if blocksIterated == len(blocks) {
break break
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"fmt" "fmt"
"github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/common/ledger/blkstorage" "github.com/hyperledger/fabric/common/ledger/blkstorage"
"github.com/hyperledger/fabric/common/ledger/testutil" "github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/util" "github.com/hyperledger/fabric/core/ledger/util"
...@@ -63,8 +62,7 @@ func checkBlocks(t *testing.T, expectedBlocks []*common.Block, store blkstorage. ...@@ -63,8 +62,7 @@ func checkBlocks(t *testing.T, expectedBlocks []*common.Block, store blkstorage.
itr, _ := store.RetrieveBlocks(0) itr, _ := store.RetrieveBlocks(0)
for i := 0; i < len(expectedBlocks); i++ { for i := 0; i < len(expectedBlocks); i++ {
blockHolder, _ := itr.Next() block, _ := itr.Next()
block := blockHolder.(ledger.BlockHolder).GetBlock()
testutil.AssertEquals(t, block, expectedBlocks[i]) testutil.AssertEquals(t, block, expectedBlocks[i])
} }
......
...@@ -49,12 +49,5 @@ type ResultsIterator interface { ...@@ -49,12 +49,5 @@ type ResultsIterator interface {
// QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries // QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries
type QueryResult interface{} type QueryResult interface{}
// BlockHolder holds block returned by the iterator in GetBlocksIterator.
// The sole purpose of this holder is to avoid desrialization if block is desired in raw bytes form (e.g., for transfer)
type BlockHolder interface {
GetBlock() *common.Block
GetBlockBytes() []byte
}
// PrunePolicy - a general interface for supporting different pruning policies // PrunePolicy - a general interface for supporting different pruning policies
type PrunePolicy interface{} type PrunePolicy interface{}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment