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