github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/server/config/toml.go (about)

     1  package config
     2  
     3  import (
     4  	"bytes"
     5  	"text/template"
     6  
     7  	tmos "github.com/fibonacci-chain/fbc/libs/tendermint/libs/os"
     8  	"github.com/spf13/viper"
     9  )
    10  
    11  const defaultConfigTemplate = `# This is a TOML config file.
    12  # For more information, see https://github.com/toml-lang/toml
    13  
    14  ##### main base config options #####
    15  
    16  # The minimum gas prices a validator is willing to accept for processing a
    17  # transaction. A transaction's fees must meet the minimum of any denomination
    18  # specified in this config (e.g. 0.25token1;0.0001token2).
    19  minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}"
    20  
    21  # HaltHeight contains a non-zero block height at which a node will gracefully
    22  # halt and shutdown that can be used to assist upgrades and testing.
    23  #
    24  # Note: Commitment of state will be attempted on the corresponding block.
    25  halt-height = {{ .BaseConfig.HaltHeight }}
    26  
    27  # HaltTime contains a non-zero minimum block time (in Unix seconds) at which
    28  # a node will gracefully halt and shutdown that can be used to assist upgrades
    29  # and testing.
    30  #
    31  # Note: Commitment of state will be attempted on the corresponding block.
    32  halt-time = {{ .BaseConfig.HaltTime }}
    33  
    34  # InterBlockCache enables inter-block caching.
    35  inter-block-cache = {{ .BaseConfig.InterBlockCache }}
    36  `
    37  
    38  var configTemplate *template.Template
    39  
    40  func init() {
    41  	var err error
    42  	tmpl := template.New("appConfigFileTemplate")
    43  	if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
    44  		panic(err)
    45  	}
    46  }
    47  
    48  // ParseConfig retrieves the default environment configuration for the
    49  // application.
    50  func ParseConfig() (*Config, error) {
    51  	conf := DefaultConfig()
    52  	err := viper.Unmarshal(conf)
    53  	return conf, err
    54  }
    55  
    56  // WriteConfigFile renders config using the template and writes it to
    57  // configFilePath.
    58  func WriteConfigFile(configFilePath string, config *Config) {
    59  	var buffer bytes.Buffer
    60  
    61  	if err := configTemplate.Execute(&buffer, config); err != nil {
    62  		panic(err)
    63  	}
    64  
    65  	tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
    66  }