Update CMakeLists.txt - play with openssl
[novacoin.git] / src / checkpoints.h
1 // Copyright (c) 2009-2012 The Bitcoin 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 #ifndef BITCOIN_CHECKPOINT_H
5 #define  BITCOIN_CHECKPOINT_H
6
7 #include "util.h"
8 #include "serialize.h"
9 #include "sync.h"
10 #include "uint256.h"
11
12 #include <map>
13
14 // max 1 hour before latest block
15 static const int64_t CHECKPOINT_MAX_SPAN = nOneHour;
16
17 #ifdef WIN32
18 #undef STRICT
19 #undef PERMISSIVE
20 #undef ADVISORY
21 #endif
22
23 class CBlockIndex;
24 class CSyncCheckpoint;
25 class CNode;
26
27 /** Block-chain checkpoints are compiled-in sanity checks.
28  * They are updated every release or three.
29  */
30 namespace Checkpoints
31 {
32     /** Checkpointing mode */
33     enum CPMode
34     {
35         // Scrict checkpoints policy, perform conflicts verification and resolve conflicts
36         STRICT = 0,
37         // Advisory checkpoints policy, perform conflicts verification but don't try to resolve them
38         ADVISORY = 1,
39         // Permissive checkpoints policy, don't perform any checking
40         PERMISSIVE = 2
41     };
42
43     // Returns true if block passes checkpoint checks
44     bool CheckHardened(int nHeight, const uint256& hash);
45
46     // Returns true if block passes banlist checks
47     bool CheckBanned(const uint256 &nHash);
48
49     // Return conservative estimate of total number of blocks, 0 if unknown
50     int GetTotalBlocksEstimate();
51
52     // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
53     CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
54
55     // Returns last checkpoint timestamp
56     unsigned int GetLastCheckpointTime();
57
58     extern uint256 hashSyncCheckpoint;
59     extern CSyncCheckpoint checkpointMessage;
60     extern uint256 hashInvalidCheckpoint;
61     extern CCriticalSection cs_hashSyncCheckpoint;
62
63     CBlockIndex* GetLastSyncCheckpoint();
64     bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
65     bool AcceptPendingSyncCheckpoint();
66     uint256 AutoSelectSyncCheckpoint();
67     bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
68     bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
69     bool ResetSyncCheckpoint();
70     void AskForPendingSyncCheckpoint(CNode* pfrom);
71     bool SetCheckpointPrivKey(std::string strPrivKey);
72     bool SendSyncCheckpoint(uint256 hashCheckpoint);
73     bool IsMatureSyncCheckpoint();
74 }
75
76 // ppcoin: synchronized checkpoint
77 class CUnsignedSyncCheckpoint
78 {
79 public:
80     int nVersion;
81     uint256 hashCheckpoint;      // checkpoint block
82
83     IMPLEMENT_SERIALIZE
84     (
85         READWRITE(this->nVersion);
86         nVersion = this->nVersion;
87         READWRITE(hashCheckpoint);
88     )
89
90     void SetNull()
91     {
92         nVersion = 1;
93         hashCheckpoint = 0;
94     }
95
96     std::string ToString() const
97     {
98         return strprintf(
99                 "CSyncCheckpoint(\n"
100                 "    nVersion       = %d\n"
101                 "    hashCheckpoint = %s\n"
102                 ")\n",
103             nVersion,
104             hashCheckpoint.ToString().c_str());
105     }
106 };
107
108 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
109 {
110 public:
111     static const std::string strMasterPubKey;
112     static std::string strMasterPrivKey;
113
114     std::vector<unsigned char> vchMsg;
115     std::vector<unsigned char> vchSig;
116
117     CSyncCheckpoint();
118
119     IMPLEMENT_SERIALIZE
120     (
121         READWRITE(vchMsg);
122         READWRITE(vchSig);
123     )
124
125     void SetNull();
126     bool IsNull() const;
127     uint256 GetHash() const;
128     bool RelayTo(CNode* pnode) const;
129     bool CheckSignature();
130     bool ProcessSyncCheckpoint(CNode* pfrom);
131 };
132
133 #endif