danicoin/tests/unit_tests/TestBlockchainGenerator.h

50 lines
1.8 KiB
C
Raw Normal View History

// Copyright (c) 2011-2015 The Cryptonote developers
2014-06-25 17:21:42 +00:00
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <vector>
#include <unordered_map>
#include "cryptonote_core/account.h"
#include "cryptonote_core/cryptonote_basic.h"
2014-08-13 10:51:37 +00:00
#include "cryptonote_core/Currency.h"
2014-06-25 17:21:42 +00:00
#include "crypto/hash.h"
2014-08-13 10:51:37 +00:00
#include "../TestGenerator/TestGenerator.h"
2014-06-25 17:21:42 +00:00
class TestBlockchainGenerator
{
public:
2014-08-13 10:51:37 +00:00
TestBlockchainGenerator(const cryptonote::Currency& currency);
2014-06-25 17:21:42 +00:00
2014-08-13 10:51:37 +00:00
std::vector<cryptonote::Block>& getBlockchain();
2014-06-25 17:21:42 +00:00
void generateEmptyBlocks(size_t count);
2014-08-13 10:51:37 +00:00
bool getBlockRewardForAddress(const cryptonote::AccountPublicAddress& address);
bool getSingleOutputTransaction(const cryptonote::AccountPublicAddress& address, uint64_t amount);
2014-08-13 10:51:37 +00:00
void addTxToBlockchain(const cryptonote::Transaction& transaction);
bool getTransactionByHash(const crypto::hash& hash, cryptonote::Transaction& tx);
const cryptonote::account_base& getMinerAccount() const { return miner_acc; }
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();
2014-06-25 17:21:42 +00:00
private:
void addGenesisBlock();
void addMiningBlock();
2014-08-13 10:51:37 +00:00
const cryptonote::Currency& m_currency;
2014-06-25 17:21:42 +00:00
test_generator generator;
cryptonote::account_base miner_acc;
2014-08-13 10:51:37 +00:00
std::vector<cryptonote::Block> m_blockchain;
std::unordered_map<crypto::hash, cryptonote::Transaction> m_txs;
std::unordered_map<crypto::hash, cryptonote::Transaction> m_txPool;
void addToBlockchain(cryptonote::Transaction const& tx);
2014-06-25 17:21:42 +00:00
};