emission for testnet network added

master
moneroexamples 8 years ago
parent d6bcf94a3d
commit 7a4a02b563

@ -128,18 +128,6 @@ int main(int ac, const char* av[]) {
cout << blockchain_path << endl; cout << blockchain_path << endl;
if (!xmreg::CurrentBlockchainStatus::init_monero_blockchain())
{
cerr << "Error accessing blockchain." << endl;
return EXIT_FAILURE;
}
// launch the status monitoring thread so that it keeps track of blockchain
// info, e.g., current height. Information from this thread is used
// by tx searching threads that are launched for each user independently,
// when they log back or create new account.
xmreg::CurrentBlockchainStatus::start_monitor_blockchain_thread();
// create instance of our MicroCore // create instance of our MicroCore
// and make pointer to the Blockchain // and make pointer to the Blockchain
@ -157,7 +145,28 @@ int main(int ac, const char* av[]) {
string deamon_url {*deamon_url_opt}; string deamon_url {*deamon_url_opt};
if (testnet && deamon_url == "http:://127.0.0.1:18081") if (testnet && deamon_url == "http:://127.0.0.1:18081")
{
deamon_url = "http:://127.0.0.1:28081"; deamon_url = "http:://127.0.0.1:28081";
}
xmreg::CurrentBlockchainStatus::blockchain_path
= blockchain_path.string();
xmreg::CurrentBlockchainStatus::testnet
= testnet;
xmreg::CurrentBlockchainStatus::deamon_url
= deamon_url;
if (!xmreg::CurrentBlockchainStatus::init_monero_blockchain())
{
cerr << "Error accessing blockchain from CurrentBlockchainStatus." << endl;
return EXIT_FAILURE;
}
// launch the status monitoring thread so that it keeps track of blockchain
// info, e.g., current height. Information from this thread is used
// by tx searching threads that are launched for each user independently,
// when they log back or create new account.
xmreg::CurrentBlockchainStatus::start_monitor_blockchain_thread();
// create instance of page class which // create instance of page class which
// contains logic for the website // contains logic for the website

@ -39,13 +39,21 @@ void
CurrentBlockchainStatus::start_monitor_blockchain_thread() CurrentBlockchainStatus::start_monitor_blockchain_thread()
{ {
string emmision_saved_file = blockchain_path + output_file; string emmision_saved_file = get_output_file_path();
if (boost::filesystem::exists(emmision_saved_file)) if (boost::filesystem::exists(emmision_saved_file))
{ {
if (!load_current_emission_amount()) if (!load_current_emission_amount())
{ {
cerr << "Cant read or has incorrect format: " << emmision_saved_file << endl; cerr << "Emission file cant be read, got corrupted or has incorrect format:\n " << emmision_saved_file
<< "\nEmission monitoring thread is not started.\nDelete the file and"
<< " restart the explorer or disable emission monitoring."
<< endl;
cerr << "Press ENTER to continue without emission monitoring or Ctr+C to exit" << endl;
cin.get();
return; return;
} }
} }
@ -62,7 +70,7 @@ CurrentBlockchainStatus::start_monitor_blockchain_thread()
save_current_emission_amount(); save_current_emission_amount();
if (searched_blk_no < current_height - 1000) if (searched_blk_no < current_height - blockchain_chunk_size)
{ {
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
} }
@ -84,11 +92,9 @@ CurrentBlockchainStatus::update_current_emission_amount()
cout << "updating emission rate: " << current_height << endl; cout << "updating emission rate: " << current_height << endl;
uint64_t no_of_blocks_to_search_at_once {1000};
uint64_t blk_no = searched_blk_no; uint64_t blk_no = searched_blk_no;
uint64_t end_block = blk_no + no_of_blocks_to_search_at_once; uint64_t end_block = blk_no + blockchain_chunk_size;
uint64_t current_blockchain_height = current_height; uint64_t current_blockchain_height = current_height;
@ -140,7 +146,7 @@ bool
CurrentBlockchainStatus::save_current_emission_amount() CurrentBlockchainStatus::save_current_emission_amount()
{ {
string emmision_saved_file = blockchain_path + output_file; string emmision_saved_file = get_output_file_path();
ofstream out(emmision_saved_file); ofstream out(emmision_saved_file);
@ -168,33 +174,39 @@ CurrentBlockchainStatus::save_current_emission_amount()
bool bool
CurrentBlockchainStatus::load_current_emission_amount() CurrentBlockchainStatus::load_current_emission_amount()
{ {
string emmision_saved_file = blockchain_path + output_file; string emmision_saved_file = get_output_file_path();
string last_saved_emmision = xmreg::read(emmision_saved_file); string last_saved_emmision = xmreg::read(emmision_saved_file);
if (last_saved_emmision.empty()) { if (last_saved_emmision.empty())
{
cerr << "Couldn't open file." << endl; cerr << "Couldn't open file." << endl;
return false; return false;
} }
last_saved_emmision.erase(last_saved_emmision.find_last_not_of(" \n\r\t")+1);
vector<string> strs; vector<string> strs;
boost::split(strs, last_saved_emmision, boost::is_any_of(",")); boost::split(strs, last_saved_emmision, boost::is_any_of(","));
if (strs.empty()) { if (strs.empty())
{
cerr << "Problem spliting string values form emission_amount." << endl; cerr << "Problem spliting string values form emission_amount." << endl;
return false; return false;
} }
uint64_t read_check_sum{0}; uint64_t read_check_sum{0};
try { try
{
searched_blk_no = boost::lexical_cast<uint64_t>(strs.at(0)); searched_blk_no = boost::lexical_cast<uint64_t>(strs.at(0));
total_emission_amount = boost::lexical_cast<uint64_t>(strs.at(1)); total_emission_amount = boost::lexical_cast<uint64_t>(strs.at(1));
total_fee_amount = boost::lexical_cast<uint64_t>(strs.at(2)); total_fee_amount = boost::lexical_cast<uint64_t>(strs.at(2));
read_check_sum = boost::lexical_cast<uint64_t>(strs.at(3)); read_check_sum = boost::lexical_cast<uint64_t>(strs.at(3));
} }
catch (boost::bad_lexical_cast &e) { catch (boost::bad_lexical_cast &e)
cerr << "Cant parse to number: " << last_saved_emmision << endl; {
cerr << "Cant parse to number date from string: " << last_saved_emmision << endl;
return false; return false;
} }
@ -202,7 +214,8 @@ CurrentBlockchainStatus::load_current_emission_amount()
+ uint64_t(total_emission_amount) + uint64_t(total_emission_amount)
+ uint64_t(total_fee_amount); + uint64_t(total_fee_amount);
if (read_check_sum != check_sum) { if (read_check_sum != check_sum)
{
cerr << "read_check_sum != check_sum: " cerr << "read_check_sum != check_sum: "
<< read_check_sum << " != " << check_sum << read_check_sum << " != " << check_sum
<< endl; << endl;
@ -214,6 +227,15 @@ CurrentBlockchainStatus::load_current_emission_amount()
} }
string
CurrentBlockchainStatus::get_output_file_path()
{
string emmision_saved_file = blockchain_path + output_file;
return emmision_saved_file;
}
vector<uint64_t> vector<uint64_t>
CurrentBlockchainStatus::get_emission_amount() CurrentBlockchainStatus::get_emission_amount()
{ {
@ -234,10 +256,14 @@ CurrentBlockchainStatus::is_thread_running()
string CurrentBlockchainStatus::blockchain_path{"/home/mwo/.bitmonero/lmdb"}; string CurrentBlockchainStatus::blockchain_path{"/home/mwo/.bitmonero/lmdb"};
bool CurrentBlockchainStatus::testnet {false};
string CurrentBlockchainStatus::output_file {"/emission_amount.txt"}; string CurrentBlockchainStatus::output_file {"/emission_amount.txt"};
string CurrentBlockchainStatus::deamon_url{"http:://127.0.0.1:18081"}; string CurrentBlockchainStatus::deamon_url{"http:://127.0.0.1:18081"};
uint64_t CurrentBlockchainStatus::blockchain_chunk_size {10000};
atomic<uint64_t> CurrentBlockchainStatus::current_height {0}; atomic<uint64_t> CurrentBlockchainStatus::current_height {0};
atomic<uint64_t> CurrentBlockchainStatus::total_emission_amount {0} ; atomic<uint64_t> CurrentBlockchainStatus::total_emission_amount {0} ;

@ -20,17 +20,23 @@ namespace xmreg
using namespace std; using namespace std;
class CurrentBlockchainStatus struct CurrentBlockchainStatus
{ {
static string blockchain_path; static string blockchain_path;
static bool testnet;
static string output_file; static string output_file;
static string deamon_url; static string deamon_url;
static uint64_t blockchain_chunk_size;
static atomic<uint64_t> current_height; static atomic<uint64_t> current_height;
static atomic<uint64_t> total_emission_amount; static atomic<uint64_t> total_emission_amount;
static atomic<uint64_t> total_fee_amount; static atomic<uint64_t> total_fee_amount;
static atomic<uint64_t> searched_blk_no; static atomic<uint64_t> searched_blk_no;
@ -41,10 +47,9 @@ class CurrentBlockchainStatus
// make object for accessing the blockchain here // make object for accessing the blockchain here
static unique_ptr<xmreg::MicroCore> mcore; static unique_ptr<xmreg::MicroCore> mcore;
static cryptonote::Blockchain *core_storage;
static cryptonote::Blockchain *core_storage;
public:
static void static void
start_monitor_blockchain_thread(); start_monitor_blockchain_thread();
@ -63,9 +68,11 @@ public:
static vector<uint64_t> static vector<uint64_t>
get_emission_amount(); get_emission_amount();
static string
get_output_file_path();
static bool static bool
is_thread_running(); is_thread_running();
}; };
} }

Loading…
Cancel
Save