Skip to content

Commit 254c1b6

Browse files
committed
[FAB-9024] Fix vet issues in AuctionApp
Change-Id: I6f5fe3e71f4296617675c42f687779c876111d11 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 542e2e6 commit 254c1b6

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

test/chaincodes/AuctionApp/art.go

+22-23
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func main() {
243243
// Start the shim -- running the fabric
244244
err := shim.Start(new(SimpleChaincode))
245245
if err != nil {
246-
fmt.Println("Error starting Item Fun Application chaincode: %s", err)
246+
fmt.Printf("Error starting Item Fun Application chaincode: %s\n", err)
247247
}
248248

249249
}
@@ -359,7 +359,7 @@ func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, function stri
359359
return (response)
360360
}
361361
} else {
362-
fmt.Println("Invoke() Invalid recType : ", args, "\n")
362+
fmt.Println("Invoke() Invalid recType : ", args)
363363
error_str := "Invoke() : Invalid recType : " + args[0]
364364
return shim.Error(error_str)
365365
}
@@ -565,7 +565,7 @@ func GetAuctionRequest(stub shim.ChaincodeStubInterface, function string, args [
565565
return shim.Error(jsonResp)
566566
}
567567

568-
fmt.Println("GetAuctionRequest() : Response : Successful - \n")
568+
fmt.Println("GetAuctionRequest() : Response : Successful - ")
569569
return shim.Success(Avalbytes)
570570
}
571571

@@ -715,7 +715,7 @@ func PostItem(stub shim.ChaincodeStubInterface, function string, args []string)
715715

716716
itemObject, err := CreateItemObject(args[0:])
717717
if err != nil {
718-
fmt.Println("PostItem(): Cannot create item object \n")
718+
fmt.Println("PostItem(): Cannot create item object ")
719719
return shim.Error("PostItem(): Cannot create item object")
720720
}
721721

@@ -741,14 +741,14 @@ func PostItem(stub shim.ChaincodeStubInterface, function string, args []string)
741741
keys := []string{args[0]}
742742
err = UpdateObject(stub, "Item", keys, buff)
743743
if err != nil {
744-
fmt.Println("PostItem() : write error while inserting record\n")
744+
fmt.Println("PostItem() : write error while inserting record")
745745
return shim.Error("PostItem() : write error while inserting record : " + err.Error())
746746
}
747747

748748
// Put an entry into the Item History Table
749749
response := PostItemLog(stub, itemObject, "INITIAL", "DEFAULT", args[12])
750750
if response.Status != shim.OK {
751-
fmt.Println("PostItemLog() : write error while inserting record\n")
751+
fmt.Println("PostItemLog() : write error while inserting record")
752752
return shim.Error("PostItemLog() : write error while inserting record : Error : " + err.Error())
753753
}
754754

