diff --git a/src/masternodes/rpc_proposals.cpp b/src/masternodes/rpc_proposals.cpp index db41c63ef2..ebfff3430d 100644 --- a/src/masternodes/rpc_proposals.cpp +++ b/src/masternodes/rpc_proposals.cpp @@ -6,9 +6,12 @@ const bool DEFAULT_RPC_GOV_NEUTRAL = false; struct VotingInfo { - int32_t votesPossible; - int32_t votesPresent; - int32_t votesYes; + int32_t votesPossible = 0; + int32_t votesPresent = 0; + int32_t votesYes = 0; + int32_t votesNo = 0; + int32_t votesNeutral = 0; + int32_t votesInvalid = 0; }; UniValue proposalToJSON(const CProposalId &propId, @@ -45,6 +48,9 @@ UniValue proposalToJSON(const CProposalId &propId, auto votesPresentPct = -1; auto votesYes = -1; auto votesYesPct = -1; + auto votesNo = -1; + auto votesNeutral = -1; + auto votesInvalid = -1; std::string votesPresentPctString = "-1"; std::string votesYesPctString = "-1"; @@ -52,6 +58,9 @@ UniValue proposalToJSON(const CProposalId &propId, if (isVotingInfoAvailable) { votesPresent = votingInfo->votesPresent; votesYes = votingInfo->votesYes; + votesNo = votingInfo->votesNo; + votesNeutral = votingInfo->votesNeutral; + votesInvalid = votingInfo->votesInvalid; votesPossible = votingInfo->votesPossible; votesPresentPct = lround(votesPresent * 10000.f / votesPossible); @@ -80,14 +89,19 @@ UniValue proposalToJSON(const CProposalId &propId, ret.pushKV("proposalEndHeight", proposalEndHeight); ret.pushKV("votingPeriod", votingPeriod); ret.pushKV("quorum", quorumString); + ret.pushKV("approvalThreshold", approvalThresholdString); if (isVotingInfoAvailable) { ret.pushKV("votesPossible", votesPossible); ret.pushKV("votesPresent", votesPresent); ret.pushKV("votesPresentPct", votesPresentPctString); ret.pushKV("votesYes", votesYes); ret.pushKV("votesYesPct", votesYesPctString); + ret.pushKV("votesNo", votesNo); + ret.pushKV("votesNeutral", votesNeutral); + ret.pushKV("votesInvalid", votesInvalid); + ret.pushKV("feeRedistributionPerVote", ValueFromAmount(DivideAmounts(prop.fee - prop.feeBurnAmount, votesPresent * COIN))); + ret.pushKV("feeRedistributionTotal", ValueFromAmount(MultiplyAmounts(DivideAmounts(prop.fee - prop.feeBurnAmount, votesPresent * COIN), votesPresent * COIN))); } - ret.pushKV("approvalThreshold", approvalThresholdString); ret.pushKV("fee", feeTotalValue); // ret.pushKV("feeBurn", feeBurnValue); if (prop.options) { @@ -768,31 +782,35 @@ UniValue getgovproposal(const JSONRPCRequest &request) { return proposalToJSON(propId, *prop, view, std::nullopt); } - uint32_t voteYes = 0, voters = 0; + VotingInfo info; + info.votesPossible = activeMasternodes.size(); + view.ForEachProposalVote( [&](const CProposalId &pId, uint8_t cycle, const uint256 &mnId, CProposalVoteType vote) { if (pId != propId || cycle != prop->cycle) { return false; } if (activeMasternodes.count(mnId)) { - ++voters; + ++info.votesPresent; if (vote == CProposalVoteType::VoteYes) { - ++voteYes; + ++info.votesYes; + } else if (vote == CProposalVoteType::VoteNo) { + ++info.votesNo; + } else if (vote == CProposalVoteType::VoteNeutral) { + ++info.votesNeutral; } } + else + ++info.votesInvalid; + return true; }, CMnVotePerCycle{propId, prop->cycle}); - if (!voters) { + if (!info.votesPresent) { return proposalToJSON(propId, *prop, view, std::nullopt); } - VotingInfo info; - info.votesPossible = activeMasternodes.size(); - info.votesPresent = voters; - info.votesYes = voteYes; - return proposalToJSON(propId, *prop, view, info); } diff --git a/test/functional/feature_on_chain_government.py b/test/functional/feature_on_chain_government.py index 1ca18500f6..50914ce234 100755 --- a/test/functional/feature_on_chain_government.py +++ b/test/functional/feature_on_chain_government.py @@ -317,6 +317,11 @@ def run_test(self): assert_equal(result["votesPresentPct"], "100.00%") assert_equal(result["votesYes"], Decimal("3")) assert_equal(result["votesYesPct"], "75.00%") + assert_equal(result["votesNo"], Decimal("1")) + assert_equal(result["votesNeutral"], Decimal("0")) + assert_equal(result["votesInvalid"], Decimal("0")) + assert_equal(result["feeRedistributionPerVote"], Decimal("0.625")) + assert_equal(result["feeRedistributionTotal"], Decimal("2.5")) assert_equal(result["approvalThreshold"], "66.67%") assert_equal(result["fee"], Decimal("5")) @@ -544,6 +549,11 @@ def run_test(self): assert_equal(result["votesPresentPct"], "100.00%") assert_equal(result["votesYes"], Decimal("2")) assert_equal(result["votesYesPct"], "50.00%") + assert_equal(result["votesNo"], Decimal("2")) + assert_equal(result["votesNeutral"], Decimal("0")) + assert_equal(result["votesInvalid"], Decimal("0")) + assert_equal(result["feeRedistributionPerVote"], Decimal("2.5")) + assert_equal(result["feeRedistributionTotal"], Decimal("10")) assert_equal(result["approvalThreshold"], "50.00%") assert_equal(result["fee"], Decimal("20")) assert_equal(result["options"], ["emergency"])