Changeset View
Changeset View
Standalone View
Standalone View
src/checkpoints.cpp
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "checkpoints.h" | #include "checkpoints.h" | ||||
#include "chain.h" | #include "chain.h" | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "reverse_iterator.h" | |||||
#include <cstdint> | #include <cstdint> | ||||
#include <boost/range/adaptor/reversed.hpp> | |||||
namespace Checkpoints { | namespace Checkpoints { | ||||
bool CheckBlock(const CCheckpointData &data, int nHeight, const uint256 &hash) { | bool CheckBlock(const CCheckpointData &data, int nHeight, const uint256 &hash) { | ||||
const MapCheckpoints &checkpoints = data.mapCheckpoints; | const MapCheckpoints &checkpoints = data.mapCheckpoints; | ||||
MapCheckpoints::const_iterator i = checkpoints.find(nHeight); | MapCheckpoints::const_iterator i = checkpoints.find(nHeight); | ||||
if (i == checkpoints.end()) { | if (i == checkpoints.end()) { | ||||
return true; | return true; | ||||
} | } | ||||
return hash == i->second; | return hash == i->second; | ||||
} | } | ||||
CBlockIndex *GetLastCheckpoint(const CCheckpointData &data) { | CBlockIndex *GetLastCheckpoint(const CCheckpointData &data) { | ||||
const MapCheckpoints &checkpoints = data.mapCheckpoints; | const MapCheckpoints &checkpoints = data.mapCheckpoints; | ||||
for (const MapCheckpoints::value_type &i : | for (const MapCheckpoints::value_type &i : reverse_iterate(checkpoints)) { | ||||
boost::adaptors::reverse(checkpoints)) { | |||||
const uint256 &hash = i.second; | const uint256 &hash = i.second; | ||||
BlockMap::const_iterator t = mapBlockIndex.find(hash); | BlockMap::const_iterator t = mapBlockIndex.find(hash); | ||||
if (t != mapBlockIndex.end()) { | if (t != mapBlockIndex.end()) { | ||||
return t->second; | return t->second; | ||||
} | } | ||||
} | } | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} // namespace Checkpoints | } // namespace Checkpoints |