2015-04-23 16:07:22 +00:00
|
|
|
// Copyright (c) 2011-2015 The Cryptonote developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
#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
|
|
|
};
|
|
|
|
|
|
|
|
}
|