Skip to content

Commit

Permalink
[FAB-8767] Move targets into its own argument
Browse files Browse the repository at this point in the history
Change-Id: I3e84ed7a2404070b2fc5671c84d33fae192a5f7f
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Mar 10, 2018
1 parent 291ba8a commit 9a98953
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 29 deletions.
7 changes: 3 additions & 4 deletions pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,10 @@ func (rc *Client) JoinChannel(channelID string, options ...RequestOption) error
}

joinChannelRequest := api.JoinChannelRequest{
Targets: peersToTxnProcessors(targets),
GenesisBlock: genesisBlock,
}

err = resource.JoinChannel(rc.ctx, joinChannelRequest)
err = resource.JoinChannel(rc.ctx, joinChannelRequest, peersToTxnProcessors(targets))
if err != nil {
return errors.WithMessage(err, "join channel failed")
}
Expand Down Expand Up @@ -357,8 +356,8 @@ func (rc *Client) InstallCC(req InstallCCRequest, options ...RequestOption) ([]I
return responses, nil
}

icr := api.InstallChaincodeRequest{Name: req.Name, Path: req.Path, Version: req.Version, Package: req.Package, Targets: peer.PeersToTxnProcessors(newTargets)}
transactionProposalResponse, _, err := resource.InstallChaincode(rc.ctx, icr)
icr := api.InstallChaincodeRequest{Name: req.Name, Path: req.Path, Version: req.Version, Package: req.Package}
transactionProposalResponse, _, err := resource.InstallChaincode(rc.ctx, 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)

Expand Down
3 changes: 0 additions & 3 deletions pkg/fab/resource/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ type InstallChaincodeRequest struct {
Version string
// required - package (chaincode package type and bytes)
Package *CCPackage
// required - proposal processor list
Targets []fab.ProposalProcessor
}

// JoinChannelRequest allows a set of peers to transact on a channel on the network
type JoinChannelRequest struct {
// The name of the channel to be joined.
Name string
GenesisBlock *common.Block
Targets []fab.ProposalProcessor
}

// CCPackage contains package type and bytes required to create CDS
Expand Down
8 changes: 4 additions & 4 deletions pkg/fab/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func LastConfigFromOrderer(ctx context.Client, channelName string, orderer fab.O
// JoinChannel sends a join channel proposal to the target peer.
//
// TODO extract targets from request into parameter.
func JoinChannel(ctx context.Client, request api.JoinChannelRequest) error {
func JoinChannel(ctx context.Client, request api.JoinChannelRequest, targets []fab.ProposalProcessor) error {

if request.GenesisBlock == nil {
return errors.New("missing block input parameter with the required genesis block")
Expand All @@ -161,7 +161,7 @@ func JoinChannel(ctx context.Client, request api.JoinChannelRequest) error {
return errors.WithMessage(err, "creation of join channel invoke request failed")
}

_, err = queryChaincode(ctx, cir, request.Targets)
_, err = queryChaincode(ctx, cir, targets)
return err
}

Expand Down Expand Up @@ -256,7 +256,7 @@ func QueryInstalledChaincodes(ctx context.Client, peer fab.ProposalProcessor) (*
}

// InstallChaincode sends an install proposal to one or more endorsing peers.
func InstallChaincode(ctx context.Client, req api.InstallChaincodeRequest) ([]*fab.TransactionProposalResponse, fab.TransactionID, error) {
func InstallChaincode(ctx context.Client, req api.InstallChaincodeRequest, targets []fab.ProposalProcessor) ([]*fab.TransactionProposalResponse, fab.TransactionID, error) {

if req.Name == "" {
return nil, fab.EmptyTransactionID, errors.New("chaincode name required")
Expand Down Expand Up @@ -291,7 +291,7 @@ func InstallChaincode(ctx context.Client, req api.InstallChaincodeRequest) ([]*f
return nil, fab.EmptyTransactionID, errors.WithMessage(err, "creation of install chaincode proposal failed")
}

transactionProposalResponse, err := txn.SendProposal(ctx, prop, req.Targets)
transactionProposalResponse, err := txn.SendProposal(ctx, prop, targets)

return transactionProposalResponse, prop.TxnID, err
}
Expand Down
22 changes: 6 additions & 16 deletions pkg/fab/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,25 @@ func TestJoinChannel(t *testing.T) {

genesisBlock := mocks.NewSimpleMockBlock()

request := api.JoinChannelRequest{
Targets: peers,
//GenesisBlock: genesisBlock,
}
err := JoinChannel(ctx, request)
request := api.JoinChannelRequest{}
err := JoinChannel(ctx, request, peers)
if err == nil {
t.Fatalf("Should not have been able to join channel because of missing GenesisBlock parameter")
}

// Test join channel with valid arguments
request = api.JoinChannelRequest{
Targets: peers,
GenesisBlock: genesisBlock,
}
if err == nil {
t.Fatalf("Should not have been able to join channel because of invalid targets")
}

// Test join channel with valid arguments
err = JoinChannel(ctx, request)
err = JoinChannel(ctx, request, peers)
if err != nil {
t.Fatalf("Did not expect error from join channel. Got: %s", err)
}

// Test failed proposal error handling
endorserServer.ProposalError = errors.New("Test Error")
request = api.JoinChannelRequest{
Targets: peers,
}
err = JoinChannel(ctx, request)
request = api.JoinChannelRequest{}
err = JoinChannel(ctx, request, peers)
if err == nil {
t.Fatalf("Expected error")
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fab/install_chaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ func testChaincodeInstallUsingChaincodePackage(t *testing.T, sdk *fabsdk.FabricS
// installCC use low level client to install chaincode
func installCC(client *context.Client, name string, path string, version string, ccPackage *api.CCPackage, targets []fab.ProposalProcessor) error {

icr := api.InstallChaincodeRequest{Name: name, Path: path, Version: version, Package: ccPackage, Targets: targets}
icr := api.InstallChaincodeRequest{Name: name, Path: path, Version: version, Package: ccPackage}

_, _, err := resource.InstallChaincode(client, icr)
_, _, err := resource.InstallChaincode(client, icr, targets)
if err != nil {
return errors.WithMessage(err, "InstallChaincode failed")
}
Expand Down

0 comments on commit 9a98953

Please sign in to comment.