/
main.go
72 lines (57 loc) · 1.77 KB
/
main.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
70
71
72
package main
import (
"fmt"
"time"
"github.com/nakji-network/connector"
"github.com/nakji-network/connector/config"
"github.com/nakji-network/connectors/woofi"
"github.com/rs/zerolog/log"
"github.com/spf13/pflag"
_ "go.uber.org/automaxprocs"
"google.golang.org/protobuf/reflect/protoreflect"
)
func main() {
c, err := connector.NewConnector()
if err != nil {
log.Fatal().Err(err).Msg("failed to instantiate connector")
}
c.Config.SetDefault("woofi.author", "nakji")
c.Config.SetDefault("woofi.version", "0_0_0")
c.Config.SetDefault("blockTime", 15*time.Second)
c.Config.SetDefault("waitBlocks", 4)
// Woo initial block is #18675185
pflag.Int64P("from-block", "f", 0, "block number to start backfill from (optional")
pflag.Int64P("num-blocks", "b", 0, "number of blocks to backfill (optional)")
pflag.Parse()
c.Config.BindPFlags(pflag.CommandLine)
if err := validateFlags(c.Config); err != nil {
log.Fatal().Err(err).Msg("input is not correct")
}
// Register topic and protobuf type mappings
protos := make([]protoreflect.ProtoMessage, len(woofi.TopicTypes))
i := 0
for _, topicProto := range woofi.TopicTypes {
protos[i] = topicProto
i++
}
c.RegisterProtos(protos...)
conf := &woofi.Config{
ConnectorName: "woofi",
NetworkName: "bsc",
FromBlock: c.Config.GetUint64("from-block"),
NumBlocks: c.Config.GetUint64("num-blocks"),
}
m := woofi.New(c, conf)
m.Start()
}
func validateFlags(conf config.IConfig) error {
fromBlock := conf.GetInt64("from-block")
numBlocks := conf.GetInt64("num-blocks")
if fromBlock < 0 {
return fmt.Errorf("backfill input value cannot be negative. from-block: %d", fromBlock)
}
if numBlocks < 0 {
return fmt.Errorf("backfill input value cannot be negative. num-blocks: %d", numBlocks)
}
return nil
}