AbstractCore added

pull/3/head
moneroexamples 5 years ago
parent 0ba67fa106
commit 5589b8257f

@ -107,6 +107,108 @@ MicroCore::get_nettype() const
return nettype;
}
void
MicroCore::get_output_key(uint64_t amount,
vector<uint64_t> const& absolute_offsets,
vector<cryptonote::output_data_t>& outputs)
const
{
core_storage.get_db()
.get_output_key(epee::span<const uint64_t>(&amount, 1),
absolute_offsets, outputs);
}
output_data_t
MicroCore::get_output_key(uint64_t amount,
uint64_t global_amount_index) const
{
return core_storage.get_db()
.get_output_key(amount, global_amount_index);
}
bool
MicroCore::get_transactions(
std::vector<crypto::hash> const& txs_ids,
std::vector<transaction>& txs,
std::vector<crypto::hash>& missed_txs) const
{
return core_storage.get_transactions(txs_ids, txs, missed_txs);
}
std::vector<block>
MicroCore::get_blocks_range(uint64_t h1, uint64_t h2) const
{
return core_storage.get_db().get_blocks_range(h1, h2);
}
uint64_t
MicroCore::get_tx_unlock_time(crypto::hash const& tx_hash) const
{
return core_storage.get_db().get_tx_unlock_time(tx_hash);
}
bool
MicroCore::have_tx(crypto::hash const& tx_hash) const
{
return core_storage.have_tx(tx_hash);
}
bool
MicroCore::tx_exists(crypto::hash const& tx_hash, uint64_t& tx_id) const
{
return core_storage.get_db().tx_exists(tx_hash, tx_id);
}
tx_out_index
MicroCore::get_output_tx_and_index(uint64_t amount, uint64_t index) const
{
return core_storage.get_db().get_output_tx_and_index(amount, index);
}
uint64_t
MicroCore::get_tx_block_height(crypto::hash const& tx_hash) const
{
return core_storage.get_db().get_tx_block_height(tx_hash);
}
std::vector<uint64_t>
MicroCore::get_tx_amount_output_indices(uint64_t tx_id) const
{
return core_storage.get_db()
.get_tx_amount_output_indices(tx_id).front();
}
bool
MicroCore::get_mempool_txs(
std::vector<tx_info>& tx_infos,
std::vector<spent_key_image_info>& key_image_infos) const
{
return m_mempool.get_transactions_and_spent_keys_info(
tx_infos, key_image_infos);
}
uint64_t
MicroCore::get_current_blockchain_height() const
{
return core_storage.get_current_blockchain_height();
}
void
MicroCore::get_output_tx_and_index(
uint64_t amount,
std::vector<uint64_t> const& offsets,
std::vector<tx_out_index>& indices) const
{
// tx_hash , index in tx
// tx_out_index is std::pair<crypto::hash, uint64_t>;
core_storage.get_db().get_output_tx_and_index(
amount, offsets, indices);
}
bool
MicroCore::get_block_from_height(uint64_t height, block& blk) const
{
@ -125,6 +227,19 @@ MicroCore::get_block_from_height(uint64_t height, block& blk) const
}
bool
MicroCore::get_outs(COMMAND_RPC_GET_OUTPUTS_BIN::request const& req,
COMMAND_RPC_GET_OUTPUTS_BIN::response& res) const
{
return core_storage.get_outs(req, res);
}
uint64_t
MicroCore::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
{
return core_storage.get_dynamic_base_fee_estimate(grace_blocks);
}
bool
MicroCore::get_block_complete_entry(block const& b, block_complete_entry& bce)
{
@ -231,24 +346,23 @@ MicroCore::get_device() const
return m_device;
}
bool
MicroCore::init_success() const
MicroCore::decrypt_payment_id(crypto::hash8& payment_id,
public_key const& public_key,
secret_key const& secret_key) const
{
return initialization_succeded;
return m_device->decrypt_payment_id(payment_id,
public_key,
secret_key);
}
//MicroCore::~MicroCore()
//{
// //cout << "\n\nMicroCore::~MicroCore()\n\n";
// if (initialization_succeded)
// {
// //core_storage.get_db().safesyncmode(true);
// if (core_storage.get_db().is_open())
// core_storage.get_db().close();
// //cout << "\n\n core_storage.get_db().close();;\n\n";
// }
bool
MicroCore::init_success() const
{
return initialization_succeded;
}
//}
}

