-
Notifications
You must be signed in to change notification settings - Fork 54
/
config.go
71 lines (58 loc) · 1.45 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
66
67
68
69
70
71
package relayer
import (
"bytes"
"text/template"
"time"
"github.com/omni-network/omni/lib/buildinfo"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"
"github.com/omni-network/omni/lib/xchain"
cmtos "github.com/cometbft/cometbft/libs/os"
_ "embed"
)
type Config struct {
RPCEndpoints xchain.RPCEndpoints
PrivateKey string
HaloURL string
Network netconf.ID
MonitoringAddr string
DBDir string
ConfirmInterval time.Duration
}
func DefaultConfig() Config {
return Config{
PrivateKey: "relayer.key",
HaloURL: "localhost:26657",
Network: "",
MonitoringAddr: ":26660",
DBDir: "./db",
ConfirmInterval: 30 * time.Second,
}
}
//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
}