Skip to content

Commit d559469

Browse files
refactor(fabric): add discovery client
This commit moves the discovery client imported from fabric into a local package, including tests. Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
1 parent cec8902 commit d559469

File tree

16 files changed

+1784
-7
lines changed

16 files changed

+1784
-7
lines changed

platform/fabric/core/generic/chaincode/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515

1616
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1717
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/cache"
18+
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/discovery"
1819
peer2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/services"
1920
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver"
2021
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
2122
discovery2 "github.com/hyperledger/fabric-protos-go-apiv2/discovery"
2223
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
23-
discovery "github.com/hyperledger/fabric/discovery/client"
2424
)
2525

2626
const (
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)