Skip to content

Commit

Permalink
Introduce changeable magnitude weight factors for polling
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Oct 20, 2024
1 parent c6b0d35 commit 4826292
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/gridcoin/voting/result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "gridcoin/protocol.h"
#include "main.h"
#include "gridcoin/beacon.h"
#include "gridcoin/quorum.h"
Expand Down Expand Up @@ -1133,6 +1134,20 @@ CAmount ResolveMoneySupplyForPoll(const Poll& poll)

return pindex->nMoneySupply;
}

Fraction ResolveMagnitudeWeightFactorForPoll(const Poll& poll)
{
Fraction magnitude_weight_factor(100, 567);

if (!poll.Expired(pindexBest->nTime)) {
ProtocolEntryOption protocol_entry = GetProtocolRegistry().Try("magnitudeweightfactor");

if (protocol_entry != nullptr) {
magnitude_weight_factor = Fraction().FromString(protocol_entry->m_value);
}
}
}

} // Anonymous namespace

// -----------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,22 @@ class Fraction {
return strprintf("%" PRId64 "/" "%" PRId64, m_numerator, m_denominator);
}

Fraction FromString(const std::string& string) const
{
std::vector<std::string> string_fraction = split(string, "/");

int64_t numerator;
int64_t denominator;

if (string_fraction.size() != 2
|| !ParseInt64(string_fraction[0], &numerator)
|| !ParseInt64(string_fraction[1], &denominator)) {
throw std::out_of_range("Fraction input string cannot be parsed to fraction.");
}

return Fraction(numerator, denominator);
}

bool operator!()
{
return IsZero();
Expand Down

0 comments on commit 4826292

Please sign in to comment.