2017-05-16 05:29:24 +00:00
|
|
|
//
|
|
|
|
// Created by mwo on 16/05/17.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef XMRBLOCKS_CURRENTBLOCKCHAINSTATUS_H
|
|
|
|
#define XMRBLOCKS_CURRENTBLOCKCHAINSTATUS_H
|
|
|
|
|
|
|
|
#include "MicroCore.h"
|
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
namespace xmreg
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2017-05-18 00:59:26 +00:00
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
2017-05-17 00:20:43 +00:00
|
|
|
struct CurrentBlockchainStatus
|
2017-05-16 05:29:24 +00:00
|
|
|
{
|
2017-05-17 00:20:43 +00:00
|
|
|
|
2017-05-17 05:30:36 +00:00
|
|
|
struct Emission
|
|
|
|
{
|
|
|
|
uint64_t coinbase;
|
|
|
|
uint64_t fee;
|
|
|
|
uint64_t blk_no;
|
|
|
|
|
|
|
|
inline uint64_t
|
|
|
|
checksum() const
|
|
|
|
{
|
|
|
|
return coinbase + fee + blk_no;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator
|
|
|
|
std::string() const
|
|
|
|
{
|
|
|
|
return to_string(blk_no) + "," + to_string(coinbase)
|
|
|
|
+ "," + to_string(fee) + "," + to_string(checksum());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 00:59:26 +00:00
|
|
|
static bf::path blockchain_path;
|
2017-05-16 05:29:24 +00:00
|
|
|
|
2017-05-17 00:20:43 +00:00
|
|
|
static bool testnet;
|
|
|
|
|
2017-05-16 05:29:24 +00:00
|
|
|
static string output_file;
|
|
|
|
|
|
|
|
static string deamon_url;
|
|
|
|
|
2017-05-19 02:22:11 +00:00
|
|
|
// how many blocks to read before thread goes to sleep
|
2017-05-17 00:20:43 +00:00
|
|
|
static uint64_t blockchain_chunk_size;
|
|
|
|
|
2017-05-19 02:22:11 +00:00
|
|
|
// gap from what we store total_emission_atomic and
|
|
|
|
// current blockchain height. We dont want to store
|
|
|
|
// what is on, e.g., top block, as this can get messy
|
|
|
|
// if the block gets orphaned or blockchain reorganization
|
|
|
|
// occurs. So the top 3 blocks (default number) will always
|
|
|
|
// be calculated in flight and added to what we have so far.
|
|
|
|
static uint64_t blockchain_chunk_gap;
|
|
|
|
|
|
|
|
// current blockchain height and
|
|
|
|
// hash of top block
|
2017-05-16 05:29:24 +00:00
|
|
|
static atomic<uint64_t> current_height;
|
|
|
|
|
2017-05-19 02:22:11 +00:00
|
|
|
|
2017-05-17 05:30:36 +00:00
|
|
|
static atomic<Emission> total_emission_atomic;
|
2017-05-16 05:29:24 +00:00
|
|
|
|
2017-05-19 02:22:11 +00:00
|
|
|
|
2017-05-16 05:29:24 +00:00
|
|
|
static std::thread m_thread;
|
|
|
|
|
|
|
|
static atomic<bool> is_running;
|
|
|
|
|
|
|
|
// make object for accessing the blockchain here
|
|
|
|
static unique_ptr<xmreg::MicroCore> mcore;
|
|
|
|
|
2017-05-17 00:20:43 +00:00
|
|
|
static cryptonote::Blockchain *core_storage;
|
2017-05-16 05:29:24 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
start_monitor_blockchain_thread();
|
|
|
|
|
|
|
|
static bool
|
|
|
|
init_monero_blockchain();
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_current_emission_amount();
|
|
|
|
|
2017-05-19 02:22:11 +00:00
|
|
|
static Emission
|
|
|
|
calculate_emission_in_blocks(uint64_t start_blk, uint64_t end_blk);
|
|
|
|
|
2017-05-16 05:29:24 +00:00
|
|
|
static bool
|
|
|
|
save_current_emission_amount();
|
|
|
|
|
|
|
|
static bool
|
|
|
|
load_current_emission_amount();
|
|
|
|
|
2017-05-17 05:30:36 +00:00
|
|
|
static Emission
|
|
|
|
get_emission();
|
2017-05-16 05:29:24 +00:00
|
|
|
|
2017-05-18 00:59:26 +00:00
|
|
|
static bf::path
|
2017-05-17 00:20:43 +00:00
|
|
|
get_output_file_path();
|
|
|
|
|
2017-05-16 05:29:24 +00:00
|
|
|
static bool
|
|
|
|
is_thread_running();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //XMRBLOCKS_CURRENTBLOCKCHAINSTATUS_H
|