-
Notifications
You must be signed in to change notification settings - Fork 244
/
topics.go
53 lines (44 loc) · 1.21 KB
/
topics.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
package topics
import (
"errors"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/p2p/discv5"
"github.com/status-im/status-go/params"
)
// TopicFlag used to parse discv5 topics.
type TopicFlag []discv5.Topic
func (f *TopicFlag) String() string {
return "discv5 topics"
}
// Set parses single topic.
func (f *TopicFlag) Set(value string) error {
*f = append(*f, discv5.Topic(strings.TrimSpace(value)))
return nil
}
// TopicLimitsFlag used to parse limits for discv5 topics.
type TopicLimitsFlag map[discv5.Topic]params.Limits
func (f *TopicLimitsFlag) String() string {
return "disv5 topics to limits map"
}
// Set parses single limit for a topic.
func (f *TopicLimitsFlag) Set(value string) error {
parts := strings.Split(strings.TrimSpace(value), "=")
if len(parts) != 2 {
return errors.New("topic must be separated by '=' from limits, e.g. 'topic1=1,1'")
}
limits := strings.Split(parts[1], ",")
if len(limits) != 2 {
return errors.New("min and max limit must be set, e.g. 'topic1=1,1'")
}
minL, err := strconv.Atoi(limits[0])
if err != nil {
return err
}
maxL, err := strconv.Atoi(limits[1])
if err != nil {
return err
}
(*f)[discv5.Topic(parts[0])] = params.NewLimits(minL, maxL)
return nil
}