Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 76be185

Browse files
committed
[FAB-8463] Organize pkg/client folder
This change reorganizes the pkg/client folder as follows: pkg/client/discovery moved to pkg/client/common/discovery pkg/client/selection moved to pkg/client/common/selection pkg/client/mocks moved to pkg/client/common/mocks pkg/client/chclient renamed to pkg/client/channel pkg/client/resmgmtclient renamed to pkg/client/resmgmt Change-Id: I204ded21dd1cbbf369b82e84b8ee586f437d381e Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent 1170db5 commit 76be185

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+181
-187
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package chclient
7+
package channel
88

99
import (
1010
"time"
Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-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

1010
import (
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.
5449
type 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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package chclient
7+
package channel
88

99
import (
1010
"fmt"
@@ -16,7 +16,7 @@ import (
1616
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
1717
"github.com/stretchr/testify/assert"
1818

19-
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/mocks"
19+
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/common/mocks"
2020
"github.com/hyperledger/fabric-sdk-go/pkg/context"
2121
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
2222
"github.com/hyperledger/fabric-sdk-go/pkg/errors/retry"
@@ -572,12 +572,12 @@ func setupTestSelection(discErr error, peers []fab.Peer) (*txnmocks.MockSelectio
572572
return mockSelection.NewSelectionService("mychannel")
573573
}
574574

575-
func setupChannelClient(peers []fab.Peer, t *testing.T) *ChannelClient {
575+
func setupChannelClient(peers []fab.Peer, t *testing.T) *Client {
576576

577577
return setupChannelClientWithError(nil, nil, peers, t)
578578
}
579579

580-
func setupChannelClientWithError(discErr error, selectionErr error, peers []fab.Peer, t *testing.T) *ChannelClient {
580+
func setupChannelClientWithError(discErr error, selectionErr error, peers []fab.Peer, t *testing.T) *Client {
581581

582582
fabCtx := setupTestContext()
583583
orderer := fcmocks.NewMockOrderer("", nil)
@@ -609,7 +609,7 @@ func setupChannelClientWithError(discErr error, selectionErr error, peers []fab.
609609
}
610610

611611
func setupChannelClientWithNodes(peers []fab.Peer,
612-
orderers []fab.Orderer, t *testing.T) *ChannelClient {
612+
orderers []fab.Orderer, t *testing.T) *Client {
613613

614614
fabCtx := setupTestContext()
615615
testChannelSvc, err := setupTestChannelService(fabCtx, orderers)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package chclient
7+
package channel
88

99
import (
1010
"github.com/hyperledger/fabric-sdk-go/pkg/errors/status"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package chclient
7+
package channel
88

99
import (
1010
"errors"
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
1515

16-
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/mocks"
16+
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/common/mocks"
1717
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
1818
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
1919
"github.com/stretchr/testify/assert"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package chclient
7+
package channel
88

99
import (
1010
"time"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package chclient
7+
package channel
88

99
import (
1010
"testing"
@@ -19,7 +19,7 @@ import (
1919

2020
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
2121

22-
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/mocks"
22+
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/common/mocks"
2323
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
2424
)
2525

File renamed without changes.

pkg/client/discovery/discoveryfilter_test.go renamed to pkg/client/common/discovery/discoveryfilter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package discovery
99
import (
1010
"testing"
1111

12-
"github.com/hyperledger/fabric-sdk-go/pkg/client/discovery/staticdiscovery"
12+
"github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/staticdiscovery"
1313
"github.com/hyperledger/fabric-sdk-go/pkg/config"
1414
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
1515
)
@@ -26,7 +26,7 @@ func (df *mockFilter) Accept(peer fab.Peer) bool {
2626

2727
func TestDiscoveryFilter(t *testing.T) {
2828

29-
config, err := config.FromFile("../../../test/fixtures/config/config_test.yaml")()
29+
config, err := config.FromFile("../../../../test/fixtures/config/config_test.yaml")()
3030
if err != nil {
3131
t.Fatalf(err.Error())
3232
}
File renamed without changes.

0 commit comments

Comments
 (0)