// 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 "CryptoNoteCore/CryptoNoteBasic.h"
#include "CryptoNoteCore/ICore.h"
#include "CryptoNoteCore/ICoreObserver.h"
#include "CryptoNoteProtocol/CryptoNoteProtocolDefinitions.h"
#include "Rpc/CoreRpcServerCommandsDefinitions.h"
class ICoreStub: public CryptoNote::ICore {
public:
ICoreStub() : topHeight(0), globalIndicesResult(false), randomOutsResult(false), poolTxVerificationResult(true) {};
ICoreStub(const CryptoNote::Block& genesisBlock) : topHeight(0), globalIndicesResult(false), randomOutsResult(false), poolTxVerificationResult(true) {
addBlock(genesisBlock);
};
virtual bool addObserver(CryptoNote::ICoreObserver* observer);
virtual bool removeObserver(CryptoNote::ICoreObserver* observer);
virtual void get_blockchain_top(uint32_t& height, Crypto::Hash& top_id);
virtual std::vector findBlockchainSupplement(const std::vector& remoteBlockIds, size_t maxCount,
uint32_t& totalBlockCount, uint32_t& startBlockIndex) override;
virtual bool get_random_outs_for_amounts(const CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_request& req,
CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_response& res);
virtual bool get_tx_outputs_gindexs(const Crypto::Hash& tx_id, std::vector& indexs);
virtual CryptoNote::i_cryptonote_protocol* get_protocol();
virtual bool handle_incoming_tx(CryptoNote::BinaryArray const& tx_blob, CryptoNote::tx_verification_context& tvc, bool keeped_by_block);
virtual std::vector getPoolTransactions() override;
virtual bool getPoolChanges(const Crypto::Hash& tailBlockId, const std::vector& knownTxsIds,
std::vector& addedTxs, std::vector& deletedTxsIds) override;
virtual bool getPoolChangesLite(const Crypto::Hash& tailBlockId, const std::vector& knownTxsIds,
std::vector& addedTxs, std::vector& deletedTxsIds) override;
virtual void getPoolChanges(const std::vector& knownTxsIds, std::vector& addedTxs,
std::vector& deletedTxsIds) override;
virtual bool queryBlocks(const std::vector& block_ids, uint64_t timestamp,
uint32_t& start_height, uint32_t& current_height, uint32_t& full_offset, std::vector& entries) override;
virtual bool queryBlocksLite(const std::vector& block_ids, uint64_t timestamp,
uint32_t& start_height, uint32_t& current_height, uint32_t& full_offset, std::vector& entries) override;
virtual bool have_block(const Crypto::Hash& id) override;
std::vector buildSparseChain() override;
std::vector buildSparseChain(const Crypto::Hash& startBlockId) override;
virtual bool get_stat_info(CryptoNote::core_stat_info& st_inf) override { return false; }
virtual bool on_idle() override { return false; }
virtual void pause_mining() override {}
virtual void update_block_template_and_resume_mining() override {}
virtual bool handle_incoming_block_blob(const CryptoNote::BinaryArray& block_blob, CryptoNote::block_verification_context& bvc, bool control_miner, bool relay_block) override { return false; }
virtual bool handle_get_objects(CryptoNote::NOTIFY_REQUEST_GET_OBJECTS::request& arg, CryptoNote::NOTIFY_RESPONSE_GET_OBJECTS::request& rsp) override { return false; }
virtual void on_synchronized() override {}
virtual bool is_ready() override { return true; }
virtual bool getOutByMSigGIndex(uint64_t amount, uint64_t gindex, CryptoNote::MultisignatureOutput& out) override { return true; }
virtual size_t addChain(const std::vector& chain) override;
virtual Crypto::Hash getBlockIdByHeight(uint32_t height) override;
virtual bool getBlockByHash(const Crypto::Hash &h, CryptoNote::Block &blk) override;
virtual bool getBlockHeight(const Crypto::Hash& blockId, uint32_t& blockHeight) override;
virtual void getTransactions(const std::vector& txs_ids, std::list& txs, std::list& missed_txs, bool checkTxPool = false) override;
virtual bool getBackwardBlocksSizes(uint32_t fromHeight, std::vector& sizes, size_t count) override;
virtual bool getBlockSize(const Crypto::Hash& hash, size_t& size) override;
virtual bool getAlreadyGeneratedCoins(const Crypto::Hash& hash, uint64_t& generatedCoins) override;
virtual bool getBlockReward(size_t medianSize, size_t currentBlockSize, uint64_t alreadyGeneratedCoins, uint64_t fee,
bool penalizeFee, uint64_t& reward, int64_t& emissionChange) override;
virtual bool scanOutputkeysForIndices(const CryptoNote::KeyInput& txInToKey, std::list>& outputReferences) override;
virtual bool getBlockDifficulty(uint32_t height, CryptoNote::difficulty_type& difficulty) override;
virtual bool getBlockContainingTx(const Crypto::Hash& txId, Crypto::Hash& blockId, uint32_t& blockHeight) override;
virtual bool getMultisigOutputReference(const CryptoNote::MultisignatureInput& txInMultisig, std::pair& outputReference) override;
virtual bool getGeneratedTransactionsNumber(uint32_t height, uint64_t& generatedTransactions) override;
virtual bool getOrphanBlocksByHeight(uint32_t height, std::vector& blocks) override;
virtual bool getBlocksByTimestamp(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t blocksNumberLimit, std::vector& blocks, uint32_t& blocksNumberWithinTimestamps) override;
virtual bool getPoolTransactionsByTimestamp(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t transactionsNumberLimit, std::vector& transactions, uint64_t& transactionsNumberWithinTimestamps) override;
virtual bool getTransactionsByPaymentId(const Crypto::Hash& paymentId, std::vector& transactions) override;
virtual std::unique_ptr getBlock(const Crypto::Hash& blockId) override;
virtual bool handleIncomingTransaction(const CryptoNote::Transaction& tx, const Crypto::Hash& txHash, size_t blobSize, CryptoNote::tx_verification_context& tvc, bool keptByBlock) override;
virtual std::error_code executeLocked(const std::function& func) override;
virtual bool addMessageQueue(CryptoNote::MessageQueue& messageQueuePtr) override;
virtual bool removeMessageQueue(CryptoNote::MessageQueue& messageQueuePtr) override;
void set_blockchain_top(uint32_t height, const Crypto::Hash& top_id);
void set_outputs_gindexs(const std::vector& indexs, bool result);
void set_random_outs(const CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_response& resp, bool result);
void addBlock(const CryptoNote::Block& block);
void addTransaction(const CryptoNote::Transaction& tx);
void setPoolTxVerificationResult(bool result);
private:
uint32_t topHeight;
Crypto::Hash topId;
std::vector globalIndices;
bool globalIndicesResult;
CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_response randomOuts;
bool randomOutsResult;
std::unordered_map blocks;
std::unordered_map blockHashByHeightIndex;
std::unordered_map blockHashByTxHashIndex;
std::unordered_map transactions;
std::unordered_map transactionPool;
bool poolTxVerificationResult;
};