Skip to content

Commit b9d7c0e

Browse files
committed
Fix cyclo and misspell linters
Signed-off-by: Antoine Chabert <antoine.chabert@tohero.fr>
1 parent 8782598 commit b9d7c0e

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

.gometalinter.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"unconvert",
1515
"varcheck",
1616
"vet",
17-
"vetshadow"
17+
"vetshadow",
18+
"misspell",
19+
"gocyclo"
1820
]
1921
}

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test:
5454

5555
lint:
5656
@echo "Lint..."
57-
@gometalinter --vendor --deadline=8m --exclude=app/vendor --exclude=chaincode/vendor ./...
57+
@gometalinter --vendor --deadline=8m --exclude=app/vendor --exclude=chaincode/vendor --cyclo-over=15 ./...
5858
@echo "Lint done"
5959

6060
##### CLEAN

app/fabric/setup.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (s *Setup) Initialize() error {
8080

8181
// Install reads the configuration stored in the Setup struct and sets up the blockchain channel and chaincode
8282
func (s *Setup) Install() error {
83-
fmt.Printf("Preparing contextes to create channel...\n")
83+
fmt.Printf("Preparing contexts to create channel...\n")
8484

8585
//clientContext allows creation of transactions using the supplied identity as the credential.
8686
clientContext := s.sdk.Context(fabsdk.WithUser(s.OrgAdminUser), fabsdk.WithOrg(s.OrdererOrgID))
@@ -98,7 +98,7 @@ func (s *Setup) Install() error {
9898
return fmt.Errorf("unable to create the channel: %v", err)
9999
}
100100

101-
fmt.Printf("Preparing contextes to make peers joinning the new channel...\n")
101+
fmt.Printf("Preparing contexts to make peers joinning the new channel...\n")
102102

103103
// Prepare context
104104
adminContext := s.sdk.Context(fabsdk.WithUser(s.OrgAdminUser), fabsdk.WithOrg(s.OrgID))

chaincode/query.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,9 @@ func (t *ResourceManagerChaincode) resources(stub shim.ChaincodeStubInterface, a
147147
if err != nil {
148148
return shim.Error(fmt.Sprintf("Unable to convert a resource: %v", err))
149149
}
150-
// If the request owner is a consumer, we give only available resources or its previously acquired
151-
if model.ActorConsumer == actorType && !resource.Available && resource.Consumer != actorID {
152-
continue
150+
if isResourceCanBeReturned(actorID, actorType, filter, &resource) {
151+
resources = append(resources, resource)
153152
}
154-
if filter == model.ResourcesFilterOnlyAvailable && !resource.Available {
155-
continue
156-
}
157-
if filter == model.ResourcesFilterOnlyUnavailable && resource.Available {
158-
continue
159-
}
160-
resources = append(resources, resource)
161153
}
162154

163155
resourcesAsByte, err := objectToByte(resources)
@@ -168,6 +160,21 @@ func (t *ResourceManagerChaincode) resources(stub shim.ChaincodeStubInterface, a
168160
return shim.Success(resourcesAsByte)
169161
}
170162

163+
// isResourceCanBeReturned check if the resource can be return to the given actor and filter given.
164+
func isResourceCanBeReturned(actorID string, actorType string, filter string, resource *model.Resource) bool {
165+
// If the request owner is a consumer, we give only available resources or its previously acquired
166+
if model.ActorConsumer == actorType && !resource.Available && resource.Consumer != actorID {
167+
return false
168+
}
169+
if filter == model.ResourcesFilterOnlyAvailable && !resource.Available {
170+
return false
171+
}
172+
if filter == model.ResourcesFilterOnlyUnavailable && resource.Available {
173+
return false
174+
}
175+
return true
176+
}
177+
171178
func (t *ResourceManagerChaincode) resourcesDeleted(stub shim.ChaincodeStubInterface, args []string) pb.Response {
172179

173180
fmt.Println("# resources deleted list")

0 commit comments

Comments
 (0)