@@ -14,15 +14,19 @@ import (
14
14
"time"
15
15
16
16
"github.com/golang/protobuf/proto"
17
+ "github.com/hyperledger/fabric/discovery/protoext"
17
18
"github.com/hyperledger/fabric/protos/discovery"
18
19
"github.com/hyperledger/fabric/protos/gossip"
19
20
"github.com/hyperledger/fabric/protos/msp"
20
21
"github.com/pkg/errors"
21
22
)
22
23
23
- var (
24
- configTypes = []discovery.QueryType {discovery .ConfigQueryType , discovery .PeerMembershipQueryType , discovery .ChaincodeQueryType , discovery .LocalMembershipQueryType }
25
- )
24
+ var configTypes = []protoext.QueryType {
25
+ protoext .ConfigQueryType ,
26
+ protoext .PeerMembershipQueryType ,
27
+ protoext .ChaincodeQueryType ,
28
+ protoext .LocalMembershipQueryType ,
29
+ }
26
30
27
31
// Client interacts with the discovery server
28
32
type Client struct {
@@ -34,7 +38,7 @@ type Client struct {
34
38
func NewRequest () * Request {
35
39
r := & Request {
36
40
invocationChainMapping : make (map [int ][]InvocationChain ),
37
- queryMapping : make (map [discovery .QueryType ]map [string ]int ),
41
+ queryMapping : make (map [protoext .QueryType ]map [string ]int ),
38
42
Request : & discovery.Request {},
39
43
}
40
44
// pre-populate types
@@ -49,7 +53,7 @@ type Request struct {
49
53
lastChannel string
50
54
lastIndex int
51
55
// map from query type to channel to expected index in response
52
- queryMapping map [discovery .QueryType ]map [string ]int
56
+ queryMapping map [protoext .QueryType ]map [string ]int
53
57
// map from expected index in response to invocation chains
54
58
invocationChainMapping map [int ][]InvocationChain
55
59
* discovery.Request
@@ -65,7 +69,7 @@ func (req *Request) AddConfigQuery() *Request {
65
69
Channel : ch ,
66
70
Query : q ,
67
71
})
68
- req .addQueryMapping (discovery .ConfigQueryType , ch )
72
+ req .addQueryMapping (protoext .ConfigQueryType , ch )
69
73
return req
70
74
}
71
75
@@ -91,7 +95,7 @@ func (req *Request) AddEndorsersQuery(interests ...*discovery.ChaincodeInterest)
91
95
invocationChains = append (invocationChains , interest .Chaincodes )
92
96
}
93
97
req .addChaincodeQueryMapping (invocationChains )
94
- req .addQueryMapping (discovery .ChaincodeQueryType , ch )
98
+ req .addQueryMapping (protoext .ChaincodeQueryType , ch )
95
99
return req , nil
96
100
}
97
101
@@ -104,7 +108,7 @@ func (req *Request) AddLocalPeersQuery() *Request {
104
108
Query : q ,
105
109
})
106
110
var ic InvocationChain
107
- req .addQueryMapping (discovery .LocalMembershipQueryType , channnelAndInvocationChain ("" , ic ))
111
+ req .addQueryMapping (protoext .LocalMembershipQueryType , channnelAndInvocationChain ("" , ic ))
108
112
return req
109
113
}
110
114
@@ -127,7 +131,7 @@ func (req *Request) AddPeersQuery(invocationChain ...*discovery.ChaincodeCall) *
127
131
ic = InvocationChain (invocationChain )
128
132
}
129
133
req .addChaincodeQueryMapping ([]InvocationChain {ic })
130
- req .addQueryMapping (discovery .PeerMembershipQueryType , channnelAndInvocationChain (ch , ic ))
134
+ req .addQueryMapping (protoext .PeerMembershipQueryType , channnelAndInvocationChain (ch , ic ))
131
135
return req
132
136
}
133
137
@@ -145,7 +149,7 @@ func (req *Request) addChaincodeQueryMapping(invocationChains []InvocationChain)
145
149
req .invocationChainMapping [req .lastIndex ] = invocationChains
146
150
}
147
151
148
- func (req * Request ) addQueryMapping (queryType discovery .QueryType , key string ) {
152
+ func (req * Request ) addQueryMapping (queryType protoext .QueryType , key string ) {
149
153
req.queryMapping [queryType ][key ] = req .lastIndex
150
154
req .lastIndex ++
151
155
}
@@ -193,7 +197,7 @@ type localResponse struct {
193
197
}
194
198
195
199
func (cr * localResponse ) Peers () ([]* Peer , error ) {
196
- return parsePeers (discovery .LocalMembershipQueryType , cr .response , "" )
200
+ return parsePeers (protoext .LocalMembershipQueryType , cr .response , "" )
197
201
}
198
202
199
203
type channelResponse struct {
@@ -203,7 +207,7 @@ type channelResponse struct {
203
207
204
208
func (cr * channelResponse ) Config () (* discovery.ConfigResult , error ) {
205
209
res , exists := cr .response [key {
206
- queryType : discovery .ConfigQueryType ,
210
+ queryType : protoext .ConfigQueryType ,
207
211
k : cr .channel ,
208
212
}]
209
213
@@ -218,7 +222,7 @@ func (cr *channelResponse) Config() (*discovery.ConfigResult, error) {
218
222
return nil , res .(error )
219
223
}
220
224
221
- func parsePeers (queryType discovery .QueryType , r response , channel string , invocationChain ... * discovery.ChaincodeCall ) ([]* Peer , error ) {
225
+ func parsePeers (queryType protoext .QueryType , r response , channel string , invocationChain ... * discovery.ChaincodeCall ) ([]* Peer , error ) {
222
226
peerKeys := key {
223
227
queryType : queryType ,
224
228
k : fmt .Sprintf ("%s %s" , channel , InvocationChain (invocationChain ).String ()),
@@ -237,22 +241,22 @@ func parsePeers(queryType discovery.QueryType, r response, channel string, invoc
237
241
}
238
242
239
243
func (cr * channelResponse ) Peers (invocationChain ... * discovery.ChaincodeCall ) ([]* Peer , error ) {
240
- return parsePeers (discovery .PeerMembershipQueryType , cr .response , cr .channel , invocationChain ... )
244
+ return parsePeers (protoext .PeerMembershipQueryType , cr .response , cr .channel , invocationChain ... )
241
245
}
242
246
243
247
func (cr * channelResponse ) Endorsers (invocationChain InvocationChain , f Filter ) (Endorsers , error ) {
244
248
// If we have a key that has no chaincode field,
245
249
// it means it's an error returned from the service
246
250
if err , exists := cr .response [key {
247
- queryType : discovery .ChaincodeQueryType ,
251
+ queryType : protoext .ChaincodeQueryType ,
248
252
k : cr .channel ,
249
253
}]; exists {
250
254
return nil , err .(error )
251
255
}
252
256
253
257
// Else, the service returned a response that isn't an error
254
258
res , exists := cr .response [key {
255
- queryType : discovery .ChaincodeQueryType ,
259
+ queryType : protoext .ChaincodeQueryType ,
256
260
k : cr .channel ,
257
261
invocationChain : invocationChain .String (),
258
262
}]
@@ -328,7 +332,7 @@ func (resp response) ForChannel(ch string) ChannelResponse {
328
332
}
329
333
330
334
type key struct {
331
- queryType discovery .QueryType
335
+ queryType protoext .QueryType
332
336
k string
333
337
invocationChain string
334
338
}
@@ -338,14 +342,14 @@ func (req *Request) computeResponse(r *discovery.Response) (response, error) {
338
342
resp := make (response )
339
343
for configType , channel2index := range req .queryMapping {
340
344
switch configType {
341
- case discovery .ConfigQueryType :
345
+ case protoext .ConfigQueryType :
342
346
err = resp .mapConfig (channel2index , r )
343
- case discovery .ChaincodeQueryType :
347
+ case protoext .ChaincodeQueryType :
344
348
err = resp .mapEndorsers (channel2index , r , req .invocationChainMapping )
345
- case discovery .PeerMembershipQueryType :
346
- err = resp .mapPeerMembership (channel2index , r , discovery .PeerMembershipQueryType )
347
- case discovery .LocalMembershipQueryType :
348
- err = resp .mapPeerMembership (channel2index , r , discovery .LocalMembershipQueryType )
349
+ case protoext .PeerMembershipQueryType :
350
+ err = resp .mapPeerMembership (channel2index , r , protoext .PeerMembershipQueryType )
351
+ case protoext .LocalMembershipQueryType :
352
+ err = resp .mapPeerMembership (channel2index , r , protoext .LocalMembershipQueryType )
349
353
}
350
354
if err != nil {
351
355
return nil , err
@@ -357,12 +361,12 @@ func (req *Request) computeResponse(r *discovery.Response) (response, error) {
357
361
358
362
func (resp response ) mapConfig (channel2index map [string ]int , r * discovery.Response ) error {
359
363
for ch , index := range channel2index {
360
- config , err := r . ConfigAt ( index )
364
+ config , err := protoext . ResponseConfigAt ( r , index )
361
365
if config == nil && err == nil {
362
366
return errors .Errorf ("expected QueryResult of either ConfigResult or Error but got %v instead" , r .Results [index ])
363
367
}
364
368
key := key {
365
- queryType : discovery .ConfigQueryType ,
369
+ queryType : protoext .ConfigQueryType ,
366
370
k : ch ,
367
371
}
368
372
@@ -376,9 +380,9 @@ func (resp response) mapConfig(channel2index map[string]int, r *discovery.Respon
376
380
return nil
377
381
}
378
382
379
- func (resp response ) mapPeerMembership (key2Index map [string ]int , r * discovery.Response , qt discovery .QueryType ) error {
383
+ func (resp response ) mapPeerMembership (key2Index map [string ]int , r * discovery.Response , qt protoext .QueryType ) error {
380
384
for k , index := range key2Index {
381
- membersRes , err := r . MembershipAt ( index )
385
+ membersRes , err := protoext . ResponseMembershipAt ( r , index )
382
386
if membersRes == nil && err == nil {
383
387
return errors .Errorf ("expected QueryResult of either PeerMembershipResult or Error but got %v instead" , r .Results [index ])
384
388
}
@@ -403,7 +407,7 @@ func (resp response) mapPeerMembership(key2Index map[string]int, r *discovery.Re
403
407
return nil
404
408
}
405
409
406
- func peersForChannel (membersRes * discovery.PeerMembershipResult , qt discovery .QueryType ) ([]* Peer , error ) {
410
+ func peersForChannel (membersRes * discovery.PeerMembershipResult , qt protoext .QueryType ) ([]* Peer , error ) {
407
411
var peers []* Peer
408
412
for org , peersOfCurrentOrg := range membersRes .PeersByOrg {
409
413
for _ , peer := range peersOfCurrentOrg .Peers {
@@ -435,23 +439,23 @@ func peersForChannel(membersRes *discovery.PeerMembershipResult, qt discovery.Qu
435
439
return peers , nil
436
440
}
437
441
438
- func isStateInfoExpected (qt discovery .QueryType ) bool {
439
- return qt != discovery .LocalMembershipQueryType
442
+ func isStateInfoExpected (qt protoext .QueryType ) bool {
443
+ return qt != protoext .LocalMembershipQueryType
440
444
}
441
445
442
446
func (resp response ) mapEndorsers (
443
447
channel2index map [string ]int ,
444
448
r * discovery.Response ,
445
449
chaincodeQueryMapping map [int ][]InvocationChain ) error {
446
450
for ch , index := range channel2index {
447
- ccQueryRes , err := r . EndorsersAt ( index )
451
+ ccQueryRes , err := protoext . ResponseEndorsersAt ( r , index )
448
452
if ccQueryRes == nil && err == nil {
449
453
return errors .Errorf ("expected QueryResult of either ChaincodeQueryResult or Error but got %v instead" , r .Results [index ])
450
454
}
451
455
452
456
if err != nil {
453
457
key := key {
454
- queryType : discovery .ChaincodeQueryType ,
458
+ queryType : protoext .ChaincodeQueryType ,
455
459
k : ch ,
456
460
}
457
461
resp [key ] = errors .New (err .Content )
@@ -475,7 +479,7 @@ func (resp response) mapEndorsersOfChannel(ccRs *discovery.ChaincodeQueryResult,
475
479
return errors .Errorf ("expected chaincode %s but got endorsement descriptor for %s" , expectedCCName , desc .Chaincode )
476
480
}
477
481
key := key {
478
- queryType : discovery .ChaincodeQueryType ,
482
+ queryType : protoext .ChaincodeQueryType ,
479
483
k : channel ,
480
484
invocationChain : invocationChain [i ].String (),
481
485
}
0 commit comments