@ -5,9 +5,6 @@
#ifndef XMREG01_MICROCORE_H
#define XMREG01_MICROCORE_H
#include <iostream>
#include <random>
#include "monero_headers.h"
namespace xmreg
@ -16,6 +13,38 @@ using namespace cryptonote;
using namespace crypto;
using namespace std;
class AbstractCore
{
public:
// the three methods below are used in input identification
// in the UniveralIdentifier. Thus we are going to make
// the identifier relay on the AbstractCore, instead of the
// concrete implementation defined below.
virtual void
get_output_key(uint64_t amount,
vector<uint64_t> const& absolute_offsets,
vector<cryptonote::output_data_t>& outputs) const = 0;
virtual void
get_output_tx_and_index(
uint64_t amount,
std::vector<uint64_t> const& offsets,
std::vector<tx_out_index>& indices) const = 0;
virtual bool
get_tx(crypto::hash const& tx_hash, transaction& tx) const = 0;
// below, with time we can other pure virtual methods
// to the AbstractCore, if needed. For now, the above three are
// essential
};
/**
* Micro version of cryptonode::core class
* Micro version of constructor,
@ -24,7 +53,8 @@ using namespace std;
* Just enough to read the blockchain
* database for use in the example.
*/
class MicroCore {
class MicroCore : public AbstractCore
{
string blockchain_path;
@ -73,100 +103,53 @@ public:
virtual void
get_output_key(uint64_t amount,
vector<uint64_t> const& absolute_offsets,
vector<cryptonote::output_data_t>& outputs) const
{
core_storage.get_db()
.get_output_key(epee::span<const uint64_t>(&amount, 1),
absolute_offsets, outputs);
}
vector<cryptonote::output_data_t>& outputs)
const override;
virtual output_data_t
get_output_key(uint64_t amount,
uint64_t global_amount_index) const
{
return core_storage.get_db()
.get_output_key(amount, global_amount_index);
}
uint64_t global_amount_index) const;
virtual bool
get_transactions(
const std::vector<crypto::hash>& txs_ids,
std::vector<crypto::hash> const& txs_ids,
std::vector<transaction>& txs,
std::vector<crypto::hash>& missed_txs) const
{
return core_storage.get_transactions(txs_ids, txs, missed_txs);
}
std::vector<crypto::hash>& missed_txs) const;
virtual std::vector<block>
get_blocks_range(const uint64_t& h1, const uint64_t& h2) const
{
return core_storage.get_db().get_blocks_range(h1, h2);
}
get_blocks_range(uint64_t h1, uint64_t h2) const;
virtual uint64_t
get_tx_unlock_time(crypto::hash const& tx_hash) const
{
return core_storage.get_db().get_tx_unlock_time(tx_hash);
}
get_tx_unlock_time(crypto::hash const& tx_hash) const;
virtual bool
have_tx(crypto::hash const& tx_hash) const
{
return core_storage.have_tx(tx_hash);
}
have_tx(crypto::hash const& tx_hash) const;
virtual bool
tx_exists(crypto::hash const& tx_hash, uint64_t& tx_id) const
{
return core_storage.get_db().tx_exists(tx_hash, tx_id);
}
tx_exists(crypto::hash const& tx_hash, uint64_t& tx_id) const;
virtual tx_out_index
get_output_tx_and_index(uint64_t const& amount, uint64_t const& index) const
{
return core_storage.get_db().get_output_tx_and_index(amount, index);
}
get_output_tx_and_index(uint64_t amount, uint64_t index) const;
virtual uint64_t
get_tx_block_height(crypto::hash const& tx_hash) const
{
return core_storage.get_db().get_tx_block_height(tx_hash);
}
get_tx_block_height(crypto::hash const& tx_hash) const;
virtual std::vector<uint64_t>
get_tx_amount_output_indices(uint64_t const& tx_id) const
{
return core_storage.get_db()
.get_tx_amount_output_indices(tx_id).front();
}
get_tx_amount_output_indices(uint64_t tx_id) const;
virtual bool
get_mempool_txs(
std::vector<tx_info>& tx_infos,
std::vector<spent_key_image_info>& key_image_infos) const
{
return m_mempool.get_transactions_and_spent_keys_info(
tx_infos, key_image_infos);
}
std::vector<spent_key_image_info>& key_image_infos) const;
virtual uint64_t
get_current_blockchain_height() const
{
return core_storage.get_current_blockchain_height();
}
get_current_blockchain_height() const;
virtual void
get_output_tx_and_index(
const uint64_t& amount,
const std::vector<uint64_t>& offsets,
std::vector<tx_out_index>& indices) const
{
// tx_hash , index in tx
// tx_out_index is std::pair<crypto::hash, uint64_t>;
core_storage.get_db().get_output_tx_and_index(
amount, offsets, indices);
}
uint64_t amount,
std::vector<uint64_t> const& offsets,
std::vector<tx_out_index>& indices) const override;
virtual bool
get_output_histogram(
@ -186,16 +169,10 @@ public:
virtual bool
get_outs(COMMAND_RPC_GET_OUTPUTS_BIN::request const& req,
COMMAND_RPC_GET_OUTPUTS_BIN::response& res) const
{
return core_storage.get_outs(req, res);
}
COMMAND_RPC_GET_OUTPUTS_BIN::response& res) const;
virtual uint64_t
get_dynamic_base_fee_estimate(uint64_t const& grace_blocks) const
{
return core_storage.get_dynamic_base_fee_estimate(grace_blocks);
}
get_dynamic_base_fee_estimate(uint64_t grace_blocks) const;
bool
get_block_complete_entry(block const& b, block_complete_entry& bce);
@ -204,18 +181,12 @@ public:
get_block_from_height(uint64_t height, block& blk) const;
virtual bool
get_tx(crypto::hash const& tx_hash, transaction& tx) const;
get_tx(crypto::hash const& tx_hash, transaction& tx) const override;
virtual bool
decrypt_payment_id(crypto::hash8& payment_id,
public_key const& public_key,
secret_key const& secret_key)
{
return m_device->decrypt_payment_id(payment_id,
public_key,
secret_key);
}
secret_key const& secret_key) const;
virtual bool
init_success() const;

