Skip to content

Commit d6b9bab

Browse files
committed
[FAB-3695] Fix endorser and orderer required check
Fix the endorser and orderer requirement checking in peer channel cmd. * Fix the wrong flag between isOrdererRequired and isEndorserRequired. * Add seperate isOrdererRequired flag to indicate whether we need orderer. * Use typedef to help people catch the boolean flag better. Change-Id: Ib01221d98ebb4c2c9647604b0d8c86d04769738c Signed-off-by: Baohua Yang <[email protected]>
1 parent 41f80f9 commit d6b9bab

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

peer/channel/channel.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ const (
3636
longDes = "Operate a channel: create|fetch|join|list."
3737
)
3838

39+
type OrdererRequirement bool
40+
type EndorserRequirement bool
41+
42+
const (
43+
EndorserRequired EndorserRequirement = true
44+
EndorserNotRequired EndorserRequirement = false
45+
OrdererRequired OrdererRequirement = true
46+
OrdererNotRequired OrdererRequirement = false
47+
)
48+
3949
var (
4050
// join related variables.
4151
genesisBlockPath string
@@ -89,8 +99,8 @@ type ChannelCmdFactory struct {
8999
BroadcastFactory BroadcastClientFactory
90100
}
91101

92-
// InitCmdFactory init the ChannelCmdFactor with default clients
93-
func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) {
102+
// InitCmdFactory init the ChannelCmdFactor with clients to endorser and orderer according to params
103+
func InitCmdFactory(isEndorserRequired EndorserRequirement, isOrdererRequired OrdererRequirement) (*ChannelCmdFactory, error) {
94104
var err error
95105

96106
cmdFact := &ChannelCmdFactory{}
@@ -104,14 +114,16 @@ func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) {
104114
return common.GetBroadcastClient(orderingEndpoint, tls, caFile)
105115
}
106116

107-
//for join, we need the endorser as well
108-
if isOrdererRequired {
117+
//for join and list, we need the endorser as well
118+
if isEndorserRequired {
109119
cmdFact.EndorserClient, err = common.GetEndorserClient()
110120
if err != nil {
111121
return nil, fmt.Errorf("Error getting endorser client %s: %s", channelFuncName, err)
112122
}
113-
} else {
123+
}
114124

125+
//for create and fetch, we need the orderer as well
126+
if isOrdererRequired {
115127
if len(strings.Split(orderingEndpoint, ":")) != 2 {
116128
return nil, fmt.Errorf("Ordering service endpoint %s is not valid or missing", orderingEndpoint)
117129
}

peer/channel/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func create(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error {
202202

203203
var err error
204204
if cf == nil {
205-
cf, err = InitCmdFactory(false)
205+
cf, err = InitCmdFactory(EndorserNotRequired, OrdererRequired)
206206
if err != nil {
207207
return err
208208
}

peer/channel/fetchconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func fetchCmd(cf *ChannelCmdFactory) *cobra.Command {
4242
func fetch(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error {
4343
var err error
4444
if cf == nil {
45-
cf, err = InitCmdFactory(false)
45+
cf, err = InitCmdFactory(EndorserNotRequired, OrdererRequired)
4646
if err != nil {
4747
return err
4848
}

peer/channel/join.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func executeJoin(cf *ChannelCmdFactory) (err error) {
128128
func join(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error {
129129
var err error
130130
if cf == nil {
131-
cf, err = InitCmdFactory(true)
131+
cf, err = InitCmdFactory(EndorserRequired, OrdererNotRequired)
132132
if err != nil {
133133
return err
134134
}

peer/channel/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func listCmd(cf *ChannelCmdFactory) *cobra.Command {
9191
func list(cf *ChannelCmdFactory) error {
9292
var err error
9393
if cf == nil {
94-
cf, err = InitCmdFactory(true)
94+
cf, err = InitCmdFactory(EndorserRequired, OrdererNotRequired)
9595
if err != nil {
9696
return err
9797
}

0 commit comments

Comments
 (0)