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
|
|
|
|
# specified in this config (e.g. 0.01photino;0.0001stake).
|
2019-01-24 02:21:02 -08:00
|
|
|
minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}"
|
2018-09-19 08:25:52 -07:00
|
|
|
`
|
|
|
|
|
|
|
|
var configTemplate *template.Template
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var err error
|
2018-12-20 11:21:39 -08:00
|
|
|
tmpl := template.New("gaiaConfigFileTemplate")
|
2018-09-19 08:25:52 -07:00
|
|
|
if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 11:21:39 -08:00
|
|
|
// ParseConfig retrieves the default environment configuration for Gaia.
|
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)
|
|
|
|
}
|