github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/discovery/client/api.go (about) 1 /* 2 Copyright hechain. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package discovery 8 9 import ( 10 "github.com/hechain20/hechain/gossip/protoext" 11 "github.com/hyperledger/fabric-protos-go/discovery" 12 "github.com/hyperledger/fabric-protos-go/peer" 13 "github.com/pkg/errors" 14 "google.golang.org/grpc" 15 ) 16 17 // ErrNotFound defines an error that means that an element wasn't found 18 var ErrNotFound = errors.New("not found") 19 20 // Signer signs a message and returns the signature and nil, 21 // or nil and error on failure 22 type Signer func(msg []byte) ([]byte, error) 23 24 // Dialer connects to the server 25 type Dialer func() (*grpc.ClientConn, error) 26 27 // Response aggregates several responses from the discovery service 28 type Response interface { 29 // ForChannel returns a ChannelResponse in the context of a given channel 30 ForChannel(string) ChannelResponse 31 32 // ForLocal returns a LocalResponse in the context of no channel 33 ForLocal() LocalResponse 34 } 35 36 // ChannelResponse aggregates responses for a given channel 37 type ChannelResponse interface { 38 // Config returns a response for a config query, or error if something went wrong 39 Config() (*discovery.ConfigResult, error) 40 41 // Peers returns a response for a peer membership query, or error if something went wrong 42 Peers(invocationChain ...*peer.ChaincodeCall) ([]*Peer, error) 43 44 // Endorsers returns the response for an endorser query for a given 45 // chaincode in a given channel context, or error if something went wrong. 46 // The method returns a random set of endorsers, such that signatures from all of them 47 // combined, satisfy the endorsement policy. 48 // The selection is based on the given selection hints: 49 // Filter: Filters and sorts the endorsers 50 // The given InvocationChain specifies the chaincode calls (along with collections) 51 // that the client passed during the construction of the request 52 Endorsers(invocationChain InvocationChain, f Filter) (Endorsers, error) 53 } 54 55 // LocalResponse aggregates responses for a channel-less scope 56 type LocalResponse interface { 57 // Peers returns a response for a local peer membership query, or error if something went wrong 58 Peers() ([]*Peer, error) 59 } 60 61 // Endorsers defines a set of peers that are sufficient 62 // for satisfying some chaincode's endorsement policy 63 type Endorsers []*Peer 64 65 // Peer aggregates identity, membership and channel-scoped information 66 // of a certain peer. 67 type Peer struct { 68 MSPID string 69 AliveMessage *protoext.SignedGossipMessage 70 StateInfoMessage *protoext.SignedGossipMessage 71 Identity []byte 72 }