Skip to content

Commit

Permalink
[Spork] CSporkManager class serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Sep 23, 2019
1 parent cd33d3c commit 806f607
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ CSporkManager sporkManager;

std::map<uint256, CSporkMessage> mapSporks;

void CSporkManager::Clear()
{
strMasterPrivKey = "";
mapSporksActive.clear();
}

// PIVX: on startup load spork values from previous session if they exist in the sporkDB
void CSporkManager::LoadSporksFromDB()
{
Expand Down Expand Up @@ -213,6 +219,12 @@ bool CSporkManager::SetPrivKey(std::string strPrivKey)
return false;
}

std::string CSporkManager::ToString() const
{
LOCK(cs);
return strprintf("Sporks: %llu", mapSporksActive.size());
}

bool CSporkMessage::Sign(std::string strSignKey)
{
std::string strMessage = std::to_string(nSporkID) + std::to_string(nValue) + std::to_string(nTimeSigned);
Expand Down
14 changes: 12 additions & 2 deletions src/spork.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,23 @@ class CSporkMessage
class CSporkManager
{
private:
CCriticalSection cs;
std::vector<unsigned char> vchSig;
mutable CCriticalSection cs;
std::string strMasterPrivKey;
std::map<int, CSporkMessage> mapSporksActive;

public:
CSporkManager() {}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
{
READWRITE(mapSporksActive);
// we don't serialize private key to prevent its leakage
}

void Clear();
void LoadSporksFromDB();

void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
Expand All @@ -120,6 +129,7 @@ class CSporkManager
int GetSporkIDByName(std::string strName);

bool SetPrivKey(std::string strPrivKey);
std::string ToString() const;
};

#endif

0 comments on commit 806f607

Please sign in to comment.