Skip to content

Commit 5e8e3c1

Browse files
C0rWinyacovm
authored andcommitted
Revert "[FAB-8245]"
This reverts commit 11ddbbe. Change-Id: Iee35ed7705ccdad6a3b4566696a1f828d0434408 Signed-off-by: Artem Barger <bartem@il.ibm.com>
1 parent 6860525 commit 5e8e3c1

File tree

4 files changed

+46
-47
lines changed

4 files changed

+46
-47
lines changed

examples/e2e_cli/scripts/script.sh

Lines changed: 1 addition & 1 deletion
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 | egrep '^[0-9]+$')
185+
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
186186
test "$VALUE" = "$2" && let rc=0
187187
done
188188
echo

peer/chaincode/common.go

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/json"
1111
"fmt"
1212
"io/ioutil"
13+
"os"
1314
"strings"
1415

1516
"github.com/golang/protobuf/proto"
@@ -33,12 +34,12 @@ import (
3334
func checkSpec(spec *pb.ChaincodeSpec) error {
3435
// Don't allow nil value
3536
if spec == nil {
36-
return errors.New("expected chaincode specification, nil received")
37+
return errors.New("Expected chaincode specification, nil received")
3738
}
3839

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

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

5657
codePackageBytes, err = container.GetChaincodePackageBytes(spec)
5758
if err != nil {
58-
err = fmt.Errorf("error getting chaincode package bytes: %s", err)
59+
err = fmt.Errorf("Error getting chaincode package bytes: %s", err)
5960
return nil, err
6061
}
6162
}
@@ -73,7 +74,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
7374
// Build the spec
7475
input := &pb.ChaincodeInput{}
7576
if err := json.Unmarshal([]byte(chaincodeCtorJSON), &input); err != nil {
76-
return spec, fmt.Errorf("chaincode argument error: %s", err)
77+
return spec, fmt.Errorf("Chaincode argument error: %s", err)
7778
}
7879

7980
chaincodeLang = strings.ToUpper(chaincodeLang)
@@ -82,7 +83,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
8283
} else {
8384
logger.Debug("java chaincode disabled")
8485
if pb.ChaincodeSpec_Type_value[chaincodeLang] == int32(pb.ChaincodeSpec_JAVA) {
85-
return nil, fmt.Errorf("java chaincode is work-in-progress and disabled")
86+
return nil, fmt.Errorf("Java chaincode is work-in-progress and disabled")
8687
}
8788
}
8889
spec = &pb.ChaincodeSpec{
@@ -93,7 +94,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
9394
return spec, nil
9495
}
9596

96-
func chaincodeInvokeOrQuery(cmd *cobra.Command, invoke bool, cf *ChaincodeCmdFactory) (err error) {
97+
func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool, cf *ChaincodeCmdFactory) (err error) {
9798
spec, err := getChaincodeSpec(cmd)
9899
if err != nil {
99100
return err
@@ -116,45 +117,43 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, invoke bool, cf *ChaincodeCmdFac
116117
logger.Debugf("ESCC invoke result: %v", proposalResp)
117118
pRespPayload, err := putils.GetProposalResponsePayload(proposalResp.Payload)
118119
if err != nil {
119-
return fmt.Errorf("error while unmarshaling proposal response payload: %s", err)
120+
return fmt.Errorf("Error while unmarshaling proposal response payload: %s", err)
120121
}
121122
ca, err := putils.GetChaincodeAction(pRespPayload.Extension)
122123
if err != nil {
123-
return fmt.Errorf("error while unmarshaling chaincode action: %s", err)
124+
return fmt.Errorf("Error while unmarshaling chaincode action: %s", err)
124125
}
125126
logger.Warningf("Endorsement failure during invoke. chaincode result: %v", ca.Response)
126127
} else {
127128
logger.Debugf("ESCC invoke result: %v", proposalResp)
128129
pRespPayload, err := putils.GetProposalResponsePayload(proposalResp.Payload)
129130
if err != nil {
130-
return fmt.Errorf("error while unmarshaling proposal response payload: %s", err)
131+
return fmt.Errorf("Error while unmarshaling proposal response payload: %s", err)
131132
}
132133
ca, err := putils.GetChaincodeAction(pRespPayload.Extension)
133134
if err != nil {
134-
return fmt.Errorf("error while unmarshaling chaincode action: %s", err)
135+
return fmt.Errorf("Error while unmarshaling chaincode action: %s", err)
135136
}
136137
logger.Infof("Chaincode invoke successful. result: %v", ca.Response)
137138
}
138139
} else {
139140
if proposalResp == nil {
140-
return fmt.Errorf("error query %s by endorsing: %s", chainFuncName, err)
141-
}
142-
143-
if chaincodeQueryRaw && chaincodeQueryHex {
144-
return fmt.Errorf("options --raw (-r) and --hex (-x) are not compatible")
141+
return fmt.Errorf("Error query %s by endorsing: %s", chainFuncName, err)
145142
}
146143

147144
if chaincodeQueryRaw {
148-
fmt.Println(proposalResp.Response.Payload)
149-
return nil
150-
}
151-
152-
if chaincodeQueryHex {
153-
fmt.Printf("%x\n", proposalResp.Response.Payload)
154-
return nil
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+
}
155156
}
156-
157-
fmt.Println(string(proposalResp.Response.Payload))
158157
}
159158
return nil
160159
}
@@ -215,20 +214,20 @@ func getCollectionConfigFromBytes(cconfBytes []byte) ([]byte, error) {
215214
ccarray = append(ccarray, cc)
216215
}
217216

