@@ -109,7 +109,23 @@ def merge(self, other: Optional['HTTPConfig']) -> None:
109109
110110
111111@dataclass
112- class ContractConfig :
112+ class NameMixin :
113+ def __post_init_post_parse__ (self ) -> None :
114+ self ._name : Optional [str ] = None
115+
116+ @property
117+ def name (self ) -> str :
118+ if self ._name is None :
119+ raise RuntimeError ('Config is not pre-initialized' )
120+ return self ._name
121+
122+ @name .setter
123+ def name (self , name : str ) -> None :
124+ self ._name = name
125+
126+
127+ @dataclass
128+ class ContractConfig (NameMixin ):
113129 """Contract config
114130
115131 :param network: Corresponding network alias, only for sanity checks
@@ -135,22 +151,6 @@ def valid_address(cls, v):
135151 return v
136152
137153
138- @dataclass
139- class NameMixin :
140- def __post_init_post_parse__ (self ) -> None :
141- self ._name : Optional [str ] = None
142-
143- @property
144- def name (self ) -> str :
145- if self ._name is None :
146- raise RuntimeError ('Config is not pre-initialized' )
147- return self ._name
148-
149- @name .setter
150- def name (self , name : str ) -> None :
151- self ._name = name
152-
153-
154154@dataclass
155155class TzktDatasourceConfig (NameMixin ):
156156 """TzKT datasource config
@@ -625,13 +625,13 @@ class BlockIndexConfig(IndexConfig):
625625
626626
627627@dataclass
628- class StaticTemplateConfig :
628+ class IndexTemplateConfig :
629629 kind = 'template'
630630 template : str
631631 values : Dict [str , str ]
632632
633633
634- IndexConfigT = Union [OperationIndexConfig , BigMapIndexConfig , BlockIndexConfig , StaticTemplateConfig ]
634+ IndexConfigT = Union [OperationIndexConfig , BigMapIndexConfig , BlockIndexConfig , IndexTemplateConfig ]
635635IndexConfigTemplateT = Union [OperationIndexConfig , BigMapIndexConfig , BlockIndexConfig ]
636636HandlerPatternConfigT = Union [OperationHandlerOriginationPatternConfig , OperationHandlerTransactionPatternConfig ]
637637
@@ -708,7 +708,7 @@ class DipDupConfig:
708708 datasources : Dict [str , DatasourceConfigT ]
709709 contracts : Dict [str , ContractConfig ] = Field (default_factory = dict )
710710 indexes : Dict [str , IndexConfigT ] = Field (default_factory = dict )
711- templates : Optional [ Dict [str , IndexConfigTemplateT ]] = None
711+ templates : Dict [str , IndexConfigTemplateT ] = Field ( default_factory = dict )
712712 database : Union [SqliteDatabaseConfig , PostgresDatabaseConfig ] = SqliteDatabaseConfig (kind = 'sqlite' )
713713 hasura : Optional [HasuraConfig ] = None
714714 jobs : Optional [Dict [str , JobConfig ]] = None
@@ -774,10 +774,10 @@ def get_configure_fn(self) -> Type:
774774 except (ModuleNotFoundError , AttributeError ) as e :
775775 raise HandlerImportError (module = module_name , obj = CONFIGURE_HANDLER ) from e
776776
777- def resolve_static_templates (self ) -> None :
777+ def resolve_index_templates (self ) -> None :
778778 _logger .info ('Substituting index templates' )
779779 for index_name , index_config in self .indexes .items ():
780- if isinstance (index_config , StaticTemplateConfig ):
780+ if isinstance (index_config , IndexTemplateConfig ):
781781 template = self .get_template (index_config .template )
782782 raw_template = json .dumps (template , default = pydantic_encoder )
783783 for key , value in index_config .values .items ():
@@ -841,10 +841,12 @@ def _pre_initialize_index(self, index_name: str, index_config: IndexConfigT) ->
841841 self ._pre_initialized .append (index_name )
842842
843843 def pre_initialize (self ) -> None :
844- for name , config in self .datasources .items ():
845- config .name = name
844+ for name , contract_config in self .contracts .items ():
845+ contract_config .name = name
846+ for name , datasource_config in self .datasources .items ():
847+ datasource_config .name = name
846848
847- self .resolve_static_templates ()
849+ self .resolve_index_templates ()
848850 for index_name , index_config in self .indexes .items ():
849851 self ._pre_initialize_index (index_name , index_config )
850852
@@ -942,7 +944,7 @@ def _initialize_index(self, index_name: str, index_config: IndexConfigT) -> None
942944 if index_name in self ._initialized :
943945 return
944946
945- if isinstance (index_config , StaticTemplateConfig ):
947+ if isinstance (index_config , IndexTemplateConfig ):
946948 raise RuntimeError ('Config is not pre-initialized' )
947949
948950 if isinstance (index_config , OperationIndexConfig ):
0 commit comments