2018-09-19 08:25:52 -07:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
const defaultConfigTemplate = `# This is a TOML config file.
|
|
|
|
# For more information, see https://github.com/toml-lang/toml
|
|
|
|
|
|
|
|
##### main base config options #####
|
|
|
|
|
2019-01-18 08:45:20 -08:00
|
|
|
# The minimum gas prices a validator is willing to accept for processing a
|
2019-02-07 18:14:54 -08:00
|
|
|
# transaction. A transaction's fees must meet the minimum of any denomination
|
2019-03-25 07:38:15 -07:00
|
|
|
# specified in this config (e.g. 0.25token1;0.0001token2).
|
2019-01-24 02:21:02 -08:00
|
|
|
minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}"
|
2019-04-23 06:33:11 -07:00
|
|
|
|
|
|
|
# HaltHeight contains a non-zero height at which a node will gracefully halt
|
|
|
|
# and shutdown that can be used to assist upgrades and testing.
|
|
|
|
halt-height = {{ .BaseConfig.HaltHeight }}
|
2018-09-19 08:25:52 -07:00
|
|
|
`
|
|
|
|
|
|
|
|
var configTemplate *template.Template
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var err error
|
2019-05-18 01:42:24 -07:00
|
|
|
tmpl := template.New("appConfigFileTemplate")
|
2018-09-19 08:25:52 -07:00
|
|
|
if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
// ParseConfig retrieves the default environment configuration for the
|
|
|
|
// application.
|
2018-09-19 08:25:52 -07:00
|
|
|
func ParseConfig() (*Config, error) {
|
|
|
|
conf := DefaultConfig()
|
|
|
|
err := viper.Unmarshal(conf)
|
|
|
|
return conf, err
|
|
|
|
}
|
|
|
|
|
2019-01-18 08:45:20 -08:00
|
|
|
// WriteConfigFile renders config using the template and writes it to
|
|
|
|
// configFilePath.
|
2018-09-19 08:25:52 -07:00
|
|
|
func WriteConfigFile(configFilePath string, config *Config) {
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
|
|
|
|
if err := configTemplate.Execute(&buffer, config); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmn.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
|
|
|
|
}
|