Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several governance object related fixes: #4

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/governance-classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ std::vector<CGovernanceObject*> CGovernanceTriggerManager::GetActiveTriggers()
{
std::vector<CGovernanceObject*> vecResults;

cout << "GetActiveTriggers: mapTrigger.size() = " << mapTrigger.size() << endl;

// LOOK AT THESE OBJECTS AND COMPILE A VALID LIST OF TRIGGERS
std::map<uint256, int>::iterator it1 = mapTrigger.begin();
while(it1 != mapTrigger.end()){
Expand All @@ -167,12 +169,15 @@ std::vector<CGovernanceObject*> CGovernanceTriggerManager::GetActiveTriggers()

if(pObj)
{
cout << "GetActiveTriggers: pObj->GetDataAsString() = " << pObj->GetDataAsString() << endl;
CSuperblock t(pObj);
vecResults.push_back(&t);
}

++it1;
}

cout << "GetActiveTriggers: vecResults.size() = " << vecResults.size() << endl;

return vecResults;
}

Expand Down Expand Up @@ -201,6 +206,8 @@ bool CSuperblockManager::IsSuperblockTriggered(int nBlockHeight)
std::vector<CGovernanceObject*> vecTriggers = triggerman.GetActiveTriggers();
//int nYesCount = 0;

cout << "Number triggers = " << vecTriggers.size() << endl;

printf("1");

BOOST_FOREACH(CGovernanceObject* pObj, vecTriggers)
Expand Down Expand Up @@ -426,4 +433,4 @@ std::string CSuperblockManager::GetRequiredPaymentsString(int nBlockHeight)
}

return ret;
}
}
31 changes: 26 additions & 5 deletions src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ bool CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj)
LOCK(cs);
std::string strError = "";

cout << "CGovernanceManager::AddGovernanceObject START" << endl;

// MAKE SURE THIS OBJECT IS OK

if(!govobj.IsValidLocally(pCurrentBlockIndex, strError, true)) {
Expand All @@ -292,8 +294,14 @@ bool CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj)

// SHOULD WE ADD THIS OBJECT TO ANY OTHER MANANGERS?

cout << "CGovernanceManager::AddGovernanceObject Before trigger block, strData = "
<< govobj.GetDataAsString()
<< ", nObjectType = " << govobj.nObjectType
<< endl;

if(govobj.nObjectType == GOVERNANCE_OBJECT_TRIGGER)
{
cout << "CGovernanceManager::AddGovernanceObject Before AddNewTrigger" << endl;
triggerman.AddNewTrigger(govobj.GetHash());
}

Expand Down Expand Up @@ -688,7 +696,7 @@ uint256 CGovernanceObject::GetHash()
// fee_tx is left out on purpose
uint256 h1 = ss.GetHash();

printf("%i %s %i %s\n", nRevision, strName, nTime, strData);
printf("%i %s %li %s\n", nRevision, strName.c_str(), nTime, strData.c_str());

return h1;
}
Expand All @@ -704,16 +712,29 @@ uint256 CGovernanceObject::GetHash()
void CGovernanceObject::LoadData()
{
// todo : 12.1
return;
//return;

if(strData.empty()) {
return;
}

// ATTEMPT TO LOAD JSON STRING FROM STRDATA
UniValue objResult(UniValue::VOBJ);
if(!GetData(objResult)) fUnparsable = true;

cout << "CGovernanceObject::LoadData strData = "
<< GetDataAsString()
<< endl;

try
{
// std::string strObjectType = objResult["type"].get_str();
// nObjectType = boost::lexical_cast<int>(strObjectType);
//std::string strObjectType = objResult["type"].get_str();
//nObjectType = boost::lexical_cast<int>(strObjectType);

std::vector<UniValue> arr1 = objResult.getValues();
std::vector<UniValue> arr2 = arr1.at( 0 ).getValues();
UniValue obj = arr2.at( 1 );
nObjectType = obj["type"].get_int();
}
catch (int e)
{
Expand Down Expand Up @@ -789,7 +810,7 @@ std::string CGovernanceObject::GetDataAsString()
vector<unsigned char> v = ParseHex(strData);
string s(v.begin(), v.end());

return strData;
return s;
}

void CGovernanceObject::UpdateLocalValidity(const CBlockIndex *pCurrentBlockIndex)
Expand Down
1 change: 1 addition & 0 deletions src/governance.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class CGovernanceObject
READWRITE(nTime);
READWRITE(nCollateralHash);
READWRITE(strData);
READWRITE(nObjectType);

// AFTER DESERIALIZATION OCCURS, CACHED VARIABLES MUST BE CALCULATED MANUALLY
}
Expand Down
3 changes: 3 additions & 0 deletions src/rpcgovernance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ UniValue gobject(const UniValue& params, bool fHelp)

CGovernanceObject govobj(hashParent, nRevision, strName, nTime, fee_tx, strData);

cout << "gobject: submit strName = " << strName
<< ", strData = " << govobj.GetDataAsString() << endl;

std::string strError = "";
if(!govobj.IsValidLocally(pindex, strError, true)){
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError);
Expand Down