// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers // // 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 . #pragma once #include #include #include #include "IBlockchainExplorer.h" #include "INode.h" #include "Common/ObserverManager.h" #include "BlockchainExplorerErrors.h" #include "Logging/LoggerRef.h" namespace CryptoNote { class BlockchainExplorer : public IBlockchainExplorer, public INodeObserver { public: BlockchainExplorer(INode& node, Logging::ILogger& logger); BlockchainExplorer(const BlockchainExplorer&) = delete; BlockchainExplorer(BlockchainExplorer&&) = delete; BlockchainExplorer& operator=(const BlockchainExplorer&) = delete; BlockchainExplorer& operator=(BlockchainExplorer&&) = delete; virtual ~BlockchainExplorer(); virtual bool addObserver(IBlockchainObserver* observer) override; virtual bool removeObserver(IBlockchainObserver* observer) override; virtual bool getBlocks(const std::vector& blockHeights, std::vector>& blocks) override; virtual bool getBlocks(const std::vector>& blockHashes, std::vector& blocks) override; virtual bool getBlockchainTop(BlockDetails& topBlock) override; virtual bool getTransactions(const std::vector>& transactionHashes, std::vector& transactions) override; virtual bool getPoolState(const std::vector>& knownPoolTransactionHashes, std::array knownBlockchainTop, bool& isBlockchainActual, std::vector& newTransactions, std::vector>& removedTransactions) override; virtual uint64_t getRewardBlocksWindow() override; virtual uint64_t getFullRewardMaxBlockSize(uint8_t majorVersion) override; virtual bool isSynchronized() override; virtual void init() override; virtual void shutdown() override; virtual void poolChanged() override; virtual void blockchainSynchronized(uint64_t topHeight) override; virtual void localBlockchainUpdated(uint64_t height) override; private: enum State { NOT_INITIALIZED, INITIALIZED }; BlockDetails knownBlockchainTop; uint64_t knownBlockchainTopHeight; std::unordered_set knownPoolState; std::atomic state; tools::ObserverManager observerManager; std::mutex mutex; INode& node; Logging::LoggerRef logger; }; }