Skip to content

Commit

Permalink
Merge "[FAB-8617] Deprecate Channel interface"
Browse files Browse the repository at this point in the history
  • Loading branch information
troyronda authored and Gerrit Code Review committed Mar 1, 2018
2 parents b8eb2d9 + eaac2fa commit 4845e91
Show file tree
Hide file tree
Showing 18 changed files with 660 additions and 692 deletions.
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ THIRDPARTY_FABRIC_COMMIT ?= v1.1.0-alpha
FIXTURE_DOCKER_REMOVE_FORCE ?= false

# Options for exercising unit tests (overridable)
FABRIC_DEPRECATED_UNITTEST ?= false
FABRIC_SDK_DEPRECATED_UNITTEST ?= false

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

FABRIC_DEPRECATED_UNITTEST := true
FABRIC_STABLE_INTTEST := true
FABRIC_STABLE_PKCS11_INTTEST := true
FABRIC_PREV_INTTEST := true
FABRIC_PRERELEASE_INTTEST := true
FABRIC_DEVSTABLE_INTTEST := false
FABRIC_SDK_DEPRECATED_UNITTEST := true
FABRIC_STABLE_INTTEST := true
FABRIC_STABLE_PKCS11_INTTEST := true
FABRIC_PREV_INTTEST := true
FABRIC_PRERELEASE_INTTEST := true
FABRIC_DEVSTABLE_INTTEST := false
endif

# Setup Go Tags
Expand Down Expand Up @@ -206,7 +206,7 @@ build-softhsm2-image:
.PHONY: unit-test
unit-test: checks depend populate
@FABRIC_SDKGO_CODELEVEL=$(FABRIC_CODELEVEL_UNITTEST_TAG) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_UNITTEST_VER) $(TEST_SCRIPTS_PATH)/unit.sh
ifeq ($(FABRIC_DEPRECATED_UNITTEST),true)
ifeq ($(FABRIC_SDK_DEPRECATED_UNITTEST),true)
@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
endif

Expand Down Expand Up @@ -325,7 +325,7 @@ dockerenv-latest-up: clean
mock-gen:
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
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
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
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
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


Expand Down Expand Up @@ -403,4 +403,3 @@ temp-clean:
clean: temp-clean
-$(GO_CMD) clean
-FIXTURE_PROJECT_NAME=$(FIXTURE_PROJECT_NAME) DOCKER_REMOVE_FORCE=$(FIXTURE_DOCKER_REMOVE_FORCE) $(TEST_SCRIPTS_PATH)/clean_integration.sh

24 changes: 8 additions & 16 deletions pkg/fab/channel/lscc.go → pkg/client/resmgmt/lscc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package channel
package resmgmt

