forked from bryanicer/fabric-sdk-go-gm
/
request.go
80 lines (64 loc) · 2.29 KB
/
request.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
69
70
71
72
73
74
75
76
77
78
79
80
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package discovery
import (
"github.com/hyperledger/fabric-protos-go/discovery"
discclient "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/discovery/client"
)
// Request aggregates several queries inside it
type Request struct {
r *discclient.Request
}
// NewRequest creates a new request
func NewRequest() *Request {
return &Request{discclient.NewRequest()}
}
// AddConfigQuery adds to the request a config query
func (req *Request) AddConfigQuery() *Request {
req.r.AddConfigQuery()
return req
}
// AddLocalPeersQuery adds to the request a local peer query
func (req *Request) AddLocalPeersQuery() *Request {
req.r.AddLocalPeersQuery()
return req
}
// OfChannel sets the next queries added to be in the given channel's context
func (req *Request) OfChannel(ch string) *Request {
req.r.OfChannel(ch)
return req
}
// AddEndorsersQuery adds to the request a query for given chaincodes
// interests are the chaincode interests that the client wants to query for.
// All interests for a given channel should be supplied in an aggregated slice
func (req *Request) AddEndorsersQuery(interests ...*discovery.ChaincodeInterest) (*Request, error) {
_, err := req.r.AddEndorsersQuery(interests...)
return req, err
}
// AddPeersQuery adds to the request a peer query
func (req *Request) AddPeersQuery(invocationChain ...*discovery.ChaincodeCall) *Request {
req.r.AddPeersQuery(invocationChain...)
return req
}
// CcCalls creates an array of ChaincodeCalls based of cc names, can be used in AddPeersQuery(CcCalls(...))
func CcCalls(ccNames ...string) []*discovery.ChaincodeCall {
var call []*discovery.ChaincodeCall
for _, ccName := range ccNames {
call = append(call, &discovery.ChaincodeCall{
Name: ccName,
})
}
return call
}
// CcInterests creates an array of ChaincodeInterests based of ChaincodeCalls, can be used in AddEndorsersQuery(CcInterests(CcCalls(...)))
func CcInterests(invocationsChains ...[]*discovery.ChaincodeCall) []*discovery.ChaincodeInterest {
var interests []*discovery.ChaincodeInterest
for _, invocationChain := range invocationsChains {
interests = append(interests, &discovery.ChaincodeInterest{
Chaincodes: invocationChain,
})
}
return interests
}