2015-07-30 15:22:07 +00:00
|
|
|
// 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 "CryptoNoteCore/Account.h"
|
|
|
|
#include "CryptoNoteCore/CryptoNoteBasic.h"
|
|
|
|
#include "CryptoNoteCore/Currency.h"
|
|
|
|
#include "CryptoNoteCore/BlockchainIndices.h"
|
|
|
|
#include "crypto/hash.h"
|
|
|
|
|
|
|
|
#include "../TestGenerator/TestGenerator.h"
|
|
|
|
|
|
|
|
class TestBlockchainGenerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestBlockchainGenerator(const CryptoNote::Currency& currency);
|
|
|
|
|
|
|
|
//TODO: get rid of this method
|
|
|
|
std::vector<CryptoNote::Block>& getBlockchain();
|
|
|
|
std::vector<CryptoNote::Block> getBlockchainCopy();
|
2015-10-01 15:27:18 +00:00
|
|
|
void generateEmptyBlocks(size_t count);
|
2015-07-30 15:22:07 +00:00
|
|
|
bool getBlockRewardForAddress(const CryptoNote::AccountPublicAddress& address);
|
|
|
|
bool generateTransactionsInOneBlock(const CryptoNote::AccountPublicAddress& address, size_t n);
|
|
|
|
bool getSingleOutputTransaction(const CryptoNote::AccountPublicAddress& address, uint64_t amount);
|
|
|
|
void addTxToBlockchain(const CryptoNote::Transaction& transaction);
|
|
|
|
bool getTransactionByHash(const Crypto::Hash& hash, CryptoNote::Transaction& tx, bool checkTxPool = false);
|
|
|
|
const CryptoNote::AccountBase& getMinerAccount() const;
|
2015-12-09 13:19:03 +00:00
|
|
|
bool generateFromBaseTx(const CryptoNote::AccountBase& address);
|
2015-07-30 15:22:07 +00:00
|
|
|
|
|
|
|
void putTxToPool(const CryptoNote::Transaction& tx);
|
|
|
|
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);
|
|
|
|
void putTxPoolToBlockchain();
|
|
|
|
void clearTxPool();
|
|
|
|
|
|
|
|
void cutBlockchain(uint32_t height);
|
|
|
|
|
|
|
|
bool addOrphan(const Crypto::Hash& hash, uint32_t height);
|
|
|
|
bool getGeneratedTransactionsNumber(uint32_t height, uint64_t& generatedTransactions);
|
|
|
|
bool getOrphanBlockIdsByHeight(uint32_t height, std::vector<Crypto::Hash>& blockHashes);
|
|
|
|
bool getBlockIdsByTimestamp(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t blocksNumberLimit, std::vector<Crypto::Hash>& hashes, uint32_t& blocksNumberWithinTimestamps);
|
|
|
|
bool getPoolTransactionIdsByTimestamp(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t transactionsNumberLimit, std::vector<Crypto::Hash>& hashes, uint64_t& transactionsNumberWithinTimestamps);
|
|
|
|
bool getTransactionIdsByPaymentId(const Crypto::Hash& paymentId, std::vector<Crypto::Hash>& transactionHashes);
|
|
|
|
|
|
|
|
bool getTransactionGlobalIndexesByHash(const Crypto::Hash& transactionHash, std::vector<uint32_t>& globalIndexes);
|
|
|
|
bool getMultisignatureOutputByGlobalIndex(uint64_t amount, uint32_t globalIndex, CryptoNote::MultisignatureOutput& out);
|
2015-08-27 18:55:14 +00:00
|
|
|
void setMinerAccount(const CryptoNote::AccountBase& account);
|
2015-07-30 15:22:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct MultisignatureOutEntry {
|
|
|
|
Crypto::Hash transactionHash;
|
|
|
|
uint16_t indexOut;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KeyOutEntry {
|
|
|
|
Crypto::Hash transactionHash;
|
|
|
|
uint16_t indexOut;
|
|
|
|
};
|
|
|
|
|
|
|
|
void addGenesisBlock();
|
|
|
|
void addMiningBlock();
|
|
|
|
|
|
|
|
const CryptoNote::Currency& m_currency;
|
|
|
|
test_generator generator;
|
|
|
|
CryptoNote::AccountBase miner_acc;
|
|
|
|
std::vector<CryptoNote::Block> m_blockchain;
|
|
|
|
std::unordered_map<Crypto::Hash, CryptoNote::Transaction> m_txs;
|
|
|
|
std::unordered_map<Crypto::Hash, std::vector<uint32_t>> transactionGlobalOuts;
|
|
|
|
std::unordered_map<uint64_t, std::vector<MultisignatureOutEntry>> multisignatureOutsIndex;
|
|
|
|
std::unordered_map<uint64_t, std::vector<KeyOutEntry>> keyOutsIndex;
|
|
|
|
|
|
|
|
std::unordered_map<Crypto::Hash, CryptoNote::Transaction> m_txPool;
|
|
|
|
mutable std::mutex m_mutex;
|
|
|
|
|
|
|
|
CryptoNote::PaymentIdIndex m_paymentIdIndex;
|
|
|
|
CryptoNote::TimestampTransactionsIndex m_timestampIndex;
|
|
|
|
CryptoNote::GeneratedTransactionsIndex m_generatedTransactionsIndex;
|
|
|
|
CryptoNote::OrphanBlocksIndex m_orthanBlocksIndex;
|
|
|
|
|
|
|
|
void addToBlockchain(const CryptoNote::Transaction& tx);
|
|
|
|
void addToBlockchain(const std::vector<CryptoNote::Transaction>& txs);
|
2015-12-09 13:19:03 +00:00
|
|
|
void addToBlockchain(const std::vector<CryptoNote::Transaction>& txs, const CryptoNote::AccountBase& minerAddress);
|
2015-07-30 15:22:07 +00:00
|
|
|
void addTx(const CryptoNote::Transaction& tx);
|
|
|
|
|
|
|
|
bool doGenerateTransactionsInOneBlock(CryptoNote::AccountPublicAddress const &address, size_t n);
|
|
|
|
};
|