@@ -11,6 +11,8 @@ Please review third_party pinning scripts and patches for more details.
1111package ledger
1212
1313import (
14+ "fmt"
15+
1416 "github.com/golang/protobuf/proto"
1517 commonledger "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/ledger"
1618 "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
@@ -23,6 +25,7 @@ import (
2325type Initializer struct {
2426 StateListeners []StateListener
2527 DeployedChaincodeInfoProvider DeployedChaincodeInfoProvider
28+ MembershipInfoProvider MembershipInfoProvider
2629}
2730
2831// PeerLedgerProvider provides handle to ledger instances
@@ -124,15 +127,30 @@ type QueryExecutor interface {
124127 GetStateMetadata (namespace , key string ) (map [string ][]byte , error )
125128 // GetStateMultipleKeys gets the values for multiple keys in a single call
126129 GetStateMultipleKeys (namespace string , keys []string ) ([][]byte , error )
130+ // GetStateRangeScanIteratorWithMetadata returns an iterator that contains all the key-values between given key ranges.
131+ // startKey is included in the results and endKey is excluded. An empty startKey refers to the first available key
132+ // and an empty endKey refers to the last available key. For scanning all the keys, both the startKey and the endKey
133+ // can be supplied as empty strings. However, a full scan should be used judiciously for performance reasons.
134+ // metadata is a map of additional query parameters
135+ // The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
136+ GetStateRangeScanIteratorWithMetadata (namespace string , startKey , endKey string , metadata map [string ]interface {}) (QueryResultsIterator , error )
127137 // ExecuteQuery executes the given query and returns an iterator that contains results of type specific to the underlying data store.
128138 // Only used for state databases that support query
129139 // For a chaincode, the namespace corresponds to the chaincodeId
130140 // The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
131141 ExecuteQuery (namespace , query string ) (commonledger.ResultsIterator , error )
142+ // ExecuteQueryWithMetadata executes the given query and returns an iterator that contains results of type specific to the underlying data store.
143+ // metadata is a map of additional query parameters
144+ // Only used for state databases that support query
145+ // For a chaincode, the namespace corresponds to the chaincodeId
146+ // The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
147+ ExecuteQueryWithMetadata (namespace , query string , metadata map [string ]interface {}) (QueryResultsIterator , error )
132148 // GetPrivateData gets the value of a private data item identified by a tuple <namespace, collection, key>
133149 GetPrivateData (namespace , collection , key string ) ([]byte , error )
134150 // GetPrivateDataMetadata gets the metadata of a private data item identified by a tuple <namespace, collection, key>
135151 GetPrivateDataMetadata (namespace , collection , key string ) (map [string ][]byte , error )
152+ // GetPrivateDataMetadataByHash gets the metadata of a private data item identified by a tuple <namespace, collection, keyhash>
153+ GetPrivateDataMetadataByHash (namespace , collection string , keyhash []byte ) (map [string ][]byte , error )
136154 // GetPrivateDataMultipleKeys gets the values for the multiple private data items in a single call
137155 GetPrivateDataMultipleKeys (namespace , collection string , keys []string ) ([][]byte , error )
138156 // GetPrivateDataRangeScanIterator returns an iterator that contains all the key-values between given key ranges.
@@ -196,6 +214,13 @@ type TxSimulator interface {
196214 GetTxSimulationResults () (* TxSimulationResults , error )
197215}
198216
217+ // QueryResultsIterator - an iterator for query result set
218+ type QueryResultsIterator interface {
219+ commonledger.ResultsIterator
220+ // GetBookmarkAndClose returns a paging bookmark and releases resources occupied by the iterator
221+ GetBookmarkAndClose () string
222+ }
223+
199224// TxPvtData encapsulates the transaction number and pvt write-set for a transaction
200225type TxPvtData struct {
201226 SeqInBlock uint64
@@ -207,18 +232,22 @@ type TxPvtData struct {
207232// to the ledger at the commit of the corresponding block
208233type MissingPrivateData struct {
209234 TxId string
210- SeqInBlock int
235+ SeqInBlock uint64
211236 Namespace string
212237 Collection string
213- Eligible bool
238+ IsEligible bool
239+ }
240+
241+ type MissingPrivateDataList struct {
242+ List []* MissingPrivateData
214243}
215244
216245// BlockAndPvtData encapsulates the block and a map that contains the tuples <seqInBlock, *TxPvtData>
217246// The map is expected to contain the entries only for the transactions that has associated pvt data
218247type BlockAndPvtData struct {
219248 Block * common.Block
220249 BlockPvtData map [uint64 ]* TxPvtData
221- Missing [] * MissingPrivateData
250+ Missing * MissingPrivateDataList
222251}
223252
224253// BlockPvtData contains the private data for a block
@@ -227,6 +256,10 @@ type BlockPvtData struct {
227256 WriteSets map [uint64 ]* TxPvtData
228257}
229258
259+ func (missing * MissingPrivateDataList ) Add (txId string , txNum uint64 , ns , coll string , isEligible bool ) {
260+ missing .List = append (missing .List , & MissingPrivateData {txId , txNum , ns , coll , isEligible })
261+ }
262+
230263// PvtCollFilter represents the set of the collection names (as keys of the map with value 'true')
231264type PvtCollFilter map [string ]bool
232265
@@ -348,7 +381,7 @@ type MissingBlockPvtdataInfo map[uint64][]*MissingCollectionPvtDataInfo
348381
349382// MissingCollectionPvtDataInfo includes the name of the chaincode and collection for which private data is missing
350383type MissingCollectionPvtDataInfo struct {
351- ChaincodeName , CollectionName string
384+ Namespace , Collection string
352385}
353386
354387// CollectionConfigInfo encapsulates a collection config for a chaincode and its committing block number
@@ -357,6 +390,23 @@ type CollectionConfigInfo struct {
357390 CommittingBlockNum uint64
358391}
359392
393+ func (missingPvtDataInfo MissingPvtDataInfo ) Add (blkNum , txNum uint64 , ns , coll string ) {
394+ missingBlockPvtDataInfo , ok := missingPvtDataInfo [blkNum ]
395+ if ! ok {
396+ missingBlockPvtDataInfo = make (MissingBlockPvtdataInfo )
397+ missingPvtDataInfo [blkNum ] = missingBlockPvtDataInfo
398+ }
399+
400+ if _ , ok := missingBlockPvtDataInfo [txNum ]; ! ok {
401+ missingBlockPvtDataInfo [txNum ] = []* MissingCollectionPvtDataInfo {}
402+ }
403+
404+ missingBlockPvtDataInfo [txNum ] = append (missingBlockPvtDataInfo [txNum ],
405+ & MissingCollectionPvtDataInfo {
406+ Namespace : ns ,
407+ Collection : coll })
408+ }
409+
360410// ErrCollectionConfigNotYetAvailable is an error which is returned from the function
361411// ConfigHistoryRetriever.CollectionConfigAt() if the latest block number committed
362412// is lower than the block number specified in the request.
@@ -376,6 +426,26 @@ func (NotFoundInIndexErr) Error() string {
376426 return "Entry not found in index"
377427}
378428
429+ // CollConfigNotDefinedError is returned whenever an operation
430+ // is requested on a collection whose config has not been defined
431+ type CollConfigNotDefinedError struct {
432+ Ns string
433+ }
434+
435+ func (e * CollConfigNotDefinedError ) Error () string {
436+ return fmt .Sprintf ("collection config not defined for chaincode [%s], pass the collection configuration upon chaincode definition/instantiation" , e .Ns )
437+ }
438+
439+ // InvalidCollNameError is returned whenever an operation
440+ // is requested on a collection whose name is invalid
441+ type InvalidCollNameError struct {
442+ Ns , Coll string
443+ }
444+
445+ func (e * InvalidCollNameError ) Error () string {
446+ return fmt .Sprintf ("collection [%s] not defined in the collection config for chaincode [%s]" , e .Coll , e .Ns )
447+ }
448+
379449// PvtdataHashMismatch is used when the hash of private write-set
380450// does not match the corresponding hash present in the block
381451// See function `PeerLedger.CommitPvtData` for the usages
@@ -418,4 +488,11 @@ type ChaincodeLifecycleDetails struct {
418488 CollectionsRemoved []string // names of the collections that are removed
419489}
420490
491+ // MembershipInfoProvider is a dependency that is used by ledger to determine whether the current peer is
492+ // a member of a collection. Gossip module is expected to provide the dependency to ledger
493+ type MembershipInfoProvider interface {
494+ // AmMemberOf checks whether the current peer is a member of the given collection
495+ AmMemberOf (channelName string , collectionPolicyConfig * common.CollectionPolicyConfig ) (bool , error )
496+ }
497+
421498//go:generate counterfeiter -o mock/deployed_ccinfo_provider.go -fake-name DeployedChaincodeInfoProvider . DeployedChaincodeInfoProvider
0 commit comments