-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathconfig.go
More file actions
106 lines (93 loc) · 2.84 KB
/
config.go
File metadata and controls
106 lines (93 loc) · 2.84 KB
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
96
97
98
99
100
101
102
103
104
105
106
package config
import (
"flare-indexer/config"
"flare-indexer/utils"
"time"
"github.com/ethereum/go-ethereum/common"
)
type Config struct {
DB config.DBConfig `toml:"db"`
Logger config.LoggerConfig `toml:"logger"`
Chain config.ChainConfig `toml:"chain"`
Metrics MetricsConfig `toml:"metrics"`
XChainIndexer IndexerConfig `toml:"x_chain_indexer"`
PChainIndexer IndexerConfig `toml:"p_chain_indexer"`
UptimeCronjob UptimeConfig `toml:"uptime_cronjob"`
Mirror MirrorConfig `toml:"mirroring_cronjob"`
ContractAddresses ContractAddresses `toml:"contract_addresses"`
}
type MetricsConfig struct {
PrometheusAddress string `toml:"prometheus_address" envconfig:"PROMETHEUS_ADDRESS"`
}
type IndexerConfig struct {
Enabled bool `toml:"enabled"`
Timeout time.Duration `toml:"timeout"`
BatchSize int `toml:"batch_size"`
StartIndex uint64 `toml:"start_index"`
}
type CronjobConfig struct {
Enabled bool `toml:"enabled"`
Timeout time.Duration `toml:"timeout"`
BatchSize int64 `toml:"batch_size"`
Delay time.Duration `toml:"delay"`
}
type MirrorConfig struct {
CronjobConfig
config.EpochConfig
}
type UptimeConfig struct {
CronjobConfig
Period time.Duration `toml:"period" envconfig:"UPTIME_EPOCH_PERIOD"`
Start utils.Timestamp `toml:"start" envconfig:"UPTIME_EPOCH_START"`
First int64 `toml:"first" envconfig:"UPTIME_EPOCH_FIRST"`
EnableVoting bool `toml:"enable_voting"`
UptimeThreshold float64 `toml:"uptime_threshold"`
DeleteOldUptimesEpochThreshold int64 `toml:"delete_old_uptimes_epoch_threshold"`
}
type ContractAddresses struct {
config.ContractAddresses
Mirroring common.Address `toml:"mirroring" envconfig:"MIRRORING_CONTRACT_ADDRESS"`
}
func newConfig() *Config {
return &Config{
XChainIndexer: IndexerConfig{
Enabled: true,
Timeout: 3000 * time.Millisecond,
BatchSize: 10,
StartIndex: 0,
},
PChainIndexer: IndexerConfig{
Enabled: true,
Timeout: 3000 * time.Millisecond,
BatchSize: 10,
StartIndex: 0,
},
UptimeCronjob: UptimeConfig{
CronjobConfig: CronjobConfig{
Enabled: false,
Timeout: 60 * time.Second,
},
},
Chain: config.ChainConfig{
NodeURL: "http://localhost:9650/",
},
}
}
func (c Config) LoggerConfig() config.LoggerConfig {
return c.Logger
}
func (c Config) ChainConfig() config.ChainConfig {
return c.Chain
}
func BuildConfig(cfgFileName string) (*Config, error) {
cfg := newConfig()
err := config.ParseConfigFile(cfg, cfgFileName, false)
if err != nil {
return nil, err
}
err = config.ReadEnv(cfg)
if err != nil {
return nil, err
}
return cfg, nil
}