@@ -24,21 +24,65 @@ import (
2424 "gopkg.in/yaml.v2"
2525)
2626
27+ // ByronGenesisConfig holds Byron era genesis parameters
28+ type ByronGenesisConfig struct {
29+ EndSlot * uint64 `yaml:"end_slot"`
30+ Epochs * uint64 `yaml:"epochs"`
31+ EpochLength uint64 `yaml:"epoch_length"`
32+ ByronSlotsPerEpoch uint64 `yaml:"byron_slots_per_epoch"`
33+ }
34+
35+ // ShelleyGenesisConfig holds Shelley era genesis parameters
36+ type ShelleyGenesisConfig struct {
37+ EpochLength uint64 `yaml:"epoch_length"`
38+ }
39+
40+ // populateByronGenesis sets defaults and validates ByronGenesisConfig
41+ func (c * Config ) populateByronGenesis () {
42+ cfg := & c .ByronGenesis
43+ // Apply defaults only when values are truly unset. Zero values are valid for Byron-less networks.
44+ if cfg .EpochLength == 0 {
45+ cfg .EpochLength = 21600
46+ }
47+ if cfg .ByronSlotsPerEpoch == 0 {
48+ cfg .ByronSlotsPerEpoch = cfg .EpochLength
49+ }
50+ if cfg .EndSlot == nil {
51+ defaultEndSlot := uint64 (4492799 )
52+ cfg .EndSlot = & defaultEndSlot
53+ }
54+ if cfg .Epochs == nil {
55+ defaultEpochs := uint64 (208 )
56+ cfg .Epochs = & defaultEpochs
57+ }
58+ // Validation after defaults was redundant; any required fields are now set.
59+ }
60+
61+ // populateShelleyGenesis sets defaults and validates ShelleyGenesisConfig
62+ func (c * Config ) populateShelleyGenesis () {
63+ cfg := & c .ShelleyGenesis
64+ if cfg .EpochLength == 0 {
65+ cfg .EpochLength = 432000
66+ }
67+ }
68+
2769const (
2870 DefaultInputPlugin = "chainsync"
2971 DefaultOutputPlugin = "log"
3072)
3173
3274type Config struct {
33- Plugin map [string ]map [string ]map [any ]any `yaml:"plugins"`
34- Logging LoggingConfig `yaml:"logging"`
35- ConfigFile string `yaml:"-"`
36- Input string `yaml:"input" envconfig:"INPUT"`
37- Output string `yaml:"output" envconfig:"OUTPUT"`
38- KupoUrl string `yaml:"kupo_url" envconfig:"KUPO_URL"`
39- Api ApiConfig `yaml:"api"`
40- Debug DebugConfig `yaml:"debug"`
41- Version bool `yaml:"-"`
75+ ByronGenesis ByronGenesisConfig `yaml:"byron_genesis" envconfig:"BYRON_GENESIS"`
76+ Plugin map [string ]map [string ]map [any ]any `yaml:"plugins"`
77+ Logging LoggingConfig `yaml:"logging"`
78+ ConfigFile string `yaml:"-"`
79+ Input string `yaml:"input" envconfig:"INPUT"`
80+ Output string `yaml:"output" envconfig:"OUTPUT"`
81+ KupoUrl string `yaml:"kupo_url" envconfig:"KUPO_URL"`
82+ Api ApiConfig `yaml:"api"`
83+ Debug DebugConfig `yaml:"debug"`
84+ ShelleyGenesis ShelleyGenesisConfig `yaml:"shelley_genesis" envconfig:"SHELLEY_GENESIS"`
85+ Version bool `yaml:"-"`
4286}
4387
4488type ApiConfig struct {
@@ -71,6 +115,14 @@ var globalConfig = &Config{
71115 Input : DefaultInputPlugin ,
72116 Output : DefaultOutputPlugin ,
73117 KupoUrl : "" ,
118+ ByronGenesis : ByronGenesisConfig {
119+ EpochLength : 21600 ,
120+ EndSlot : func () * uint64 { v := uint64 (4492799 ); return & v }(),
121+ Epochs : func () * uint64 { v := uint64 (208 ); return & v }(),
122+ },
123+ ShelleyGenesis : ShelleyGenesisConfig {
124+ EpochLength : 432000 ,
125+ },
74126}
75127
76128func (c * Config ) Load (configFile string ) error {
@@ -86,12 +138,13 @@ func (c *Config) Load(configFile string) error {
86138 }
87139 }
88140 // Load config values from environment variables
89- // We use "dummy" as the app name here to (mostly) prevent picking up env
90- // vars that we hadn't explicitly specified in annotations above
91141 err := envconfig .Process ("dummy" , c )
92142 if err != nil {
93143 return fmt .Errorf ("error processing environment: %w" , err )
94144 }
145+ // Populate Byron and Shelley genesis configs (from nview)
146+ c .populateByronGenesis ()
147+ c .populateShelleyGenesis ()
95148 return nil
96149}
97150
0 commit comments