-
Notifications
You must be signed in to change notification settings - Fork 504
/
params.go
69 lines (58 loc) · 1.66 KB
/
params.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
69
package subscribe
import "github.com/0xPolygon/polygon-edge/txpool/proto"
var (
params = &subscribeParams{}
)
var (
addedFlag = "added"
promotedFlag = "promoted"
demotedFlag = "demoted"
enqueuedFlag = "enqueued"
droppedFlag = "dropped"
prunedPromotedFlag = "pruned-promoted"
prunedEnqueuedFlag = "pruned-enqueued"
)
type subscribeParams struct {
eventSubscriptionMap map[proto.EventType]*bool
supportedEvents []proto.EventType
}
func (sp *subscribeParams) initEventMap() {
falseRaw := false
sp.eventSubscriptionMap = map[proto.EventType]*bool{
proto.EventType_ADDED: &falseRaw,
proto.EventType_ENQUEUED: &falseRaw,
proto.EventType_PROMOTED: &falseRaw,
proto.EventType_DROPPED: &falseRaw,
proto.EventType_DEMOTED: &falseRaw,
proto.EventType_PRUNED_PROMOTED: &falseRaw,
proto.EventType_PRUNED_ENQUEUED: &falseRaw,
}
}
func (sp *subscribeParams) init() {
sp.setSpecifiedEvents()
if !sp.areEventsSpecified() {
sp.setAllEvents()
}
}
func (sp *subscribeParams) setSpecifiedEvents() {
sp.supportedEvents = make([]proto.EventType, 0)
for eventType, eventIsSupported := range sp.eventSubscriptionMap {
if *eventIsSupported {
sp.supportedEvents = append(sp.supportedEvents, eventType)
}
}
}
func (sp *subscribeParams) areEventsSpecified() bool {
return len(sp.supportedEvents) != 0
}
func (sp *subscribeParams) setAllEvents() {
sp.supportedEvents = []proto.EventType{
proto.EventType_ADDED,
proto.EventType_ENQUEUED,
proto.EventType_PROMOTED,
proto.EventType_DROPPED,
proto.EventType_DEMOTED,
proto.EventType_PRUNED_PROMOTED,
proto.EventType_PRUNED_ENQUEUED,
}
}