2015-05-27 12:08:46 +00:00
|
|
|
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
|
2015-04-06 16:13:07 +00:00
|
|
|
//
|
|
|
|
// This file is part of Bytecoin.
|
|
|
|
//
|
|
|
|
// Bytecoin is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Bytecoin is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CommonTypes.h"
|
|
|
|
#include "IStreamSerializable.h"
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "Serialization/ISerializer.h"
|
2015-04-06 16:13:07 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace CryptoNote {
|
|
|
|
|
|
|
|
class SynchronizationState : public IStreamSerializable {
|
|
|
|
public:
|
|
|
|
|
|
|
|
struct CheckResult {
|
|
|
|
bool detachRequired;
|
2015-07-30 15:22:07 +00:00
|
|
|
uint32_t detachHeight;
|
2015-04-06 16:13:07 +00:00
|
|
|
bool hasNewBlocks;
|
2015-07-30 15:22:07 +00:00
|
|
|
uint32_t newBlockHeight;
|
2015-04-06 16:13:07 +00:00
|
|
|
};
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
typedef std::vector<Crypto::Hash> ShortHistory;
|
2015-04-06 16:13:07 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
explicit SynchronizationState(const Crypto::Hash& genesisBlockHash) {
|
2015-04-06 16:13:07 +00:00
|
|
|
m_blockchain.push_back(genesisBlockHash);
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
ShortHistory getShortHistory(uint32_t localHeight) const;
|
2015-04-06 16:13:07 +00:00
|
|
|
CheckResult checkInterval(const BlockchainInterval& interval) const;
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
void detach(uint32_t height);
|
|
|
|
void addBlocks(const Crypto::Hash* blockHashes, uint32_t height, uint32_t count);
|
|
|
|
uint32_t getHeight() const;
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
// IStreamSerializable
|
|
|
|
virtual void save(std::ostream& os) override;
|
|
|
|
virtual void load(std::istream& in) override;
|
|
|
|
|
|
|
|
// serialization
|
2015-05-27 12:08:46 +00:00
|
|
|
CryptoNote::ISerializer& serialize(CryptoNote::ISerializer& s, const std::string& name);
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
std::vector<Crypto::Hash> m_blockchain;
|
2015-04-06 16:13:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|