@@ -147,17 +147,9 @@ func (t *ResourceManagerChaincode) resources(stub shim.ChaincodeStubInterface, a
147
147
if err != nil {
148
148
return shim .Error (fmt .Sprintf ("Unable to convert a resource: %v" , err ))
149
149
}
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 )
153
152
}
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 )
161
153
}
162
154
163
155
resourcesAsByte , err := objectToByte (resources )
@@ -168,6 +160,21 @@ func (t *ResourceManagerChaincode) resources(stub shim.ChaincodeStubInterface, a
168
160
return shim .Success (resourcesAsByte )
169
161
}
170
162
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
+
171
178
func (t * ResourceManagerChaincode ) resourcesDeleted (stub shim.ChaincodeStubInterface , args []string ) pb.Response {
172
179
173
180
fmt .Println ("# resources deleted list" )
0 commit comments