@@ -21,10 +21,10 @@ func ParseLiveIngestorType(str string) (LiveIngestorType, error) {
2121
2222// ChaintracksServiceConfig holds configuration for Chaintracks service, including the BSV network selection.
2323type ChaintracksServiceConfig struct {
24- Chain BSVNetwork `mapstructure:"-"`
25- LiveIngestors []LiveIngestorType `mapstructure:"live_ingestors"`
26- CDNBulkIngestors []CDNBulkIngestorConfig `mapstructure:"cdn_bulk_ingestors "`
27- WocAPIKey string `mapstructure:"woc_api_key"`
24+ Chain BSVNetwork `mapstructure:"-"`
25+ LiveIngestors []LiveIngestorType `mapstructure:"live_ingestors"`
26+ BulkIngestors []BulkIngestorConfig `mapstructure:"bulk_ingestors "`
27+ WocAPIKey string `mapstructure:"woc_api_key"`
2828}
2929
3030// Validate checks if the Chain field in ChaintracksServiceConfig holds a valid BSV network type.
@@ -46,9 +46,9 @@ func (c *ChaintracksServiceConfig) Validate() error {
4646 }
4747 }
4848
49- for i := range c .CDNBulkIngestors {
50- if err := c .CDNBulkIngestors [i ].Validate (); err != nil {
51- return fmt .Errorf ("invalid CDN bulk ingestor config at index %d: %w" , i , err )
49+ for i := range c .BulkIngestors {
50+ if err := c .BulkIngestors [i ].Validate (); err != nil {
51+ return fmt .Errorf ("invalid bulk ingestor config at index %d: %w" , i , err )
5252 }
5353 }
5454
@@ -62,15 +62,66 @@ func DefaultChaintracksServiceConfig() ChaintracksServiceConfig {
6262 LiveIngestors : []LiveIngestorType {
6363 LiveIngestorTypeWocPoll ,
6464 },
65- CDNBulkIngestors : []CDNBulkIngestorConfig {
65+ BulkIngestors : []BulkIngestorConfig {
6666 {
67- SourceURL : BabbageBlockHeadersCDN ,
67+ Type : ChaintracksCDN ,
68+ CDNConfig : & CDNBulkIngestorConfig {
69+ SourceURL : BabbageBlockHeadersCDN ,
70+ },
71+ },
72+ {
73+ Type : WhatsOnChainCDN ,
6874 },
6975 },
7076 WocAPIKey : "" ,
7177 }
7278}
7379
80+ // BulkIngestorType defines the type of bulk ingestor used to retrieve blockchain data from different sources.
81+ type BulkIngestorType string
82+
83+ // Supported BulkIngestorType values.
84+ const (
85+ ChaintracksCDN BulkIngestorType = "chaintracks_cdn"
86+ WhatsOnChainCDN BulkIngestorType = "whats_on_chain_cdn"
87+ )
88+
89+ // BulkIngestorConfig defines configuration for a bulk ingestor used to fetch blockchain data such as block headers.
90+ type BulkIngestorConfig struct {
91+ Type BulkIngestorType `mapstructure:"type"`
92+
93+ // CDNConfig is required if Type is ChaintracksCDN
94+ CDNConfig * CDNBulkIngestorConfig `mapstructure:"cdn_config"`
95+ }
96+
97+ // Validate checks if the BulkIngestorConfig is properly configured for the specified Type and returns an error if not valid.
98+ func (b * BulkIngestorConfig ) Validate () error {
99+ switch b .Type {
100+ case ChaintracksCDN :
101+ if b .CDNConfig == nil {
102+ return fmt .Errorf ("cdn_config is required for chaintracks_cdn bulk ingestor" )
103+ }
104+ if err := b .CDNConfig .Validate (); err != nil {
105+ return fmt .Errorf ("invalid cdn_config: %w" , err )
106+ }
107+ case WhatsOnChainCDN :
108+ // No additional config required for WhatsOnChainCDN
109+ default :
110+ return fmt .Errorf ("invalid bulk ingestor type: %s" , b .Type )
111+ }
112+ return nil
113+ }
114+
115+ // String returns a human-readable representation of the BulkIngestorConfig, including type and CDN source URL when applicable.
116+ func (b * BulkIngestorConfig ) String () string {
117+ detailed := ""
118+ if b .Type == ChaintracksCDN && b .CDNConfig != nil {
119+ detailed = fmt .Sprintf (" (source_url=%s)" , b .CDNConfig .SourceURL )
120+ }
121+
122+ return fmt .Sprintf ("%s%s" , b .Type , detailed )
123+ }
124+
74125// CDNBulkIngestorConfig holds configuration options for a bulk ingestor that fetches block headers from a CDN source.
75126type CDNBulkIngestorConfig struct {
76127 SourceURL string `mapstructure:"source_url"`
0 commit comments