Skip to content

Commit

Permalink
Merge pull request #27 from dOrgTech/v2-develop
Browse files Browse the repository at this point in the history
Merge v2 Develop to v2 Master
  • Loading branch information
Man-Jain authored Jan 26, 2023
2 parents 0fafa65 + 0b32760 commit 28d82c7
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 11 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM dipdup/dipdup:6.1.2

COPY requirements.txt .

RUN pip3 install -r requirements.txt

COPY . .
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.3'
services:
hasura:
depends_on:
- db
# command:
# - "hasura metadata track --all-tables [--schema public]"
ports:
- '0.0.0.0:8080:8080'
environment:
- 'HASURA_GRAPHQL_DATABASE_URL=postgres://indexer:qwerty@hb-indexer-postgres:5432/indexer_db'
- HASURA_GRAPHQL_ENABLE_CONSOLE=true
- HASURA_GRAPHQL_DEV_MODE=true
- HASURA_GRAPHQL_ADMIN_SECRET=changeme
- HASURA_GRAPHQL_UNAUTHORIZED_ROLE=indexer
- HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES=true
image: hasura/graphql-engine:v2.8.3.cli-migrations-v3
db:
container_name: hb-indexer-postgres
ports:
- '0.0.0.0:5432:5432'
environment:
- POSTGRES_USER=indexer
- POSTGRES_PASSWORD=qwerty
- POSTGRES_DB=indexer_db
image: postgres
indexer:
build: .
depends_on:
- db
command: ["-c", "dipdup.yml", "run"]
environment:
- PG_HOST=db
- PG_PORT=5432
- PG_USER=indexer
- PG_PASSWORD=qwerty
- PG_DB=indexer_db
- PG_SCHEMA=public
ports:
- 0.0.0.0:9000:9000
19 changes: 17 additions & 2 deletions registrydao/handlers/on_unstake_vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@ async def on_unstake_vote(
) -> None:
try:
dao_address = unstake_vote.data.target_address
proposal_key = unstake_vote.parameter.__root__[0]

dao = await models.DAO.get(address=dao_address)
proposal = await models.Proposal.get(key=proposal_key, dao=dao)

voter = await models.Holder.get_or_create(address=unstake_vote.data.sender_address)

await update_ledger(dao_address, unstake_vote.data.diffs)

votes = await models.Vote.filter(proposal=proposal, voter=voter[0])

for vote in votes:
vote.staked = False
await vote.save()

except Exception as e:
print("Error in on_unstake_vote: " + str(unstake_vote.data.target_address))
print(e)
print("Error in on_unstake_vote: " +
str(unstake_vote.data.target_address))
print(e)
9 changes: 5 additions & 4 deletions registrydao/handlers/on_vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ async def on_vote(
support=support,
voter=voter[0],
defaults={
'amount':amount
}
'amount': amount
},
staked=True
)

if support:
proposal.upvotes = float(proposal.upvotes) + float(amount)
else:
proposal.downvotes = float(proposal.downvotes) + float(amount)

await proposal.save()
except Exception as e:
print("Error in on_vote: " + str(vote.data.target_address))
print(e)
print(e)
15 changes: 10 additions & 5 deletions registrydao/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class RegistryExtra(Model):
class Meta:
table = 'registry_extra'


class TreasuryExtra(Model):
id = fields.IntField(pk=True)
dao: fields.ForeignKeyRelation[DAOType] = fields.ForeignKeyField(
Expand Down Expand Up @@ -129,6 +130,7 @@ class Meta:
table = 'ledger'
unique_together = (("dao", "holder"),)


class ProposalStatus(Model):
id = fields.IntField(pk=True)
description = fields.CharField(36)
Expand All @@ -143,8 +145,8 @@ class Proposal(Model):
dao: fields.ForeignKeyRelation[DAO] = fields.ForeignKeyField(
"models.DAO"
)
hash=fields.CharField(128)
key=fields.CharField(128)
hash = fields.CharField(128)
key = fields.CharField(128)
upvotes = fields.DecimalField(54, 18)
downvotes = fields.DecimalField(54, 18)
start_level = fields.IntField()
Expand All @@ -153,9 +155,9 @@ class Proposal(Model):
proposer: fields.ForeignKeyRelation[Holder] = fields.ForeignKeyField(
"models.Holder"
)
voting_stage_num=fields.CharField(50)
proposer_frozen_token=fields.CharField(50)
quorum_threshold=fields.DecimalField(54, 18)
voting_stage_num = fields.CharField(50)
proposer_frozen_token = fields.CharField(50)
quorum_threshold = fields.DecimalField(54, 18)
votes: fields.ReverseRelation["Vote"]
status_updates: fields.ReverseRelation["ProposalStatusUpdates"]

Expand All @@ -169,6 +171,7 @@ class Vote(Model):
"models.Proposal"
)
amount = fields.DecimalField(54, 18)
staked = fields.BooleanField()
support = fields.BooleanField()
voter: fields.ForeignKeyRelation[Holder] = fields.ForeignKeyField(
"models.Holder"
Expand All @@ -177,6 +180,7 @@ class Vote(Model):
class Meta:
table = 'votes'


class Transfer(Model):
id = fields.IntField(pk=True)
timestamp = fields.DatetimeField()
Expand All @@ -189,6 +193,7 @@ class Transfer(Model):
from_address = fields.CharField(36)
hash = fields.CharField(128)


class ProposalStatusUpdates(Model):
id = fields.IntField(pk=True)
timestamp = fields.DatetimeField()
Expand Down

0 comments on commit 28d82c7

Please sign in to comment.