forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
executable file
·68 lines (56 loc) · 2.2 KB
/
opts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package eventhubclient
import (
"time"
"github.com/hyperledger/fabric-sdk-go/pkg/common/options"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)
var blockInterests = []*pb.Interest{&pb.Interest{EventType: pb.EventType_BLOCK}}
var filteredBlockInterests = []*pb.Interest{&pb.Interest{EventType: pb.EventType_FILTEREDBLOCK}}
type params struct {
connProvider api.ConnectionProvider
interests []*pb.Interest
permitBlockEvents bool
respTimeout time.Duration
}
func defaultParams() *params {
return ¶ms{
connProvider: ehConnProvider,
interests: blockInterests,
respTimeout: 5 * time.Second,
permitBlockEvents: true,
}
}
// WithBlockEvents indicates that block events are to be received.
func WithBlockEvents() options.Opt {
return func(p options.Params) {
if setter, ok := p.(connectionProviderAndInterestsSetter); ok {
setter.SetConnectionProviderAndInterests(ehConnProvider, blockInterests, true)
}
}
}
// withConnectionProviderAndInterests is used only for testing
func withConnectionProviderAndInterests(connProvider api.ConnectionProvider, interests []*pb.Interest, permitBlockEvents bool) options.Opt {
return func(p options.Params) {
if setter, ok := p.(connectionProviderAndInterestsSetter); ok {
setter.SetConnectionProviderAndInterests(connProvider, interests, permitBlockEvents)
}
}
}
type connectionProviderAndInterestsSetter interface {
SetConnectionProviderAndInterests(connProvider api.ConnectionProvider, interests []*pb.Interest, permitBlockEvents bool)
}
func (p *params) SetResponseTimeout(value time.Duration) {
logger.Debugf("ResponseTimeout: %s", value)
p.respTimeout = value
}
func (p *params) SetConnectionProviderAndInterests(connProvider api.ConnectionProvider, interests []*pb.Interest, permitBlockEvents bool) {
logger.Debugf("ConnProvider: %#v, Interests: %#v, PermitBlockEvents: %t", connProvider, interests, permitBlockEvents)
p.connProvider = connProvider
p.interests = interests
p.permitBlockEvents = permitBlockEvents
}