-
Notifications
You must be signed in to change notification settings - Fork 0
/
lscc.go
75 lines (62 loc) · 2.25 KB
/
lscc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package resource
import (
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/aiguo186/fabric-sdk-go-gm/internal/github.com/aiguo186/fabric/protoutil"
"github.com/aiguo186/fabric-sdk-go-gm/pkg/common/providers/fab"
"github.com/aiguo186/fabric-sdk-go-gm/pkg/fab/txn"
"github.com/pkg/errors"
)
const (
lscc = "lscc"
lsccInstall = "install"
lsccInstalledChaincodes = "getinstalledchaincodes"
)
// 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(txh fab.TransactionHeader, request ChaincodeInstallRequest) (*fab.TransactionProposal, error) {
cir, err := createInstallInvokeRequest(request)
if err != nil {
return nil, errors.WithMessage(err, "creating lscc install invocation request failed")
}
return txn.CreateChaincodeInvokeProposal(txh, cir)
}
func createInstallInvokeRequest(request ChaincodeInstallRequest) (fab.ChaincodeInvokeRequest, error) {
// Generate arguments for install
args := [][]byte{}
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}
ccdsBytes, err := protoutil.Marshal(ccds)
if err != nil {
return fab.ChaincodeInvokeRequest{}, errors.WithMessage(err, "marshal of chaincode deployment spec failed")
}
args = append(args, ccdsBytes)
cir := fab.ChaincodeInvokeRequest{
ChaincodeID: lscc,
Fcn: lsccInstall,
Args: args,
}
return cir, nil
}
func createInstalledChaincodesInvokeRequest() fab.ChaincodeInvokeRequest {
cir := fab.ChaincodeInvokeRequest{
ChaincodeID: lscc,
Fcn: lsccInstalledChaincodes,
}
return cir
}