@@ -24,21 +24,71 @@ 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+ // ShelleyTransEpoch holds transition slot/epoch info
41+ type ShelleyTransEpoch struct {
42+ FirstShelleySlot uint64 `yaml:"first_shelley_slot"`
43+ FirstShelleyEpoch uint64 `yaml:"first_shelley_epoch"`
44+ }
45+
46+ // populateByronGenesis sets defaults and validates ByronGenesisConfig
47+ func (c * Config ) populateByronGenesis () {
48+ cfg := & c .ByronGenesis
49+ // Apply defaults only when values are truly unset. Zero values are valid for Byron-less networks.
50+ if cfg .EpochLength == 0 {
51+ cfg .EpochLength = 21600
52+ }
53+ if cfg .ByronSlotsPerEpoch == 0 {
54+ cfg .ByronSlotsPerEpoch = cfg .EpochLength
55+ }
56+ if cfg .EndSlot == nil {
57+ defaultEndSlot := uint64 (4492799 )
58+ cfg .EndSlot = & defaultEndSlot
59+ }
60+ if cfg .Epochs == nil {
61+ defaultEpochs := uint64 (208 )
62+ cfg .Epochs = & defaultEpochs
63+ }
64+ // Validation after defaults was redundant; any required fields are now set.
65+ }
66+
67+ // populateShelleyGenesis sets defaults and validates ShelleyGenesisConfig
68+ func (c * Config ) populateShelleyGenesis () {
69+ cfg := & c .ShelleyGenesis
70+ if cfg .EpochLength == 0 {
71+ cfg .EpochLength = 432000
72+ }
73+ }
74+
2775const (
2876 DefaultInputPlugin = "chainsync"
2977 DefaultOutputPlugin = "log"
3078)
3179
3280type 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:"-"`
81+ ByronGenesis ByronGenesisConfig `yaml:"byron_genesis" envconfig:"BYRON_GENESIS"`
82+ Plugin map [string ]map [string ]map [any ]any `yaml:"plugins"`
83+ Logging LoggingConfig `yaml:"logging"`
84+ ConfigFile string `yaml:"-"`
85+ Input string `yaml:"input" envconfig:"INPUT"`
86+ Output string `yaml:"output" envconfig:"OUTPUT"`
87+ KupoUrl string `yaml:"kupo_url" envconfig:"KUPO_URL"`
88+ Api ApiConfig `yaml:"api"`
89+ Debug DebugConfig `yaml:"debug"`
90+ ShelleyGenesis ShelleyGenesisConfig `yaml:"shelley_genesis" envconfig:"SHELLEY_GENESIS"`
91+ Version bool `yaml:"-"`
4292}
4393
4494type ApiConfig struct {
@@ -71,6 +121,14 @@ var globalConfig = &Config{
71121 Input : DefaultInputPlugin ,
72122 Output : DefaultOutputPlugin ,
73123 KupoUrl : "" ,
124+ ByronGenesis : ByronGenesisConfig {
125+ EpochLength : 21600 ,
126+ EndSlot : func () * uint64 { v := uint64 (4492799 ); return & v }(),
127+ Epochs : func () * uint64 { v := uint64 (208 ); return & v }(),
128+ },
129+ ShelleyGenesis : ShelleyGenesisConfig {
130+ EpochLength : 432000 ,
131+ },
74132}
75133
76134func (c * Config ) Load (configFile string ) error {
@@ -86,12 +144,13 @@ func (c *Config) Load(configFile string) error {
86144 }
87145 }
88146 // 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
91147 err := envconfig .Process ("dummy" , c )
92148 if err != nil {
93149 return fmt .Errorf ("error processing environment: %w" , err )
94150 }
151+ // Populate Byron and Shelley genesis configs (from nview)
152+ c .populateByronGenesis ()
153+ c .populateShelleyGenesis ()
95154 return nil
96155}
97156
0 commit comments