-
Notifications
You must be signed in to change notification settings - Fork 175
/
toml.go
78 lines (58 loc) · 1.91 KB
/
toml.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
package helper
import (
"bytes"
"text/template"
"github.com/spf13/viper"
cmn "github.com/tendermint/tendermint/libs/common"
)
// Note: any changes to the comments/variables/mapstructure
// must be reflected in the appropriate struct in helper/config.go
const defaultConfigTemplate = `# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
##### RPC and REST configs #####
# RPC endpoint for ethereum chain
eth_rpc_url = "{{ .EthRPCUrl }}"
# RPC endpoint for bor chain
bor_rpc_url = "{{ .BorRPCUrl }}"
# RPC endpoint for tendermint
tendermint_rpc_url = "{{ .TendermintRPCUrl }}"
# Heimdall REST server endpoint
heimdall_rest_server = "{{ .HeimdallServerURL }}"
#### Bridge configs ####
# AMQP endpoint
amqp_url = "{{ .AmqpURL }}"
## Poll intervals
checkpoint_poll_interval = "{{ .CheckpointerPollInterval }}"
syncer_poll_interval = "{{ .SyncerPollInterval }}"
noack_poll_interval = "{{ .NoACKPollInterval }}"
clerk_poll_interval = "{{ .ClerkPollInterval }}"
span_poll_interval = "{{ .SpanPollInterval }}"
#### gas limits ####
main_chain_gas_limit = "{{ .MainchainGasLimit }}"
##### Timeout Config #####
no_ack_wait_time = "{{ .NoACKWaitTime }}"
`
var configTemplate *template.Template
func init() {
var err error
tmpl := template.New("appConfigFileTemplate")
if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
panic(err)
}
}
// ParseConfig retrieves the default environment configuration for the
// application.
func ParseConfig() (*Configuration, error) {
conf := GetDefaultHeimdallConfig()
err := viper.Unmarshal(conf)
return &conf, err
}
// WriteConfigFile renders config using the template and writes it to
// configFilePath.
func WriteConfigFile(configFilePath string, config *Configuration) {
var buffer bytes.Buffer
if err := configTemplate.Execute(&buffer, config); err != nil {
panic(err)
}
cmn.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
}