forked from omni-network/omni
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
66 lines (53 loc) · 1.32 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
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"
"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
}
func DefaultConfig() Config {
return Config{
PrivateKey: "relayer.key",
HaloURL: "localhost:26657",
Network: "",
MonitoringAddr: ":26660",
}
}
//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
}