2015-02-24 15:02:22 +01:00
|
|
|
// Copyright (c) 2014-2015 The Darkcoin developers
|
2015-02-23 21:01:21 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2015-02-24 15:02:22 +01:00
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
#ifndef MASTERNODEMAN_H
|
|
|
|
#define MASTERNODEMAN_H
|
|
|
|
|
|
|
|
#include "bignum.h"
|
|
|
|
#include "sync.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "core.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "script.h"
|
|
|
|
#include "base58.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "masternode.h"
|
|
|
|
|
|
|
|
#define MASTERNODES_DUMP_SECONDS (15*60)
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class CMasternodeMan;
|
|
|
|
|
|
|
|
extern CMasternodeMan mnodeman;
|
|
|
|
extern std::vector<CTxIn> vecMasternodeAskedFor;
|
|
|
|
extern map<uint256, CMasternodePaymentWinner> mapSeenMasternodeVotes;
|
|
|
|
extern map<int64_t, uint256> mapCacheBlockHashes;
|
|
|
|
|
|
|
|
void DumpMasternodes();
|
|
|
|
|
|
|
|
/** Access to the MN database (masternodes.dat) */
|
|
|
|
class CMasternodeDB
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
boost::filesystem::path pathMN;
|
|
|
|
public:
|
|
|
|
CMasternodeDB();
|
|
|
|
bool Write(const CMasternodeMan &mnodemanToSave);
|
|
|
|
bool Read(CMasternodeMan& mnodemanToLoad);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CMasternodeMan
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// critical section to protect the inner data structures
|
|
|
|
mutable CCriticalSection cs;
|
|
|
|
|
|
|
|
// map to hold all MNs
|
|
|
|
std::vector<CMasternode> vMasternodes;
|
|
|
|
|
2015-02-24 11:39:29 +01:00
|
|
|
// keep track of latest time whem vMasternodes was changed
|
|
|
|
int64_t lastTimeChanged;
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
IMPLEMENT_SERIALIZE
|
|
|
|
(
|
|
|
|
// serialized format:
|
|
|
|
// * version byte (currently 0)
|
|
|
|
// * masternodes vector
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
unsigned char nVersion = 0;
|
|
|
|
READWRITE(nVersion);
|
2015-02-24 11:39:29 +01:00
|
|
|
READWRITE(lastTimeChanged);
|
2015-02-23 21:01:21 +01:00
|
|
|
READWRITE(vMasternodes);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
CMasternodeMan();
|
|
|
|
CMasternodeMan(CMasternodeMan& other);
|
|
|
|
|
|
|
|
// Find an entry
|
|
|
|
CMasternode* Find(const CTxIn& vin);
|
|
|
|
|
|
|
|
// Find a random entry
|
|
|
|
CMasternode* FindRandom();
|
|
|
|
|
|
|
|
//Find an entry thta do not match every entry provided vector
|
|
|
|
CMasternode* FindNotInVec(const std::vector<CTxIn> &vVins);
|
|
|
|
|
|
|
|
// Add an entry
|
|
|
|
bool Add(CMasternode &mn);
|
|
|
|
|
|
|
|
// Check all masternodes
|
|
|
|
void Check();
|
|
|
|
|
|
|
|
// Check all masternodes and remove inactive
|
|
|
|
void CheckAndRemove();
|
|
|
|
|
|
|
|
// Clear masternode vector
|
2015-02-24 11:39:29 +01:00
|
|
|
void Clear() { vMasternodes.clear(); lastTimeChanged = 0; }
|
2015-02-23 21:01:21 +01:00
|
|
|
|
|
|
|
// Return the number of (unique) masternodes
|
|
|
|
int size() { return vMasternodes.size(); }
|
|
|
|
|
|
|
|
// Get the current winner for this block
|
|
|
|
CMasternode* GetCurrentMasterNode(int mod=1, int64_t nBlockHeight=0, int minProtocol=0);
|
|
|
|
|
|
|
|
int GetMasternodeRank(const CTxIn &vin, int64_t nBlockHeight, int minProtocol=0);
|
|
|
|
|
|
|
|
int CountMasternodesAboveProtocol(int protocolVersion);
|
|
|
|
|
|
|
|
int CountEnabled();
|
|
|
|
|
2015-02-24 11:39:29 +01:00
|
|
|
std::vector<CMasternode> GetFullMasternodeVector() { Check(); return vMasternodes; }
|
2015-02-23 21:01:21 +01:00
|
|
|
|
|
|
|
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
|
|
|
|
2015-02-24 11:39:29 +01:00
|
|
|
void UpdateLastTimeChanged() { lastTimeChanged = GetAdjustedTime(); }
|
|
|
|
|
|
|
|
bool UpdateNeeded() { return lastTimeChanged < GetAdjustedTime() - MASTERNODE_REMOVAL_SECONDS; }
|
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|