import (
"github.com/golang/protobuf/proto"
Expand All @@ -26,17 +26,17 @@ const (
vscc = "vscc"
)

// ChaincodeProposalType reflects transitions in the chaincode lifecycle
type ChaincodeProposalType int
// chaincodeProposalType reflects transitions in the chaincode lifecycle
type chaincodeProposalType int

// Define chaincode proposal types
const (
InstantiateChaincode ChaincodeProposalType = iota
InstantiateChaincode chaincodeProposalType = iota
UpgradeChaincode
)

// ChaincodeDeployRequest holds parameters for creating an instantiate or upgrade chaincode proposal.
type ChaincodeDeployRequest struct {
// chaincodeDeployRequest holds parameters for creating an instantiate or upgrade chaincode proposal.
type chaincodeDeployRequest struct {
Name string
Path string
Version string
Expand All @@ -45,8 +45,8 @@ type ChaincodeDeployRequest struct {
CollConfig []*common.CollectionConfig
}

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

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

return txn.CreateChaincodeInvokeProposal(txh, cir)
}

func createChaincodesInvokeRequest() fab.ChaincodeInvokeRequest {
cir := fab.ChaincodeInvokeRequest{
ChaincodeID: lscc,
Fcn: lsccChaincodes,
}
return cir
}
11 changes: 5 additions & 6 deletions pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/errors/multi"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/orderer"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
Expand Down Expand Up @@ -400,12 +399,12 @@ func checkRequiredInstallCCParams(req InstallCCRequest) error {

// InstantiateCC instantiates chaincode using default settings
func (rc *Client) InstantiateCC(channelID string, req InstantiateCCRequest, options ...RequestOption) error {
return rc.sendCCProposal(channel.InstantiateChaincode, channelID, req, options...)
return rc.sendCCProposal(InstantiateChaincode, channelID, req, options...)
}

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

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

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

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

// create a transaction proposal for chaincode deployment
deployProposal := channel.ChaincodeDeployRequest(req)
deployProposal := chaincodeDeployRequest(req)
deployCtx := fabContext{
ProviderContext: rc.provider,
IdentityContext: rc.identity,
Expand All @@ -476,7 +475,7 @@ func (rc *Client) sendCCProposal(ccProposalType channel.ChaincodeProposalType, c
if err != nil {
return errors.WithMessage(err, "create transaction ID failed")
}
tp, err := channel.CreateChaincodeDeployProposal(txid, ccProposalType, channelID, deployProposal)
tp, err := createChaincodeDeployProposal(txid, ccProposalType, channelID, deployProposal)
if err != nil {
return errors.WithMessage(err, "creating chaincode deploy transaction proposal failed")
}
Expand Down
34 changes: 2 additions & 32 deletions pkg/client/resmgmt/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/common/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"

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

channel, err := channel.New(ctx, fcmocks.NewMockChannelCfg("mychannel"))
if err != nil {
t.Fatalf("Error setting up channel: %v", err)
}
err = channel.AddOrderer(orderer)
if err != nil {
t.Fatalf("Error adding orderer: %v", err)
}
rc.channelProvider.(*fcmocks.MockChannelProvider).SetChannel("mychannel", channel)

// Setup target peers
var peers []fab.Peer
peer1, _ := peer.New(fcmocks.NewMockConfig(), peer.WithURL("example.com"))
peers = append(peers, peer1)

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

channel, err := channel.New(ctx, fcmocks.NewMockChannelCfg("mychannel"))
if err != nil {
t.Fatalf("Error setting up channel: %v", err)
}
err = channel.AddOrderer(orderer)
if err != nil {
t.Fatalf("Error adding orderer: %v", err)
}
rc.channelProvider.(*fcmocks.MockChannelProvider).SetChannel("mychannel", channel)

// Setup target peers
var peers []fab.Peer
peer1, _ := peer.New(fcmocks.NewMockConfig(), peer.WithURL("example.com"))
peers = append(peers, peer1)

// Test valid join channel request (success)
err = rc.JoinChannel("mychannel", WithTargets(peer1))
err := rc.JoinChannel("mychannel", WithTargets(peer1))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1037,15 +1016,6 @@ func TestCCProposal(t *testing.T) {
orderer := fcmocks.NewMockOrderer("", nil)
rc := setupResMgmtClient(ctx, nil, t)

channel, err := channel.New(ctx, fcmocks.NewMockChannelCfg("mychannel"))
if err != nil {
t.Fatalf("Error setting up channel: %v", err)
}
err = channel.AddOrderer(orderer)
if err != nil {
t.Fatalf("Error adding orderer: %v", err)
}
rc.channelProvider.(*fcmocks.MockChannelProvider).SetChannel("mychannel", channel)
transactor := txnmocks.MockTransactor{
Ctx: ctx,
ChannelID: "mychannel",
Expand Down
45 changes: 0 additions & 45 deletions pkg/context/api/fab/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,11 @@ SPDX-License-Identifier: Apache-2.0
package fab

import (
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
mspCfg "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)

// Channel ...
/**
* Channel representing a Channel with which the client SDK interacts.
*
* The Channel object captures settings for a channel, which is created by
* the orderers to isolate transactions delivery to peers participating on channel.
* A channel must be initialized after it has been configured with the list of peers
* and orderers. The initialization sends a get configuration block request to the
* primary orderer to retrieve the configuration settings for this channel.
*/
type Channel interface {
Name() string
ChannelConfig() (*common.ConfigEnvelope, error)

SendInstantiateProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope,
collConfig []*common.CollectionConfig, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)
SendUpgradeProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)

// Network
// Deprecated: getters/setters are deprecated from interface.
AddPeer(peer Peer) error
RemovePeer(peer Peer)
Peers() []Peer
AnchorPeers() []OrgAnchorPeer
SetPrimaryPeer(peer Peer) error
PrimaryPeer() Peer
AddOrderer(orderer Orderer) error
RemoveOrderer(orderer Orderer)
Orderers() []Orderer
SetMSPManager(mspManager msp.MSPManager)
MSPManager() msp.MSPManager
OrganizationUnits() ([]string, error)

// Query
QueryInfo() (*common.BlockchainInfo, error)
QueryBlock(blockNumber int) (*common.Block, error)
QueryBlockByHash(blockHash []byte) (*common.Block, error)
QueryTransaction(transactionID TransactionID) (*pb.ProcessedTransaction, error)
QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error)
QueryByChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
QueryBySystemChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
QueryConfigBlock(targets []ProposalProcessor, minResponses int) (*common.ConfigEnvelope, error)
}

// ChannelLedger provides access to the underlying ledger for a channel.
type ChannelLedger interface {
QueryInfo(targets []ProposalProcessor) ([]*BlockchainInfoResponse, error)
Expand Down
59 changes: 59 additions & 0 deletions pkg/context/api/fab/deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package fab

import (
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)

// Channel ...
/**
* Channel representing a Channel with which the client SDK interacts.
*
* The Channel object captures settings for a channel, which is created by
* the orderers to isolate transactions delivery to peers participating on channel.
* A channel must be initialized after it has been configured with the list of peers
* and orderers. The initialization sends a get configuration block request to the
* primary orderer to retrieve the configuration settings for this channel.
*/
type Channel interface {
Name() string
ChannelConfig() (*common.ConfigEnvelope, error)

SendInstantiateProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope,
collConfig []*common.CollectionConfig, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)
SendUpgradeProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)

// Network
// Deprecated: getters/setters are deprecated from interface.
AddPeer(peer Peer) error
RemovePeer(peer Peer)
Peers() []Peer
AnchorPeers() []OrgAnchorPeer
SetPrimaryPeer(peer Peer) error
PrimaryPeer() Peer
AddOrderer(orderer Orderer) error
RemoveOrderer(orderer Orderer)
Orderers() []Orderer
SetMSPManager(mspManager msp.MSPManager)
MSPManager() msp.MSPManager
OrganizationUnits() ([]string, error)

// Query
QueryInfo() (*common.BlockchainInfo, error)
QueryBlock(blockNumber int) (*common.Block, error)
QueryBlockByHash(blockHash []byte) (*common.Block, error)
QueryTransaction(transactionID TransactionID) (*pb.ProcessedTransaction, error)
QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error)
QueryByChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
QueryBySystemChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
QueryConfigBlock(targets []ProposalProcessor, minResponses int) (*common.ConfigEnvelope, error)
}
Loading

0 comments on commit 4845e91

Please sign in to comment.