@@ -19,6 +19,8 @@ import (
1919 "github.com/hyperledger/fabric-sdk-go/pkg/logging"
2020 "github.com/hyperledger/fabric-sdk-go/pkg/logging/deflogger"
2121 "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
22+
23+ chmgmt "github.com/hyperledger/fabric-sdk-go/api/apitxn/chmgmtclient"
2224)
2325
2426// Options encapsulates configuration for the SDK
@@ -58,6 +60,12 @@ type ChannelClientOpts struct {
5860 ConfigProvider apiconfig.Config
5961}
6062
63+ // ChannelMgmtClientOpts provides options for creating channel management client
64+ type ChannelMgmtClientOpts struct {
65+ OrgName string
66+ ConfigProvider apiconfig.Config
67+ }
68+
6169// ProviderInit interface allows for initializing providers
6270type ProviderInit interface {
6371 Initialize (sdk * FabricSDK ) error
@@ -195,6 +203,49 @@ func (sdk *FabricSDK) NewSystemClient(s context.Session) (apifabclient.FabricCli
195203 return client , nil
196204}
197205
206+ // NewChannelMgmtClient returns a new client for managing channels
207+ func (sdk * FabricSDK ) NewChannelMgmtClient (userName string ) (chmgmt.ChannelMgmtClient , error ) {
208+
209+ // Read default org name from configuration
210+ client , err := sdk .configProvider .Client ()
211+ if err != nil {
212+ return nil , errors .WithMessage (err , "unable to retrieve client from network config" )
213+ }
214+
215+ if client .Organization == "" {
216+ return nil , errors .New ("must provide default organisation name in configuration" )
217+ }
218+
219+ opt := & ChannelMgmtClientOpts {OrgName : client .Organization , ConfigProvider : sdk .configProvider }
220+
221+ return sdk .NewChannelMgmtClientWithOpts (userName , opt )
222+ }
223+
224+ // NewChannelMgmtClientWithOpts returns a new client for managing channels with options
225+ func (sdk * FabricSDK ) NewChannelMgmtClientWithOpts (userName string , opt * ChannelMgmtClientOpts ) (chmgmt.ChannelMgmtClient , error ) {
226+
227+ if opt == nil || opt .OrgName == "" {
228+ return nil , errors .New ("organization name must be provided" )
229+ }
230+
231+ session , err := sdk .NewPreEnrolledUserSession (opt .OrgName , userName )
232+ if err != nil {
233+ return nil , errors .WithMessage (err , "failed to get pre-enrolled user session" )
234+ }
235+
236+ configProvider := sdk .ConfigProvider ()
237+ if opt .ConfigProvider != nil {
238+ configProvider = opt .ConfigProvider
239+ }
240+
241+ client , err := sdk .SessionFactory .NewChannelMgmtClient (sdk , session , configProvider )
242+ if err != nil {
243+ return nil , errors .WithMessage (err , "failed to create new channel management client" )
244+ }
245+
246+ return client , nil
247+ }
248+
198249// NewChannelClient returns a new client for a channel
199250func (sdk * FabricSDK ) NewChannelClient (channelID string , userName string ) (apitxn.ChannelClient , error ) {
200251
0 commit comments