-
Notifications
You must be signed in to change notification settings - Fork 292
/
toml.go
56 lines (44 loc) · 1.53 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
package config
import (
"bytes"
"text/template"
"github.com/spf13/viper"
tmos "github.com/tendermint/tendermint/libs/os"
)
const defaultConfigTemplate = `# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
##### main base config options #####
# The maximum gas amount can be spent for contract query.
# The contract query will invoke contract execution vm,
# so we need to restrict the max usage to prevent DoS attack
contract-query-gas-limit = "{{ .BaseConfig.ContractQueryGasLimit }}"
# Storing instances in the LRU will have no effect on the results
# (still deterministic), but should lower execution time at
# the cost of increased memory usage. We cannot pick universal
# parameters for this, so we should allow node operators to set it.
lru-size = "{{ .BaseConfig.CacheSize }}"
`
var configTemplate *template.Template
func init() {
var err error
tmpl := template.New("wasmConfigFileTemplate")
if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
panic(err)
}
}
// ParseConfig retrieves the default environment configuration for the
// application.
func ParseConfig() (*Config, error) {
conf := DefaultConfig()
err := viper.Unmarshal(conf)
return conf, err
}
// WriteConfigFile renders config using the template and writes it to
// configFilePath.
func WriteConfigFile(configFilePath string, config *Config) {
var buffer bytes.Buffer
if err := configTemplate.Execute(&buffer, config); err != nil {
panic(err)
}
tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
}