github.com/true-sqn/fabric@v2.1.1+incompatible/discovery/client/api.go (about)

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