Skip to content

Commit f1c0f64

Browse files
nirrozenbaumC0rWin
authored andcommitted
[FAB-8245] remove extra chars from peer cli output
removed the print of extra characters while printing the output of a block, also fixed capitalized error messages to lower case. Change-Id: Ibe75c3f612f3e13c2880810b2f692fdb98acea85 Signed-off-by: nirro <nirro@il.ibm.com> Signed-off-by: Artem Barger <bartem@il.ibm.com>
1 parent e8cc36f commit f1c0f64

File tree

4 files changed

+45
-47
lines changed

4 files changed

+45
-47
lines changed

examples/e2e_cli/scripts/script.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ chaincodeQuery () {
182182
sleep 3
183183
echo "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs"
184184
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
185-
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
185+
test $? -eq 0 && VALUE=$(cat log.txt | egrep '^[0-9]+$')
186186
test "$VALUE" = "$2" && let rc=0
187187
done
188188
echo

peer/chaincode/common.go

+38-40
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/json"
1111
"fmt"
1212
"io/ioutil"
13-
"os"
1413
"strings"
1514

1615
"github.com/golang/protobuf/proto"
@@ -34,12 +33,12 @@ import (
3433
func checkSpec(spec *pb.ChaincodeSpec) error {
3534
// Don't allow nil value
3635
if spec == nil {
37-
return errors.New("Expected chaincode specification, nil received")
36+
return errors.New("expected chaincode specification, nil received")
3837
}
3938

4039
platform, err := platforms.Find(spec.Type)
4140
if err != nil {
42-
return fmt.Errorf("Failed to determine platform type: %s", err)
41+
return fmt.Errorf("failed to determine platform type: %s", err)
4342
}
4443

4544
return platform.ValidateSpec(spec)
@@ -56,7 +55,7 @@ func getChaincodeDeploymentSpec(spec *pb.ChaincodeSpec, crtPkg bool) (*pb.Chainc
5655

5756
codePackageBytes, err = container.GetChaincodePackageBytes(spec)
5857
if err != nil {
59-
err = fmt.Errorf("Error getting chaincode package bytes: %s", err)
58+
err = fmt.Errorf("error getting chaincode package bytes: %s", err)
6059
return nil, err
6160
}
6261
}
@@ -74,7 +73,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
7473
// Build the spec
7574
input := &pb.ChaincodeInput{}
7675
if err := json.Unmarshal([]byte(chaincodeCtorJSON), &input); err != nil {
77-
return spec, fmt.Errorf("Chaincode argument error: %s", err)
76+
return spec, fmt.Errorf("chaincode argument error: %s", err)
7877
}
7978

8079
chaincodeLang = strings.ToUpper(chaincodeLang)
@@ -83,7 +82,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
8382
} else {
8483
logger.Debug("java chaincode disabled")
8584
if pb.ChaincodeSpec_Type_value[chaincodeLang] == int32(pb.ChaincodeSpec_JAVA) {
86-
return nil, fmt.Errorf("Java chaincode is work-in-progress and disabled")
85+
return nil, fmt.Errorf("java chaincode is work-in-progress and disabled")
8786
}
8887
}
8988
spec = &pb.ChaincodeSpec{
@@ -94,7 +93,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
9493
return spec, nil
9594
}
9695

97-
func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool, cf *ChaincodeCmdFactory) (err error) {
96+
func chaincodeInvokeOrQuery(cmd *cobra.Command, invoke bool, cf *ChaincodeCmdFactory) (err error) {
9897
spec, err := getChaincodeSpec(cmd)
9998
if err != nil {
10099
return err
@@ -117,43 +116,42 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool, cf *
117116
logger.Debugf("ESCC invoke result: %v", proposalResp)
118117
pRespPayload, err := putils.GetProposalResponsePayload(proposalResp.Payload)
119118
if err != nil {
120-
return fmt.Errorf("Error while unmarshaling proposal response payload: %s", err)
119+
return fmt.Errorf("error while unmarshaling proposal response payload: %s", err)
121120
}
122121
ca, err := putils.GetChaincodeAction(pRespPayload.Extension)
123122
if err != nil {
124-
return fmt.Errorf("Error while unmarshaling chaincode action: %s", err)
123+
return fmt.Errorf("error while unmarshaling chaincode action: %s", err)
125124
}
126125
logger.Warningf("Endorsement failure during invoke. chaincode result: %v", ca.Response)
127126
} else {
128127
logger.Debugf("ESCC invoke result: %v", proposalResp)
129128
pRespPayload, err := putils.GetProposalResponsePayload(proposalResp.Payload)
130129
if err != nil {
131-
return fmt.Errorf("Error while unmarshaling proposal response payload: %s", err)
130+
return fmt.Errorf("error while unmarshaling proposal response payload: %s", err)
132131
}
133132
ca, err := putils.GetChaincodeAction(pRespPayload.Extension)
134133
if err != nil {
135-
return fmt.Errorf("Error while unmarshaling chaincode action: %s", err)
134+
return fmt.Errorf("error while unmarshaling chaincode action: %s", err)
136135
}
137136
logger.Infof("Chaincode invoke successful. result: %v", ca.Response)
138137
}
139138
} else {
140139
if proposalResp == nil {
141-
return fmt.Errorf("Error query %s by endorsing: %s", chainFuncName, err)
140+
return fmt.Errorf("error query %s by endorsing: %s", chainFuncName, err)
142141
}
143142

143+
if chaincodeQueryRaw && chaincodeQueryHex {
144+
return fmt.Errorf("options --raw (-r) and --hex (-x) are not compatible")
145+
}
144146
if chaincodeQueryRaw {
145-
if chaincodeQueryHex {
146-
return fmt.Errorf("Options --raw (-r) and --hex (-x) are not compatible")
147-
}
148-
fmt.Print("Query Result (Raw): ")
149-
os.Stdout.Write(proposalResp.Response.Payload)
150-
} else {
151-
if chaincodeQueryHex {
152-
fmt.Printf("Query Result: %x\n", proposalResp.Response.Payload)
153-
} else {
154-
fmt.Printf("Query Result: %s\n", string(proposalResp.Response.Payload))
155-
}
147+
fmt.Println(proposalResp.Response.Payload)
148+
return nil
149+
}
150+
if chaincodeQueryHex {
151+
fmt.Printf("%x\n", proposalResp.Response.Payload)
152+
return nil
156153
}
154+
fmt.Println(string(proposalResp.Response.Payload))
157155
}
158156
return nil
159157
}
@@ -214,20 +212,20 @@ func getCollectionConfigFromBytes(cconfBytes []byte) ([]byte, error) {
214212
ccarray = append(ccarray, cc)
215213
}
216214

217-
ccp := &pcommon.CollectionConfigPackage{ccarray}
215+
ccp := &pcommon.CollectionConfigPackage{Config: ccarray}
218216
return proto.Marshal(ccp)
219217
}
220218

