Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions shim/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ type ChaincodeStubInterface interface {
GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string,
pageSize int32, bookmark string) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error)

// GetAllStatesCompositeKeyWithPagination returns a range iterator over all set of
// keys with composite keys in the ledger.
// The bookmark works the same way as when GetStateByPartialCompositeKeyWithPagination is called.
// This call is only supported in a read only transaction.
GetAllStatesCompositeKeyWithPagination(pageSize int32,
bookmark string) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error)

// CreateCompositeKey combines the given `attributes` to form a composite
// key. The objectType and attributes are expected to have only valid utf8
// strings and should not contain U+0000 (nil byte) and U+10FFFF
Expand Down
13 changes: 13 additions & 0 deletions shim/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,19 @@ func (s *ChaincodeStub) GetQueryResultWithPagination(query string, pageSize int3
return s.handleGetQueryResult(collection, query, metadata)
}

// GetAllStatesCompositeKeyWithPagination ...
func (s *ChaincodeStub) GetAllStatesCompositeKeyWithPagination(pageSize int32,
bookmark string) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) {
collection := ""
metadata, err := createQueryMetadata(pageSize, bookmark)
if err != nil {
return nil, nil, err
}
startKey := compositeKeyNamespace
endKey := compositeKeyNamespace + string(maxUnicodeRuneValue)
return s.handleGetStateByRange(collection, startKey, endKey, metadata)
}

// --------- Batch State functions ----------

// StartWriteBatch documentation can be found in interfaces.go
Expand Down
10 changes: 10 additions & 0 deletions shim/stub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,16 @@ func TestChaincodeStubHandlers(t *testing.T) {
assert.Equal(t, "book", qrm.GetBookmark())
assert.Equal(t, int32(1), qrm.GetFetchedRecordsCount())

sqi, qrm, err = s.GetAllStatesCompositeKeyWithPagination(1, "book")
assert.NoError(t, err)
kv, err = sqi.Next()
if err != nil {
t.Fatalf("Unexpected error for GetAllStatesCompositeKeyWithPagination: %s", err)
}
requireProtoEqual(t, expectedResult, kv)
assert.Equal(t, "book", qrm.GetBookmark())
assert.Equal(t, int32(1), qrm.GetFetchedRecordsCount())

sqi, qrm, err = s.GetQueryResultWithPagination("query", 1, "book")
assert.NoError(t, err)
kv, err = sqi.Next()
Expand Down
Loading