Add txn type parametrisation for converter
This commit is contained in:
@@ -44,7 +44,7 @@ class ConverterConfig:
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class Converter[RecordT: Record, ConfigT: ConverterConfig]:
|
class Converter[RecordT: Record, TxnT: PartialTXN, ConfigT: ConverterConfig]:
|
||||||
"""
|
"""
|
||||||
ABC for Record -> Transaction conversion interface.
|
ABC for Record -> Transaction conversion interface.
|
||||||
|
|
||||||
@@ -60,6 +60,7 @@ class Converter[RecordT: Record, ConfigT: ConverterConfig]:
|
|||||||
|
|
||||||
record_type: ClassVar[Type[RecordT]]
|
record_type: ClassVar[Type[RecordT]]
|
||||||
config_type: ClassVar[Type[ConfigT]]
|
config_type: ClassVar[Type[ConfigT]]
|
||||||
|
txn_type: ClassVar[Type[TxnT]]
|
||||||
|
|
||||||
def __init__(self, config: ConfigT, **kwargs):
|
def __init__(self, config: ConfigT, **kwargs):
|
||||||
self.config = config
|
self.config = config
|
||||||
@@ -68,7 +69,7 @@ class Converter[RecordT: Record, ConfigT: ConverterConfig]:
|
|||||||
def qual_name(cls):
|
def qual_name(cls):
|
||||||
return f"{cls.converter_name}_v{cls.version}"
|
return f"{cls.converter_name}_v{cls.version}"
|
||||||
|
|
||||||
def annotation(self, record: RecordT, partial: PartialTXN) -> Optional[str]:
|
def annotation(self, record: RecordT, partial: TxnT) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
Optional user-readable note/warning to attach to a mapped record.
|
Optional user-readable note/warning to attach to a mapped record.
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ class Converter[RecordT: Record, ConfigT: ConverterConfig]:
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def convert(self, record: RecordT, ruleset: RuleSet) -> PartialTXN | _SKIPT:
|
def convert(self, record: RecordT, ruleset: RuleSet) -> TxnT | _SKIPT:
|
||||||
"""
|
"""
|
||||||
The meat of the conversion process.
|
The meat of the conversion process.
|
||||||
Take a raw Record from the data and convert it into a partial transaction,
|
Take a raw Record from the data and convert it into a partial transaction,
|
||||||
|
|||||||
@@ -97,9 +97,10 @@ class CBAConfig(ConverterConfig):
|
|||||||
|
|
||||||
|
|
||||||
@available_converter
|
@available_converter
|
||||||
class CBAConverter(Converter[CBARecord, CBAConfig]):
|
class CBAConverter(Converter[CBARecord, PartialTXN, CBAConfig]):
|
||||||
record_type = CBARecord
|
record_type = CBARecord
|
||||||
config_type = CBAConfig
|
config_type = CBAConfig
|
||||||
|
txn_type = PartialTXN
|
||||||
converter_name = "cbacsv"
|
converter_name = "cbacsv"
|
||||||
version = "0"
|
version = "0"
|
||||||
display_name = "CBACSV converter v0"
|
display_name = "CBACSV converter v0"
|
||||||
|
|||||||
@@ -94,9 +94,10 @@ class CBASTConfig(ConverterConfig):
|
|||||||
|
|
||||||
|
|
||||||
@available_converter
|
@available_converter
|
||||||
class CBASTConverter(Converter[CBASTRecord, CBASTConfig]):
|
class CBASTConverter(Converter[CBASTRecord, PartialTXN, CBASTConfig]):
|
||||||
record_type = CBASTRecord
|
record_type = CBASTRecord
|
||||||
config_type = CBASTConfig
|
config_type = CBASTConfig
|
||||||
|
txn_type = PartialTXN
|
||||||
converter_name = "cbast"
|
converter_name = "cbast"
|
||||||
version = "0"
|
version = "0"
|
||||||
display_name = "CBAST converter v0"
|
display_name = "CBAST converter v0"
|
||||||
|
|||||||
@@ -65,9 +65,10 @@ class SampleConfig(ConverterConfig):
|
|||||||
|
|
||||||
|
|
||||||
@available_converter
|
@available_converter
|
||||||
class SampleConverter(Converter[SampleRecord, SampleConfig]):
|
class SampleConverter(Converter[SampleRecord, PartialTXN, SampleConfig]):
|
||||||
record_type = SampleRecord
|
record_type = SampleRecord
|
||||||
config_type = SampleConfig
|
config_type = SampleConfig
|
||||||
|
txn_type = PartialTXN
|
||||||
converter_name = "sample"
|
converter_name = "sample"
|
||||||
version = "0"
|
version = "0"
|
||||||
display_name = "Sample converter v0"
|
display_name = "Sample converter v0"
|
||||||
|
|||||||
@@ -213,9 +213,10 @@ class WiseConfig(ConverterConfig):
|
|||||||
|
|
||||||
|
|
||||||
@available_converter
|
@available_converter
|
||||||
class WiseConverter(Converter[WiseRecord, WiseConfig]):
|
class WiseConverter(Converter[WiseRecord, PartialTXN, WiseConfig]):
|
||||||
record_type = WiseRecord
|
record_type = WiseRecord
|
||||||
config_type = WiseConfig
|
config_type = WiseConfig
|
||||||
|
txn_type = PartialTXN
|
||||||
converter_name = "wise"
|
converter_name = "wise"
|
||||||
version = "0"
|
version = "0"
|
||||||
display_name = "Wise Record Converter v0"
|
display_name = "Wise Record Converter v0"
|
||||||
|
|||||||
Reference in New Issue
Block a user