You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

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