2016-08-17 09:08:25 +02:00
|
|
|
// Copyright (c) 2014-2016 The Dash Core developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
//#define ENABLE_DASH_DEBUG
|
|
|
|
|
|
|
|
#include "governance-classes.h"
|
|
|
|
|
|
|
|
#include "core_io.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "init.h"
|
|
|
|
#include "chainparams.h"
|
|
|
|
|
|
|
|
#include "consensus/consensus.h"
|
|
|
|
#include "consensus/merkle.h"
|
|
|
|
#include "consensus/validation.h"
|
|
|
|
|
|
|
|
#include "governance.h"
|
|
|
|
#include "masternode.h"
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <univalue.h>
|
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
// DECLARE GLOBAL VARIABLES FOR GOVERNANCE CLASSES
|
|
|
|
CGovernanceTriggerManager triggerman;
|
|
|
|
|
|
|
|
// SPLIT UP STRING BY DELIMITER
|
2016-10-22 18:52:14 +02:00
|
|
|
// http://www.boost.org/doc/libs/1_58_0/doc/html/boost/algorithm/split_idp202406848.html
|
2016-08-17 09:08:25 +02:00
|
|
|
std::vector<std::string> SplitBy(std::string strCommand, std::string strDelimit)
|
|
|
|
{
|
|
|
|
std::vector<std::string> vParts;
|
|
|
|
boost::split(vParts, strCommand, boost::is_any_of(strDelimit));
|
|
|
|
|
|
|
|
for(int q=0; q<(int)vParts.size(); q++) {
|
|
|
|
if(strDelimit.find(vParts[q]) != std::string::npos) {
|
|
|
|
vParts.erase(vParts.begin()+q);
|
|
|
|
--q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vParts;
|
|
|
|
}
|
|
|
|
|
|
|
|
CAmount ParsePaymentAmount(const std::string& strAmount)
|
|
|
|
{
|
|
|
|
DBG( cout << "ParsePaymentAmount Start: strAmount = " << strAmount << endl; );
|
|
|
|
|
|
|
|
CAmount nAmount = 0;
|
|
|
|
if (strAmount.empty()) {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "ParsePaymentAmount: Amount is empty";
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
if(strAmount.size() > 20) {
|
|
|
|
// String is much too long, the functions below impose stricter
|
|
|
|
// requirements
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "ParsePaymentAmount: Amount string too long";
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
// Make sure the string makes sense as an amount
|
|
|
|
// Note: No spaces allowed
|
|
|
|
// Also note: No scientific notation
|
|
|
|
size_t pos = strAmount.find_first_not_of("0123456789.");
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "ParsePaymentAmount: Amount string contains invalid character";
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pos = strAmount.find(".");
|
2016-09-12 09:40:00 +02:00
|
|
|
if (pos == 0) {
|
2016-08-17 09:08:25 +02:00
|
|
|
// JSON doesn't allow values to start with a decimal point
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "ParsePaymentAmount: Invalid amount string, leading decimal point not allowed";
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure there's no more than 1 decimal point
|
|
|
|
if ((pos != std::string::npos) && (strAmount.find(".", pos+1) != std::string::npos)) {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "ParsePaymentAmount: Invalid amount string, too many decimal points";
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note this code is taken from AmountFromValue in rpcserver.cpp
|
|
|
|
// which is used for parsing the amounts in createrawtransaction.
|
|
|
|
if (!ParseFixedPoint(strAmount, 8, &nAmount)) {
|
|
|
|
nAmount = 0;
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "ParsePaymentAmount: ParseFixedPoint failed for string: " << strAmount;
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
if (!MoneyRange(nAmount)) {
|
|
|
|
nAmount = 0;
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "ParsePaymentAmount: Invalid amount string, value outside of valid money range";
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DBG( cout << "ParsePaymentAmount Returning true nAmount = " << nAmount << endl; );
|
|
|
|
|
|
|
|
return nAmount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add Governance Object
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool CGovernanceTriggerManager::AddNewTrigger(uint256 nHash)
|
|
|
|
{
|
|
|
|
DBG( cout << "CGovernanceTriggerManager::AddNewTrigger: Start" << endl; );
|
|
|
|
AssertLockHeld(governance.cs);
|
|
|
|
|
|
|
|
// IF WE ALREADY HAVE THIS HASH, RETURN
|
2016-09-12 09:40:00 +02:00
|
|
|
if(mapTrigger.count(nHash)) {
|
|
|
|
DBG(
|
2016-08-17 09:08:25 +02:00
|
|
|
cout << "CGovernanceTriggerManager::AddNewTrigger: Already have hash"
|
|
|
|
<< ", nHash = " << nHash.GetHex()
|
|
|
|
<< ", count = " << mapTrigger.count(nHash)
|
|
|
|
<< ", mapTrigger.size() = " << mapTrigger.size()
|
|
|
|
<< endl; );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
CSuperblock_sptr pSuperblock;
|
2016-08-17 09:08:25 +02:00
|
|
|
try {
|
2016-09-12 09:40:00 +02:00
|
|
|
CSuperblock_sptr pSuperblockTmp(new CSuperblock(nHash));
|
|
|
|
pSuperblock = pSuperblockTmp;
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
2016-09-12 09:40:00 +02:00
|
|
|
catch(std::exception& e) {
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "CGovernanceTriggerManager::AddNewTrigger Error creating superblock"
|
|
|
|
<< ", e.what() = " << e.what()
|
|
|
|
<< endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
LogPrintf("CGovernanceTriggerManager::AddNewTrigger -- Error creating superblock: %s\n", e.what());
|
2016-08-17 09:08:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-12 09:40:00 +02:00
|
|
|
catch(...) {
|
2016-08-17 09:08:25 +02:00
|
|
|
LogPrintf("CGovernanceTriggerManager::AddNewTrigger: Unknown Error creating superblock\n");
|
|
|
|
DBG( cout << "CGovernanceTriggerManager::AddNewTrigger Error creating superblock catchall" << endl; );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
pSuperblock->SetStatus(SEEN_OBJECT_IS_VALID);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
DBG( cout << "CGovernanceTriggerManager::AddNewTrigger: Inserting trigger" << endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
mapTrigger.insert(std::make_pair(nHash, pSuperblock));
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
DBG( cout << "CGovernanceTriggerManager::AddNewTrigger: End" << endl; );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Clean And Remove
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CGovernanceTriggerManager::CleanAndRemove()
|
|
|
|
{
|
2016-11-05 17:13:30 +01:00
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Start\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: Start" << endl; );
|
|
|
|
AssertLockHeld(governance.cs);
|
|
|
|
|
|
|
|
// LOOK AT THESE OBJECTS AND COMPILE A VALID LIST OF TRIGGERS
|
2016-09-12 09:40:00 +02:00
|
|
|
for(trigger_m_it it = mapTrigger.begin(); it != mapTrigger.end(); ++it) {
|
2016-08-17 09:08:25 +02:00
|
|
|
//int nNewStatus = -1;
|
|
|
|
CGovernanceObject* pObj = governance.FindGovernanceObject((*it).first);
|
2016-09-12 09:40:00 +02:00
|
|
|
if(!pObj) {
|
2016-08-17 09:08:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-09-12 09:40:00 +02:00
|
|
|
CSuperblock_sptr& pSuperblock = it->second;
|
|
|
|
if(!pSuperblock) {
|
2016-08-17 09:08:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// IF THIS ISN'T A TRIGGER, WHY ARE WE HERE?
|
|
|
|
if(pObj->GetObjectType() != GOVERNANCE_OBJECT_TRIGGER) {
|
2016-09-12 09:40:00 +02:00
|
|
|
pSuperblock->SetStatus(SEEN_OBJECT_ERROR_INVALID);
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove triggers that are invalid or already executed
|
|
|
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: mapTrigger.size() = " << mapTrigger.size() << endl; );
|
2016-11-05 17:13:30 +01:00
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- mapTrigger.size() = %d\n", mapTrigger.size());
|
2016-08-17 09:08:25 +02:00
|
|
|
trigger_m_it it = mapTrigger.begin();
|
2016-09-12 09:40:00 +02:00
|
|
|
while(it != mapTrigger.end()) {
|
2016-08-17 09:08:25 +02:00
|
|
|
bool remove = false;
|
2016-09-12 09:40:00 +02:00
|
|
|
CSuperblock_sptr& pSuperblock = it->second;
|
|
|
|
if(!pSuperblock) {
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: NULL superblock marked for removal " << endl; );
|
2016-11-05 17:13:30 +01:00
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- NULL superblock marked for removal\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
remove = true;
|
2016-09-12 09:40:00 +02:00
|
|
|
} else {
|
|
|
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: superblock status = " << pSuperblock->GetStatus() << endl; );
|
2016-11-05 17:13:30 +01:00
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- superblock status = %d\n", pSuperblock->GetStatus());
|
2016-09-12 09:40:00 +02:00
|
|
|
switch(pSuperblock->GetStatus()) {
|
2016-08-17 09:08:25 +02:00
|
|
|
case SEEN_OBJECT_ERROR_INVALID:
|
|
|
|
case SEEN_OBJECT_UNKNOWN:
|
2016-11-05 17:13:30 +01:00
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Unknown or invalid trigger found\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
remove = true;
|
|
|
|
break;
|
|
|
|
case SEEN_OBJECT_IS_VALID:
|
2016-12-03 20:46:08 +01:00
|
|
|
case SEEN_OBJECT_EXECUTED:
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
2016-09-12 09:40:00 +02:00
|
|
|
int nTriggerBlock = pSuperblock->GetBlockStart();
|
2016-10-30 20:36:52 +01:00
|
|
|
// Rough approximation: a cycle of superblock ++
|
2016-12-03 20:46:08 +01:00
|
|
|
int nExpirationBlock = nTriggerBlock + GOVERNANCE_TRIGGER_EXPIRATION_BLOCKS;
|
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- nTriggerBlock = %d, nExpirationBlock = %d\n", nTriggerBlock, nExpirationBlock);
|
2016-09-12 09:40:00 +02:00
|
|
|
if(governance.GetCachedBlockHeight() > nExpirationBlock) {
|
2016-11-05 17:13:30 +01:00
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Outdated trigger found\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
remove = true;
|
2016-09-12 09:40:00 +02:00
|
|
|
CGovernanceObject* pgovobj = pSuperblock->GetGovernanceObject();
|
|
|
|
if(pgovobj) {
|
2016-11-05 17:13:30 +01:00
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Expiring outdated object: %s\n", pgovobj->GetHash().ToString());
|
2016-09-12 09:40:00 +02:00
|
|
|
pgovobj->fExpired = true;
|
2016-11-18 15:17:00 +01:00
|
|
|
pgovobj->nDeletionTime = GetAdjustedTime();
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-12 09:40:00 +02:00
|
|
|
|
|
|
|
if(remove) {
|
|
|
|
DBG(
|
2016-08-17 09:08:25 +02:00
|
|
|
string strdata = "NULL";
|
2016-09-12 09:40:00 +02:00
|
|
|
CGovernanceObject* pgovobj = pSuperblock->GetGovernanceObject();
|
|
|
|
if(pgovobj) {
|
|
|
|
strdata = pgovobj->GetDataAsString();
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
2016-09-12 09:40:00 +02:00
|
|
|
cout << "CGovernanceTriggerManager::CleanAndRemove: Removing object: "
|
2016-08-17 09:08:25 +02:00
|
|
|
<< strdata
|
|
|
|
<< endl;
|
|
|
|
);
|
2016-11-05 17:13:30 +01:00
|
|
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Removing trigger object\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
mapTrigger.erase(it++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: End" << endl; );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Active Triggers
|
|
|
|
*
|
|
|
|
* - Look through triggers and scan for active ones
|
|
|
|
* - Return the triggers in a list
|
|
|
|
*/
|
|
|
|
|
|
|
|
std::vector<CSuperblock_sptr> CGovernanceTriggerManager::GetActiveTriggers()
|
|
|
|
{
|
|
|
|
AssertLockHeld(governance.cs);
|
|
|
|
std::vector<CSuperblock_sptr> vecResults;
|
|
|
|
|
|
|
|
DBG( cout << "GetActiveTriggers: mapTrigger.size() = " << mapTrigger.size() << endl; );
|
|
|
|
|
|
|
|
// LOOK AT THESE OBJECTS AND COMPILE A VALID LIST OF TRIGGERS
|
|
|
|
trigger_m_it it = mapTrigger.begin();
|
|
|
|
while(it != mapTrigger.end()) {
|
|
|
|
|
|
|
|
CGovernanceObject* pObj = governance.FindGovernanceObject((*it).first);
|
|
|
|
|
|
|
|
if(pObj) {
|
|
|
|
DBG( cout << "GetActiveTriggers: pObj->GetDataAsString() = " << pObj->GetDataAsString() << endl; );
|
|
|
|
vecResults.push_back(it->second);
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG( cout << "GetActiveTriggers: vecResults.size() = " << vecResults.size() << endl; );
|
|
|
|
|
|
|
|
return vecResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is Superblock Triggered
|
|
|
|
*
|
|
|
|
* - Does this block have a non-executed and actived trigger?
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool CSuperblockManager::IsSuperblockTriggered(int nBlockHeight)
|
|
|
|
{
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- Start nBlockHeight = %d\n", nBlockHeight);
|
2016-08-22 03:41:40 +02:00
|
|
|
if (!CSuperblock::IsValidBlockHeight(nBlockHeight)) {
|
2016-08-17 09:08:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCK(governance.cs);
|
|
|
|
// GET ALL ACTIVE TRIGGERS
|
|
|
|
std::vector<CSuperblock_sptr> vecTriggers = triggerman.GetActiveTriggers();
|
|
|
|
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- vecTriggers.size() = %d\n", vecTriggers.size());
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "IsSuperblockTriggered Number triggers = " << vecTriggers.size() << endl; );
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
BOOST_FOREACH(CSuperblock_sptr pSuperblock, vecTriggers)
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
2016-09-12 09:40:00 +02:00
|
|
|
if(!pSuperblock) {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrintf("CSuperblockManager::IsSuperblockTriggered -- Non-superblock found, continuing\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "IsSuperblockTriggered Not a superblock, continuing " << endl; );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
CGovernanceObject* pObj = pSuperblock->GetGovernanceObject();
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
if(!pObj) {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrintf("CSuperblockManager::IsSuperblockTriggered -- pObj == NULL, continuing\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "IsSuperblockTriggered pObj is NULL, continuing" << endl; );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- data = %s\n", pObj->GetDataAsString());
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
// note : 12.1 - is epoch calculation correct?
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
if(nBlockHeight != pSuperblock->GetBlockStart()) {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- block height doesn't match nBlockHeight = %d, blockStart = %d, continuing\n",
|
|
|
|
nBlockHeight,
|
|
|
|
pSuperblock->GetBlockStart());
|
2016-09-12 09:40:00 +02:00
|
|
|
DBG( cout << "IsSuperblockTriggered Not the target block, continuing"
|
2016-10-17 20:54:28 +02:00
|
|
|
<< ", nBlockHeight = " << nBlockHeight
|
|
|
|
<< ", superblock->GetBlockStart() = " << pSuperblock->GetBlockStart()
|
|
|
|
<< endl; );
|
2016-08-17 09:08:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MAKE SURE THIS TRIGGER IS ACTIVE VIA FUNDING CACHE FLAG
|
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
if(pObj->IsSetCachedFunding()) {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- fCacheFunding = true, returning true\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "IsSuperblockTriggered returning true" << endl; );
|
|
|
|
return true;
|
2016-09-12 09:40:00 +02:00
|
|
|
}
|
2016-08-17 09:08:25 +02:00
|
|
|
else {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- fCacheFunding = false, continuing\n");
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "IsSuperblockTriggered No fCachedFunding, continuing" << endl; );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
bool CSuperblockManager::GetBestSuperblock(CSuperblock_sptr& pSuperblockRet, int nBlockHeight)
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
2016-08-22 03:41:40 +02:00
|
|
|
if(!CSuperblock::IsValidBlockHeight(nBlockHeight)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
AssertLockHeld(governance.cs);
|
|
|
|
std::vector<CSuperblock_sptr> vecTriggers = triggerman.GetActiveTriggers();
|
|
|
|
int nYesCount = 0;
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
BOOST_FOREACH(CSuperblock_sptr pSuperblock, vecTriggers) {
|
|
|
|
if(!pSuperblock) {
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "GetBestSuperblock Not a superblock, continuing" << endl; );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
CGovernanceObject* pObj = pSuperblock->GetGovernanceObject();
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
if(!pObj) {
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "GetBestSuperblock pObj is NULL, continuing" << endl; );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
if(nBlockHeight != pSuperblock->GetBlockStart()) {
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "GetBestSuperblock Not the target block, continuing" << endl; );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DO WE HAVE A NEW WINNER?
|
|
|
|
|
|
|
|
int nTempYesCount = pObj->GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING);
|
|
|
|
DBG( cout << "GetBestSuperblock nTempYesCount = " << nTempYesCount << endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
if(nTempYesCount > nYesCount) {
|
2016-08-17 09:08:25 +02:00
|
|
|
nYesCount = nTempYesCount;
|
2016-09-12 09:40:00 +02:00
|
|
|
pSuperblockRet = pSuperblock;
|
|
|
|
DBG( cout << "GetBestSuperblock Valid superblock found, pSuperblock set" << endl; );
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nYesCount > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create Superblock Payments
|
|
|
|
*
|
|
|
|
* - Create the correct payment structure for a given superblock
|
|
|
|
*/
|
|
|
|
|
2016-08-28 12:11:36 +02:00
|
|
|
void CSuperblockManager::CreateSuperblock(CMutableTransaction& txNewRet, int nBlockHeight, std::vector<CTxOut>& voutSuperblockRet)
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock Start" << endl; );
|
|
|
|
|
|
|
|
LOCK(governance.cs);
|
|
|
|
|
|
|
|
// GET THE BEST SUPERBLOCK FOR THIS BLOCK HEIGHT
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
CSuperblock_sptr pSuperblock;
|
|
|
|
if(!CSuperblockManager::GetBestSuperblock(pSuperblock, nBlockHeight)) {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblockManager::CreateSuperblock -- Can't find superblock for height %d\n", nBlockHeight);
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock Failed to get superblock for height, returning" << endl; );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-28 12:11:36 +02:00
|
|
|
// make sure it's empty, just in case
|
|
|
|
voutSuperblockRet.clear();
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-28 12:11:36 +02:00
|
|
|
// CONFIGURE SUPERBLOCK OUTPUTS
|
2016-08-19 13:53:49 +02:00
|
|
|
|
2016-08-28 12:11:36 +02:00
|
|
|
// Superblock payments are appended to the end of the coinbase vout vector
|
2016-09-12 09:40:00 +02:00
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock Number payments: " << pSuperblock->CountPayments() << endl; );
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
// TODO: How many payments can we add before things blow up?
|
|
|
|
// Consider at least following limits:
|
|
|
|
// - max coinbase tx size
|
|
|
|
// - max "budget" available
|
2016-09-12 09:40:00 +02:00
|
|
|
for(int i = 0; i < pSuperblock->CountPayments(); i++) {
|
2016-08-17 09:08:25 +02:00
|
|
|
CGovernancePayment payment;
|
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock i = " << i << endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
if(pSuperblock->GetPayment(i, payment)) {
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock Payment found " << endl; );
|
|
|
|
// SET COINBASE OUTPUT TO SUPERBLOCK SETTING
|
|
|
|
|
2016-08-28 12:11:36 +02:00
|
|
|
CTxOut txout = CTxOut(payment.nAmount, payment.script);
|
|
|
|
txNewRet.vout.push_back(txout);
|
|
|
|
voutSuperblockRet.push_back(txout);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
// PRINT NICE LOG OUTPUT FOR SUPERBLOCK PAYMENT
|
|
|
|
|
|
|
|
CTxDestination address1;
|
|
|
|
ExtractDestination(payment.script, address1);
|
|
|
|
CBitcoinAddress address2(address1);
|
|
|
|
|
|
|
|
// TODO: PRINT NICE N.N DASH OUTPUT
|
|
|
|
|
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock Before LogPrintf call, nAmount = " << payment.nAmount << endl; );
|
|
|
|
LogPrintf("NEW Superblock : output %d (addr %s, amount %d)\n", i, address2.ToString(), payment.nAmount);
|
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock After LogPrintf call " << endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
} else {
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock Payment not found " << endl; );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG( cout << "CSuperblockManager::CreateSuperblock End" << endl; );
|
|
|
|
}
|
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
bool CSuperblockManager::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
|
|
|
// GET BEST SUPERBLOCK, SHOULD MATCH
|
|
|
|
LOCK(governance.cs);
|
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
CSuperblock_sptr pSuperblock;
|
|
|
|
if(CSuperblockManager::GetBestSuperblock(pSuperblock, nBlockHeight)) {
|
|
|
|
return pSuperblock->IsValid(txNew, nBlockHeight, blockReward);
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSuperblock::
|
|
|
|
CSuperblock()
|
|
|
|
: nGovObjHash(),
|
|
|
|
nEpochStart(0),
|
|
|
|
nStatus(SEEN_OBJECT_UNKNOWN),
|
|
|
|
vecPayments()
|
|
|
|
{}
|
|
|
|
|
|
|
|
CSuperblock::
|
|
|
|
CSuperblock(uint256& nHash)
|
|
|
|
: nGovObjHash(nHash),
|
|
|
|
nEpochStart(0),
|
|
|
|
nStatus(SEEN_OBJECT_UNKNOWN),
|
|
|
|
vecPayments()
|
|
|
|
{
|
|
|
|
DBG( cout << "CSuperblock Constructor Start" << endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
CGovernanceObject* pGovObj = GetGovernanceObject();
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
if(!pGovObj) {
|
|
|
|
DBG( cout << "CSuperblock Constructor pGovObjIn is NULL, returning" << endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error("CSuperblock: Failed to find Governance Object");
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "CSuperblock Constructor pGovObj : "
|
|
|
|
<< pGovObj->GetDataAsString()
|
2016-11-13 18:52:34 +01:00
|
|
|
<< ", nObjectType = " << pGovObj->GetObjectType()
|
2016-08-17 09:08:25 +02:00
|
|
|
<< endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
if (pGovObj->GetObjectType() != GOVERNANCE_OBJECT_TRIGGER) {
|
|
|
|
DBG( cout << "CSuperblock Constructor pHoObj not a trigger, returning" << endl; );
|
2016-09-12 09:40:00 +02:00
|
|
|
throw std::runtime_error("CSuperblock: Governance Object not a trigger");
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UniValue obj = pGovObj->GetJSONObject();
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
// FIRST WE GET THE START EPOCH, THE DATE WHICH THE PAYMENT SHALL OCCUR
|
2016-08-29 00:08:27 +02:00
|
|
|
nEpochStart = obj["event_block_height"].get_int();
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
// NEXT WE GET THE PAYMENT INFORMATION AND RECONSTRUCT THE PAYMENT VECTOR
|
|
|
|
std::string strAddresses = obj["payment_addresses"].get_str();
|
|
|
|
std::string strAmounts = obj["payment_amounts"].get_str();
|
|
|
|
ParsePaymentSchedule(strAddresses, strAmounts);
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblock -- nEpochStart = %d, strAddresses = %s, strAmounts = %s, vecPayments.size() = %d\n",
|
|
|
|
nEpochStart, strAddresses, strAmounts, vecPayments.size());
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
DBG( cout << "CSuperblock Constructor End" << endl; );
|
|
|
|
}
|
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
/**
|
|
|
|
* Is Valid Superblock Height
|
|
|
|
*
|
|
|
|
* - See if a block at this height can be a superblock
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool CSuperblock::IsValidBlockHeight(int nBlockHeight)
|
|
|
|
{
|
|
|
|
// SUPERBLOCKS CAN HAPPEN ONLY after hardfork and only ONCE PER CYCLE
|
|
|
|
return nBlockHeight >= Params().GetConsensus().nSuperblockStartBlock &&
|
|
|
|
((nBlockHeight % Params().GetConsensus().nSuperblockCycle) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight)
|
|
|
|
{
|
|
|
|
const Consensus::Params& consensusParams = Params().GetConsensus();
|
|
|
|
|
|
|
|
if(!IsValidBlockHeight(nBlockHeight)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// min subsidy for high diff networks and vice versa
|
|
|
|
int nBits = consensusParams.fPowAllowMinDifficultyBlocks ? UintToArith256(consensusParams.powLimit).GetCompact() : 1;
|
|
|
|
// some part of all blocks issued during the cycle goes to superblock, see GetBlockSubsidy
|
|
|
|
CAmount nSuperblockPartOfSubsidy = GetBlockSubsidy(nBits, nBlockHeight, consensusParams, true);
|
|
|
|
CAmount nPaymentsLimit = nSuperblockPartOfSubsidy * consensusParams.nSuperblockCycle;
|
|
|
|
LogPrint("gobject", "CSuperblock::GetPaymentsLimit -- Valid superblock height %d, payments max %lld\n", nBlockHeight, nPaymentsLimit);
|
|
|
|
|
|
|
|
return nPaymentsLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSuperblock::ParsePaymentSchedule(std::string& strPaymentAddresses, std::string& strPaymentAmounts)
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
|
|
|
// SPLIT UP ADDR/AMOUNT STRINGS AND PUT IN VECTORS
|
|
|
|
|
|
|
|
std::vector<std::string> vecParsed1;
|
|
|
|
std::vector<std::string> vecParsed2;
|
|
|
|
vecParsed1 = SplitBy(strPaymentAddresses, "|");
|
|
|
|
vecParsed2 = SplitBy(strPaymentAmounts, "|");
|
|
|
|
|
|
|
|
// IF THESE DONT MATCH, SOMETHING IS WRONG
|
|
|
|
|
|
|
|
if (vecParsed1.size() != vecParsed2.size()) {
|
|
|
|
std::ostringstream ostr;
|
2016-10-17 20:54:28 +02:00
|
|
|
ostr << "CSuperblock::ParsePaymentSchedule -- Mismatched payments and amounts";
|
|
|
|
LogPrintf("%s\n", ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vecParsed1.size() == 0) {
|
|
|
|
std::ostringstream ostr;
|
2016-10-17 20:54:28 +02:00
|
|
|
ostr << "CSuperblock::ParsePaymentSchedule -- Error no payments";
|
|
|
|
LogPrintf("%s\n", ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// LOOP THROUGH THE ADDRESSES/AMOUNTS AND CREATE PAYMENTS
|
|
|
|
/*
|
2016-09-12 09:40:00 +02:00
|
|
|
ADDRESSES = [ADDR1|2|3|4|5|6]
|
|
|
|
AMOUNTS = [AMOUNT1|2|3|4|5|6]
|
2016-08-17 09:08:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
DBG( cout << "CSuperblock::ParsePaymentSchedule vecParsed1.size() = " << vecParsed1.size() << endl; );
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)vecParsed1.size(); i++) {
|
|
|
|
CBitcoinAddress address(vecParsed1[i]);
|
2016-09-12 09:40:00 +02:00
|
|
|
if (!address.IsValid()) {
|
2016-08-17 09:08:25 +02:00
|
|
|
std::ostringstream ostr;
|
2016-10-17 20:54:28 +02:00
|
|
|
ostr << "CSuperblock::ParsePaymentSchedule -- Invalid Dash Address : " << vecParsed1[i];
|
|
|
|
LogPrintf("%s\n", ostr.str());
|
2016-08-17 09:08:25 +02:00
|
|
|
throw std::runtime_error(ostr.str());
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
DBG( cout << "CSuperblock::ParsePaymentSchedule i = " << i
|
2016-08-17 09:08:25 +02:00
|
|
|
<< ", vecParsed2[i] = " << vecParsed2[i]
|
|
|
|
<< endl; );
|
|
|
|
|
|
|
|
CAmount nAmount = ParsePaymentAmount(vecParsed2[i]);
|
|
|
|
|
|
|
|
DBG( cout << "CSuperblock::ParsePaymentSchedule: "
|
|
|
|
<< "amount string = " << vecParsed2[i]
|
|
|
|
<< ", nAmount = " << nAmount
|
|
|
|
<< endl; );
|
|
|
|
|
|
|
|
CGovernancePayment payment(address, nAmount);
|
|
|
|
if(payment.IsValid()) {
|
|
|
|
vecPayments.push_back(payment);
|
|
|
|
}
|
2016-10-17 20:54:28 +02:00
|
|
|
else {
|
|
|
|
vecPayments.clear();
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "CSuperblock::ParsePaymentSchedule -- Invalid payment found: address = " << address.ToString()
|
|
|
|
<< ", amount = " << nAmount;
|
|
|
|
LogPrintf("%s\n", ostr.str());
|
|
|
|
throw std::runtime_error(ostr.str());
|
|
|
|
}
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
bool CSuperblock::GetPayment(int nPaymentIndex, CGovernancePayment& paymentRet)
|
|
|
|
{
|
|
|
|
if((nPaymentIndex<0) || (nPaymentIndex >= (int)vecPayments.size())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
paymentRet = vecPayments[nPaymentIndex];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CAmount CSuperblock::GetPaymentsTotalAmount()
|
|
|
|
{
|
|
|
|
CAmount nPaymentsTotalAmount = 0;
|
|
|
|
int nPayments = CountPayments();
|
|
|
|
|
|
|
|
for(int i = 0; i < nPayments; i++) {
|
|
|
|
nPaymentsTotalAmount += vecPayments[i].nAmount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nPaymentsTotalAmount;
|
|
|
|
}
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is Transaction Valid
|
|
|
|
*
|
|
|
|
* - Does this transaction match the superblock?
|
|
|
|
*/
|
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
bool CSuperblock::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
|
|
|
// TODO : LOCK(cs);
|
|
|
|
// No reason for a lock here now since this method only accesses data
|
|
|
|
// internal to *this and since CSuperblock's are accessed only through
|
|
|
|
// shared pointers there's no way our object can get deleted while this
|
|
|
|
// code is running.
|
2016-08-22 03:41:40 +02:00
|
|
|
if(!IsValidBlockHeight(nBlockHeight)) {
|
|
|
|
LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid, incorrect block height\n");
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
std::string strPayeesPossible = "";
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
// CONFIGURE SUPERBLOCK OUTPUTS
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-19 13:53:49 +02:00
|
|
|
int nOutputs = txNew.vout.size();
|
|
|
|
int nPayments = CountPayments();
|
|
|
|
int nMinerPayments = nOutputs - nPayments;
|
|
|
|
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblock::IsValid nOutputs = %d, nPayments = %d, strData = %s\n",
|
2016-11-13 18:52:34 +01:00
|
|
|
nOutputs, nPayments, GetGovernanceObject()->GetDataAsHex());
|
2016-10-17 20:54:28 +02:00
|
|
|
|
2016-08-19 13:53:49 +02:00
|
|
|
// We require an exact match (including order) between the expected
|
|
|
|
// superblock payments and the payments actually in the block, after
|
|
|
|
// skipping any initial miner payments.
|
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
if(nMinerPayments < 0) {
|
2016-08-19 13:53:49 +02:00
|
|
|
// This means the block cannot have all the superblock payments
|
|
|
|
// so it is not valid.
|
2016-08-22 03:41:40 +02:00
|
|
|
// TODO: could that be that we just hit coinbase size limit?
|
|
|
|
LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid, too few superblock payments\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// payments should not exceed limit
|
|
|
|
CAmount nPaymentsTotalAmount = GetPaymentsTotalAmount();
|
|
|
|
CAmount nPaymentsLimit = GetPaymentsLimit(nBlockHeight);
|
|
|
|
if(nPaymentsTotalAmount > nPaymentsLimit) {
|
|
|
|
LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid, payments limit exceeded: payments %lld, limit %lld\n", nPaymentsTotalAmount, nPaymentsLimit);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// miner should not get more than he would usually get
|
|
|
|
CAmount nBlockValue = txNew.GetValueOut();
|
|
|
|
if(nBlockValue > blockReward + nPaymentsTotalAmount) {
|
|
|
|
LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid, block value limit exceeded: block %lld, limit %lld\n", nBlockValue, blockReward + nPaymentsTotalAmount);
|
2016-08-19 13:53:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
for(int i = 0; i < nPayments; i++) {
|
|
|
|
CGovernancePayment payment;
|
2016-08-22 03:41:40 +02:00
|
|
|
if(!GetPayment(i, payment)) {
|
2016-08-19 13:53:49 +02:00
|
|
|
// This shouldn't happen so log a warning
|
2016-08-22 03:41:40 +02:00
|
|
|
LogPrintf("CSuperblock::IsValid -- WARNING: Failed to find payment: %d of %d total payments\n", i, nPayments);
|
2016-08-19 13:53:49 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-19 13:53:49 +02:00
|
|
|
int nVoutIndex = nMinerPayments + i;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-19 13:53:49 +02:00
|
|
|
bool fPaymentMatch = ((payment.script == txNew.vout[nVoutIndex].scriptPubKey) &&
|
|
|
|
(payment.nAmount == txNew.vout[nVoutIndex].nValue));
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
if(!fPaymentMatch) {
|
2016-08-19 13:53:49 +02:00
|
|
|
// MISMATCHED SUPERBLOCK OUTPUT!
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-19 13:53:49 +02:00
|
|
|
CTxDestination address1;
|
|
|
|
ExtractDestination(payment.script, address1);
|
|
|
|
CBitcoinAddress address2(address1);
|
2016-10-22 18:52:14 +02:00
|
|
|
LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid: output n %d payment %d to %s\n", nVoutIndex, payment.nAmount, address2.ToString());
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-19 13:53:49 +02:00
|
|
|
return false;
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Required Payment String
|
|
|
|
*
|
|
|
|
* - Get a string representing the payments required for a given superblock
|
|
|
|
*/
|
|
|
|
|
|
|
|
std::string CSuperblockManager::GetRequiredPaymentsString(int nBlockHeight)
|
|
|
|
{
|
|
|
|
LOCK(governance.cs);
|
|
|
|
std::string ret = "Unknown";
|
|
|
|
|
|
|
|
// GET BEST SUPERBLOCK
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
CSuperblock_sptr pSuperblock;
|
|
|
|
if(!GetBestSuperblock(pSuperblock, nBlockHeight)) {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrint("gobject", "CSuperblockManager::GetRequiredPaymentsString -- Can't find superblock for height %d\n", nBlockHeight);
|
2016-08-17 09:08:25 +02:00
|
|
|
return "error";
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
// LOOP THROUGH SUPERBLOCK PAYMENTS, CONFIGURE OUTPUT STRING
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
for(int i = 0; i < pSuperblock->CountPayments(); i++) {
|
2016-08-17 09:08:25 +02:00
|
|
|
CGovernancePayment payment;
|
2016-09-12 09:40:00 +02:00
|
|
|
if(pSuperblock->GetPayment(i, payment)) {
|
2016-08-17 09:08:25 +02:00
|
|
|
// PRINT NICE LOG OUTPUT FOR SUPERBLOCK PAYMENT
|
|
|
|
|
|
|
|
CTxDestination address1;
|
|
|
|
ExtractDestination(payment.script, address1);
|
|
|
|
CBitcoinAddress address2(address1);
|
|
|
|
|
|
|
|
// RETURN NICE OUTPUT FOR CONSOLE
|
|
|
|
|
|
|
|
if(ret != "Unknown") {
|
|
|
|
ret += ", " + address2.ToString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret = address2.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|