1 // Copyright (c) 2009-2012 The Bitcoin developers
2 // Copyright (c) 2011-2012 The PPCoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_CHECKPOINT_H
6 #define BITCOIN_CHECKPOINT_H
12 #define STAKE_MIN_AGE (60 * 60 * 24) // minimum age for coin age
16 class CSyncCheckpoint;
18 /** Block-chain checkpoints are compiled-in sanity checks.
19 * They are updated every release or three.
23 // Returns true if block passes checkpoint checks
24 bool CheckHardened(int nHeight, const uint256& hash);
26 // Return conservative estimate of total number of blocks, 0 if unknown
27 int GetTotalBlocksEstimate();
29 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
30 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
32 extern uint256 hashSyncCheckpoint;
33 extern CSyncCheckpoint checkpointMessage;
34 extern uint256 hashInvalidCheckpoint;
35 extern CCriticalSection cs_hashSyncCheckpoint;
37 CBlockIndex* GetLastSyncCheckpoint();
38 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
39 bool AcceptPendingSyncCheckpoint();
40 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
41 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
42 bool ResetSyncCheckpoint();
43 void AskForPendingSyncCheckpoint(CNode* pfrom);
44 bool SendSyncCheckpoint(uint256 hashCheckpoint);
47 // ppcoin: synchronized checkpoint
48 class CUnsignedSyncCheckpoint
52 uint256 hashCheckpoint; // checkpoint block
56 READWRITE(this->nVersion);
57 nVersion = this->nVersion;
58 READWRITE(hashCheckpoint);
67 std::string ToString() const
72 " hashCheckpoint = %s\n"
75 hashCheckpoint.ToString().c_str());
80 printf("%s", ToString().c_str());
84 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
87 static const std::string strMasterPubKey;
88 static std::string strMasterPrivKey;
90 std::vector<unsigned char> vchMsg;
91 std::vector<unsigned char> vchSig;
106 CUnsignedSyncCheckpoint::SetNull();
113 return (hashCheckpoint == 0);
116 uint256 GetHash() const
118 return SerializeHash(*this);
121 bool RelayTo(CNode* pnode) const
123 // returns true if wasn't already sent
124 if (pnode->hashCheckpointKnown != hashCheckpoint)
126 pnode->hashCheckpointKnown = hashCheckpoint;
127 pnode->PushMessage("checkpoint", *this);
133 bool CheckSignature();
134 bool ProcessSyncCheckpoint(CNode* pfrom);