Skip to content

Commit 37050be

Browse files
KElkhiyaouiadecaro
authored andcommitted
[FAB-11359] tms transactor: list tokens
- add GetStateRangeScanIterator() to the LedgerReader interface - implement tms ListTokens - add proto messages for unspent tokens - test Change-Id: I2b597974a17d47a73da3347480af1fdbc9dfe219 Signed-off-by: Kaoutar Elkhiyaoui <kao@zurich.ibm.com>
1 parent 7173857 commit 37050be

File tree

8 files changed

+691
-16
lines changed

8 files changed

+691
-16
lines changed

token/ledger/ledger.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@ SPDX-License-Identifier: Apache-2.0
66

77
package ledger
88

9+
import "github.com/hyperledger/fabric/common/ledger"
10+
11+
//go:generate counterfeiter -o mock/ledger_reader.go -fake-name LedgerReader . LedgerReader
12+
913
// LedgerReader interface, used to read from a ledger.
1014
type LedgerReader interface {
1115
// GetState gets the value for given namespace and key. For a chaincode, the namespace corresponds to the chaincodeId
1216
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)
1324
}
1425

1526
//go:generate counterfeiter -o mock/ledger_writer.go -fake-name LedgerWriter . LedgerWriter
@@ -20,3 +31,14 @@ type LedgerWriter interface {
2031
// SetState sets the given value for the given namespace and key. For a chaincode, the namespace corresponds to the chaincodeId
2132
SetState(namespace string, key string, value []byte) error
2233
}
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+
}

token/ledger/mock/ledger_reader.go

Lines changed: 176 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/ledger/mock/ledger_writer.go

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)