github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/test/e2e/node/config.go (about) 1 package main 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/BurntSushi/toml" 8 9 "github.com/badrootd/nibiru-cometbft/test/e2e/app" 10 ) 11 12 // Config is the application configuration. 13 type Config struct { 14 ChainID string `toml:"chain_id"` 15 Listen string 16 Protocol string 17 Dir string 18 Mode string `toml:"mode"` 19 PersistInterval uint64 `toml:"persist_interval"` 20 SnapshotInterval uint64 `toml:"snapshot_interval"` 21 RetainBlocks uint64 `toml:"retain_blocks"` 22 ValidatorUpdates map[string]map[string]uint8 `toml:"validator_update"` 23 PrivValServer string `toml:"privval_server"` 24 PrivValKey string `toml:"privval_key"` 25 PrivValState string `toml:"privval_state"` 26 KeyType string `toml:"key_type"` 27 } 28 29 // App extracts out the application specific configuration parameters 30 func (cfg *Config) App() *app.Config { 31 return &app.Config{ 32 Dir: cfg.Dir, 33 SnapshotInterval: cfg.SnapshotInterval, 34 RetainBlocks: cfg.RetainBlocks, 35 KeyType: cfg.KeyType, 36 ValidatorUpdates: cfg.ValidatorUpdates, 37 PersistInterval: cfg.PersistInterval, 38 } 39 } 40 41 // LoadConfig loads the configuration from disk. 42 func LoadConfig(file string) (*Config, error) { 43 cfg := &Config{ 44 Listen: "unix:///var/run/app.sock", 45 Protocol: "socket", 46 PersistInterval: 1, 47 } 48 _, err := toml.DecodeFile(file, &cfg) 49 if err != nil { 50 return nil, fmt.Errorf("failed to load config from %q: %w", file, err) 51 } 52 return cfg, cfg.Validate() 53 } 54 55 // Validate validates the configuration. We don't do exhaustive config 56 // validation here, instead relying on Testnet.Validate() to handle it. 57 // 58 //nolint:goconst 59 func (cfg Config) Validate() error { 60 switch { 61 case cfg.ChainID == "": 62 return errors.New("chain_id parameter is required") 63 case cfg.Listen == "" && cfg.Protocol != "builtin": 64 return errors.New("listen parameter is required") 65 default: 66 return nil 67 } 68 }