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

Commit eaac2fa

Browse files
committed
[FAB-8617] Deprecate Channel interface
Moves all the duplicated code to channel/deprecated.go and puts the deprecated build tag on the file. Note: This change was tested with: 'FABRIC_SDK_DEPRECATED_UNITTEST=true make unit-tests' Change-Id: I3fba72a7f6a59dd628098bdce13a2b559e853637 Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
1 parent 5c6b705 commit eaac2fa

File tree

18 files changed

+660
-692
lines changed

18 files changed

+660
-692
lines changed

Makefile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ THIRDPARTY_FABRIC_COMMIT ?= v1.1.0-alpha
7171
FIXTURE_DOCKER_REMOVE_FORCE ?= false
7272

7373
# Options for exercising unit tests (overridable)
74-
FABRIC_DEPRECATED_UNITTEST ?= false
74+
FABRIC_SDK_DEPRECATED_UNITTEST ?= false
7575

7676
# Code levels to exercise integration/e2e tests against (overridable)
7777
FABRIC_STABLE_INTTEST ?= true
@@ -132,12 +132,12 @@ GO_DEP_COMMIT := v0.4.1
132132
ifdef JENKINS_URL
133133
export FABRIC_SDKGO_DEPEND_INSTALL=true
134134

135-
FABRIC_DEPRECATED_UNITTEST := true
136-
FABRIC_STABLE_INTTEST := true
137-
FABRIC_STABLE_PKCS11_INTTEST := true
138-
FABRIC_PREV_INTTEST := true
139-
FABRIC_PRERELEASE_INTTEST := true
140-
FABRIC_DEVSTABLE_INTTEST := false
135+
FABRIC_SDK_DEPRECATED_UNITTEST := true
136+
FABRIC_STABLE_INTTEST := true
137+
FABRIC_STABLE_PKCS11_INTTEST := true
138+
FABRIC_PREV_INTTEST := true
139+
FABRIC_PRERELEASE_INTTEST := true
140+
FABRIC_DEVSTABLE_INTTEST := false
141141
endif
142142

143143
# Setup Go Tags
@@ -206,7 +206,7 @@ build-softhsm2-image:
206206
.PHONY: unit-test
207207
unit-test: checks depend populate
208208
@FABRIC_SDKGO_CODELEVEL=$(FABRIC_CODELEVEL_UNITTEST_TAG) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_UNITTEST_VER) $(TEST_SCRIPTS_PATH)/unit.sh
209-
ifeq ($(FABRIC_DEPRECATED_UNITTEST),true)
209+
ifeq ($(FABRIC_SDK_DEPRECATED_UNITTEST),true)
210210
@GO_TAGS="$(GO_TAGS) deprecated" GO_TESTFLAGS="$(GO_TESTFLAGS) -count=1" FABRIC_SDKGO_CODELEVEL=$(FABRIC_CODELEVEL_UNITTEST_TAG) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_UNITTEST_VER) $(TEST_SCRIPTS_PATH)/unit.sh
211211
endif
212212

@@ -325,7 +325,7 @@ dockerenv-latest-up: clean
325325
mock-gen:
326326
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api IdentityManager | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/mocks/mockidmgr.gen.go
327327
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/core Config | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/core/mocks/mockconfig.gen.go
328-
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/fab/mocks/mockcontextapi.gen.go
328+
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/fab/mocks/mockcontextapi.gen.go
329329
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api CoreProviders,SvcProviders,Providers,CoreProviderFactory,ServiceProviderFactory,SessionClientFactory | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/fabsdk/mocks/mockfabsdkapi.gen.go
330330

331331

@@ -403,4 +403,3 @@ temp-clean:
403403
clean: temp-clean
404404
-$(GO_CMD) clean
405405
-FIXTURE_PROJECT_NAME=$(FIXTURE_PROJECT_NAME) DOCKER_REMOVE_FORCE=$(FIXTURE_DOCKER_REMOVE_FORCE) $(TEST_SCRIPTS_PATH)/clean_integration.sh
406-
Lines changed: 8 additions & 16 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 channel
7+
package resmgmt
88

