11"""Functionality for interacting with db-sync."""
22
3+ import enum
34import functools
45import itertools
56import logging
2021NO_RESPONSE_STR = "No response returned from db-sync:"
2122
2223
24+ class ActionTypes (enum .StrEnum ):
25+ COMMITTEE = "committee"
26+ CONSTITUTION = "constitution"
27+
28+
2329def get_address_reward (
2430 address : str , epoch_from : int = 0 , epoch_to : int = 99999999
2531) -> dbsync_types .RewardRecord :
@@ -1593,7 +1599,7 @@ def table_exists(table: str) -> bool:
15931599 return table in table_names
15941600
15951601
1596- def check_epoch_state (epoch_no : int , txid : str , change_type : str = "" ) -> None :
1602+ def check_epoch_state (epoch_no : int , txid : str , action_type : ActionTypes ) -> None :
15971603 """Check governance stats per epoch in dbsync."""
15981604 if not configuration .HAS_DBSYNC :
15991605 return
@@ -1604,20 +1610,22 @@ def check_epoch_state(epoch_no: int, txid: str, change_type: str = "") -> None:
16041610 msg = f"No information about epoch state in dbsync for epoch: { epoch_no } "
16051611 raise ValueError (msg )
16061612
1607- if change_type == "committee" :
1613+ if action_type == ActionTypes . COMMITTEE :
16081614 dbsync_committee_info = list (dbsync_queries .query_new_committee_info (txhash = txid ))[- 1 ]
16091615 es_committee_id = epoch_state_data [0 ].committee_id
16101616 tx_committee_id = dbsync_committee_info .id
16111617 assert es_committee_id == tx_committee_id , (
16121618 f"Committee id mismatch between epoch_state { es_committee_id } "
16131619 f"and committee table { tx_committee_id } ."
16141620 )
1615-
1616- if change_type == "constitution" :
1621+ elif action_type == ActionTypes .CONSTITUTION :
16171622 dbsync_constitution_info = list (dbsync_queries .query_new_constitution (txhash = txid ))[- 1 ]
16181623 es_constitution_id = epoch_state_data [0 ].constitution_id
16191624 tx_constitution_id = dbsync_constitution_info .id
16201625 assert es_constitution_id == tx_constitution_id , (
16211626 f"Committee id mismatch between epoch_state { es_constitution_id } "
16221627 f"and committee table { tx_constitution_id } ."
16231628 )
1629+ else :
1630+ msg = f"Unsupported action type for epoch state check: { action_type .value } "
1631+ raise ValueError (msg )
0 commit comments