-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
95 lines (87 loc) · 2.63 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"time"
"github.com/iotexproject/chainlink-relayer/relayer"
"go.uber.org/config"
)
type Configuration struct {
Mode int `yaml:"mode"`
Interval time.Duration `yaml:"interval"`
StartHeight uint64 `yaml:"startHeight"`
DatabaseURL string `yaml:"databaseURL"`
SourceClientURL string `yaml:"sourceClientURL"`
TargetClientURL string `yaml:"targetClientURL"`
TargetChainID uint32 `yaml:"targetChainID"`
PrivateKey string `yaml:"privateKey"`
AggregatorPairs map[string]relayer.AggregatorConfig `yaml:"aggregatorPairs"`
ExchangeAggregators map[string]map[string]string `yaml:"exchangeAggregators"`
HookUrl string `yaml:"hookUrl"`
BatchSize uint64 `yaml:"batchSize"`
}
var defaultConfig = Configuration{}
var configFile = flag.String("config", "", "path of config file")
func init() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage:", os.Args[0], "-config <filename>")
flag.PrintDefaults()
}
}
func main() {
flag.Parse()
opts := []config.YAMLOption{config.Static(defaultConfig), config.Expand(os.LookupEnv)}
if *configFile != "" {
opts = append(opts, config.File(*configFile))
}
if cf, exists := os.LookupEnv("OVERWRITE_CONFIG_FILE"); exists {
opts = append(opts, config.File(cf))
}
yaml, err := config.NewYAML(opts...)
if err != nil {
log.Fatalln(err)
}
var cfg Configuration
if err := yaml.Get(config.Root).Populate(&cfg); err != nil {
log.Fatalln(err)
}
if pk, exists := os.LookupEnv("RELAYER_PRIVATE_KEY"); exists {
cfg.PrivateKey = pk
}
if url, exists := os.LookupEnv("DATABASE_URL"); exists {
cfg.DatabaseURL = url
}
if url, exists := os.LookupEnv("SOURCE_CLIENT_URL"); exists {
cfg.SourceClientURL = url
}
if url, exists := os.LookupEnv("TARGET_CLIENT_URL"); exists {
cfg.TargetClientURL = url
}
if url, exists := os.LookupEnv("HOOK_URL"); exists {
cfg.HookUrl = url
}
service, err := relayer.NewService(
cfg.Interval,
cfg.Mode,
cfg.StartHeight,
cfg.DatabaseURL,
cfg.SourceClientURL,
cfg.TargetChainID,
cfg.TargetClientURL,
cfg.PrivateKey,
cfg.AggregatorPairs,
cfg.ExchangeAggregators,
cfg.HookUrl,
cfg.BatchSize,
)
if err != nil {
log.Fatalln(err)
}
if err := service.Start(context.Background()); err != nil {
log.Fatalln(err)
}
select {}
}