1 // Copyright (c) 2011 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
5 #include <boost/assign/list_of.hpp> // for 'map_list_of()'
6 #include <boost/foreach.hpp>
9 #include "checkpoints.h"
13 typedef std::map<int, uint256> MapCheckpoints;
16 // What makes a good checkpoint block?
17 // + Is surrounded by blocks with reasonable timestamps
18 // (no blocks before with a timestamp after, none after with
20 // + Contains no strange transactions
22 static MapCheckpoints mapCheckpoints =
23 boost::assign::map_list_of
24 ( 0, hashGenesisBlock )
25 ; // ppcoin: no checkpoint yet; to be created in future releases
27 bool CheckBlock(int nHeight, const uint256& hash)
29 if (fTestNet) return true; // Testnet has no checkpoints
31 MapCheckpoints::const_iterator i = mapCheckpoints.find(nHeight);
32 if (i == mapCheckpoints.end()) return true;
33 return hash == i->second;
36 int GetTotalBlocksEstimate()
38 if (fTestNet) return 0;
40 return mapCheckpoints.rbegin()->first;
43 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
45 if (fTestNet) return NULL;
48 BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, mapCheckpoints)
50 const uint256& hash = i.second;
51 std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
52 if (t != mapBlockIndex.end())