Fix sign comparison warning & replace unsigned int with uint32_t for nIn.
[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 <map>
8 #include "util.h"
9 #include "net.h"
10
11 // max 1 hour before latest block
12 static const int64_t CHECKPOINT_MAX_SPAN = nOneHour;
13
14 class uint256;
15 class CBlockIndex;
16 class CSyncCheckpoint;
17
18 // Block-chain checkpoints are compiled-in sanity checks.
19 // They are updated every release or three.
20 namespace Checkpoints
21 {
22     // Checkpointing mode
23     enum CPMode
24     {
25         // Scrict checkpoints policy, perform conflicts verification and resolve conflicts
26         CP_STRICT = 0,
27         // Advisory checkpoints policy, perform conflicts verification but don't try to resolve them
28         CP_ADVISORY = 1,
29         // Permissive checkpoints policy, don't perform any checking
30         CP_PERMISSIVE = 2
31     };
32
33     // Returns true if block passes checkpoint checks
34     bool CheckHardened(int nHeight, const uint256& hash);
35
36     // Returns true if block passes banlist checks
37     bool CheckBanned(const uint256 &nHash);
38
39     // Return conservative estimate of total number of blocks, 0 if unknown
40     int GetTotalBlocksEstimate();
41
42     // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
43     CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
44
45     // Returns last checkpoint timestamp
46     unsigned int GetLastCheckpointTime();
47
48     extern uint256 hashSyncCheckpoint;
49     extern CSyncCheckpoint checkpointMessage;
50     extern uint256 hashInvalidCheckpoint;
51     extern CCriticalSection cs_hashSyncCheckpoint;
52
53     CBlockIndex* GetLastSyncCheckpoint();
54     bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
55     bool AcceptPendingSyncCheckpoint();
56     uint256 AutoSelectSyncCheckpoint();
57     bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
58     bool WantedByPendingSyncCheckpoint(const uint256 &hashBlock);
59     bool ResetSyncCheckpoint();
60     void AskForPendingSyncCheckpoint(CNode* pfrom);
61     bool SetCheckpointPrivKey(const std::string &strPrivKey);
62     bool SendSyncCheckpoint(const uint256 &hashCheckpoint);
63     bool IsMatureSyncCheckpoint();
64 }
65
66 // ppcoin: synchronized checkpoint
67 class CUnsignedSyncCheckpoint
68 {
69 public:
70     int32_t nVersion;
71     uint256 hashCheckpoint;      // checkpoint block
72
73     IMPLEMENT_SERIALIZE
74     (
75         READWRITE(this->nVersion);
76         nVersion = this->nVersion;
77         READWRITE(hashCheckpoint);
78     )
79
80     void SetNull();
81     std::string ToString() const;
82 };
83
84 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
85 {
86 public:
87     static const std::string strMasterPubKey;
88     static std::string strMasterPrivKey;
89
90     std::vector<unsigned char> vchMsg;
91     std::vector<unsigned char> vchSig;
92
93     CSyncCheckpoint();
94
95     IMPLEMENT_SERIALIZE
96     (
97         READWRITE(vchMsg);
98         READWRITE(vchSig);
99     )
100
101     void SetNull();
102     bool IsNull() const;
103     uint256 GetHash() const;
104     bool RelayTo(CNode* pnode) const;
105     bool CheckSignature();
106     bool ProcessSyncCheckpoint(CNode* pfrom);
107 };
108
109 #endif