Skip to content

Commit

Permalink
FAB-8326 NodeSDK - fix golang lint issues
Browse files Browse the repository at this point in the history
Fix a few lint issues with the golang chaincode.

Change-Id: I310ecdedaaeed2c6b3cd0ea1b6a8700a6cc67af4
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed Mar 20, 2018
1 parent c0be611 commit 66d5e96
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
19 changes: 10 additions & 9 deletions test/fixtures/src/github.com/events_cc/events_cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ type EventSender struct {
func (t *EventSender) Init(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("*********** Init ***********")

err := stub.PutState("num_events", []byte("0"))
err := stub.PutState("numEvents", []byte("0"))
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
}

// Invoke - invoke the chaincode
func (t *EventSender) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("*********** Invoke ***********")
function, args := stub.GetFunctionAndParameters()
Expand Down Expand Up @@ -67,20 +68,20 @@ func (t *EventSender) invoke(stub shim.ChaincodeStubInterface) pb.Response {
if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 2")
}
b, err := stub.GetState("num_events")
b, err := stub.GetState("numEvents")
if err != nil {
return shim.Error("Failed to get state")
}
num_events, _ := strconv.Atoi(string(b))
numEvents, _ := strconv.Atoi(string(b))

tosend := "Event " + string(b) + args[1]
eventName := "evtsender" + args[0]

logger.Infof("########### invoke - num_events:%s\n", num_events)
logger.Infof("########### invoke - numEvents:%s\n", numEvents)
logger.Infof("########### invoke - tosend:%s\n", tosend)
logger.Infof("########### invoke - eventName:%s\n", eventName)

err = stub.PutState("num_events", []byte(strconv.Itoa(num_events+1)))
err = stub.PutState("numEvents", []byte(strconv.Itoa(numEvents+1)))
if err != nil {
return shim.Error(err.Error())
}
Expand All @@ -96,7 +97,7 @@ func (t *EventSender) invoke(stub shim.ChaincodeStubInterface) pb.Response {
func (t *EventSender) clear(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### clear ###########")

err := stub.PutState("num_events", []byte("0"))
err := stub.PutState("numEvents", []byte("0"))
if err != nil {
return shim.Error(err.Error())
}
Expand All @@ -107,9 +108,9 @@ func (t *EventSender) clear(stub shim.ChaincodeStubInterface) pb.Response {
func (t *EventSender) query(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### query ###########")

b, err := stub.GetState("num_events")
num_events, _ := strconv.Atoi(string(b))
logger.Infof("########### query - num_events:%s\n", num_events)
b, err := stub.GetState("numEvents")
numEvents, _ := strconv.Atoi(string(b))
logger.Infof("########### query - numEvents:%s\n", numEvents)

if err != nil {
return shim.Error("Failed to get state")
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/src/github.com/example_cc/example_cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var logger = shim.NewLogger("example_cc0")
type SimpleChaincode struct {
}

// Init - initialize the state
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### example_cc0 Init ###########")

Expand Down Expand Up @@ -70,12 +71,12 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}

// Transaction makes payment of X units from A to B
// Invoke - Transaction makes payment of X units from A to B
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### example_cc0 Invoke ###########")

function, args := stub.GetFunctionAndParameters()

if function == "delete" {
// Deletes an entity from its state
return t.delete(stub, args)
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/src/github.com/example_cc1/example_cc1.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var logger = shim.NewLogger("example_cc1")
type SimpleChaincode struct {
}

//Init - instantiation of the state
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {

logger.Info("########### example_cc1 Init ###########")
Expand All @@ -39,7 +40,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return t.testTransient(stub)
}

// Transaction makes payment of X units from A to B
// Invoke - Transaction makes payment of X units from A to B
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### example_cc1 Invoke ###########")

Expand Down Expand Up @@ -109,7 +110,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
return shim.Error("Invalid transaction amount, expecting a integer value")
}
Aval = Aval - X
Bval = Bval + X + 10 //new version chaincode gives a bonus
Bval = Bval + X + 10 //new version chaincode gives a bonus
logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval)

// Write the state back to the ledger
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/src/github.com/example_cc2/example_cc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var logger = shim.NewLogger("example_cc2")
type SimpleChaincode struct {
}

// Re-initialize one of the parties' asset holdings
// Init - Re-initialize one of the parties' asset holdings
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {

logger.Info("########### example_cc2 Init ###########")
Expand All @@ -58,7 +58,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}

// Transaction makes payment of X units from A to B
// Invoke - Transaction makes payment of X units from A to B
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
logger.Info("########### example_cc1 Invoke ###########")

Expand Down

0 comments on commit 66d5e96

Please sign in to comment.