From 0745b17c2d1fbf9d57a5925b62b84db4ddceabc7 Mon Sep 17 00:00:00 2001 From: NIK Date: Wed, 11 Oct 2023 19:41:36 +0800 Subject: [PATCH] add group winner edge --- include/upvote_election/common.hpp | 1 + src/upvote_election/election_group.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/upvote_election/common.hpp b/include/upvote_election/common.hpp index a848470..43e58ec 100644 --- a/include/upvote_election/common.hpp +++ b/include/upvote_election/common.hpp @@ -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"); diff --git a/src/upvote_election/election_group.cpp b/src/upvote_election/election_group.cpp index d51a6e4..5d8f036 100644 --- a/src/upvote_election/election_group.cpp +++ b/src/upvote_election/election_group.cpp @@ -124,11 +124,18 @@ void ElectionGroup::vote(int64_t from, int64_t to) majorityWinner = to; } } - + std::vector 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(); }