Skip to content

Commit

Permalink
fix: Weighted votes
Browse files Browse the repository at this point in the history
  • Loading branch information
clockworkgr committed Mar 8, 2024
1 parent dda0c20 commit f5997f6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions database/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,16 @@ WHERE proposal_deposit.height <= excluded.height`
// SaveVote allows to save for the given height and the message vote
func (db *Db) SaveVote(vote types.Vote) error {
query := `
INSERT INTO proposal_vote (proposal_id, voter_address, option, timestamp, height)
VALUES ($1, $2, $3, $4, $5)`
INSERT INTO proposal_vote (proposal_id, voter_address, option, weight, timestamp, height)
VALUES ($1, $2, $3, $4, $5, $6)`

// Store the voter account
err := db.SaveAccounts([]types.Account{types.NewAccount(vote.Voter)})
if err != nil {
return fmt.Errorf("error while storing voter account: %s", err)
}

_, err = db.SQL.Exec(query, vote.ProposalID, vote.Voter, vote.Option.String(), vote.Timestamp, vote.Height)
_, err = db.SQL.Exec(query, vote.ProposalID, vote.Voter, vote.Option.String(), vote.Weight, vote.Timestamp, vote.Height)
if err != nil {
return fmt.Errorf("error while storing vote: %s", err)
}
Expand Down
1 change: 1 addition & 0 deletions database/schema/08-gov.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ CREATE TABLE proposal_vote
proposal_id INTEGER NOT NULL REFERENCES proposal (id),
voter_address TEXT NOT NULL REFERENCES account (address),
option TEXT NOT NULL,
weight TEXT NOT NULL,
timestamp TIMESTAMP,
height BIGINT NOT NULL
);
Expand Down
2 changes: 2 additions & 0 deletions modules/gov/handle_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (m *Module) HandleMsg(index int, msg sdk.Msg, tx *juno.Tx) error {
return m.handleMsgDeposit(tx, cosmosMsg)
case *govtypes.MsgVote:
return m.handleMsgVote(tx, cosmosMsg)
case *govtypes.MsgVoteWeighted:
return m.handleMsgVoteWeighted(tx, cosmosMsg)
}

return nil
Expand Down

0 comments on commit f5997f6

Please sign in to comment.