Skip to content

Commit 04eed73

Browse files
committed
[FAB-3923] Remove dead code and duplicate from CSCC
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]>
1 parent e754035 commit 04eed73

File tree

2 files changed

+4
-45
lines changed

2 files changed

+4
-45
lines changed

core/scc/cscc/configure.go

-17
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ package cscc
2424
import (
2525
"fmt"
2626

27-
"errors"
28-
2927
"github.com/golang/protobuf/proto"
3028
"github.com/hyperledger/fabric/common/flogging"
3129
"github.com/hyperledger/fabric/common/policies"
@@ -174,21 +172,6 @@ func joinChain(blockBytes []byte) pb.Response {
174172
return shim.Success(nil)
175173
}
176174

177-
func getChannelFromConfigBlock(blockBytes []byte) (string, error) {
178-
if blockBytes == nil {
179-
return "", errors.New("Configuration block must not be nil.")
180-
}
181-
block, err := utils.GetBlockFromBlockBytes(blockBytes)
182-
if err != nil {
183-
return "", fmt.Errorf("Failed to reconstruct the configuration block, %s", err)
184-
}
185-
chainID, err := utils.GetChainIDFromBlock(block)
186-
if err != nil {
187-
return "", fmt.Errorf("Failed to get the chain ID from the configuration block, %s", err)
188-
}
189-
return chainID, nil
190-
}
191-
192175
func updateConfigBlock(blockBytes []byte) pb.Response {
193176
if blockBytes == nil {
194177
return shim.Error("Configuration block must not be nil.")

core/scc/cscc/configure_test.go

+4-28
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/hyperledger/fabric/msp/mgmt/testtools"
4242
peergossip "github.com/hyperledger/fabric/peer/gossip"
4343
"github.com/hyperledger/fabric/peer/gossip/mocks"
44-
"github.com/hyperledger/fabric/protos/common"
4544
pb "github.com/hyperledger/fabric/protos/peer"
4645
"github.com/hyperledger/fabric/protos/utils"
4746
"github.com/spf13/viper"
@@ -197,7 +196,7 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
197196

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

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

288287
func mockConfigBlock() []byte {
289-
var blockBytes []byte
288+
var blockBytes []byte = nil
290289
block, err := configtxtest.MakeGenesisBlock("mytestchainid")
291-
if err != nil {
292-
blockBytes = nil
293-
} else {
290+
if err == nil {
294291
blockBytes = utils.MarshalOrPanic(block)
295292
}
296293
return blockBytes
297294
}
298-
299-
func getChainID(blockBytes []byte) (string, error) {
300-
block := &common.Block{}
301-
if err := proto.Unmarshal(blockBytes, block); err != nil {
302-
return "", err
303-
}
304-
envelope := &common.Envelope{}
305-
if err := proto.Unmarshal(block.Data.Data[0], envelope); err != nil {
306-
return "", err
307-
}
308-
payload := &common.Payload{}
309-
if err := proto.Unmarshal(envelope.Payload, payload); err != nil {
310-
return "", err
311-
}
312-
chdr, err := utils.UnmarshalChannelHeader(payload.Header.ChannelHeader)
313-
if err != nil {
314-
return "", err
315-
}
316-
fmt.Printf("Channel id: %v\n", chdr.ChannelId)
317-
return chdr.ChannelId, nil
318-
}

0 commit comments

Comments
 (0)