Dash Core  0.12.2.1
P2P Digital Currency
spork.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2017 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef SPORK_H
6 #define SPORK_H
7 
8 #include "hash.h"
9 #include "net.h"
10 #include "utilstrencodings.h"
11 
12 class CSporkMessage;
13 class CSporkManager;
14 
15 /*
16  Don't ever reuse these IDs for other sporks
17  - This would result in old clients getting confused about which spork is for what
18 */
19 static const int SPORK_START = 10001;
20 static const int SPORK_END = 10013;
21 
22 static const int SPORK_2_INSTANTSEND_ENABLED = 10001;
23 static const int SPORK_3_INSTANTSEND_BLOCK_FILTERING = 10002;
24 static const int SPORK_5_INSTANTSEND_MAX_VALUE = 10004;
25 static const int SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT = 10007;
26 static const int SPORK_9_SUPERBLOCKS_ENABLED = 10008;
27 static const int SPORK_10_MASTERNODE_PAY_UPDATED_NODES = 10009;
28 static const int SPORK_12_RECONSIDER_BLOCKS = 10011;
29 static const int SPORK_13_OLD_SUPERBLOCK_FLAG = 10012;
30 static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013;
31 
32 static const int64_t SPORK_2_INSTANTSEND_ENABLED_DEFAULT = 0; // ON
33 static const int64_t SPORK_3_INSTANTSEND_BLOCK_FILTERING_DEFAULT = 0; // ON
34 static const int64_t SPORK_5_INSTANTSEND_MAX_VALUE_DEFAULT = 1000; // 1000 DASH
35 static const int64_t SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT_DEFAULT = 4070908800ULL;// OFF
36 static const int64_t SPORK_9_SUPERBLOCKS_ENABLED_DEFAULT = 4070908800ULL;// OFF
37 static const int64_t SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT = 4070908800ULL;// OFF
38 static const int64_t SPORK_12_RECONSIDER_BLOCKS_DEFAULT = 0; // 0 BLOCKS
39 static const int64_t SPORK_13_OLD_SUPERBLOCK_FLAG_DEFAULT = 4070908800ULL;// OFF
40 static const int64_t SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT = 4070908800ULL;// OFF
41 
42 extern std::map<uint256, CSporkMessage> mapSporks;
44 
45 //
46 // Spork classes
47 // Keep track of all of the network spork settings
48 //
49 
51 {
52 private:
53  std::vector<unsigned char> vchSig;
54 
55 public:
56  int nSporkID;
57  int64_t nValue;
58  int64_t nTimeSigned;
59 
60  CSporkMessage(int nSporkID, int64_t nValue, int64_t nTimeSigned) :
62  nValue(nValue),
64  {}
65 
67  nSporkID(0),
68  nValue(0),
69  nTimeSigned(0)
70  {}
71 
72 
74 
75  template <typename Stream, typename Operation>
76  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
81  }
82 
83  uint256 GetHash() const
84  {
86  ss << nSporkID;
87  ss << nValue;
88  ss << nTimeSigned;
89  return ss.GetHash();
90  }
91 
92  bool Sign(std::string strSignKey);
93  bool CheckSignature();
94  void Relay(CConnman& connman);
95 };
96 
97 
99 {
100 private:
101  std::vector<unsigned char> vchSig;
102  std::string strMasterPrivKey;
103  std::map<int, CSporkMessage> mapSporksActive;
104 
105 public:
106 
108 
109  void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman);
110  void ExecuteSpork(int nSporkID, int nValue);
111  bool UpdateSpork(int nSporkID, int64_t nValue, CConnman& connman);
112 
113  bool IsSporkActive(int nSporkID);
114  int64_t GetSporkValue(int nSporkID);
115  int GetSporkIDByName(std::string strName);
116  std::string GetSporkNameByID(int nSporkID);
117 
118  bool SetPrivKey(std::string strPrivKey);
119 };
120 
121 #endif
void ProcessSpork(CNode *pfrom, std::string &strCommand, CDataStream &vRecv, CConnman &connman)
Definition: spork.cpp:20
static const int64_t SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT
Definition: spork.h:40
static const int64_t SPORK_9_SUPERBLOCKS_ENABLED_DEFAULT
Definition: spork.h:36
static const int64_t SPORK_5_INSTANTSEND_MAX_VALUE_DEFAULT
Definition: spork.h:34
static const int SPORK_10_MASTERNODE_PAY_UPDATED_NODES
Definition: spork.h:27
std::map< uint256, CSporkMessage > mapSporks
Definition: spork.cpp:18
#define READWRITE(obj)
Definition: serialize.h:175
static const int SPORK_3_INSTANTSEND_BLOCK_FILTERING
Definition: spork.h:23
static const int SPORK_5_INSTANTSEND_MAX_VALUE
Definition: spork.h:24
int nSporkID
Definition: spork.h:56
std::vector< unsigned char > vchSig
Definition: spork.h:53
static const int SPORK_9_SUPERBLOCKS_ENABLED
Definition: spork.h:26
bool CheckSignature()
Definition: spork.cpp:245
Definition: net.h:108
int GetSporkIDByName(std::string strName)
Definition: spork.cpp:170
CSporkManager()
Definition: spork.h:107
std::string GetSporkNameByID(int nSporkID)
Definition: spork.cpp:186
std::vector< unsigned char > vchSig
Definition: spork.h:101
int64_t nTimeSigned
Definition: spork.h:58
int64_t nValue
Definition: spork.h:57
uint256 GetHash()
Definition: hash.h:254
CSporkManager sporkManager
Definition: spork.cpp:14
Definition: net.h:661
std::map< int, CSporkMessage > mapSporksActive
Definition: spork.h:103
static const int SPORK_13_OLD_SUPERBLOCK_FLAG
Definition: spork.h:29
std::string strMasterPrivKey
Definition: spork.h:102
uint256 GetHash() const
Definition: spork.h:83
static const int SPORK_END
Definition: spork.h:20
static const int SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT
Definition: spork.h:25
bool Sign(std::string strSignKey)
Definition: spork.cpp:220
ADD_SERIALIZE_METHODS
Definition: spork.h:73
void Relay(CConnman &connman)
Definition: spork.cpp:260
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: spork.h:76
static const int SPORK_12_RECONSIDER_BLOCKS
Definition: spork.h:28
bool UpdateSpork(int nSporkID, int64_t nValue, CConnman &connman)
Definition: spork.cpp:104
static const int SPORK_14_REQUIRE_SENTINEL_FLAG
Definition: spork.h:30
CSporkMessage(int nSporkID, int64_t nValue, int64_t nTimeSigned)
Definition: spork.h:60
static const int64_t SPORK_13_OLD_SUPERBLOCK_FLAG_DEFAULT
Definition: spork.h:39
static const int64_t SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT_DEFAULT
Definition: spork.h:35
static const int PROTOCOL_VERSION
Definition: version.h:13
static const int64_t SPORK_3_INSTANTSEND_BLOCK_FILTERING_DEFAULT
Definition: spork.h:33
void ExecuteSpork(int nSporkID, int nValue)
Definition: spork.cpp:75
static const int64_t SPORK_2_INSTANTSEND_ENABLED_DEFAULT
Definition: spork.h:32
bool SetPrivKey(std::string strPrivKey)
Definition: spork.cpp:204
bool IsSporkActive(int nSporkID)
Definition: spork.cpp:120
static const int64_t SPORK_12_RECONSIDER_BLOCKS_DEFAULT
Definition: spork.h:38
static const int SPORK_START
Definition: spork.h:19
int64_t GetSporkValue(int nSporkID)
Definition: spork.cpp:148
static const int SPORK_2_INSTANTSEND_ENABLED
Definition: spork.h:22
static const int64_t SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT
Definition: spork.h:37
CSporkMessage()
Definition: spork.h:66