126 lines
8 KiB
C++
126 lines
8 KiB
C++
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
#include "INode.h"
|
|
#include "cryptonote_core/cryptonote_basic.h"
|
|
#include "TestBlockchainGenerator.h"
|
|
#include "Common/ObserverManager.h"
|
|
#include "wallet/WalletAsyncContextCounter.h"
|
|
|
|
|
|
class INodeDummyStub : public CryptoNote::INode
|
|
{
|
|
public:
|
|
virtual bool addObserver(CryptoNote::INodeObserver* observer) override;
|
|
virtual bool removeObserver(CryptoNote::INodeObserver* observer) override;
|
|
|
|
virtual void init(const CryptoNote::INode::Callback& callback) {callback(std::error_code());};
|
|
virtual bool shutdown() { return true; };
|
|
|
|
virtual size_t getPeerCount() const { return 0; };
|
|
virtual uint64_t getLastLocalBlockHeight() const { return 0; };
|
|
virtual uint64_t getLastKnownBlockHeight() const { return 0; };
|
|
virtual uint64_t getLocalBlockCount() const override { return 0; };
|
|
virtual uint64_t getKnownBlockCount() const override { return 0; };
|
|
virtual uint64_t getLastLocalBlockTimestamp() const override { return 0; }
|
|
|
|
virtual void getNewBlocks(std::list<crypto::hash>&& knownBlockIds, std::list<CryptoNote::block_complete_entry>& newBlocks, uint64_t& startHeight, const Callback& callback) {callback(std::error_code());};
|
|
|
|
virtual void relayTransaction(const CryptoNote::Transaction& transaction, const Callback& callback) {callback(std::error_code());};
|
|
virtual void getRandomOutsByAmounts(std::vector<uint64_t>&& amounts, uint64_t outsCount, std::vector<CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount>& result, const Callback& callback) {callback(std::error_code());};
|
|
virtual void getTransactionOutsGlobalIndices(const crypto::hash& transactionHash, std::vector<uint64_t>& outsGlobalIndices, const Callback& callback) { callback(std::error_code()); };
|
|
virtual void getPoolSymmetricDifference(std::vector<crypto::hash>&& known_pool_tx_ids, crypto::hash known_block_id, bool& is_bc_actual, std::vector<CryptoNote::Transaction>& new_txs, std::vector<crypto::hash>& deleted_tx_ids, const Callback& callback) override { is_bc_actual = true; callback(std::error_code()); };
|
|
virtual void queryBlocks(std::list<crypto::hash>&& knownBlockIds, uint64_t timestamp, std::list<CryptoNote::BlockCompleteEntry>& newBlocks, uint64_t& startHeight, const Callback& callback) { callback(std::error_code()); };
|
|
|
|
virtual void getBlocks(const std::vector<uint64_t>& blockHeights, std::vector<std::vector<CryptoNote::BlockDetails>>& blocks, const Callback& callback) { callback(std::error_code()); };
|
|
virtual void getBlocks(const std::vector<crypto::hash>& blockHashes, std::vector<CryptoNote::BlockDetails>& blocks, const Callback& callback) { callback(std::error_code()); };
|
|
virtual void getTransactions(const std::vector<crypto::hash>& transactionHashes, std::vector<CryptoNote::TransactionDetails>& transactions, const Callback& callback) { callback(std::error_code()); };
|
|
virtual void isSynchronized(bool& syncStatus, const Callback& callback) { callback(std::error_code()); };
|
|
|
|
void updateObservers();
|
|
|
|
tools::ObserverManager<CryptoNote::INodeObserver> observerManager;
|
|
|
|
};
|
|
|
|
class INodeTrivialRefreshStub : public INodeDummyStub
|
|
{
|
|
public:
|
|
INodeTrivialRefreshStub(TestBlockchainGenerator& generator) :
|
|
m_lastHeight(1), m_blockchainGenerator(generator), m_nextTxError(false), m_getMaxBlocks(std::numeric_limits<size_t>::max()), m_nextTxToPool(false), m_synchronized(false) {};
|
|
|
|
void setGetNewBlocksLimit(size_t maxBlocks) { m_getMaxBlocks = maxBlocks; }
|
|
|
|
virtual uint64_t getLastLocalBlockHeight() const { return m_blockchainGenerator.getBlockchain().size() - 1; };
|
|
virtual uint64_t getLastKnownBlockHeight() const { return m_blockchainGenerator.getBlockchain().size() - 1; };
|
|
|
|
virtual void getNewBlocks(std::list<crypto::hash>&& knownBlockIds, std::list<CryptoNote::block_complete_entry>& newBlocks, uint64_t& startHeight, const Callback& callback);
|
|
|
|
virtual void relayTransaction(const CryptoNote::Transaction& transaction, const Callback& callback);
|
|
virtual void getRandomOutsByAmounts(std::vector<uint64_t>&& amounts, uint64_t outsCount, std::vector<CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount>& result, const Callback& callback);
|
|
virtual void getTransactionOutsGlobalIndices(const crypto::hash& transactionHash, std::vector<uint64_t>& outsGlobalIndices, const Callback& callback);
|
|
virtual void queryBlocks(std::list<crypto::hash>&& knownBlockIds, uint64_t timestamp, std::list<CryptoNote::BlockCompleteEntry>& newBlocks, uint64_t& startHeight, const Callback& callback) override;
|
|
virtual void getPoolSymmetricDifference(std::vector<crypto::hash>&& known_pool_tx_ids, crypto::hash known_block_id, bool& is_bc_actual,
|
|
std::vector<CryptoNote::Transaction>& new_txs, std::vector<crypto::hash>& deleted_tx_ids, const Callback& callback) override;
|
|
|
|
virtual void getBlocks(const std::vector<uint64_t>& blockHeights, std::vector<std::vector<CryptoNote::BlockDetails>>& blocks, const Callback& callback) override;
|
|
virtual void getBlocks(const std::vector<crypto::hash>& blockHashes, std::vector<CryptoNote::BlockDetails>& blocks, const Callback& callback) override;
|
|
virtual void getTransactions(const std::vector<crypto::hash>& transactionHashes, std::vector<CryptoNote::TransactionDetails>& transactions, const Callback& callback) override;
|
|
virtual void isSynchronized(bool& syncStatus, const Callback& callback) override;
|
|
|
|
virtual void startAlternativeChain(uint64_t height);
|
|
void setNextTransactionError();
|
|
void setNextTransactionToPool();
|
|
void includeTransactionsFromPoolToBlock();
|
|
|
|
void setSynchronizedStatus(bool status);
|
|
|
|
void sendPoolChanged();
|
|
void sendLocalBlockchainUpdated();
|
|
|
|
std::vector<crypto::hash> calls_getTransactionOutsGlobalIndices;
|
|
|
|
virtual ~INodeTrivialRefreshStub();
|
|
|
|
protected:
|
|
void doGetNewBlocks(std::list<crypto::hash> knownBlockIds, std::list<CryptoNote::block_complete_entry>& newBlocks,
|
|
uint64_t& startHeight, std::vector<CryptoNote::Block> blockchain, const Callback& callback);
|
|
void doGetTransactionOutsGlobalIndices(const crypto::hash& transactionHash, std::vector<uint64_t>& outsGlobalIndices, const Callback& callback);
|
|
void doRelayTransaction(const CryptoNote::Transaction& transaction, const Callback& callback);
|
|
void doGetRandomOutsByAmounts(std::vector<uint64_t> amounts, uint64_t outsCount, std::vector<CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount>& result, const Callback& callback);
|
|
void doGetPoolSymmetricDifference(std::vector<crypto::hash>& known_pool_tx_ids, crypto::hash known_block_id, bool& is_bc_actual,
|
|
std::vector<CryptoNote::Transaction>& new_txs, std::vector<crypto::hash>& deleted_tx_ids, const Callback& callback);
|
|
|
|
void doGetBlocks(const std::vector<uint64_t>& blockHeights, std::vector<std::vector<CryptoNote::BlockDetails>>& blocks, const Callback& callback);
|
|
void doGetBlocks(const std::vector<crypto::hash>& blockHashes, std::vector<CryptoNote::BlockDetails>& blocks, const Callback& callback);
|
|
void doGetTransactions(const std::vector<crypto::hash>& transactionHashes, std::vector<CryptoNote::TransactionDetails>& transactions, const Callback& callback);
|
|
|
|
size_t m_getMaxBlocks;
|
|
uint64_t m_lastHeight;
|
|
TestBlockchainGenerator& m_blockchainGenerator;
|
|
bool m_nextTxError;
|
|
bool m_nextTxToPool;
|
|
std::mutex m_multiWalletLock;
|
|
CryptoNote::WalletAsyncContextCounter m_asyncCounter;
|
|
|
|
bool m_synchronized;
|
|
};
|