In the previous section, we mentioned that getStateByRange does not work with composite keys. How can we then implement a function that will return all objects of the same type?
getStateByPartialCompositeKey from ChaincodeStub perfectly fits the purpose.
This function returns an iterator, which can be used to iterate over all composite keys, whose prefix matches the given partial composite key.
Let getByType(objType) be a new operation, which returns all states of a specified type. Then, an implementation of this operation in SimpleContract will look the following way:
As you can see, the above method looks similar to getByRange. It also uses the same type of iterator object, though this iterator object is obtained from a different method, getStateByPartialCompositeKey. Furthermore, since getByType works with composite keys, we should parse the response accordingly.