Skip to content

Commit

Permalink
Create governance.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 1, 2024
1 parent 93053e5 commit c3b945b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/governance/governance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Governance:
def __init__(self):
self.proposals = {} # proposal_id -> Proposal
self.proposal_count = 0

def create_proposal(self, title, description, proposer):
self.proposal_count += 1
proposal_id = self.proposal_count
proposal = Proposal(proposal_id, title, description, proposer)
self.proposals[proposal_id] = proposal
print(f"Proposal created: {title} (ID: {proposal_id}) by {proposer}.")
return proposal_id

def get_proposal(self, proposal_id):
return self.proposals.get(proposal_id)

def get_all_proposals(self):
return self.proposals.values()

class Proposal:
def __init__(self, proposal_id, title, description, proposer):
self.proposal_id = proposal_id
self.title = title
self.description = description
self.proposer = proposer
self.votes = {} # voter -> vote (True for yes, False for no)
self.status = "Pending"

def vote(self, voter, support):
if self.status != "Pending":
print("Voting is closed for this proposal.")
return
self.votes[voter] = support
print(f"{voter} voted {'yes' if support else 'no'} on proposal {self.proposal_id}.")

def tally_votes(self):
if self.status != "Pending":
print("Voting is closed for this proposal.")
return
yes_votes = sum(1 for vote in self.votes.values() if vote)
no_votes = len(self.votes) - yes_votes
self.status = "Passed" if yes_votes > no_votes else "Rejected"
print(f"Proposal {self.proposal_id} has been {self.status}. Yes: {yes_votes}, No: {no_votes}.")

0 comments on commit c3b945b

Please sign in to comment.