218-
ccp := &pcommon.CollectionConfigPackage{Config: ccarray}
217+
ccp := &pcommon.CollectionConfigPackage{ccarray}
219218
return proto.Marshal(ccp)
220219
}
221220

222221
func checkChaincodeCmdParams(cmd *cobra.Command) error {
223222
//we need chaincode name for everything, including deploy
224223
if chaincodeName == common.UndefinedParamValue {
225-
return fmt.Errorf("must supply value for %s name parameter", chainFuncName)
224+
return fmt.Errorf("Must supply value for %s name parameter.", chainFuncName)
226225
}
227226

228227
if cmd.Name() == instantiateCmdName || cmd.Name() == installCmdName ||
229228
cmd.Name() == upgradeCmdName || cmd.Name() == packageCmdName {
230229
if chaincodeVersion == common.UndefinedParamValue {
231-
return fmt.Errorf("chaincode version is not provided for %s", cmd.Name())
230+
return fmt.Errorf("Chaincode version is not provided for %s", cmd.Name())
232231
}
233232
}
234233

@@ -249,7 +248,7 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
249248
if policy != common.UndefinedParamValue {
250249
p, err := cauthdsl.FromString(policy)
251250
if err != nil {
252-
return fmt.Errorf("invalid policy %s", policy)
251+
return fmt.Errorf("Invalid policy %s", policy)
253252
}
254253
policyMarshalled = putils.MarshalOrPanic(p)
255254
}
@@ -271,7 +270,7 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
271270
var f interface{}
272271
err := json.Unmarshal([]byte(chaincodeCtorJSON), &f)
273272
if err != nil {
274-
return fmt.Errorf("chaincode argument error: %s", err)
273+
return fmt.Errorf("Chaincode argument error: %s", err)
275274
}
276275
m := f.(map[string]interface{})
277276
sm := make(map[string]interface{})
@@ -306,24 +305,24 @@ func InitCmdFactory(isEndorserRequired, isOrdererRequired bool) (*ChaincodeCmdFa
306305
if isEndorserRequired {
307306
endorserClient, err = common.GetEndorserClientFnc()
308307
if err != nil {
309-
return nil, fmt.Errorf("error getting endorser client %s: %s", chainFuncName, err)
308+
return nil, fmt.Errorf("Error getting endorser client %s: %s", chainFuncName, err)
310309
}
311310
}
312311

313312
signer, err := common.GetDefaultSignerFnc()
314313
if err != nil {
315-
return nil, fmt.Errorf("error getting default signer: %s", err)
314+
return nil, fmt.Errorf("Error getting default signer: %s", err)
316315
}
317316

318317
var broadcastClient common.BroadcastClient
319318
if isOrdererRequired {
320319
if len(common.OrderingEndpoint) == 0 {
321320
orderingEndpoints, err := common.GetOrdererEndpointOfChainFnc(channelID, signer, endorserClient)
322321
if err != nil {
323-
return nil, fmt.Errorf("error getting (%s) orderer endpoint: %s", channelID, err)
322+
return nil, fmt.Errorf("Error getting (%s) orderer endpoint: %s", channelID, err)
324323
}
325324
if len(orderingEndpoints) == 0 {
326-
return nil, fmt.Errorf("error no orderer endpoint got for %s", channelID)
325+
return nil, fmt.Errorf("Error no orderer endpoint got for %s", channelID)
327326
}
328327
logger.Infof("Get chain(%s) orderer endpoint: %s", channelID, orderingEndpoints[0])
329328
// override viper env
@@ -333,7 +332,7 @@ func InitCmdFactory(isEndorserRequired, isOrdererRequired bool) (*ChaincodeCmdFa
333332
broadcastClient, err = common.GetBroadcastClientFnc()
334333

335334
if err != nil {
336-
return nil, fmt.Errorf("error getting broadcast client: %s", err)
335+
return nil, fmt.Errorf("Error getting broadcast client: %s", err)
337336
}
338337
}
339338
return &ChaincodeCmdFactory{
@@ -368,7 +367,7 @@ func ChaincodeInvokeOrQuery(
368367

369368
creator, err := signer.Serialize()
370369
if err != nil {
371-
return nil, fmt.Errorf("error serializing identity for %s: %s", signer.GetIdentifier(), err)
370+
return nil, fmt.Errorf("Error serializing identity for %s: %s", signer.GetIdentifier(), err)
372371
}
373372

374373
funcName := "invoke"
@@ -380,7 +379,7 @@ func ChaincodeInvokeOrQuery(
380379
var tMap map[string][]byte
381380
if transient != "" {
382381
if err := json.Unmarshal([]byte(transient), &tMap); err != nil {
383-
return nil, fmt.Errorf("error parsing transient string: %s", err)
382+
return nil, fmt.Errorf("Error parsing transient string: %s", err)
384383
}
385384
}
386385

@@ -393,13 +392,13 @@ func ChaincodeInvokeOrQuery(
393392
var signedProp *pb.SignedProposal
394393
signedProp, err = putils.GetSignedProposal(prop, signer)
395394
if err != nil {
396-
return nil, fmt.Errorf("error creating signed proposal %s: %s", funcName, err)
395+
return nil, fmt.Errorf("Error creating signed proposal %s: %s", funcName, err)
397396
}
398397

399398
var proposalResp *pb.ProposalResponse
400399
proposalResp, err = endorserClient.ProcessProposal(context.Background(), signedProp)
401400
if err != nil {
402-
return nil, fmt.Errorf("error endorsing %s: %s", funcName, err)
401+
return nil, fmt.Errorf("Error endorsing %s: %s", funcName, err)
403402
}
404403

405404
if invoke {
@@ -410,12 +409,12 @@ func ChaincodeInvokeOrQuery(
410409
// assemble a signed transaction (it's an Envelope message)
411410
env, err := putils.CreateSignedTx(prop, signer, proposalResp)
412411
if err != nil {
413-
return proposalResp, fmt.Errorf("could not assemble transaction, err %s", err)
412+
return proposalResp, fmt.Errorf("Could not assemble transaction, err %s", err)
414413
}
415414

416415
// send the envelope for ordering
417416
if err = bc.Send(env); err != nil {
418-
return proposalResp, fmt.Errorf("error sending transaction %s: %s", funcName, err)
417+
return proposalResp, fmt.Errorf("Error sending transaction %s: %s", funcName, err)
419418
}
420419
}
421420
}

peer/chaincode/invoke.go

Lines changed: 3 additions & 3 deletions
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, cf)
36+
return chaincodeInvoke(cmd, args, 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, cf *ChaincodeCmdFactory) error {
49+
func chaincodeInvoke(cmd *cobra.Command, args []string, 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, cf *ChaincodeCmdFactory) error {
5959
}
6060
defer cf.BroadcastClient.Close()
6161

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

peer/chaincode/query.go

Lines changed: 3 additions & 3 deletions
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, cf)
36+
return chaincodeQuery(cmd, args, 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, cf *ChaincodeCmdFactory) error {
55+
func chaincodeQuery(cmd *cobra.Command, args []string, 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, cf *ChaincodeCmdFactory) error {
6464
}
6565
}
6666

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

0 commit comments

Comments
 (0)