diff --git a/registrydao/constants.py b/registrydao/constants.py index 1c01fc3..1d6e5c3 100644 --- a/registrydao/constants.py +++ b/registrydao/constants.py @@ -1,5 +1,4 @@ -DIPDUP_METADATA_API = 'https://metadata.dipdup.net/api/rest' NETWORK_MAP = { "mainnet": "mainnet", - "ghostnet": "ghostnet", -} \ No newline at end of file + "ghostnet": "ghostnet" +} diff --git a/registrydao/handlers/on_flush.py b/registrydao/handlers/on_flush.py index e763e14..f65730d 100644 --- a/registrydao/handlers/on_flush.py +++ b/registrydao/handlers/on_flush.py @@ -27,25 +27,24 @@ async def on_flush( dao.guardian = flush.data.storage["guardian"] await dao.save() - created_status = await models.ProposalStatus.get(description='created') executed_status = await models.ProposalStatus.get(description='executed') rejected_and_flushed_status = await models.ProposalStatus.get(description='rejected_and_flushed') dropped_status = await models.ProposalStatus.get(description='dropped') - created_proposals = await models.Proposal.filter(dao=dao, status_updates__status=created_status) - - for i in range(len(created_proposals)): - if created_proposals[i].key not in non_flushed_or_executed_keys: - is_rejected = int(created_proposals[i].downvotes) >= int(created_proposals[i].quorum_threshold) - is_passed = (int(created_proposals[i].upvotes) >= int(created_proposals[i].quorum_threshold)) and not is_rejected - is_dropped = await models.ProposalStatusUpdates.exists(proposal=created_proposals[i], status=dropped_status) - is_executed = await models.ProposalStatusUpdates.exists(proposal=created_proposals[i], status=executed_status) + all_proposals = await models.Proposal.filter(dao=dao) + + for i in range(len(all_proposals)): + if all_proposals[i].key not in non_flushed_or_executed_keys: + is_rejected = int(all_proposals[i].downvotes) >= int(all_proposals[i].quorum_threshold) + is_passed = (int(all_proposals[i].upvotes) >= int(all_proposals[i].quorum_threshold)) and not is_rejected + is_dropped = await models.ProposalStatusUpdates.exists(proposal=all_proposals[i], status=dropped_status) + is_executed = await models.ProposalStatusUpdates.exists(proposal=all_proposals[i], status=executed_status) if is_passed and not is_dropped and not is_executed: - await models.ProposalStatusUpdates.get_or_create(status=executed_status, proposal=created_proposals[i], timestamp=flush.data.timestamp, level=flush.data.level) + await models.ProposalStatusUpdates.get_or_create(status=executed_status, proposal=all_proposals[i], timestamp=flush.data.timestamp, level=flush.data.level) elif is_rejected and not is_dropped and not is_executed: - await models.ProposalStatusUpdates.get_or_create(status=rejected_and_flushed_status, proposal=created_proposals[i], timestamp=flush.data.timestamp, level=flush.data.level) + await models.ProposalStatusUpdates.get_or_create(status=rejected_and_flushed_status, proposal=all_proposals[i], timestamp=flush.data.timestamp, level=flush.data.level) elif not is_dropped and not is_executed: - await models.ProposalStatusUpdates.get_or_create(status=dropped_status, proposal=created_proposals[i], timestamp=flush.data.timestamp, level=flush.data.level) + await models.ProposalStatusUpdates.get_or_create(status=dropped_status, proposal=all_proposals[i], timestamp=flush.data.timestamp, level=flush.data.level) except Exception as e: print("Error in on_flush: " + flush.data.target_address) print(e) \ No newline at end of file diff --git a/registrydao/handlers/on_origination.py b/registrydao/handlers/on_origination.py index 81326b1..1ab27a6 100644 --- a/registrydao/handlers/on_origination.py +++ b/registrydao/handlers/on_origination.py @@ -4,7 +4,7 @@ from datetime import datetime from importlib.metadata import metadata from registrydao.utils.ctx import extract_network_from_ctx -from registrydao.constants import DIPDUP_METADATA_API, NETWORK_MAP +from registrydao.constants import NETWORK_MAP from registrydao.utils.http import fetch from dipdup.context import HandlerContext @@ -20,8 +20,8 @@ def find_in_json(key_to_compare: str, key_name: str, data): async def wait_and_fetch_metadata(network: str, dao_address: str): fetched_metadata_location = await fetch(f'https://api.{NETWORK_MAP[network]}.tzkt.io/v1/contracts/{dao_address}/bigmaps/metadata/keys') - metadata_location_hash = fetched_metadata_location[0]["value"] - metadata_uri = bytes.fromhex(metadata_location_hash).decode('utf-8') + metadata_location_hex = fetched_metadata_location[0]["value"] + metadata_uri = bytes.fromhex(metadata_location_hex).decode('utf-8') metadata_contract = metadata_uri.split('/')[2] fetched_metadata = await fetch(f'https://api.{NETWORK_MAP[network]}.tzkt.io/v1/contracts/{metadata_contract}/bigmaps/metadata/keys/metadataKey') metadata = bytes.fromhex(fetched_metadata["value"]).decode('utf-8')