-
Notifications
You must be signed in to change notification settings - Fork 1
/
extensions.go
68 lines (58 loc) · 1.68 KB
/
extensions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package discovery
import (
"github.com/golang/protobuf/proto"
)
// QueryType defines the types of service discovery requests
type QueryType uint8
const (
InvalidQueryType QueryType = iota
ConfigQueryType
PeerMembershipQueryType
ChaincodeQueryType
LocalMembershipQueryType
)
// GetType returns the type of the request
func (q *Query) GetType() QueryType {
if q.GetCcQuery() != nil {
return ChaincodeQueryType
}
if q.GetConfigQuery() != nil {
return ConfigQueryType
}
if q.GetPeerQuery() != nil {
return PeerMembershipQueryType
}
if q.GetLocalPeers() != nil {
return LocalMembershipQueryType
}
return InvalidQueryType
}
// ToRequest deserializes this SignedRequest's payload
// and returns the serialized Request in its object form.
// Returns an error in case the operation fails.
func (sr *SignedRequest) ToRequest() (*Request, error) {
req := &Request{}
return req, proto.Unmarshal(sr.Payload, req)
}
// ConfigAt returns the ConfigResult at a given index in the Response,
// or an Error if present.
func (m *Response) ConfigAt(i int) (*ConfigResult, *Error) {
r := m.Results[i]
return r.GetConfigResult(), r.GetError()
}
// MembershipAt returns the PeerMembershipResult at a given index in the Response,
// or an Error if present.
func (m *Response) MembershipAt(i int) (*PeerMembershipResult, *Error) {
r := m.Results[i]
return r.GetMembers(), r.GetError()
}
// EndorsersAt returns the PeerMembershipResult at a given index in the Response,
// or an Error if present.
func (m *Response) EndorsersAt(i int) (*ChaincodeQueryResult, *Error) {
r := m.Results[i]
return r.GetCcQueryRes(), r.GetError()
}