Skip to content

Commit

Permalink
Address linter issues in integration/chaincode
Browse files Browse the repository at this point in the history
- handle errors
- remove dead code

Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm authored and Brett Logan committed May 23, 2020
1 parent 9606553 commit b969b28
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
22 changes: 16 additions & 6 deletions integration/chaincode/keylevelep/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ func delOrgs(stub shim.ChaincodeStubInterface) pb.Response {
// get the endorsement policy for the key
var epBytes []byte
var err error
if parameters[0] == "pub" {
switch parameters[0] {
case "pub":
epBytes, err = stub.GetStateValidationParameter("pub")
} else if parameters[0] == "priv" {
case "priv":
epBytes, err = stub.GetPrivateDataValidationParameter("col", "priv")
} else {
default:
return shim.Error("Unknown key specified")
}
if err != nil {
return shim.Error(err.Error())
}

ep, err := statebased.NewStateEP(epBytes)
if err != nil {
return shim.Error(err.Error())
Expand Down Expand Up @@ -163,13 +168,18 @@ func listOrgs(stub shim.ChaincodeStubInterface) pb.Response {
// get the endorsement policy for the key
var epBytes []byte
var err error
if parameters[0] == "pub" {
switch parameters[0] {
case "pub":
epBytes, err = stub.GetStateValidationParameter("pub")
} else if parameters[0] == "priv" {
case "priv":
epBytes, err = stub.GetPrivateDataValidationParameter("col", "priv")
} else {
default:
return shim.Error("Unknown key specified")
}
if err != nil {
return shim.Error(err.Error())
}

ep, err := statebased.NewStateEP(epBytes)
if err != nil {
return shim.Error(err.Error())
Expand Down
19 changes: 6 additions & 13 deletions integration/chaincode/marbles/marbles_chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ type marble struct {
Owner string `json:"owner"`
}

// ===================================================================================
// Main
// ===================================================================================
func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting Simple chaincode: %s", err)
}
}

// Init initializes chaincode
// ===========================
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
Expand Down Expand Up @@ -228,7 +218,10 @@ func (t *SimpleChaincode) initMarble(stub shim.ChaincodeStubInterface, args []st
// Save index entry to state. Only the key name is needed, no need to store a duplicate copy of the marble.
// Note - passing a 'nil' value will effectively delete the key from state, therefore we pass null character as value
value := []byte{0x00}
stub.PutState(colorNameIndexKey, value)
err = stub.PutState(colorNameIndexKey, value)
if err != nil {
return shim.Error(err.Error())
}

// ==== Marble saved and indexed. Return success ====
fmt.Println("- end init marble")
Expand Down Expand Up @@ -361,7 +354,7 @@ func constructQueryResponseFromIterator(resultsIterator shim.StateQueryIteratorI
return nil, err
}
// Add a comma before array members, suppress it for the first array member
if bArrayMemberAlreadyWritten == true {
if bArrayMemberAlreadyWritten {
buffer.WriteString(",")
}
buffer.WriteString("{\"Key\":")
Expand Down Expand Up @@ -717,7 +710,7 @@ func (t *SimpleChaincode) getHistoryForMarble(stub shim.ChaincodeStubInterface,
return shim.Error(err.Error())
}
// Add a comma before array members, suppress it for the first array member
if bArrayMemberAlreadyWritten == true {
if bArrayMemberAlreadyWritten {
buffer.WriteString(",")
}
buffer.WriteString("{\"TxId\":")
Expand Down
5 changes: 4 additions & 1 deletion integration/chaincode/marbles_private/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ func (t *MarblesPrivateChaincode) initMarble(stub shim.ChaincodeStubInterface, a
// Save index entry to state. Only the key name is needed, no need to store a duplicate copy of the marble.
// Note - passing a 'nil' value will effectively delete the key from state, therefore we pass null character as value
value := []byte{0x00}
stub.PutPrivateData("collectionMarbles", colorNameIndexKey, value)
err = stub.PutPrivateData("collectionMarbles", colorNameIndexKey, value)
if err != nil {
return shim.Error(err.Error())
}

// ==== Marble saved and indexed. Return success ====
fmt.Println("- end init marble")
Expand Down

0 comments on commit b969b28

Please sign in to comment.