@@ -6,10 +6,21 @@ SPDX-License-Identifier: Apache-2.0
6
6
7
7
package ledger
8
8
9
+ import "github.com/hyperledger/fabric/common/ledger"
10
+
11
+ //go:generate counterfeiter -o mock/ledger_reader.go -fake-name LedgerReader . LedgerReader
12
+
9
13
// LedgerReader interface, used to read from a ledger.
10
14
type LedgerReader interface {
11
15
// GetState gets the value for given namespace and key. For a chaincode, the namespace corresponds to the chaincodeId
12
16
GetState (namespace string , key string ) ([]byte , error )
17
+
18
+ // GetStateRangeScanIterator returns an iterator that contains all the Key-values between given Key ranges.
19
+ // startKey is included in the results and endKey is excluded. An empty startKey refers to the first available Key
20
+ // and an empty endKey refers to the last available Key. For scanning all the keys, both the startKey and the endKey
21
+ // can be supplied as empty strings. However, a full scan should be used judiciously for performance reasons.
22
+ // The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
23
+ GetStateRangeScanIterator (namespace string , startKey string , endKey string ) (ledger.ResultsIterator , error )
13
24
}
14
25
15
26
//go:generate counterfeiter -o mock/ledger_writer.go -fake-name LedgerWriter . LedgerWriter
@@ -20,3 +31,14 @@ type LedgerWriter interface {
20
31
// SetState sets the given value for the given namespace and key. For a chaincode, the namespace corresponds to the chaincodeId
21
32
SetState (namespace string , key string , value []byte ) error
22
33
}
34
+
35
+ //go:generate counterfeiter -o mock/results_iterator.go -fake-name ResultsIterator . ResultsIterator
36
+
37
+ // ResultsIterator - an iterator for query result set
38
+ type ResultsIterator interface {
39
+ // Next returns the next item in the result set. The `QueryResult` is expected to be nil when
40
+ // the iterator gets exhausted
41
+ Next () (ledger.QueryResult , error )
42
+ // Close releases resources occupied by the iterator
43
+ Close ()
44
+ }
0 commit comments