Skip to content

Commit

Permalink
add group winner edge
Browse files Browse the repository at this point in the history
  • Loading branch information
n13 committed Oct 11, 2023
1 parent 076fdfb commit 0745b17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/upvote_election/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace links {
inline constexpr auto NEXT_ROUND = eosio::name("ue.nextrnd");
inline constexpr auto ROUND_CANDIDATE = eosio::name("ue.candidate");
inline constexpr auto ROUND_WINNER = eosio::name("ue.winner");
inline constexpr auto GROUP_WINNER = eosio::name("ue.group.win");
inline constexpr auto ELECTION_GROUP = eosio::name("ue.elctngrp");
inline constexpr auto UP_VOTE_VOTE = eosio::name("ue.vote");
inline constexpr auto UPVOTE_GROUP_WINNER = eosio::name("ue.winner");
Expand Down
11 changes: 9 additions & 2 deletions src/upvote_election/election_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,18 @@ void ElectionGroup::vote(int64_t from, int64_t to)
majorityWinner = to;
}
}

std::vector<Edge> winnerEdges = getDao().getGraph().getEdgesFrom(getId(), links::GROUP_WINNER);
if (winnerEdges.size() > 0) {
winnerEdges[0].erase();
}

if (majorityWinner > 0 && selfVotes[majorityWinner]) {
setWinner(majorityWinner);
update();
Edge(getDao().get_self(), getDao().get_self(), getId(), majorityWinner, links::GROUP_WINNER);
} else {
setWinner(-1);
}
update();

}

Expand Down

0 comments on commit 0745b17

Please sign in to comment.