-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FABG-886] wrap internal discovery.Request
Purpose of this commit is to expose internal Request and make Service Discovery client usable outside of sdk. - Wrapped internal Request - Proxied all the methods of internal Request - Added helper methods CcCalls CcInterests for building the Request obj - Fixed signatures of the Service Discovery client methods with wrapped Request - Fixed tests Signed-off-by: kopaygorodsky <[email protected]> Change-Id: Id70bd1db0d4ddb6d3d567375602e11f4762b9f6c
- Loading branch information
1 parent
1ad9245
commit 8e3a900
Showing
9 changed files
with
94 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package discovery | ||
|
||
import ( | ||
discclient "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/discovery/client" | ||
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/discovery" | ||
) | ||
|
||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters