diff --git a/peer/channel/channel.go b/peer/channel/channel.go index f109fe37e83..76e00c9a306 100644 --- a/peer/channel/channel.go +++ b/peer/channel/channel.go @@ -36,6 +36,16 @@ const ( longDes = "Operate a channel: create|fetch|join|list." ) +type OrdererRequirement bool +type EndorserRequirement bool + +const ( + EndorserRequired EndorserRequirement = true + EndorserNotRequired EndorserRequirement = false + OrdererRequired OrdererRequirement = true + OrdererNotRequired OrdererRequirement = false +) + var ( // join related variables. genesisBlockPath string @@ -89,8 +99,8 @@ type ChannelCmdFactory struct { BroadcastFactory BroadcastClientFactory } -// InitCmdFactory init the ChannelCmdFactor with default clients -func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) { +// InitCmdFactory init the ChannelCmdFactor with clients to endorser and orderer according to params +func InitCmdFactory(isEndorserRequired EndorserRequirement, isOrdererRequired OrdererRequirement) (*ChannelCmdFactory, error) { var err error cmdFact := &ChannelCmdFactory{} @@ -104,14 +114,16 @@ func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) { return common.GetBroadcastClient(orderingEndpoint, tls, caFile) } - //for join, we need the endorser as well - if isOrdererRequired { + //for join and list, we need the endorser as well + if isEndorserRequired { cmdFact.EndorserClient, err = common.GetEndorserClient() if err != nil { return nil, fmt.Errorf("Error getting endorser client %s: %s", channelFuncName, err) } - } else { + } + //for create and fetch, we need the orderer as well + if isOrdererRequired { if len(strings.Split(orderingEndpoint, ":")) != 2 { return nil, fmt.Errorf("Ordering service endpoint %s is not valid or missing", orderingEndpoint) } diff --git a/peer/channel/create.go b/peer/channel/create.go index 443a79dfc2a..74569fc2100 100644 --- a/peer/channel/create.go +++ b/peer/channel/create.go @@ -202,7 +202,7 @@ func create(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error { var err error if cf == nil { - cf, err = InitCmdFactory(false) + cf, err = InitCmdFactory(EndorserNotRequired, OrdererRequired) if err != nil { return err } diff --git a/peer/channel/fetchconfig.go b/peer/channel/fetchconfig.go index b1f9fec3959..96bd2952a28 100644 --- a/peer/channel/fetchconfig.go +++ b/peer/channel/fetchconfig.go @@ -42,7 +42,7 @@ func fetchCmd(cf *ChannelCmdFactory) *cobra.Command { func fetch(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error { var err error if cf == nil { - cf, err = InitCmdFactory(false) + cf, err = InitCmdFactory(EndorserNotRequired, OrdererRequired) if err != nil { return err } diff --git a/peer/channel/join.go b/peer/channel/join.go index 8caa6c51c46..9f220269967 100644 --- a/peer/channel/join.go +++ b/peer/channel/join.go @@ -128,7 +128,7 @@ func executeJoin(cf *ChannelCmdFactory) (err error) { func join(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error { var err error if cf == nil { - cf, err = InitCmdFactory(true) + cf, err = InitCmdFactory(EndorserRequired, OrdererNotRequired) if err != nil { return err } diff --git a/peer/channel/list.go b/peer/channel/list.go index bb54261d481..a7347be6fed 100644 --- a/peer/channel/list.go +++ b/peer/channel/list.go @@ -91,7 +91,7 @@ func listCmd(cf *ChannelCmdFactory) *cobra.Command { func list(cf *ChannelCmdFactory) error { var err error if cf == nil { - cf, err = InitCmdFactory(true) + cf, err = InitCmdFactory(EndorserRequired, OrdererNotRequired) if err != nil { return err }