@@ -22,31 +22,31 @@ import (
22
22
"golang.org/x/net/context"
23
23
24
24
"github.com/hyperledger/fabric/core/util"
25
- "github.com/hyperledger/fabric/msp"
26
- "github.com/hyperledger/fabric/peer/common"
27
25
protcommon "github.com/hyperledger/fabric/protos/common"
28
26
pb "github.com/hyperledger/fabric/protos/peer"
29
27
"github.com/hyperledger/fabric/protos/utils"
30
28
"github.com/spf13/cobra"
31
29
)
32
30
33
- // Cmd returns the cobra command for Chaincode Deploy
34
- func deployCmd () * cobra.Command {
35
- return chaincodeDeployCmd
36
- }
31
+ var chaincodeDeployCmd * cobra.Command
32
+
33
+ // deployCmd returns the cobra command for Chaincode Deploy
34
+ func deployCmd (cf * ChaincodeCmdFactory ) * cobra.Command {
35
+ chaincodeDeployCmd = & cobra.Command {
36
+ Use : "deploy" ,
37
+ Short : fmt .Sprintf ("Deploy the specified chaincode to the network." ),
38
+ Long : fmt .Sprintf (`Deploy the specified chaincode to the network.` ),
39
+ ValidArgs : []string {"1" },
40
+ RunE : func (cmd * cobra.Command , args []string ) error {
41
+ return chaincodeDeploy (cmd , args , cf )
42
+ },
43
+ }
37
44
38
- var chaincodeDeployCmd = & cobra.Command {
39
- Use : "deploy" ,
40
- Short : fmt .Sprintf ("Deploy the specified chaincode to the network." ),
41
- Long : fmt .Sprintf (`Deploy the specified chaincode to the network.` ),
42
- ValidArgs : []string {"1" },
43
- RunE : func (cmd * cobra.Command , args []string ) error {
44
- return chaincodeDeploy (cmd , args )
45
- },
45
+ return chaincodeDeployCmd
46
46
}
47
47
48
48
//deploy the command via Endorser
49
- func deploy (cmd * cobra.Command ) (* protcommon.Envelope , error ) {
49
+ func deploy (cmd * cobra.Command , cf * ChaincodeCmdFactory ) (* protcommon.Envelope , error ) {
50
50
spec , err := getChaincodeSpecification (cmd )
51
51
if err != nil {
52
52
return nil , err
@@ -57,41 +57,32 @@ func deploy(cmd *cobra.Command) (*protcommon.Envelope, error) {
57
57
return nil , fmt .Errorf ("Error getting chaincode code %s: %s" , chainFuncName , err )
58
58
}
59
59
60
- endorserClient , err := common .GetEndorserClient (cmd )
61
- if err != nil {
62
- return nil , fmt .Errorf ("Error getting endorser client %s: %s" , chainFuncName , err )
63
- }
64
- signer , err := msp .GetLocalMSP ().GetDefaultSigningIdentity ()
65
- if err != nil {
66
- return nil , fmt .Errorf ("Error obtaining the default signing identity, err %s" , err )
67
- }
68
-
69
- creator , err := signer .Serialize ()
60
+ creator , err := cf .Signer .Serialize ()
70
61
if err != nil {
71
- return nil , fmt .Errorf ("Error serializing the default signing identity, err %s" , err )
62
+ return nil , fmt .Errorf ("Error serializing identity for %s: %s \n " , cf . Signer . Identifier () , err )
72
63
}
73
64
74
65
uuid := util .GenerateUUID ()
75
66
76
- prop , err := utils .CreateProposalFromCDS (uuid , chainID , cds , creator )
67
+ prop , err := utils .CreateDeployProposalFromCDS (uuid , chainID , cds , creator )
77
68
if err != nil {
78
69
return nil , fmt .Errorf ("Error creating proposal %s: %s\n " , chainFuncName , err )
79
70
}
80
71
81
72
var signedProp * pb.SignedProposal
82
- signedProp , err = utils .GetSignedProposal (prop , signer )
73
+ signedProp , err = utils .GetSignedProposal (prop , cf . Signer )
83
74
if err != nil {
84
75
return nil , fmt .Errorf ("Error creating signed proposal %s: %s\n " , chainFuncName , err )
85
76
}
86
77
87
- proposalResponse , err := endorserClient .ProcessProposal (context .Background (), signedProp )
78
+ proposalResponse , err := cf . EndorserClient .ProcessProposal (context .Background (), signedProp )
88
79
if err != nil {
89
80
return nil , fmt .Errorf ("Error endorsing %s: %s\n " , chainFuncName , err )
90
81
}
91
82
92
83
if proposalResponse != nil {
93
84
// assemble a signed transaction (it's an Envelope message)
94
- env , err := utils .CreateSignedTx (prop , signer , proposalResponse )
85
+ env , err := utils .CreateSignedTx (prop , cf . Signer , proposalResponse )
95
86
if err != nil {
96
87
return nil , fmt .Errorf ("Could not assemble transaction, err %s" , err )
97
88
}
@@ -105,14 +96,22 @@ func deploy(cmd *cobra.Command) (*protcommon.Envelope, error) {
105
96
// chaincodeDeploy deploys the chaincode. On success, the chaincode name
106
97
// (hash) is printed to STDOUT for use by subsequent chaincode-related CLI
107
98
// commands.
108
- func chaincodeDeploy (cmd * cobra.Command , args []string ) error {
109
- env , err := deploy (cmd )
99
+ func chaincodeDeploy (cmd * cobra.Command , args []string , cf * ChaincodeCmdFactory ) error {
100
+ var err error
101
+ if cf == nil {
102
+ cf , err = InitCmdFactory ()
103
+ if err != nil {
104
+ return err
105
+ }
106
+ }
107
+ defer cf .BroadcastClient .Close ()
108
+ env , err := deploy (cmd , cf )
110
109
if err != nil {
111
110
return err
112
111
}
113
112
114
113
if env != nil {
115
- err = sendTransaction (env )
114
+ err = cf . BroadcastClient . Send (env )
116
115
}
117
116
118
117
return err
0 commit comments