Skip to content

Commit bf9e091

Browse files
authored
Merge pull request #26 from dOrgTech/v3-develop
Merge v3 Develop to v3 Master
2 parents b184317 + e3c1ca1 commit bf9e091

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

registrydao/handlers/on_unstake_vote.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,22 @@ async def on_unstake_vote(
1616
) -> None:
1717
try:
1818
dao_address = unstake_vote.data.target_address
19+
proposal_key = unstake_vote.parameter.__root__[0]
20+
21+
dao = await models.DAO.get(address=dao_address)
22+
proposal = await models.Proposal.get(key=proposal_key, dao=dao)
23+
24+
voter = await models.Holder.get_or_create(address=unstake_vote.data.sender_address)
25+
1926
await update_ledger(dao_address, unstake_vote.data.diffs)
27+
28+
votes = await models.Vote.filter(proposal=proposal, voter=voter[0])
29+
30+
for vote in votes:
31+
vote.staked = False
32+
await vote.save()
33+
2034
except Exception as e:
21-
print("Error in on_unstake_vote: " + str(unstake_vote.data.target_address))
22-
print(e)
35+
print("Error in on_unstake_vote: " +
36+
str(unstake_vote.data.target_address))
37+
print(e)

registrydao/handlers/on_vote.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ async def on_vote(
3333
support=support,
3434
voter=voter[0],
3535
defaults={
36-
'amount':amount
37-
}
36+
'amount': amount
37+
},
38+
staked=True
3839
)
3940

4041
if support:
4142
proposal.upvotes = float(proposal.upvotes) + float(amount)
4243
else:
4344
proposal.downvotes = float(proposal.downvotes) + float(amount)
44-
45+
4546
await proposal.save()
4647
except Exception as e:
4748
print("Error in on_vote: " + str(vote.data.target_address))
48-
print(e)
49+
print(e)

registrydao/models.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class RegistryExtra(Model):
8787
class Meta:
8888
table = 'registry_extra'
8989

90+
9091
class TreasuryExtra(Model):
9192
id = fields.IntField(pk=True)
9293
dao: fields.ForeignKeyRelation[DAOType] = fields.ForeignKeyField(
@@ -102,6 +103,7 @@ class TreasuryExtra(Model):
102103
class Meta:
103104
table = 'treasury_extra'
104105

106+
105107
class LambdaExtra(Model):
106108
id = fields.IntField(pk=True)
107109
dao: fields.ForeignKeyRelation[DAOType] = fields.ForeignKeyField(
@@ -120,6 +122,7 @@ class LambdaExtra(Model):
120122
class Meta:
121123
table = 'lambda_extra'
122124

125+
123126
class Holder(Model):
124127
id = fields.IntField(pk=True)
125128
address = fields.CharField(36, unique=True)
@@ -148,6 +151,7 @@ class Meta:
148151
table = 'ledger'
149152
unique_together = (("dao", "holder"),)
150153

154+
151155
class ProposalStatus(Model):
152156
id = fields.IntField(pk=True)
153157
description = fields.CharField(36)
@@ -162,8 +166,8 @@ class Proposal(Model):
162166
dao: fields.ForeignKeyRelation[DAO] = fields.ForeignKeyField(
163167
"models.DAO"
164168
)
165-
hash=fields.CharField(128)
166-
key=fields.CharField(128)
169+
hash = fields.CharField(128)
170+
key = fields.CharField(128)
167171
upvotes = fields.DecimalField(54, 18)
168172
downvotes = fields.DecimalField(54, 18)
169173
start_level = fields.IntField()
@@ -172,9 +176,9 @@ class Proposal(Model):
172176
proposer: fields.ForeignKeyRelation[Holder] = fields.ForeignKeyField(
173177
"models.Holder"
174178
)
175-
voting_stage_num=fields.CharField(50)
176-
proposer_frozen_token=fields.CharField(50)
177-
quorum_threshold=fields.DecimalField(54, 18)
179+
voting_stage_num = fields.CharField(50)
180+
proposer_frozen_token = fields.CharField(50)
181+
quorum_threshold = fields.DecimalField(54, 18)
178182
votes: fields.ReverseRelation["Vote"]
179183
status_updates: fields.ReverseRelation["ProposalStatusUpdates"]
180184

@@ -188,6 +192,7 @@ class Vote(Model):
188192
"models.Proposal"
189193
)
190194
amount = fields.DecimalField(54, 18)
195+
staked = fields.BooleanField()
191196
support = fields.BooleanField()
192197
voter: fields.ForeignKeyRelation[Holder] = fields.ForeignKeyField(
193198
"models.Holder"
@@ -196,6 +201,7 @@ class Vote(Model):
196201
class Meta:
197202
table = 'votes'
198203

204+
199205
class Transfer(Model):
200206
id = fields.IntField(pk=True)
201207
timestamp = fields.DatetimeField()
@@ -208,6 +214,7 @@ class Transfer(Model):
208214
from_address = fields.CharField(36)
209215
hash = fields.CharField(128)
210216

217+
211218
class ProposalStatusUpdates(Model):
212219
id = fields.IntField(pk=True)
213220
timestamp = fields.DatetimeField()

0 commit comments

Comments
 (0)