2016-01-18 15:33:29 +00:00
|
|
|
// Copyright (c) 2011-2016 The Cryptonote developers
|
2015-04-23 16:07:22 +00:00
|
|
|
// 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 <cstdint>
|
2015-12-09 13:19:03 +00:00
|
|
|
#include <future>
|
2015-04-06 16:13:07 +00:00
|
|
|
#include <system_error>
|
2015-12-09 13:19:03 +00:00
|
|
|
#include <unordered_set>
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
#include "crypto/crypto.h"
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "CryptoNoteCore/CryptoNoteBasic.h"
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
#include "IObservable.h"
|
|
|
|
#include "IStreamSerializable.h"
|
|
|
|
#include "ITransfersSynchronizer.h"
|
|
|
|
|
|
|
|
namespace CryptoNote {
|
|
|
|
|
|
|
|
struct CompleteBlock;
|
|
|
|
|
|
|
|
class IBlockchainSynchronizerObserver {
|
|
|
|
public:
|
2015-08-27 18:55:14 +00:00
|
|
|
virtual void synchronizationProgressUpdated(uint32_t processedBlockCount, uint32_t totalBlockCount) {}
|
2015-04-06 16:13:07 +00:00
|
|
|
virtual void synchronizationCompleted(std::error_code result) {}
|
|
|
|
};
|
|
|
|
|
2015-12-09 13:19:03 +00:00
|
|
|
class IBlockchainConsumerObserver;
|
|
|
|
|
|
|
|
class IBlockchainConsumer : public IObservable<IBlockchainConsumerObserver> {
|
2015-04-06 16:13:07 +00:00
|
|
|
public:
|
2015-07-30 15:22:07 +00:00
|
|
|
virtual ~IBlockchainConsumer() {}
|
2015-04-06 16:13:07 +00:00
|
|
|
virtual SynchronizationStart getSyncStart() = 0;
|
2015-12-09 13:19:03 +00:00
|
|
|
virtual const std::unordered_set<Crypto::Hash>& getKnownPoolTxIds() const = 0;
|
2015-07-30 15:22:07 +00:00
|
|
|
virtual void onBlockchainDetach(uint32_t height) = 0;
|
|
|
|
virtual bool onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) = 0;
|
|
|
|
virtual std::error_code onPoolUpdated(const std::vector<std::unique_ptr<ITransactionReader>>& addedTransactions, const std::vector<Crypto::Hash>& deletedTransactions) = 0;
|
2015-12-09 13:19:03 +00:00
|
|
|
|
|
|
|
virtual std::error_code addUnconfirmedTransaction(const ITransactionReader& transaction) = 0;
|
|
|
|
virtual void removeUnconfirmedTransaction(const Crypto::Hash& transactionHash) = 0;
|
2015-04-06 16:13:07 +00:00
|
|
|
};
|
|
|
|
|
2015-12-09 13:19:03 +00:00
|
|
|
class IBlockchainConsumerObserver {
|
|
|
|
public:
|
|
|
|
virtual void onBlocksAdded(IBlockchainConsumer* consumer, const std::vector<Crypto::Hash>& blockHashes) {}
|
|
|
|
virtual void onBlockchainDetach(IBlockchainConsumer* consumer, uint32_t blockIndex) {}
|
|
|
|
virtual void onTransactionDeleteBegin(IBlockchainConsumer* consumer, Crypto::Hash transactionHash) {}
|
|
|
|
virtual void onTransactionDeleteEnd(IBlockchainConsumer* consumer, Crypto::Hash transactionHash) {}
|
|
|
|
virtual void onTransactionUpdated(IBlockchainConsumer* consumer, const Crypto::Hash& transactionHash, const std::vector<ITransfersContainer*>& containers) {}
|
|
|
|
};
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
class IBlockchainSynchronizer :
|
|
|
|
public IObservable<IBlockchainSynchronizerObserver>,
|
|
|
|
public IStreamSerializable {
|
|
|
|
public:
|
|
|
|
virtual void addConsumer(IBlockchainConsumer* consumer) = 0;
|
|
|
|
virtual bool removeConsumer(IBlockchainConsumer* consumer) = 0;
|
2015-12-09 13:19:03 +00:00
|
|
|
virtual IStreamSerializable* getConsumerState(IBlockchainConsumer* consumer) const = 0;
|
|
|
|
virtual std::vector<Crypto::Hash> getConsumerKnownBlocks(IBlockchainConsumer& consumer) const = 0;
|
|
|
|
|
|
|
|
virtual std::future<std::error_code> addUnconfirmedTransaction(const ITransactionReader& transaction) = 0;
|
|
|
|
virtual std::future<void> removeUnconfirmedTransaction(const Crypto::Hash& transactionHash) = 0;
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
virtual void start() = 0;
|
|
|
|
virtual void stop() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|