@@ -757,7 +757,7 @@ func PostItem(stub shim.ChaincodeStubInterface, function string, args []string)
757757
keys = []string{"2016", args[6], args[0]}
758758
err = UpdateObject(stub, "ItemCat", keys, buff)
759759
if err != nil {
760-
fmt.Println("PostItem() : Write error while inserting record into ItemCat \n")
760+
fmt.Println("PostItem() : Write error while inserting record into ItemCat ")
761761
return shim.Error("PostItem() : Write error while inserting record into ItemCat : Error : " + err.Error())
762762
}
763763
}
@@ -795,7 +795,7 @@ func CreateItemObject(args []string) (ItemObject, error) {
795795
if _, err := os.Stat(imagePath); err == nil {
796796
fmt.Println(imagePath, " exists!")
797797
} else {
798-
fmt.Println("CreateItemObject(): Cannot find or load Picture File = %s : %s\n", imagePath, err)
798+
fmt.Printf("CreateItemObject(): Cannot find or load Picture File = %s : %s\n", imagePath, err)
799799
return myItem, errors.New("CreateItemObject(): ART Picture File not found " + imagePath)
800800
}
801801

@@ -879,7 +879,7 @@ func TransferItem(stub shim.ChaincodeStubInterface, function string, args []stri
879879
var err error
880880

881881
if len(args) < 6 {
882-
fmt.Println("TransferItem() : Requires 6 arguments Item#, Owner#, Key#, newOwnerID#, XFER \n")
882+
fmt.Println("TransferItem() : Requires 6 arguments Item#, Owner#, Key#, newOwnerID#, XFER ")
883883
return shim.Error("TransferItem() : Requires 6 arguments Item#, Owner#, Key#, newOwnerID#, XFER")
884884
}
885885

@@ -946,7 +946,7 @@ func TransferItem(stub shim.ChaincodeStubInterface, function string, args []stri
946946

947947
response = PostItemLog(stub, myItem, "Transfer", args[1], args[5])
948948
if response.Status != shim.OK {
949-
fmt.Println("TransferItem() : PostItemLog() write error while inserting record\n")
949+
fmt.Println("TransferItem() : PostItemLog() write error while inserting record")
950950
return shim.Error(err.Error())
951951
}
952952

@@ -1040,7 +1040,7 @@ func PostItemLog(stub shim.ChaincodeStubInterface, item ItemObject, status strin
10401040
keys := []string{iLog.ItemID, iLog.Status, iLog.AuctionedBy, currentDateTime}
10411041
err = UpdateObject(stub, "ItemHistory", keys, buff)
10421042
if err != nil {
1043-
fmt.Println("PostItemLog() : write error while inserting record\n")
1043+
fmt.Println("PostItemLog() : write error while inserting record")
10441044
return shim.Error(err.Error())
10451045
}
10461046
}
@@ -1101,7 +1101,7 @@ func PostAuctionRequest(stub shim.ChaincodeStubInterface, function string, args
11011101
keys := []string{args[0]}
11021102
err = UpdateObject(stub, "Auction", keys, buff)
11031103
if err != nil {
1104-
fmt.Println("PostAuctionRequest() : write error while inserting record\n")
1104+
fmt.Println("PostAuctionRequest() : write error while inserting record")
11051105
return shim.Error(err.Error())
11061106
}
11071107

@@ -1111,7 +1111,7 @@ func PostAuctionRequest(stub shim.ChaincodeStubInterface, function string, args
11111111
io, err := JSONtoAR(itemObject)
11121112
response := PostItemLog(stub, io, "ReadyForAuc", ar.AuctionHouseID, ar.TimeStamp)
11131113
if response.Status != shim.OK {
1114-
fmt.Println("PostItemLog() : write error while inserting record\n")
1114+
fmt.Println("PostItemLog() : write error while inserting record")
11151115
return shim.Error(err.Error())
11161116
}
11171117

@@ -1122,7 +1122,7 @@ func PostAuctionRequest(stub shim.ChaincodeStubInterface, function string, args
11221122
keys = []string{"2016", args[0]}
11231123
err = UpdateObject(stub, "AucInit", keys, buff)
11241124
if err != nil {
1125-
fmt.Println("PostAuctionRequest() : write error while inserting record into AucInit\n")
1125+
fmt.Println("PostAuctionRequest() : write error while inserting record into AucInit")
11261126
return shim.Error(err.Error())
11271127
}
11281128

@@ -1211,7 +1211,7 @@ func PostTransaction(stub shim.ChaincodeStubInterface, function string, args []s
12111211
// Post an Item Log
12121212
itemObject, err := JSONtoAR(lastUpdatedItemOBCObject)
12131213
if err != nil {
1214-
fmt.Println("PostTransaction() : Conversion error JSON to ItemRecord\n")
1214+
fmt.Println("PostTransaction() : Conversion error JSON to ItemRecord")
12151215
return shim.Error(err.Error())
12161216
}
12171217

@@ -1221,7 +1221,7 @@ func PostTransaction(stub shim.ChaincodeStubInterface, function string, args []s
12211221

12221222
response = PostItemLog(stub, itemObject, "NA", "DEFAULT", args[5])
12231223
if response.Status != shim.OK {
1224-
fmt.Println("PostTransaction() : write error while inserting item log record\n")
1224+
fmt.Println("PostTransaction() : write error while inserting item log record")
12251225
return shim.Error(err.Error())
12261226
}
12271227

@@ -1238,11 +1238,11 @@ func PostTransaction(stub shim.ChaincodeStubInterface, function string, args []s
12381238
keys := []string{args[0], args[3]}
12391239
err = UpdateObject(stub, "Trans", keys, buff)
12401240
if err != nil {
1241-
fmt.Println("PostTransaction() : write error while inserting record\n")
1241+
fmt.Println("PostTransaction() : write error while inserting record")
12421242
return shim.Error(err.Error())
12431243
}
12441244

1245-
fmt.Println("PostTransaction() : Posted Transaction Record Successfully\n")
1245+
fmt.Println("PostTransaction() : Posted Transaction Record Successfully")
12461246

12471247
// Returns New Key. To get Transaction Details, run GetTransaction
12481248

@@ -1366,7 +1366,7 @@ func PostBid(stub shim.ChaincodeStubInterface, function string, args []string) p
13661366
keys := []string{args[0], args[2]}
13671367
err = UpdateObject(stub, "Bid", keys, buff)
13681368
if err != nil {
1369-
fmt.Println("PostBid() : write error while inserting record\n")
1369+
fmt.Println("PostBid() : write error while inserting record")
13701370
return shim.Error(err.Error())
13711371
}
13721372
}
@@ -2234,7 +2234,7 @@ func OpenAuctionForBids(stub shim.ChaincodeStubInterface, function string, args
22342234
// Add the Auction to Open Bucket
22352235
err = UpdateObject(stub, "AucOpen", keys, buff)
22362236
if err != nil {
2237-
fmt.Println("OpenAuctionForBids() : write error while inserting record into AucInit\n")
2237+
fmt.Println("OpenAuctionForBids() : write error while inserting record into AucInit")
22382238
return shim.Error(err.Error())
22392239
}
22402240

@@ -2494,7 +2494,7 @@ func UpdateAuctionStatus(stub shim.ChaincodeStubInterface, tableName string, ar
24942494
keys := []string{ar.AuctionID}
24952495
err = ReplaceObject(stub, "Auction", keys, buff)
24962496
if err != nil {
2497-
fmt.Println("UpdateAuctionStatus() : write error while inserting record\n")
2497+
fmt.Println("UpdateAuctionStatus() : write error while inserting record")
24982498
return shim.Error(err.Error())
24992499
}
25002500
return shim.Success(buff)
@@ -2526,7 +2526,7 @@ func ProcessQueryResult(stub shim.ChaincodeStubInterface, Avalbytes []byte, args
25262526

25272527
ar, err := JSONtoAR(Avalbytes) //
25282528
if err != nil {
2529-
fmt.Println("ProcessRequestType(): Cannot create itemObject \n")
2529+
fmt.Println("ProcessRequestType(): Cannot create itemObject ")
25302530
return err
25312531
}
25322532
// Decrypt Image and Save Image in a file
@@ -2595,6 +2595,5 @@ func ProcessQueryResult(stub shim.ChaincodeStubInterface, Avalbytes []byte, args
25952595
default:
25962596
return errors.New("Unknown")
25972597
}
2598-
return nil
25992598

26002599
}

test/chaincodes/AuctionApp/table_api.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ func ChkRecType(args []string) bool {
117117
func CheckRecType(rt string) bool {
118118
for _, val := range recType {
119119
if val == rt {
120-
fmt.Println("CheckRequestType() : Valid Request Type , val : ", val, rt, "\n")
120+
fmt.Println("CheckRequestType() : Valid Request Type , val : ", val, rt)
121121
return true
122122
}
123123
}
124-
fmt.Println("CheckRequestType() : Invalid Request Type , val : ", rt, "\n")
124+
fmt.Println("CheckRequestType() : Invalid Request Type , val : ", rt)
125125
return false
126126
}
127127

@@ -188,7 +188,7 @@ func UpdateObject(stub shim.ChaincodeStubInterface, objectType string, keys []st
188188
// Add Object JSON to state
189189
err = stub.PutState(compositeKey, objectData)
190190
if err != nil {
191-
fmt.Println("UpdateObject() : Error inserting Object into State Database %s", err)
191+
fmt.Printf("UpdateObject() : Error inserting Object into State Database %s\n", err)
192192
return err
193193
}
194194

@@ -215,7 +215,7 @@ func DeleteObject(stub shim.ChaincodeStubInterface, objectType string, keys []st
215215
// Remove object from the State Database
216216
err = stub.DelState(compositeKey)
217217
if err != nil {
218-
fmt.Println("DeleteObject() : Error deleting Object into State Database %s", err)
218+
fmt.Printf("DeleteObject() : Error deleting Object into State Database %s\n", err)
219219
return err
220220
}
221221
fmt.Println("DeleteObject() : ", "Object : ", objectType, " Key : ", compositeKey)
@@ -235,7 +235,7 @@ func DeleteAllObjects(stub shim.ChaincodeStubInterface, objectType string) error
235235
// Remove object from the State Database
236236
err := stub.DelState(compositeKey)
237237
if err != nil {
238-
fmt.Println("DeleteAllObjects() : Error deleting all Object into State Database %s", err)
238+
fmt.Printf("DeleteAllObjects() : Error deleting all Object into State Database %s\n", err)
239239
return err
240240
}
241241
fmt.Println("DeleteObject() : ", "Object : ", objectType, " Key : ", compositeKey)
@@ -263,7 +263,7 @@ func ReplaceObject(stub shim.ChaincodeStubInterface, objectType string, keys []s
263263
// Add Party JSON to state
264264
err = stub.PutState(compositeKey, objectData)
265265
if err != nil {
266-
fmt.Println("ReplaceObject() : Error replacing Object in State Database %s", err)
266+
fmt.Printf("ReplaceObject() : Error replacing Object in State Database %s\n", err)
267267
return err
268268
}
269269

@@ -317,15 +317,15 @@ func QueryObjectWithProcessingFunction(stub shim.ChaincodeStubInterface, objectT
317317
}
318318

319319
if Avalbytes == nil {
320-
return nil, fmt.Errorf("QueryObject: No Data Found for Compound Key : ", compoundKey)
320+
return nil, fmt.Errorf("QueryObject: No Data Found for Compound Key : %v", compoundKey)
321321
}
322322

323323
// Perform Any additional processing of data
324324
fmt.Println("fname() : Successful - Proceeding to fname")
325325

326326
err = fname(stub, Avalbytes, keys)
327327
if err != nil {
328-
fmt.Println("QueryLedger() : Cannot execute : ", fname)
328+
fmt.Println("QueryLedger() : Cannot execute fname")
329329
jsonResp := "{\"fname() Error\":\" Cannot create Object for key " + compoundKey + "\"}"
330330
return Avalbytes, errors.New(jsonResp)
331331
}
@@ -378,7 +378,7 @@ func GetKeyList(stub shim.ChaincodeStubInterface, args []string) (shim.StateQuer
378378
///////////////////////////////////////////////////////////////////////////////////////////
379379
func GetQueryResultForQueryString(stub shim.ChaincodeStubInterface, queryString string) ([]byte, error) {
380380

381-
fmt.Println("GetQueryResultForQueryString() : getQueryResultForQueryString queryString:\n%s\n", queryString)
381+
fmt.Printf("GetQueryResultForQueryString() : getQueryResultForQueryString queryString:\n%s\n", queryString)
382382

383383
resultsIterator, err := stub.GetQueryResult(queryString)
384384
if err != nil {
@@ -413,7 +413,7 @@ func GetQueryResultForQueryString(stub shim.ChaincodeStubInterface, queryString
413413
}
414414
buffer.WriteString("]")
415415

416-
fmt.Println("GetQueryResultForQueryString(): getQueryResultForQueryString queryResult:\n%s\n", buffer.String())
416+
fmt.Printf("GetQueryResultForQueryString(): getQueryResultForQueryString queryResult:\n%s\n", buffer.String())
417417

418418
return buffer.Bytes(), nil
419419
}
@@ -475,7 +475,7 @@ func VerifyAtLeastOneKeyIsPresent(objectType string, args []string) error {
475475
}
476476

477477
if nCol < 1 {
478-
error_str := fmt.Sprintf("VerifyAtLeastOneKeyIsPresent() Failed: Atleast 1 Key must is needed : nKeys : %s, nCol : %s ", nKeys, nCol)
478+
error_str := fmt.Sprintf("VerifyAtLeastOneKeyIsPresent() Failed: Atleast 1 Key must is needed : nKeys : %d, nCol : %d ", nKeys, nCol)
479479
fmt.Println(error_str)
480480
return errors.New(error_str)
481481
}

0 commit comments

Comments
 (0)