Skip to content

Commit

Permalink
Merge branch 'execute-patch' of github.com:dOrgTech/homebase-indexer …
Browse files Browse the repository at this point in the history
…into lambda-patch
  • Loading branch information
Man-Jain committed Oct 11, 2022
2 parents af64a1e + 5b71023 commit ee0c481
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
5 changes: 2 additions & 3 deletions registrydao/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
DIPDUP_METADATA_API = 'https://metadata.dipdup.net/api/rest'
NETWORK_MAP = {
"mainnet": "mainnet",
"ghostnet": "ghostnet",
}
"ghostnet": "ghostnet"
}
23 changes: 11 additions & 12 deletions registrydao/handlers/on_flush.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions registrydao/handlers/on_origination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit ee0c481

Please sign in to comment.