// Copyright (c) 2011-2016 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #pragma once #include #include #include #include "IBlockchainExplorer.h" #include "INode.h" #include "Common/ObserverManager.h" #include "BlockchainExplorerErrors.h" #include "Wallet/WalletAsyncContextCounter.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 getBlocks(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t blocksNumberLimit, std::vector& blocks, uint32_t& blocksNumberWithinTimestamps) override; virtual bool getBlockchainTop(BlockDetails& topBlock) override; virtual bool getTransactions(const std::vector& transactionHashes, std::vector& transactions) override; virtual bool getTransactionsByPaymentId(const Crypto::Hash& paymentId, std::vector& transactions) override; virtual bool getPoolTransactions(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t transactionsNumberLimit, std::vector& transactions, uint64_t& transactionsNumberWithinTimestamps) override; virtual bool getPoolState(const std::vector& knownPoolTransactionHashes, Crypto::Hash 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(uint32_t topHeight) override; virtual void localBlockchainUpdated(uint32_t height) override; typedef WalletAsyncContextCounter AsyncContextCounter; private: void poolUpdateEndHandler(); class PoolUpdateGuard { public: PoolUpdateGuard(); bool beginUpdate(); bool endUpdate(); private: enum class State { NONE, UPDATING, UPDATE_REQUIRED }; std::atomic m_state; }; enum State { NOT_INITIALIZED, INITIALIZED }; BlockDetails knownBlockchainTop; uint32_t knownBlockchainTopHeight; std::unordered_set knownPoolState; std::atomic state; std::atomic synchronized; std::atomic observersCounter; Tools::ObserverManager observerManager; std::mutex mutex; INode& node; Logging::LoggerRef logger; AsyncContextCounter asyncContextCounter; PoolUpdateGuard poolUpdateGuard; }; }