@ -120,7 +120,7 @@ public:
Input(address_parse_info const* _a,
secret_key const* _viewkey,
known_outputs_t const* _known_outputs,
MicroCore* _mcore)
AbstractCore const* _mcore)
: BaseIdentifier(_a, _viewkey),
known_outputs {_known_outputs},
mcore {_mcore}
@ -158,7 +158,7 @@ protected:
secret_key const* viewkey {nullptr};
known_outputs_t const* known_outputs {nullptr};
MicroCore* mcore {nullptr};
AbstractCore const* mcore {nullptr};
vector<info> identified_inputs;
};

@ -46,8 +46,8 @@ public:
bool(uint64_t height, block& blk));
MOCK_CONST_METHOD2(get_blocks_range,
std::vector<block>(const uint64_t& h1,
const uint64_t& h2));
std::vector<block>(uint64_t h1,
uint64_t h2));
MOCK_CONST_METHOD3(get_transactions,
bool(const std::vector<crypto::hash>& txs_ids,
@ -64,11 +64,11 @@ public:
uint64_t& tx_id));
MOCK_CONST_METHOD2(get_output_tx_and_index,
tx_out_index(uint64_t const& amount,
uint64_t const& index));
tx_out_index(uint64_t amount,
uint64_t index));
MOCK_CONST_METHOD3(get_output_tx_and_index,
void(const uint64_t& amount,
void(uint64_t amount,
const std::vector<uint64_t> &offsets,
std::vector<tx_out_index> &indices));
@ -89,8 +89,8 @@ public:
std::vector<uint64_t>(uint64_t const& tx_id));
MOCK_CONST_METHOD2(get_random_outs_for_amounts,
bool(COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request const& req,
COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response& res));
bool(COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request const& req,
COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response& res));
MOCK_CONST_METHOD2(get_outs,
bool(const COMMAND_RPC_GET_OUTPUTS_BIN::request& req,

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save