Skip to content

Commit

Permalink
[FAB-3923] Remove dead code and duplicate from CSCC
Browse files Browse the repository at this point in the history
This commit takes care to remove duplicated and unused code from the
CSCC package, e.g. getChainID function which already exists in utility
package and also getChannelFromConfigBlock which no one actually use.

Change-Id: I92a5a511f375fe201fac84965fe85bdb1cee51e1
Signed-off-by: Artem Barger <[email protected]>
  • Loading branch information
C0rWin committed May 17, 2017
1 parent e754035 commit 04eed73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 45 deletions.
17 changes: 0 additions & 17 deletions core/scc/cscc/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ package cscc
import (
"fmt"

"errors"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/policies"
Expand Down Expand Up @@ -174,21 +172,6 @@ func joinChain(blockBytes []byte) pb.Response {
return shim.Success(nil)
}

func getChannelFromConfigBlock(blockBytes []byte) (string, error) {
if blockBytes == nil {
return "", errors.New("Configuration block must not be nil.")
}
block, err := utils.GetBlockFromBlockBytes(blockBytes)
if err != nil {
return "", fmt.Errorf("Failed to reconstruct the configuration block, %s", err)
}
chainID, err := utils.GetChainIDFromBlock(block)
if err != nil {
return "", fmt.Errorf("Failed to get the chain ID from the configuration block, %s", err)
}
return chainID, nil
}

func updateConfigBlock(blockBytes []byte) pb.Response {
if blockBytes == nil {
return shim.Error("Configuration block must not be nil.")
Expand Down
32 changes: 4 additions & 28 deletions core/scc/cscc/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/hyperledger/fabric/msp/mgmt/testtools"
peergossip "github.com/hyperledger/fabric/peer/gossip"
"github.com/hyperledger/fabric/peer/gossip/mocks"
"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
"github.com/spf13/viper"
Expand Down Expand Up @@ -197,7 +196,7 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {

// Query the configuration block
//chainID := []byte{143, 222, 22, 192, 73, 145, 76, 110, 167, 154, 118, 66, 132, 204, 113, 168}
chainID, err := getChainID(blockBytes)
chainID, err := utils.GetChainIDFromBlockBytes(blockBytes)
if err != nil {
t.Fatalf("cscc invoke JoinChain failed with: %v", err)
}
Expand Down Expand Up @@ -274,7 +273,7 @@ func TestConfigerInvokeUpdateConfigBlock(t *testing.T) {

// Query the configuration block
//chainID := []byte{143, 222, 22, 192, 73, 145, 76, 110, 167, 154, 118, 66, 132, 204, 113, 168}
chainID, err := getChainID(blockBytes)
chainID, err := utils.GetChainIDFromBlockBytes(blockBytes)
if err != nil {
t.Fatalf("cscc invoke UpdateConfigBlock failed with: %v", err)
}
Expand All @@ -286,33 +285,10 @@ func TestConfigerInvokeUpdateConfigBlock(t *testing.T) {
}

func mockConfigBlock() []byte {
var blockBytes []byte
var blockBytes []byte = nil
block, err := configtxtest.MakeGenesisBlock("mytestchainid")
if err != nil {
blockBytes = nil
} else {
if err == nil {
blockBytes = utils.MarshalOrPanic(block)
}
return blockBytes
}

func getChainID(blockBytes []byte) (string, error) {
block := &common.Block{}
if err := proto.Unmarshal(blockBytes, block); err != nil {
return "", err
}
envelope := &common.Envelope{}
if err := proto.Unmarshal(block.Data.Data[0], envelope); err != nil {
return "", err
}
payload := &common.Payload{}
if err := proto.Unmarshal(envelope.Payload, payload); err != nil {
return "", err
}
chdr, err := utils.UnmarshalChannelHeader(payload.Header.ChannelHeader)
if err != nil {
return "", err
}
fmt.Printf("Channel id: %v\n", chdr.ChannelId)
return chdr.ChannelId, nil
}

0 comments on commit 04eed73

Please sign in to comment.