Skip to content

Commit

Permalink
Fix spork RPC to use new spork defs
Browse files Browse the repository at this point in the history
This also removes the need for SPORK_START/SPORK_END
  • Loading branch information
random-zebra committed Sep 23, 2019
1 parent fd05256 commit 50bfe70
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
20 changes: 9 additions & 11 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <univalue.h>

extern std::vector<CSporkDef> sporkDefs;


/**
* @note Do not add or change anything in the information returned by this
Expand Down Expand Up @@ -289,27 +291,23 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
*/
UniValue spork(const UniValue& params, bool fHelp)
{
SporkId nSporkID;
if (params.size() == 1 && params[0].get_str() == "show") {
UniValue ret(UniValue::VOBJ);
for (int i = SPORK_START; i <= SPORK_END; i++) {
nSporkID = (SporkId) i;
if (sporkManager.GetSporkNameByID((SporkId) nSporkID) != "Unknown")
ret.push_back(Pair(sporkManager.GetSporkNameByID(nSporkID), sporkManager.GetSporkValue(nSporkID)));
for (const auto& sporkDef : sporkDefs) {
ret.push_back(Pair(sporkDef.name, sporkManager.GetSporkValue(sporkDef.sporkId)));
}
return ret;
} else if (params.size() == 1 && params[0].get_str() == "active") {
UniValue ret(UniValue::VOBJ);
for (int i = SPORK_START; i <= SPORK_END; i++) {
nSporkID = (SporkId) i;
if (sporkManager.GetSporkNameByID(nSporkID) != "Unknown")
ret.push_back(Pair(sporkManager.GetSporkNameByID(nSporkID), sporkManager.IsSporkActive(nSporkID)));
for (const auto& sporkDef : sporkDefs) {
ret.push_back(Pair(sporkDef.name, sporkManager.IsSporkActive(sporkDef.sporkId)));
}
return ret;
} else if (params.size() == 2) {
nSporkID = sporkManager.GetSporkIDByName(params[0].get_str());
// advanced mode, update spork values
SporkId nSporkID = sporkManager.GetSporkIDByName(params[0].get_str());
if (nSporkID == SPORK_INVALID) {
return "Invalid spork name";
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid spork name");
}

// SPORK VALUE
Expand Down
21 changes: 6 additions & 15 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
#include "spork.h"
#include "sporkdb.h"

class CSporkMessage;
class CSporkManager;

CSporkManager sporkManager;

std::map<uint256, CSporkMessage> mapSporks;

#define MAKE_SPORK_DEF(name, defaultValue) CSporkDef(name, defaultValue, #name)

Expand All @@ -31,6 +25,9 @@ std::vector<CSporkDef> sporkDefs = {
MAKE_SPORK_DEF(SPORK_16_ZEROCOIN_MAINTENANCE_MODE, 4070908800ULL), // OFF
};

CSporkManager sporkManager;
std::map<uint256, CSporkMessage> mapSporks;

CSporkManager::CSporkManager()
{
for (auto& sporkDef : sporkDefs) {
Expand All @@ -48,17 +45,11 @@ void CSporkManager::Clear()
// PIVX: on startup load spork values from previous session if they exist in the sporkDB
void CSporkManager::LoadSporksFromDB()
{
SporkId id;
for (int i = SPORK_START; i <= SPORK_END; ++i) {
id = (SporkId) i;
// Since not all spork IDs are in use, we have to exclude undefined IDs
std::string strSpork = sporkManager.GetSporkNameByID(id);
if (strSpork == "Unknown") continue;

for (const auto& sporkDef : sporkDefs) {
// attempt to read spork from sporkDB
CSporkMessage spork;
if (!pSporkDB->ReadSpork(id, spork)) {
LogPrintf("%s : no previous value for %s found in database\n", __func__, strSpork);
if (!pSporkDB->ReadSpork(sporkDef.sporkId, spork)) {
LogPrintf("%s : no previous value for %s found in database\n", __func__, sporkDef.name);
continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/spork.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class CSporkMessage;
class CSporkManager;

extern std::vector<CSporkDef> sporkDefs;
extern std::map<uint256, CSporkMessage> mapSporks;
extern CSporkManager sporkManager;

Expand Down
2 changes: 0 additions & 2 deletions src/sporkid.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ enum SporkId : int32_t {
SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2 = 10014,
SPORK_16_ZEROCOIN_MAINTENANCE_MODE = 10015,

SPORK_START = SPORK_2_SWIFTTX,
SPORK_END = SPORK_16_ZEROCOIN_MAINTENANCE_MODE,
SPORK_INVALID = -1
};

Expand Down

0 comments on commit 50bfe70

Please sign in to comment.