Implement projection of MN reward winners in "masternode winners"
This commit is contained in:
parent
e6b699bc26
commit
44706dc88a
@ -254,13 +254,10 @@ void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blo
|
||||
nBlockHeight, blockReward, voutMasternodeStr, txNew.ToString());
|
||||
}
|
||||
|
||||
std::string GetRequiredPaymentsString(int nBlockHeight)
|
||||
std::string GetLegacyRequiredPaymentsString(int nBlockHeight)
|
||||
{
|
||||
// IF WE HAVE A ACTIVATED TRIGGER FOR THIS HEIGHT - IT IS A SUPERBLOCK, GET THE REQUIRED PAYEES
|
||||
if(CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) {
|
||||
if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) {
|
||||
return mnpayments.GetRequiredPaymentsString(nBlockHeight) + ", " + CSuperblockManager::GetRequiredPaymentsString(nBlockHeight);
|
||||
}
|
||||
return CSuperblockManager::GetRequiredPaymentsString(nBlockHeight);
|
||||
}
|
||||
|
||||
@ -268,6 +265,54 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
|
||||
return mnpayments.GetRequiredPaymentsString(nBlockHeight);
|
||||
}
|
||||
|
||||
std::string GetRequiredPaymentsString(int nBlockHeight, const CDeterministicMNCPtr &payee)
|
||||
{
|
||||
std::string strPayee = "Unknown";
|
||||
if (payee) {
|
||||
CTxDestination dest;
|
||||
if (!ExtractDestination(payee->pdmnState->scriptPayout, dest))
|
||||
assert(false);
|
||||
strPayee = CBitcoinAddress(dest).ToString();
|
||||
}
|
||||
if (CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) {
|
||||
strPayee += ", " + CSuperblockManager::GetRequiredPaymentsString(nBlockHeight);
|
||||
}
|
||||
return strPayee;
|
||||
}
|
||||
|
||||
std::map<int, std::string> GetRequiredPaymentsStrings(int nStartHeight, int nEndHeight)
|
||||
{
|
||||
std::map<int, std::string> mapPayments;
|
||||
|
||||
LOCK(cs_main);
|
||||
int nChainTipHeight = chainActive.Height();
|
||||
|
||||
bool doProjection = false;
|
||||
for(int h = nStartHeight; h < nEndHeight; h++) {
|
||||
if (deterministicMNManager->IsDeterministicMNsSporkActive(h)) {
|
||||
if (h <= nChainTipHeight) {
|
||||
auto payee = deterministicMNManager->GetListForBlock(chainActive[h - 1]->GetBlockHash()).GetMNPayee();
|
||||
mapPayments.emplace(h, GetRequiredPaymentsString(h, payee));
|
||||
} else {
|
||||
doProjection = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
mapPayments.emplace(h, GetLegacyRequiredPaymentsString(h));
|
||||
}
|
||||
}
|
||||
if (doProjection) {
|
||||
auto projection = deterministicMNManager->GetListAtChainTip().GetProjectedMNPayees(nEndHeight - nChainTipHeight);
|
||||
for (size_t i = 0; i < projection.size(); i++) {
|
||||
auto payee = projection[i];
|
||||
int h = nChainTipHeight + 1 + i;
|
||||
mapPayments.emplace(h, GetRequiredPaymentsString(h, payee));
|
||||
}
|
||||
}
|
||||
|
||||
return mapPayments;
|
||||
}
|
||||
|
||||
void CMasternodePayments::Clear()
|
||||
{
|
||||
LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes);
|
||||
@ -731,23 +776,10 @@ std::string CMasternodeBlockPayees::GetRequiredPaymentsString() const
|
||||
|
||||
std::string CMasternodePayments::GetRequiredPaymentsString(int nBlockHeight) const
|
||||
{
|
||||
if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) {
|
||||
LOCK(cs_main);
|
||||
auto pindex = chainActive[nBlockHeight - 1];
|
||||
auto payee = deterministicMNManager->GetListForBlock(pindex->GetBlockHash()).GetMNPayee();
|
||||
if (!payee) {
|
||||
return "Unknown";
|
||||
}
|
||||
CTxDestination dest;
|
||||
if (!ExtractDestination(payee->pdmnState->scriptPayout, dest))
|
||||
assert(false);
|
||||
return CBitcoinAddress(dest).ToString();
|
||||
} else {
|
||||
LOCK(cs_mapMasternodeBlocks);
|
||||
const auto it = mapMasternodeBlocks.find(nBlockHeight);
|
||||
return it == mapMasternodeBlocks.end() ? "Unknown" : it->second.GetRequiredPaymentsString();
|
||||
}
|
||||
}
|
||||
|
||||
bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward) const
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ extern CMasternodePayments mnpayments;
|
||||
bool IsBlockValueValid(const CBlock& block, int nBlockHeight, CAmount blockReward, std::string& strErrorRet);
|
||||
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
|
||||
void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& voutSuperblockPaymentsRet);
|
||||
std::string GetRequiredPaymentsString(int nBlockHeight);
|
||||
std::map<int, std::string> GetRequiredPaymentsStrings(int nStartHeight, int nEndHeight);
|
||||
|
||||
class CMasternodePayee
|
||||
{
|
||||
|
@ -801,11 +801,9 @@ UniValue masternode_winners(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'masternode winners ( \"count\" \"filter\" )'");
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
|
||||
for (int i = nHeight - nLast; i < nHeight + 20; i++) {
|
||||
std::string strPayment = GetRequiredPaymentsString(i);
|
||||
if (strFilter !="" && strPayment.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strprintf("%d", i), strPayment));
|
||||
auto mapPayments = GetRequiredPaymentsStrings(nHeight - nLast, nHeight + 20);
|
||||
for (const auto &p : mapPayments) {
|
||||
obj.push_back(Pair(strprintf("%d", p.first), p.second));
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
Loading…
Reference in New Issue
Block a user