dash/src/spork.h

120 lines
3.8 KiB
C
Raw Normal View History

2016-12-20 14:26:45 +01:00
// Copyright (c) 2014-2017 The Dash Core developers
2015-02-09 21:54:51 +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-09 21:54:51 +01:00
#ifndef SPORK_H
#define SPORK_H
#include "hash.h"
#include "net.h"
#include "utilstrencodings.h"
2015-04-03 00:51:08 +02:00
class CSporkMessage;
class CSporkManager;
/*
Don't ever reuse these IDs for other sporks
- This would result in old clients getting confused about which spork is for what
*/
static const int SPORK_START = 10001;
static const int SPORK_END = 10013;
static const int SPORK_2_INSTANTSEND_ENABLED = 10001;
static const int SPORK_3_INSTANTSEND_BLOCK_FILTERING = 10002;
static const int SPORK_5_INSTANTSEND_MAX_VALUE = 10004;
static const int SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT = 10007;
static const int SPORK_9_SUPERBLOCKS_ENABLED = 10008;
static const int SPORK_10_MASTERNODE_PAY_UPDATED_NODES = 10009;
static const int SPORK_12_RECONSIDER_BLOCKS = 10011;
static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013;
static const int64_t SPORK_2_INSTANTSEND_ENABLED_DEFAULT = 0; // ON
static const int64_t SPORK_3_INSTANTSEND_BLOCK_FILTERING_DEFAULT = 0; // ON
static const int64_t SPORK_5_INSTANTSEND_MAX_VALUE_DEFAULT = 1000; // 1000 DASH
2016-12-14 14:33:46 +01:00
static const int64_t SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT_DEFAULT = 4070908800ULL;// OFF
static const int64_t SPORK_9_SUPERBLOCKS_ENABLED_DEFAULT = 4070908800ULL;// OFF
static const int64_t SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT = 4070908800ULL;// OFF
static const int64_t SPORK_12_RECONSIDER_BLOCKS_DEFAULT = 0; // 0 BLOCKS
2016-12-14 14:33:46 +01:00
static const int64_t SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT = 4070908800ULL;// OFF
2015-02-09 21:54:51 +01:00
extern std::map<uint256, CSporkMessage> mapSporks;
extern CSporkManager sporkManager;
//
// Spork classes
// Keep track of all of the network spork settings
2015-02-09 21:54:51 +01:00
//
class CSporkMessage
{
private:
2015-02-09 21:54:51 +01:00
std::vector<unsigned char> vchSig;
public:
2015-02-09 21:54:51 +01:00
int nSporkID;
2015-02-11 15:47:21 +01:00
int64_t nValue;
2015-02-09 21:54:51 +01:00
int64_t nTimeSigned;
CSporkMessage(int nSporkID, int64_t nValue, int64_t nTimeSigned) :
nSporkID(nSporkID),
nValue(nValue),
nTimeSigned(nTimeSigned)
{}
CSporkMessage() :
nSporkID(0),
nValue(0),
nTimeSigned(0)
{}
2015-02-09 21:54:51 +01:00
2015-04-03 00:51:08 +02:00
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
2015-02-09 21:54:51 +01:00
READWRITE(nSporkID);
2015-02-11 15:47:21 +01:00
READWRITE(nValue);
2015-02-09 21:54:51 +01:00
READWRITE(nTimeSigned);
READWRITE(vchSig);
2015-04-03 00:51:08 +02:00
}
uint256 GetHash() const
{
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
ss << nSporkID;
ss << nValue;
ss << nTimeSigned;
return ss.GetHash();
}
bool Sign(const std::string& strSignKey);
bool CheckSignature();
void Relay(CConnman& connman);
2015-02-09 21:54:51 +01:00
};
class CSporkManager
{
private:
std::vector<unsigned char> vchSig;
std::string strMasterPrivKey;
std::map<int, CSporkMessage> mapSporksActive;
2015-02-09 21:54:51 +01:00
public:
CSporkManager() {}
2015-02-09 21:54:51 +01:00
void ProcessSpork(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
void ExecuteSpork(int nSporkID, int nValue);
bool UpdateSpork(int nSporkID, int64_t nValue, CConnman& connman);
2015-02-09 21:54:51 +01:00
bool IsSporkActive(int nSporkID);
int64_t GetSporkValue(int nSporkID);
int GetSporkIDByName(const std::string& strName);
std::string GetSporkNameByID(int nSporkID);
bool SetPrivKey(const std::string& strPrivKey);
2015-02-09 21:54:51 +01:00
};
2015-04-03 00:51:08 +02:00
#endif