99
import (
1010
"github.com/golang/protobuf/proto"
@@ -26,17 +26,17 @@ const (
2626
vscc = "vscc"
2727
)
2828

29-
// ChaincodeProposalType reflects transitions in the chaincode lifecycle
30-
type ChaincodeProposalType int
29+
// chaincodeProposalType reflects transitions in the chaincode lifecycle
30+
type chaincodeProposalType int
3131

3232
// Define chaincode proposal types
3333
const (
34-
InstantiateChaincode ChaincodeProposalType = iota
34+
InstantiateChaincode chaincodeProposalType = iota
3535
UpgradeChaincode
3636
)
3737

38-
// ChaincodeDeployRequest holds parameters for creating an instantiate or upgrade chaincode proposal.
39-
type ChaincodeDeployRequest struct {
38+
// chaincodeDeployRequest holds parameters for creating an instantiate or upgrade chaincode proposal.
39+
type chaincodeDeployRequest struct {
4040
Name string
4141
Path string
4242
Version string
@@ -45,8 +45,8 @@ type ChaincodeDeployRequest struct {
4545
CollConfig []*common.CollectionConfig
4646
}
4747

48-
// CreateChaincodeDeployProposal creates an instantiate or upgrade chaincode proposal.
49-
func CreateChaincodeDeployProposal(txh fab.TransactionHeader, deploy ChaincodeProposalType, channelID string, chaincode ChaincodeDeployRequest) (*fab.TransactionProposal, error) {
48+
// createChaincodeDeployProposal creates an instantiate or upgrade chaincode proposal.
49+
func createChaincodeDeployProposal(txh fab.TransactionHeader, deploy chaincodeProposalType, channelID string, chaincode chaincodeDeployRequest) (*fab.TransactionProposal, error) {
5050

5151
// Generate arguments for deploy (channel, marshaled CCDS, marshaled chaincode policy, marshaled collection policy)
5252
args := [][]byte{}
@@ -98,11 +98,3 @@ func CreateChaincodeDeployProposal(txh fab.TransactionHeader, deploy ChaincodePr
9898

9999
return txn.CreateChaincodeInvokeProposal(txh, cir)
100100
}
101-
102-
func createChaincodesInvokeRequest() fab.ChaincodeInvokeRequest {
103-
cir := fab.ChaincodeInvokeRequest{
104-
ChaincodeID: lscc,
105-
Fcn: lsccChaincodes,
106-
}
107-
return cir
108-
}

pkg/client/resmgmt/resmgmt.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"github.com/hyperledger/fabric-sdk-go/pkg/context"
1919
"github.com/hyperledger/fabric-sdk-go/pkg/errors/multi"
20-
"github.com/hyperledger/fabric-sdk-go/pkg/fab/channel"
2120
"github.com/hyperledger/fabric-sdk-go/pkg/fab/orderer"
2221
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
2322
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
@@ -400,12 +399,12 @@ func checkRequiredInstallCCParams(req InstallCCRequest) error {
400399

401400
// InstantiateCC instantiates chaincode using default settings
402401
func (rc *Client) InstantiateCC(channelID string, req InstantiateCCRequest, options ...RequestOption) error {
403-
return rc.sendCCProposal(channel.InstantiateChaincode, channelID, req, options...)
402+
return rc.sendCCProposal(InstantiateChaincode, channelID, req, options...)
404403
}
405404

406405
// UpgradeCC upgrades chaincode with optional custom options (specific peers, filtered peers, timeout)
407406
func (rc *Client) UpgradeCC(channelID string, req UpgradeCCRequest, options ...RequestOption) error {
408-
return rc.sendCCProposal(channel.UpgradeChaincode, channelID, InstantiateCCRequest(req), options...)
407+
return rc.sendCCProposal(UpgradeChaincode, channelID, InstantiateCCRequest(req), options...)
409408
}
410409

411410
// QueryInstalledChaincodes queries the installed chaincodes on a peer.
@@ -421,7 +420,7 @@ func (rc *Client) QueryChannels(proposalProcessor fab.ProposalProcessor) (*pb.Ch
421420
}
422421

423422
// sendCCProposal sends proposal for type Instantiate, Upgrade
424-
func (rc *Client) sendCCProposal(ccProposalType channel.ChaincodeProposalType, channelID string, req InstantiateCCRequest, options ...RequestOption) error {
423+
func (rc *Client) sendCCProposal(ccProposalType chaincodeProposalType, channelID string, req InstantiateCCRequest, options ...RequestOption) error {
425424

426425
if err := checkRequiredCCProposalParams(channelID, req); err != nil {
427426
return err
@@ -466,7 +465,7 @@ func (rc *Client) sendCCProposal(ccProposalType channel.ChaincodeProposalType, c
466465
}
467466

468467
// create a transaction proposal for chaincode deployment
469-
deployProposal := channel.ChaincodeDeployRequest(req)
468+
deployProposal := chaincodeDeployRequest(req)
470469
deployCtx := fabContext{
471470
ProviderContext: rc.provider,
472471
IdentityContext: rc.identity,
@@ -476,7 +475,7 @@ func (rc *Client) sendCCProposal(ccProposalType channel.ChaincodeProposalType, c
476475
if err != nil {
477476
return errors.WithMessage(err, "create transaction ID failed")
478477
}
479-
tp, err := channel.CreateChaincodeDeployProposal(txid, ccProposalType, channelID, deployProposal)
478+
tp, err := createChaincodeDeployProposal(txid, ccProposalType, channelID, deployProposal)
480479
if err != nil {
481480
return errors.WithMessage(err, "creating chaincode deploy transaction proposal failed")
482481
}

pkg/client/resmgmt/resmgmt_test.go

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/common/mocks"
2828
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
2929

30-
"github.com/hyperledger/fabric-sdk-go/pkg/fab/channel"
3130
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
3231
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
3332
)
@@ -67,23 +66,13 @@ func TestJoinChannel(t *testing.T) {
6766
orderer.(fcmocks.MockOrderer).EnqueueForSendDeliver(fcmocks.NewSimpleMockBlock())
6867
rc := setupResMgmtClient(ctx, nil, t)
6968

70-
channel, err := channel.New(ctx, fcmocks.NewMockChannelCfg("mychannel"))
71-
if err != nil {
72-
t.Fatalf("Error setting up channel: %v", err)
73-
}
74-
err = channel.AddOrderer(orderer)
75-
if err != nil {
76-
t.Fatalf("Error adding orderer: %v", err)
77-
}
78-
rc.channelProvider.(*fcmocks.MockChannelProvider).SetChannel("mychannel", channel)
79-
8069
// Setup target peers
8170
var peers []fab.Peer
8271
peer1, _ := peer.New(fcmocks.NewMockConfig(), peer.WithURL("example.com"))
8372
peers = append(peers, peer1)
8473

8574
// Test valid join channel request (success)
86-
err = rc.JoinChannel("mychannel", WithTargets(peer1))
75+
err := rc.JoinChannel("mychannel", WithTargets(peer1))
8776
if err != nil {
8877
t.Fatal(err)
8978
}
@@ -109,23 +98,13 @@ func TestJoinChannelWithFilter(t *testing.T) {
10998
//the target filter ( client option) will be set
11099
rc := setupResMgmtClient(ctx, nil, t)
111100

112-
channel, err := channel.New(ctx, fcmocks.NewMockChannelCfg("mychannel"))
113-
if err != nil {
114-
t.Fatalf("Error setting up channel: %v", err)
115-
}
116-
err = channel.AddOrderer(orderer)
117-
if err != nil {
118-
t.Fatalf("Error adding orderer: %v", err)
119-
}
120-
rc.channelProvider.(*fcmocks.MockChannelProvider).SetChannel("mychannel", channel)
121-
122101
// Setup target peers
123102
var peers []fab.Peer
124103
peer1, _ := peer.New(fcmocks.NewMockConfig(), peer.WithURL("example.com"))
125104
peers = append(peers, peer1)
126105

127106
// Test valid join channel request (success)
128-
err = rc.JoinChannel("mychannel", WithTargets(peer1))
107+
err := rc.JoinChannel("mychannel", WithTargets(peer1))
129108
if err != nil {
130109
t.Fatal(err)
131110
}
@@ -1037,15 +1016,6 @@ func TestCCProposal(t *testing.T) {
10371016
orderer := fcmocks.NewMockOrderer("", nil)
10381017
rc := setupResMgmtClient(ctx, nil, t)
10391018

1040-
channel, err := channel.New(ctx, fcmocks.NewMockChannelCfg("mychannel"))
1041-
if err != nil {
1042-
t.Fatalf("Error setting up channel: %v", err)
1043-
}
1044-
err = channel.AddOrderer(orderer)
1045-
if err != nil {
1046-
t.Fatalf("Error adding orderer: %v", err)
1047-
}
1048-
rc.channelProvider.(*fcmocks.MockChannelProvider).SetChannel("mychannel", channel)
10491019
transactor := txnmocks.MockTransactor{
10501020
Ctx: ctx,
10511021
ChannelID: "mychannel",

pkg/context/api/fab/channel.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,11 @@ SPDX-License-Identifier: Apache-2.0
77
package fab
88

99
import (
10-
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
1110
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
1211
mspCfg "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
1312
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
1413
)
1514

16-
// Channel ...
17-
/**
18-
* Channel representing a Channel with which the client SDK interacts.
19-
*
20-
* The Channel object captures settings for a channel, which is created by
21-
* the orderers to isolate transactions delivery to peers participating on channel.
22-
* A channel must be initialized after it has been configured with the list of peers
23-
* and orderers. The initialization sends a get configuration block request to the
24-
* primary orderer to retrieve the configuration settings for this channel.
25-
*/
26-
type Channel interface {
27-
Name() string
28-
ChannelConfig() (*common.ConfigEnvelope, error)
29-
30-
SendInstantiateProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope,
31-
collConfig []*common.CollectionConfig, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)
32-
SendUpgradeProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)
33-
34-
// Network
35-
// Deprecated: getters/setters are deprecated from interface.
36-
AddPeer(peer Peer) error
37-
RemovePeer(peer Peer)
38-
Peers() []Peer
39-
AnchorPeers() []OrgAnchorPeer
40-
SetPrimaryPeer(peer Peer) error
41-
PrimaryPeer() Peer
42-
AddOrderer(orderer Orderer) error
43-
RemoveOrderer(orderer Orderer)
44-
Orderers() []Orderer
45-
SetMSPManager(mspManager msp.MSPManager)
46-
MSPManager() msp.MSPManager
47-
OrganizationUnits() ([]string, error)
48-
49-
// Query
50-
QueryInfo() (*common.BlockchainInfo, error)
51-
QueryBlock(blockNumber int) (*common.Block, error)
52-
QueryBlockByHash(blockHash []byte) (*common.Block, error)
53-
QueryTransaction(transactionID TransactionID) (*pb.ProcessedTransaction, error)
54-
QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error)
55-
QueryByChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
56-
QueryBySystemChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
57-
QueryConfigBlock(targets []ProposalProcessor, minResponses int) (*common.ConfigEnvelope, error)
58-
}
59-
6015
// ChannelLedger provides access to the underlying ledger for a channel.
6116
type ChannelLedger interface {
6217
QueryInfo(targets []ProposalProcessor) ([]*BlockchainInfoResponse, error)

pkg/context/api/fab/deprecated.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// +build deprecated
2+
3+
/*
4+
Copyright SecureKey Technologies Inc. All Rights Reserved.
5+
6+
SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
package fab
10+
11+
import (
12+
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
13+
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
14+
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
15+
)
16+
17+
// Channel ...
18+
/**
19+
* Channel representing a Channel with which the client SDK interacts.
20+
*
21+
* The Channel object captures settings for a channel, which is created by
22+
* the orderers to isolate transactions delivery to peers participating on channel.
23+
* A channel must be initialized after it has been configured with the list of peers
24+
* and orderers. The initialization sends a get configuration block request to the
25+
* primary orderer to retrieve the configuration settings for this channel.
26+
*/
27+
type Channel interface {
28+
Name() string
29+
ChannelConfig() (*common.ConfigEnvelope, error)
30+
31+
SendInstantiateProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope,
32+
collConfig []*common.CollectionConfig, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)
33+
SendUpgradeProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)
34+
35+
// Network
36+
// Deprecated: getters/setters are deprecated from interface.
37+
AddPeer(peer Peer) error
38+
RemovePeer(peer Peer)
39+
Peers() []Peer
40+
AnchorPeers() []OrgAnchorPeer
41+
SetPrimaryPeer(peer Peer) error
42+
PrimaryPeer() Peer
43+
AddOrderer(orderer Orderer) error
44+
RemoveOrderer(orderer Orderer)
45+
Orderers() []Orderer
46+
SetMSPManager(mspManager msp.MSPManager)
47+
MSPManager() msp.MSPManager
48+
OrganizationUnits() ([]string, error)
49+
50+
// Query
51+
QueryInfo() (*common.BlockchainInfo, error)
52+
QueryBlock(blockNumber int) (*common.Block, error)
53+
QueryBlockByHash(blockHash []byte) (*common.Block, error)
54+
QueryTransaction(transactionID TransactionID) (*pb.ProcessedTransaction, error)
55+
QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error)
56+
QueryByChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
57+
QueryBySystemChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
58+
QueryConfigBlock(targets []ProposalProcessor, minResponses int) (*common.ConfigEnvelope, error)
59+
}

0 commit comments

Comments
 (0)