221219
func checkChaincodeCmdParams(cmd *cobra.Command) error {
222220
//we need chaincode name for everything, including deploy
223221
if chaincodeName == common.UndefinedParamValue {
224-
return fmt.Errorf("Must supply value for %s name parameter.", chainFuncName)
222+
return fmt.Errorf("must supply value for %s name parameter", chainFuncName)
225223
}
226224

227225
if cmd.Name() == instantiateCmdName || cmd.Name() == installCmdName ||
228226
cmd.Name() == upgradeCmdName || cmd.Name() == packageCmdName {
229227
if chaincodeVersion == common.UndefinedParamValue {
230-
return fmt.Errorf("Chaincode version is not provided for %s", cmd.Name())
228+
return fmt.Errorf("chaincode version is not provided for %s", cmd.Name())
231229
}
232230
}
233231

@@ -248,7 +246,7 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
248246
if policy != common.UndefinedParamValue {
249247
p, err := cauthdsl.FromString(policy)
250248
if err != nil {
251-
return fmt.Errorf("Invalid policy %s", policy)
249+
return fmt.Errorf("invalid policy %s", policy)
252250
}
253251
policyMarshalled = putils.MarshalOrPanic(p)
254252
}
@@ -270,7 +268,7 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
270268
var f interface{}
271269
err := json.Unmarshal([]byte(chaincodeCtorJSON), &f)
272270
if err != nil {
273-
return fmt.Errorf("Chaincode argument error: %s", err)
271+
return fmt.Errorf("chaincode argument error: %s", err)
274272
}
275273
m := f.(map[string]interface{})
276274
sm := make(map[string]interface{})
@@ -305,24 +303,24 @@ func InitCmdFactory(isEndorserRequired, isOrdererRequired bool) (*ChaincodeCmdFa
305303
if isEndorserRequired {
306304
endorserClient, err = common.GetEndorserClientFnc()
307305
if err != nil {
308-
return nil, fmt.Errorf("Error getting endorser client %s: %s", chainFuncName, err)
306+
return nil, fmt.Errorf("error getting endorser client %s: %s", chainFuncName, err)
309307
}
310308
}
311309

312310
signer, err := common.GetDefaultSignerFnc()
313311
if err != nil {
314-
return nil, fmt.Errorf("Error getting default signer: %s", err)
312+
return nil, fmt.Errorf("error getting default signer: %s", err)
315313
}
316314

317315
var broadcastClient common.BroadcastClient
318316
if isOrdererRequired {
319317
if len(common.OrderingEndpoint) == 0 {
320318
orderingEndpoints, err := common.GetOrdererEndpointOfChainFnc(channelID, signer, endorserClient)
321319
if err != nil {
322-
return nil, fmt.Errorf("Error getting (%s) orderer endpoint: %s", channelID, err)
320+
return nil, fmt.Errorf("error getting (%s) orderer endpoint: %s", channelID, err)
323321
}
324322
if len(orderingEndpoints) == 0 {
325-
return nil, fmt.Errorf("Error no orderer endpoint got for %s", channelID)
323+
return nil, fmt.Errorf("error no orderer endpoint got for %s", channelID)
326324
}
327325
logger.Infof("Get chain(%s) orderer endpoint: %s", channelID, orderingEndpoints[0])
328326
// override viper env
@@ -332,7 +330,7 @@ func InitCmdFactory(isEndorserRequired, isOrdererRequired bool) (*ChaincodeCmdFa
332330
broadcastClient, err = common.GetBroadcastClientFnc()
333331

334332
if err != nil {
335-
return nil, fmt.Errorf("Error getting broadcast client: %s", err)
333+
return nil, fmt.Errorf("error getting broadcast client: %s", err)
336334
}
337335
}
338336
return &ChaincodeCmdFactory{
@@ -367,7 +365,7 @@ func ChaincodeInvokeOrQuery(
367365

368366
creator, err := signer.Serialize()
369367
if err != nil {
370-
return nil, fmt.Errorf("Error serializing identity for %s: %s", signer.GetIdentifier(), err)
368+
return nil, fmt.Errorf("error serializing identity for %s: %s", signer.GetIdentifier(), err)
371369
}
372370

373371
funcName := "invoke"
@@ -379,26 +377,26 @@ func ChaincodeInvokeOrQuery(
379377
var tMap map[string][]byte
380378
if transient != "" {
381379
if err := json.Unmarshal([]byte(transient), &tMap); err != nil {
382-
return nil, fmt.Errorf("Error parsing transient string: %s", err)
380+
return nil, fmt.Errorf("error parsing transient string: %s", err)
383381
}
384382
}
385383

386384
var prop *pb.Proposal
387385
prop, _, err = putils.CreateChaincodeProposalWithTransient(pcommon.HeaderType_ENDORSER_TRANSACTION, cID, invocation, creator, tMap)
388386
if err != nil {
389-
return nil, fmt.Errorf("Error creating proposal %s: %s", funcName, err)
387+
return nil, fmt.Errorf("error creating proposal %s: %s", funcName, err)
390388
}
391389

392390
var signedProp *pb.SignedProposal
393391
signedProp, err = putils.GetSignedProposal(prop, signer)
394392
if err != nil {
395-
return nil, fmt.Errorf("Error creating signed proposal %s: %s", funcName, err)
393+
return nil, fmt.Errorf("error creating signed proposal %s: %s", funcName, err)
396394
}
397395

398396
var proposalResp *pb.ProposalResponse
399397
proposalResp, err = endorserClient.ProcessProposal(context.Background(), signedProp)
400398
if err != nil {
401-
return nil, fmt.Errorf("Error endorsing %s: %s", funcName, err)
399+
return nil, fmt.Errorf("error endorsing %s: %s", funcName, err)
402400
}
403401

404402
if invoke {
@@ -409,12 +407,12 @@ func ChaincodeInvokeOrQuery(
409407
// assemble a signed transaction (it's an Envelope message)
410408
env, err := putils.CreateSignedTx(prop, signer, proposalResp)
411409
if err != nil {
412-
return proposalResp, fmt.Errorf("Could not assemble transaction, err %s", err)
410+
return proposalResp, fmt.Errorf("could not assemble transaction, err %s", err)
413411
}
414412

415413
// send the envelope for ordering
416414
if err = bc.Send(env); err != nil {
417-
return proposalResp, fmt.Errorf("Error sending transaction %s: %s", funcName, err)
415+
return proposalResp, fmt.Errorf("error sending transaction %s: %s", funcName, err)
418416
}
419417
}
420418
}

peer/chaincode/invoke.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func invokeCmd(cf *ChaincodeCmdFactory) *cobra.Command {
3333
Long: fmt.Sprintf("Invoke the specified %s. It will try to commit the endorsed transaction to the network.", chainFuncName),
3434
ValidArgs: []string{"1"},
3535
RunE: func(cmd *cobra.Command, args []string) error {
36-
return chaincodeInvoke(cmd, args, cf)
36+
return chaincodeInvoke(cmd, cf)
3737
},
3838
}
3939
flagList := []string{
@@ -46,7 +46,7 @@ func invokeCmd(cf *ChaincodeCmdFactory) *cobra.Command {
4646
return chaincodeInvokeCmd
4747
}
4848

49-
func chaincodeInvoke(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
49+
func chaincodeInvoke(cmd *cobra.Command, cf *ChaincodeCmdFactory) error {
5050
if channelID == "" {
5151
return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag")
5252
}
@@ -59,5 +59,5 @@ func chaincodeInvoke(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory)
5959
}
6060
defer cf.BroadcastClient.Close()
6161

62-
return chaincodeInvokeOrQuery(cmd, args, true, cf)
62+
return chaincodeInvokeOrQuery(cmd, true, cf)
6363
}

peer/chaincode/query.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func queryCmd(cf *ChaincodeCmdFactory) *cobra.Command {
3333
Long: fmt.Sprintf("Get endorsed result of %s function call and print it. It won't generate transaction.", chainFuncName),
3434
ValidArgs: []string{"1"},
3535
RunE: func(cmd *cobra.Command, args []string) error {
36-
return chaincodeQuery(cmd, args, cf)
36+
return chaincodeQuery(cmd, cf)
3737
},
3838
}
3939
flagList := []string{
@@ -52,7 +52,7 @@ func queryCmd(cf *ChaincodeCmdFactory) *cobra.Command {
5252
return chaincodeQueryCmd
5353
}
5454

55-
func chaincodeQuery(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
55+
func chaincodeQuery(cmd *cobra.Command, cf *ChaincodeCmdFactory) error {
5656
if channelID == "" {
5757
return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag")
5858
}
@@ -64,5 +64,5 @@ func chaincodeQuery(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory)
6464
}
6565
}
6666

67-
return chaincodeInvokeOrQuery(cmd, args, false, cf)
67+
return chaincodeInvokeOrQuery(cmd, false, cf)
6868
}

0 commit comments

Comments
 (0)