diff --git a/pkg/client/resmgmt/example_test.go b/pkg/client/resmgmt/example_test.go index b4c20a0788..ede9aa60ca 100644 --- a/pkg/client/resmgmt/example_test.go +++ b/pkg/client/resmgmt/example_test.go @@ -14,7 +14,7 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab" sdkCtx "github.com/hyperledger/fabric-sdk-go/pkg/context" "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks" - "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api" + "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource" mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" @@ -50,7 +50,7 @@ func Example() { } // Install example chaincode to peer - installReq := InstallCCRequest{Name: "ExampleCC", Version: "v0", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("bytes")}} + installReq := InstallCCRequest{Name: "ExampleCC", Version: "v0", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("bytes")}} _, err = c.InstallCC(installReq, WithTargets(peer)) if err != nil { fmt.Printf("failed to install chaincode: %v", err) @@ -263,7 +263,7 @@ func ExampleClient_InstallCC() { fmt.Println("failed to create client") } - req := InstallCCRequest{Name: "ExampleCC", Version: "v0", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("bytes")}} + req := InstallCCRequest{Name: "ExampleCC", Version: "v0", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("bytes")}} responses, err := c.InstallCC(req, WithTargets(mockPeer())) if err != nil { fmt.Printf("failed to install chaincode: %v", err) diff --git a/pkg/client/resmgmt/resmgmt.go b/pkg/client/resmgmt/resmgmt.go index 2389779086..d9c9be6ea7 100644 --- a/pkg/client/resmgmt/resmgmt.go +++ b/pkg/client/resmgmt/resmgmt.go @@ -43,7 +43,6 @@ import ( contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context" "github.com/hyperledger/fabric-sdk-go/pkg/fab/peer" "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource" - "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api" "github.com/hyperledger/fabric-sdk-go/pkg/fab/txn" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" "github.com/pkg/errors" @@ -54,7 +53,7 @@ type InstallCCRequest struct { Name string Path string Version string - Package *api.CCPackage + Package *resource.CCPackage } // InstallCCResponse contains install chaincode response status @@ -235,7 +234,7 @@ func (rc *Client) JoinChannel(channelID string, options ...RequestOption) error return errors.WithMessage(err, "genesis block retrieval failed") } - joinChannelRequest := api.JoinChannelRequest{ + joinChannelRequest := resource.JoinChannelRequest{ GenesisBlock: genesisBlock, } @@ -421,7 +420,7 @@ func (rc *Client) InstallCC(req InstallCCRequest, options ...RequestOption) ([]I } func (rc *Client) sendIntallCCRequest(req InstallCCRequest, reqCtx reqContext.Context, newTargets []fab.Peer, responses []InstallCCResponse) []InstallCCResponse { - icr := api.InstallChaincodeRequest{Name: req.Name, Path: req.Path, Version: req.Version, Package: req.Package} + icr := resource.InstallChaincodeRequest{Name: req.Name, Path: req.Path, Version: req.Version, Package: req.Package} transactionProposalResponse, _, _ := resource.InstallChaincode(reqCtx, icr, peer.PeersToTxnProcessors(newTargets)) for _, v := range transactionProposalResponse { logger.Debugf("Install chaincode '%s' endorser '%s' returned ProposalResponse status:%v", req.Name, v.Endorser, v.Status) @@ -873,7 +872,7 @@ func (rc *Client) SaveChannel(req SaveChannelRequest, options ...RequestOption) return SaveChannelResponse{}, err } - request := api.CreateChannelRequest{ + request := resource.CreateChannelRequest{ Name: req.ChannelID, Orderer: orderer, Config: chConfig, diff --git a/pkg/client/resmgmt/resmgmt_test.go b/pkg/client/resmgmt/resmgmt_test.go index 660f1d3ede..ca37add8ae 100644 --- a/pkg/client/resmgmt/resmgmt_test.go +++ b/pkg/client/resmgmt/resmgmt_test.go @@ -35,7 +35,7 @@ import ( fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab" fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks" "github.com/hyperledger/fabric-sdk-go/pkg/fab/peer" - "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api" + "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/provider/fabpvdr" mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl" @@ -523,7 +523,7 @@ func TestInstallCCWithOpts(t *testing.T) { Status: http.StatusOK, MockRoles: []string{}, MockCert: nil, MockMSP: "Org1MSP", Payload: responseBytes} // Already installed chaincode request - req := InstallCCRequest{Name: "name", Version: "version", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("code")}} + req := InstallCCRequest{Name: "name", Version: "version", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("code")}} responses, err := rc.InstallCC(req, WithTargets(&peer1)) if err != nil { t.Fatal(err) @@ -542,7 +542,7 @@ func TestInstallCCWithOpts(t *testing.T) { } // Chaincode not found request (it will be installed) - req = InstallCCRequest{Name: "ID", Version: "v0", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("code")}} + req = InstallCCRequest{Name: "ID", Version: "v0", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("code")}} responses, err = rc.InstallCC(req, WithTargets(&peer1)) if err != nil { t.Fatal(err) @@ -566,7 +566,7 @@ func TestInstallCCWithOptsError(t *testing.T) { peer1 := fcmocks.MockPeer{MockName: "Peer1", MockURL: "http://peer1.com", Status: http.StatusOK, MockRoles: []string{}, MockCert: nil, MockMSP: "Org1MSP"} - req := InstallCCRequest{Name: "error", Version: "v0", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("code")}} + req := InstallCCRequest{Name: "error", Version: "v0", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("code")}} // Test both targets and filter provided (error condition) _, err := rc.InstallCC(req, WithTargets(&peer1), WithTargetFilter(&mspFilter{mspID: "Org1MSP"})) @@ -585,7 +585,7 @@ func TestInstallError(t *testing.T) { peer2 := fcmocks.MockPeer{MockName: "Peer1", MockURL: "http://peer1.com", Status: http.StatusOK, MockRoles: []string{}, MockCert: nil, MockMSP: "Org1MSP"} - req := InstallCCRequest{Name: "ID", Version: "v0", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("code")}} + req := InstallCCRequest{Name: "ID", Version: "v0", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("code")}} _, err := rc.InstallCC(req, WithTargets(&peer1, &peer2)) assert.NotNil(t, err) assert.Contains(t, err.Error(), testErr.Error()) @@ -598,7 +598,7 @@ func TestInstallCC(t *testing.T) { Status: http.StatusOK, MockRoles: []string{}, MockCert: nil, MockMSP: "Org1MSP"} // Chaincode that is not installed already (it will be installed) - req := InstallCCRequest{Name: "ID", Version: "v0", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("code")}} + req := InstallCCRequest{Name: "ID", Version: "v0", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("code")}} responses, err := rc.InstallCC(req, WithTargets(&peer2)) if err != nil { t.Fatal(err) @@ -665,7 +665,7 @@ func TestInstallCCWithDifferentMSP(t *testing.T) { rc := setupResMgmtClient(t, ctx) // Valid request - req := InstallCCRequest{Name: "name", Version: "version", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("code")}} + req := InstallCCRequest{Name: "name", Version: "version", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("code")}} // No targets and no filter -- default filter msp doesn't match discovery service peer msp _, err := rc.InstallCC(req) @@ -713,7 +713,7 @@ func TestInstallCCDiscoveryError(t *testing.T) { rc := setupResMgmtClientWithDiscoveryError(t, ctx, errors.New("Test Error")) // Test InstallCC discovery service error - req := InstallCCRequest{Name: "ID", Version: "v0", Path: "path", Package: &api.CCPackage{Type: 1, Code: []byte("code")}} + req := InstallCCRequest{Name: "ID", Version: "v0", Path: "path", Package: &resource.CCPackage{Type: 1, Code: []byte("code")}} // Test InstallCC discovery service error // if targets are not provided discovery service is used diff --git a/pkg/fab/ccpackager/gopackager/packager.go b/pkg/fab/ccpackager/gopackager/packager.go index 9c58cccde2..1a119317ac 100644 --- a/pkg/fab/ccpackager/gopackager/packager.go +++ b/pkg/fab/ccpackager/gopackager/packager.go @@ -18,7 +18,7 @@ import ( "time" "github.com/hyperledger/fabric-sdk-go/pkg/common/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api" + "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource" "github.com/pkg/errors" "fmt" @@ -42,7 +42,7 @@ var keep = []string{".c", ".h", ".s", ".go", ".yaml", ".json"} var logger = logging.NewLogger("fabsdk/fab") // NewCCPackage creates new go lang chaincode package -func NewCCPackage(chaincodePath string, goPath string) (*api.CCPackage, error) { +func NewCCPackage(chaincodePath string, goPath string) (*resource.CCPackage, error) { if chaincodePath == "" { return nil, errors.New("chaincode path must be provided") @@ -75,7 +75,7 @@ func NewCCPackage(chaincodePath string, goPath string) (*api.CCPackage, error) { return nil, err } - ccPkg := &api.CCPackage{Type: pb.ChaincodeSpec_GOLANG, Code: tarBytes} + ccPkg := &resource.CCPackage{Type: pb.ChaincodeSpec_GOLANG, Code: tarBytes} return ccPkg, nil } diff --git a/pkg/fab/resource/api/api.go b/pkg/fab/resource/api.go similarity index 99% rename from pkg/fab/resource/api/api.go rename to pkg/fab/resource/api.go index 1bbd511a02..ff8e4aee75 100644 --- a/pkg/fab/resource/api/api.go +++ b/pkg/fab/resource/api.go @@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package api +package resource import ( "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab" diff --git a/pkg/fab/resource/resource.go b/pkg/fab/resource/resource.go index 383e5980d2..eb5121a94d 100644 --- a/pkg/fab/resource/resource.go +++ b/pkg/fab/resource/resource.go @@ -23,7 +23,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp" contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context" ccomm "github.com/hyperledger/fabric-sdk-go/pkg/core/config/comm" - "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api" "github.com/hyperledger/fabric-sdk-go/pkg/fab/txn" "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" @@ -77,7 +76,7 @@ func SignChannelConfig(ctx context.Client, config []byte, signer msp.SigningIden } // CreateChannel calls the orderer to start building the new channel. -func CreateChannel(reqCtx reqContext.Context, request api.CreateChannelRequest, opts ...Opt) (fab.TransactionID, error) { +func CreateChannel(reqCtx reqContext.Context, request CreateChannelRequest, opts ...Opt) (fab.TransactionID, error) { if request.Orderer == nil { return fab.EmptyTransactionID, errors.New("missing orderer request parameter for the initialize channel") } @@ -118,7 +117,7 @@ func CreateChannel(reqCtx reqContext.Context, request api.CreateChannelRequest, } // TODO: this function was extracted from createOrUpdateChannel, but needs a closer examination. -func createChannelFromEnvelope(reqCtx reqContext.Context, request api.CreateChannelRequest) (fab.TransactionID, error) { +func createChannelFromEnvelope(reqCtx reqContext.Context, request CreateChannelRequest) (fab.TransactionID, error) { env, err := extractSignedEnvelope(request.Envelope) if err != nil { return fab.EmptyTransactionID, errors.WithMessage(err, "signed envelope not valid") @@ -176,7 +175,7 @@ func LastConfigFromOrderer(reqCtx reqContext.Context, channelName string, ordere // JoinChannel sends a join channel proposal to the target peer. // // TODO extract targets from request into parameter. -func JoinChannel(reqCtx reqContext.Context, request api.JoinChannelRequest, targets []fab.ProposalProcessor, opts ...Opt) error { +func JoinChannel(reqCtx reqContext.Context, request JoinChannelRequest, targets []fab.ProposalProcessor, opts ...Opt) error { if request.GenesisBlock == nil { return errors.New("missing block input parameter with the required genesis block") @@ -226,7 +225,7 @@ func extractSignedEnvelope(reqEnvelope []byte) (*fab.SignedEnvelope, error) { } // createOrUpdateChannel creates a new channel or updates an existing channel. -func createOrUpdateChannel(reqCtx reqContext.Context, txh *txn.TransactionHeader, request api.CreateChannelRequest) error { +func createOrUpdateChannel(reqCtx reqContext.Context, txh *txn.TransactionHeader, request CreateChannelRequest) error { configUpdateEnvelope := &common.ConfigUpdateEnvelope{ ConfigUpdate: request.Config, @@ -311,7 +310,7 @@ func QueryInstalledChaincodes(reqCtx reqContext.Context, peer fab.ProposalProces } // InstallChaincode sends an install proposal to one or more endorsing peers. -func InstallChaincode(reqCtx reqContext.Context, req api.InstallChaincodeRequest, targets []fab.ProposalProcessor, opts ...Opt) ([]*fab.TransactionProposalResponse, fab.TransactionID, error) { +func InstallChaincode(reqCtx reqContext.Context, req InstallChaincodeRequest, targets []fab.ProposalProcessor, opts ...Opt) ([]*fab.TransactionProposalResponse, fab.TransactionID, error) { if req.Name == "" { return nil, fab.EmptyTransactionID, errors.New("chaincode name required") diff --git a/pkg/fab/resource/resource_test.go b/pkg/fab/resource/resource_test.go index b9d80fea61..90b683ee1a 100644 --- a/pkg/fab/resource/resource_test.go +++ b/pkg/fab/resource/resource_test.go @@ -23,7 +23,6 @@ import ( contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context" "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks" "github.com/hyperledger/fabric-sdk-go/pkg/fab/peer" - "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api" mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp" "github.com/hyperledger/fabric-sdk-go/test/metadata" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" @@ -66,7 +65,7 @@ func TestCreateChannel(t *testing.T) { // Create channel without envelope reqCtx, cancel := contextImpl.NewRequest(ctx, contextImpl.WithTimeout(10*time.Second)) defer cancel() - _, err = CreateChannel(reqCtx, api.CreateChannelRequest{ + _, err = CreateChannel(reqCtx, CreateChannelRequest{ Orderer: orderer, Name: "mychannel", }) @@ -75,7 +74,7 @@ func TestCreateChannel(t *testing.T) { } // Create channel without orderer - _, err = CreateChannel(reqCtx, api.CreateChannelRequest{ + _, err = CreateChannel(reqCtx, CreateChannelRequest{ Envelope: configTx, Name: "mychannel", }) @@ -84,7 +83,7 @@ func TestCreateChannel(t *testing.T) { } // Create channel without name - _, err = CreateChannel(reqCtx, api.CreateChannelRequest{ + _, err = CreateChannel(reqCtx, CreateChannelRequest{ Envelope: configTx, Orderer: orderer, }) @@ -93,7 +92,7 @@ func TestCreateChannel(t *testing.T) { } // Test with valid cofiguration - request := api.CreateChannelRequest{ + request := CreateChannelRequest{ Envelope: configTx, Orderer: orderer, Name: "mychannel", @@ -124,7 +123,7 @@ func TestJoinChannel(t *testing.T) { genesisBlock := mocks.NewSimpleMockBlock() - request := api.JoinChannelRequest{} + request := JoinChannelRequest{} reqCtx, cancel := contextImpl.NewRequest(ctx, contextImpl.WithTimeout(10*time.Second)) defer cancel() err := JoinChannel(reqCtx, request, peers) @@ -133,7 +132,7 @@ func TestJoinChannel(t *testing.T) { } // Test join channel with valid arguments - request = api.JoinChannelRequest{ + request = JoinChannelRequest{ GenesisBlock: genesisBlock, } err = JoinChannel(reqCtx, request, peers) @@ -143,7 +142,7 @@ func TestJoinChannel(t *testing.T) { // Test failed proposal error handling endorserServer.ProposalError = errors.New("Test Error") - request = api.JoinChannelRequest{} + request = JoinChannelRequest{} err = JoinChannel(reqCtx, request, peers) if err == nil { t.Fatalf("Expected error") diff --git a/test/integration/fab/install_chaincode_test.go b/test/integration/fab/install_chaincode_test.go index 7fa093d9b0..5d7a0c7e45 100644 --- a/test/integration/fab/install_chaincode_test.go +++ b/test/integration/fab/install_chaincode_test.go @@ -18,7 +18,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/context" packager "github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/gopackager" "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource" - "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" "github.com/hyperledger/fabric-sdk-go/test/integration" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" @@ -151,9 +150,9 @@ func testChaincodeInstallUsingChaincodePackage(t *testing.T, sdk *fabsdk.FabricS } // installCC use low level client to install chaincode -func installCC(t *testing.T, reqCtx reqContext.Context, name string, path string, version string, ccPackage *api.CCPackage, targets []fab.ProposalProcessor) error { +func installCC(t *testing.T, reqCtx reqContext.Context, name string, path string, version string, ccPackage *resource.CCPackage, targets []fab.ProposalProcessor) error { - icr := api.InstallChaincodeRequest{Name: name, Path: path, Version: version, Package: ccPackage} + icr := resource.InstallChaincodeRequest{Name: name, Path: path, Version: version, Package: ccPackage} r, _, err := resource.InstallChaincode(reqCtx, icr, targets, resource.WithRetry(retry.DefaultResMgmtOpts)) if err != nil { diff --git a/test/integration/orgs/multiple_orgs_test.go b/test/integration/orgs/multiple_orgs_test.go index 889450175c..6d909a7dfc 100644 --- a/test/integration/orgs/multiple_orgs_test.go +++ b/test/integration/orgs/multiple_orgs_test.go @@ -34,7 +34,7 @@ import ( selection "github.com/hyperledger/fabric-sdk-go/pkg/client/common/selection/dynamicselection" "github.com/hyperledger/fabric-sdk-go/pkg/client/channel" - "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api" + "github.com/hyperledger/fabric-sdk-go/pkg/fab/resource" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl" ) @@ -241,7 +241,7 @@ func testCCPolicy(chClientOrg2User *channel.Client, t *testing.T) { } } -func upgradeCC(ccPkg *api.CCPackage, org1ResMgmt *resmgmt.Client, t *testing.T, org2ResMgmt *resmgmt.Client) { +func upgradeCC(ccPkg *resource.CCPackage, org1ResMgmt *resmgmt.Client, t *testing.T, org2ResMgmt *resmgmt.Client) { installCCReq := resmgmt.InstallCCRequest{Name: "exampleCC", Path: "github.com/example_cc", Version: "1", Package: ccPkg} // Install example cc version '1' to Org1 peers _, err := org1ResMgmt.InstallCC(installCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts)) @@ -341,7 +341,7 @@ func verifyErrorFromCC(chClientOrg1User *channel.Client, t *testing.T) { } } -func createCC(t *testing.T, org1ResMgmt *resmgmt.Client, org2ResMgmt *resmgmt.Client, ccPkg *api.CCPackage) { +func createCC(t *testing.T, org1ResMgmt *resmgmt.Client, org2ResMgmt *resmgmt.Client, ccPkg *resource.CCPackage) { installCCReq := resmgmt.InstallCCRequest{Name: "exampleCC", Path: "github.com/example_cc", Version: "0", Package: ccPkg} // Install example cc to Org1 peers _, err := org1ResMgmt.InstallCC(installCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts))