@@ -4,17 +4,17 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44SPDX-License-Identifier: Apache-2.0
55*/
66
7- // Package chclient enables channel client
8- package chclient
7+ // Package channel enables access to a channel on a Fabric network.
8+ package channel
99
1010import (
1111 "reflect"
1212 "time"
1313
1414 "github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
1515
16- "github.com/hyperledger/fabric-sdk-go/pkg/client/discovery"
17- "github.com/hyperledger/fabric-sdk-go/pkg/client/discovery/greylist"
16+ "github.com/hyperledger/fabric-sdk-go/pkg/client/common/ discovery"
17+ "github.com/hyperledger/fabric-sdk-go/pkg/client/common/ discovery/greylist"
1818 "github.com/hyperledger/fabric-sdk-go/pkg/context"
1919 "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
2020 "github.com/hyperledger/fabric-sdk-go/pkg/errors/multi"
@@ -30,17 +30,12 @@ const (
3030 defaultHandlerTimeout = time .Second * 10
3131)
3232
33- // ChannelClient enables access to a Fabric network.
34- /*
35- * A channel client instance provides a handler to interact with peers on specified channel.
36- * An application that requires interaction with multiple channels should create a separate
37- * instance of the channel client for each channel. Channel client supports non-admin functions only.
38- *
39- * Each Client instance maintains {@link Channel} instance representing channel and the associated
40- * private ledgers.
41- *
42- */
43- type ChannelClient struct {
33+ // Client enables access to a channel on a Fabric network.
34+ //
35+ // A channel client instance provides a handler to interact with peers on specified channel.
36+ // An application that requires interaction with multiple channels should create a separate
37+ // instance of the channel client for each channel. Channel client supports non-admin functions only.
38+ type Client struct {
4439 context context.ProviderContext
4540 discovery fab.DiscoveryService
4641 selection fab.SelectionService
@@ -50,16 +45,16 @@ type ChannelClient struct {
5045 greylist * greylist.Filter
5146}
5247
53- // Context holds the providers and services needed to create a ChannelClient .
48+ // Context holds the providers and services needed to create a Client .
5449type Context struct {
5550 context.ProviderContext
5651 DiscoveryService fab.DiscoveryService
5752 SelectionService fab.SelectionService
5853 ChannelService fab.ChannelService
5954}
6055
61- // New returns a ChannelClient instance.
62- func New (c Context ) (* ChannelClient , error ) {
56+ // New returns a Client instance.
57+ func New (c Context ) (* Client , error ) {
6358 greylistProvider := greylist .New (c .Config ().TimeoutOrDefault (core .DiscoveryGreylistExpiry ))
6459
6560 eventHub , err := c .ChannelService .EventHub ()
@@ -78,7 +73,7 @@ func New(c Context) (*ChannelClient, error) {
7873 return nil , errors .WithMessage (err , "channel client creation failed" )
7974 }
8075
81- channelClient := ChannelClient {
76+ channelClient := Client {
8277 greylist : greylistProvider ,
8378 context : c ,
8479 discovery : discovery .NewDiscoveryFilterService (c .DiscoveryService , greylistProvider ),
@@ -92,17 +87,17 @@ func New(c Context) (*ChannelClient, error) {
9287}
9388
9489// Query chaincode using request and optional options provided
95- func (cc * ChannelClient ) Query (request Request , options ... Option ) (Response , error ) {
90+ func (cc * Client ) Query (request Request , options ... Option ) (Response , error ) {
9691 return cc .InvokeHandler (NewQueryHandler (), request , cc .addDefaultTimeout (core .Query , options ... )... )
9792}
9893
9994// Execute prepares and executes transaction using request and optional options provided
100- func (cc * ChannelClient ) Execute (request Request , options ... Option ) (Response , error ) {
95+ func (cc * Client ) Execute (request Request , options ... Option ) (Response , error ) {
10196 return cc .InvokeHandler (NewExecuteHandler (), request , cc .addDefaultTimeout (core .Execute , options ... )... )
10297}
10398
10499//InvokeHandler invokes handler using request and options provided
105- func (cc * ChannelClient ) InvokeHandler (handler Handler , request Request , options ... Option ) (Response , error ) {
100+ func (cc * Client ) InvokeHandler (handler Handler , request Request , options ... Option ) (Response , error ) {
106101 //Read execute tx options
107102 txnOpts , err := cc .prepareOptsFromOptions (options ... )
108103 if err != nil {
@@ -135,7 +130,7 @@ func (cc *ChannelClient) InvokeHandler(handler Handler, request Request, options
135130 }
136131}
137132
138- func (cc * ChannelClient ) resolveRetry (ctx * RequestContext , opts Opts ) bool {
133+ func (cc * Client ) resolveRetry (ctx * RequestContext , opts Opts ) bool {
139134 errs , ok := ctx .Error .(multi.Errors )
140135 if ! ok {
141136 errs = append (errs , ctx .Error )
@@ -157,7 +152,7 @@ func (cc *ChannelClient) resolveRetry(ctx *RequestContext, opts Opts) bool {
157152}
158153
159154//prepareHandlerContexts prepares context objects for handlers
160- func (cc * ChannelClient ) prepareHandlerContexts (request Request , options Opts ) (* RequestContext , * ClientContext , error ) {
155+ func (cc * Client ) prepareHandlerContexts (request Request , options Opts ) (* RequestContext , * ClientContext , error ) {
161156
162157 if request .ChaincodeID == "" || request .Fcn == "" {
163158 return nil , nil , errors .New ("ChaincodeID and Fcn are required" )
@@ -186,7 +181,7 @@ func (cc *ChannelClient) prepareHandlerContexts(request Request, options Opts) (
186181}
187182
188183//prepareOptsFromOptions Reads apitxn.Opts from Option array
189- func (cc * ChannelClient ) prepareOptsFromOptions (options ... Option ) (Opts , error ) {
184+ func (cc * Client ) prepareOptsFromOptions (options ... Option ) (Opts , error ) {
190185 txnOpts := Opts {}
191186 for _ , option := range options {
192187 err := option (& txnOpts )
@@ -198,7 +193,7 @@ func (cc *ChannelClient) prepareOptsFromOptions(options ...Option) (Opts, error)
198193}
199194
200195//addDefaultTimeout adds given default timeout if it is missing in options
201- func (cc * ChannelClient ) addDefaultTimeout (timeOutType core.TimeoutType , options ... Option ) []Option {
196+ func (cc * Client ) addDefaultTimeout (timeOutType core.TimeoutType , options ... Option ) []Option {
202197 txnOpts := Opts {}
203198 for _ , option := range options {
204199 option (& txnOpts )
@@ -211,7 +206,7 @@ func (cc *ChannelClient) addDefaultTimeout(timeOutType core.TimeoutType, options
211206}
212207
213208// Close releases channel client resources (disconnects event hub etc.)
214- func (cc * ChannelClient ) Close () error {
209+ func (cc * Client ) Close () error {
215210 if cc .eventHub .IsConnected () == true {
216211 return cc .eventHub .Disconnect ()
217212 }
@@ -222,7 +217,7 @@ func (cc *ChannelClient) Close() error {
222217// RegisterChaincodeEvent registers chain code event
223218// @param {chan bool} channel which receives event details when the event is complete
224219// @returns {object} object handle that should be used to unregister
225- func (cc * ChannelClient ) RegisterChaincodeEvent (notify chan <- * CCEvent , chainCodeID string , eventID string ) (Registration , error ) {
220+ func (cc * Client ) RegisterChaincodeEvent (notify chan <- * CCEvent , chainCodeID string , eventID string ) (Registration , error ) {
226221
227222 if cc .eventHub .IsConnected () == false {
228223 if err := cc .eventHub .Connect (); err != nil {
@@ -239,7 +234,7 @@ func (cc *ChannelClient) RegisterChaincodeEvent(notify chan<- *CCEvent, chainCod
239234}
240235
241236// UnregisterChaincodeEvent removes chain code event registration
242- func (cc * ChannelClient ) UnregisterChaincodeEvent (registration Registration ) error {
237+ func (cc * Client ) UnregisterChaincodeEvent (registration Registration ) error {
243238
244239 switch regType := registration .(type ) {
245240
0 commit comments