-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-8376] Refactor deployment spec creation
This change remove usage of proto util's deployment spec creation. Change-Id: I26b227af7e519ef4fe8172fa0310ceda848b76b4 Signed-off-by: Troy Ronda <[email protected]>
- Loading branch information
Showing
11 changed files
with
150 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package resource | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/golang/protobuf/ptypes" | ||
"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/txn" | ||
"github.com/pkg/errors" | ||
|
||
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" | ||
protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" | ||
|
||
fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient" | ||
) | ||
|
||
// ChaincodeInstallRequest requests chaincode installation on the network | ||
type ChaincodeInstallRequest struct { | ||
Name string | ||
Path string | ||
Version string | ||
Package *ChaincodePackage | ||
} | ||
|
||
// ChaincodePackage contains package type and bytes required to create CDS | ||
type ChaincodePackage struct { | ||
Type pb.ChaincodeSpec_Type | ||
Code []byte | ||
} | ||
|
||
// CreateChaincodeInstallProposal creates an install chaincode proposal. | ||
func CreateChaincodeInstallProposal(ctx fab.IdentityContext, request ChaincodeInstallRequest) (*fab.TransactionProposal, error) { | ||
|
||
// Generate arguments for install | ||
args := [][]byte{} | ||
timestamp := time.Now() | ||
ts, err := ptypes.TimestampProto(timestamp) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to create timestamp in install proposal") | ||
} | ||
|
||
ccds := &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ | ||
Type: request.Package.Type, ChaincodeId: &pb.ChaincodeID{Name: request.Name, Path: request.Path, Version: request.Version}}, | ||
CodePackage: request.Package.Code, EffectiveDate: ts} | ||
ccdsBytes, err := protos_utils.Marshal(ccds) | ||
if err != nil { | ||
return nil, errors.WithMessage(err, "marshal of chaincode deployment spec failed") | ||
} | ||
args = append(args, ccdsBytes) | ||
|
||
args = append(args, []byte("escc")) | ||
args = append(args, []byte("vscc")) | ||
|
||
cir := fab.ChaincodeInvokeRequest{ | ||
ChaincodeID: "lscc", | ||
Fcn: "install", | ||
Args: args, | ||
} | ||
return txn.CreateChaincodeInvokeProposal(ctx, "", cir) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package resource | ||
|
||
import ( | ||
"testing" | ||
|
||
fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient" | ||
"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/txn" | ||
|
||
"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/mocks" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateChaincodeInstallProposal(t *testing.T) { | ||
c := setupTestClient() | ||
peer := mocks.MockPeer{MockName: "Peer1", MockURL: "peer1.example.com", MockRoles: []string{}, MockCert: nil, Payload: []byte("A"), Status: 200} | ||
|
||
request := ChaincodeInstallRequest{ | ||
Name: "examplecc", | ||
Path: "github.com/examplecc", | ||
Version: "1", | ||
Package: &ChaincodePackage{}, | ||
} | ||
|
||
prop, err := CreateChaincodeInstallProposal(c.clientContext, request) | ||
assert.Nil(t, err, "CreateChaincodeInstallProposal failed") | ||
|
||
_, err = txn.SendProposal(c.clientContext, prop, []fab.ProposalProcessor{&peer}) | ||
assert.Nil(t, err, "sending mock proposal failed") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.