@@ -166,46 +166,46 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool) (err
166
166
invocation .IdGenerationAlg = customIDGenAlg
167
167
}
168
168
169
- if invoke {
170
- endorserClient , err := common .GetEndorserClient (cmd )
171
- if err != nil {
172
- return fmt .Errorf ("Error getting endorser client %s: %s" , chainFuncName , err )
173
- }
169
+ endorserClient , err := common .GetEndorserClient (cmd )
170
+ if err != nil {
171
+ return fmt .Errorf ("Error getting endorser client %s: %s" , chainFuncName , err )
172
+ }
174
173
175
- // TODO: how should we get signing ID from the command line?
176
- mspID := "DEFAULT"
177
- id := "PEER"
178
- signingIdentity := & msp.IdentityIdentifier {Mspid : msp.ProviderIdentifier {Value : mspID }, Value : id }
174
+ // TODO: how should we get signing ID from the command line?
175
+ mspID := "DEFAULT"
176
+ id := "PEER"
177
+ signingIdentity := & msp.IdentityIdentifier {Mspid : msp.ProviderIdentifier {Value : mspID }, Value : id }
179
178
180
- // TODO: how should we obtain the config for the MSP from the command line? a hardcoded test config?
181
- signer , err := msp .GetManager ().GetSigningIdentity (signingIdentity )
182
- if err != nil {
183
- return fmt .Errorf ("Error obtaining signing identity for %s: %s\n " , signingIdentity , err )
184
- }
179
+ // TODO: how should we obtain the config for the MSP from the command line? a hardcoded test config?
180
+ signer , err := msp .GetManager ().GetSigningIdentity (signingIdentity )
181
+ if err != nil {
182
+ return fmt .Errorf ("Error obtaining signing identity for %s: %s\n " , signingIdentity , err )
183
+ }
185
184
186
- creator , err := signer .Serialize ()
187
- if err != nil {
188
- return fmt .Errorf ("Error serializing identity for %s: %s\n " , signingIdentity , err )
189
- }
185
+ creator , err := signer .Serialize ()
186
+ if err != nil {
187
+ return fmt .Errorf ("Error serializing identity for %s: %s\n " , signingIdentity , err )
188
+ }
190
189
191
- var prop * pb.Proposal
192
- prop , err = putils .CreateProposalFromCIS (invocation , creator )
193
- if err != nil {
194
- return fmt .Errorf ("Error creating proposal %s: %s\n " , chainFuncName , err )
195
- }
190
+ var prop * pb.Proposal
191
+ prop , err = putils .CreateProposalFromCIS (invocation , creator )
192
+ if err != nil {
193
+ return fmt .Errorf ("Error creating proposal %s: %s\n " , chainFuncName , err )
194
+ }
196
195
197
- var signedProp * pb.SignedProposal
198
- signedProp , err = putils .GetSignedProposal (prop , signer )
199
- if err != nil {
200
- return fmt .Errorf ("Error creating signed proposal %s: %s\n " , chainFuncName , err )
201
- }
196
+ var signedProp * pb.SignedProposal
197
+ signedProp , err = putils .GetSignedProposal (prop , signer )
198
+ if err != nil {
199
+ return fmt .Errorf ("Error creating signed proposal %s: %s\n " , chainFuncName , err )
200
+ }
202
201
203
- var proposalResp * pb.ProposalResponse
204
- proposalResp , err = endorserClient .ProcessProposal (context .Background (), signedProp )
205
- if err != nil {
206
- return fmt .Errorf ("Error endorsing %s: %s\n " , chainFuncName , err )
207
- }
202
+ var proposalResp * pb.ProposalResponse
203
+ proposalResp , err = endorserClient .ProcessProposal (context .Background (), signedProp )
204
+ if err != nil {
205
+ return fmt .Errorf ("Error endorsing %s: %s\n " , chainFuncName , err )
206
+ }
208
207
208
+ if invoke {
209
209
if proposalResp != nil {
210
210
// assemble a signed transaction (it's an Envelope message)
211
211
env , err := putils .CreateSignedTx (prop , signer , proposalResp )
@@ -218,8 +218,26 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool) (err
218
218
return fmt .Errorf ("Error sending transaction %s: %s\n " , chainFuncName , err )
219
219
}
220
220
}
221
-
222
221
logger .Infof ("Invoke result: %v" , proposalResp )
222
+ } else {
223
+ if proposalResp == nil {
224
+ return fmt .Errorf ("Error query %s by endorsing: %s\n " , chainFuncName , err )
225
+ }
226
+
227
+ if chaincodeQueryRaw {
228
+ if chaincodeQueryHex {
229
+ err = errors .New ("Options --raw (-r) and --hex (-x) are not compatible\n " )
230
+ return
231
+ }
232
+ fmt .Print ("Query Result (Raw): " )
233
+ os .Stdout .Write (proposalResp .Response .Payload )
234
+ } else {
235
+ if chaincodeQueryHex {
236
+ fmt .Printf ("Query Result: %x\n " , proposalResp .Response .Payload )
237
+ } else {
238
+ fmt .Printf ("Query Result: %s\n " , string (proposalResp .Response .Payload ))
239
+ }
240
+ }
223
241
}
224
242
225
243
return nil
0 commit comments