forked from omni-network/omni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
65 lines (52 loc) · 1.27 KB
/
config.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
package relayer
import (
"bytes"
"text/template"
"github.com/omni-network/omni/lib/buildinfo"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/log"
cmtos "github.com/cometbft/cometbft/libs/os"
_ "embed"
)
type Config struct {
PrivateKey string
HaloURL string
NetworkFile string
MonitoringAddr string
StateFile string
}
func DefaultConfig() Config {
return Config{
PrivateKey: "relayer.key",
HaloURL: "localhost:26657",
NetworkFile: "network.json",
MonitoringAddr: ":26660",
StateFile: "relayer-state.json",
}
}
//go:embed config.toml.tmpl
var tomlTemplate []byte
// WriteConfigTOML writes the toml halo config to disk.
func WriteConfigTOML(cfg Config, logCfg log.Config, path string) error {
var buffer bytes.Buffer
t, err := template.New("").Parse(string(tomlTemplate))
if err != nil {
return errors.Wrap(err, "parse template")
}
s := struct {
Config
Log log.Config
Version string
}{
Config: cfg,
Log: logCfg,
Version: buildinfo.Version(),
}
if err := t.Execute(&buffer, s); err != nil {
return errors.Wrap(err, "execute template")
}
if err := cmtos.WriteFile(path, buffer.Bytes(), 0o644); err != nil {
return errors.Wrap(err, "write config")
}
return nil
}