initializing monero blockchain access added to main.cpp

pull/1/head
moneroexamples 8 years ago
parent f696e7114f
commit f4cfa81100

@ -59,41 +59,39 @@ if (!xmreg::get_blockchain_path(bc_path_opt, blockchain_path, testnet))
cout << "Blockchain path: " << blockchain_path.string() << endl;
// enable basic monero log output
xmreg::enable_monero_log();
// create instance of our MicroCore
// and make pointer to the Blockchain
xmreg::MicroCore mcore;
cryptonote::Blockchain* core_storage;
// setup blockchain status monitoring thread
xmreg::CurrentBlockchainStatus::set_blockchain_path(blockchain_path.string());
xmreg::CurrentBlockchainStatus::set_testnet(false);
xmreg::CurrentBlockchainStatus::refresh_block_status_every_seconds = 30;
// initialize mcore and core_storage
if (!xmreg::init_blockchain(blockchain_path.string(),
mcore, core_storage))
// since CurrentBlockchainStatus class monitors current status
// of the blockchain (e.g, current height), its seems logical to
// make static objects for accessing the blockchain in this class.
// this way monero accesssing blockchain variables (i.e. mcore and core_storage)
// are not passed around like crazy everywhere.
// There are here, and this is the only class that
// has direct access to blockchain.
if (!xmreg::CurrentBlockchainStatus::init_monero_blockchain())
{
cerr << "Error accessing blockchain." << endl;
return EXIT_FAILURE;
}
// setup blockchain status monitoring thread
xmreg::CurrentBlockchainStatus::set_blockchain_path(blockchain_path.string());
xmreg::CurrentBlockchainStatus::set_testnet(false);
xmreg::CurrentBlockchainStatus::refresh_block_status_every_seconds = 30;
// 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 launch upon for each user independent.
xmreg::CurrentBlockchainStatus::start_monitor_blockchain_thread();
xmreg::YourMoneroRequests::show_logs = true;
xmreg::YourMoneroRequests::show_logs = true;
xmreg::YourMoneroRequests your_xmr(
shared_ptr<xmreg::MySqlAccounts>(new xmreg::MySqlAccounts{}));
auto login = your_xmr.make_resource(
&xmreg::YourMoneroRequests::login , "/login");

@ -49,6 +49,12 @@ struct CurrentBlockchainStatus
static uint64_t refresh_block_status_every_seconds;
// since this class monitors current status
// of the blockchain, its seems logical to
// make object for accessing the blockchain here
static xmreg::MicroCore mcore;
static cryptonote::Blockchain* core_storage;
static
void start_monitor_blockchain_thread()
{
@ -87,15 +93,35 @@ struct CurrentBlockchainStatus
{
testnet = is_testnet;
}
static bool
init_monero_blockchain()
{
// enable basic monero log output
xmreg::enable_monero_log();
// initialize mcore and core_storage
if (!xmreg::init_blockchain(blockchain_path,
mcore, core_storage))
{
cerr << "Error accessing blockchain." << endl;
return false;
}
return true;
}
};
// initialize static variables
atomic<uint64_t> CurrentBlockchainStatus::current_height {0};
string CurrentBlockchainStatus::blockchain_path {"/home/mwo/.blockchain/lmdb"};
bool CurrentBlockchainStatus::testnet {false};
bool CurrentBlockchainStatus::is_running {false};
std::thread CurrentBlockchainStatus::m_thread;
uint64_t CurrentBlockchainStatus::refresh_block_status_every_seconds {60};
atomic<uint64_t> CurrentBlockchainStatus::current_height {0};
string CurrentBlockchainStatus::blockchain_path {"/home/mwo/.blockchain/lmdb"};
bool CurrentBlockchainStatus::testnet {false};
bool CurrentBlockchainStatus::is_running {false};
std::thread CurrentBlockchainStatus::m_thread;
uint64_t CurrentBlockchainStatus::refresh_block_status_every_seconds {60};
xmreg::MicroCore CurrentBlockchainStatus::mcore;
cryptonote::Blockchain* CurrentBlockchainStatus::core_storage;
class TxSearch
{

Loading…
Cancel
Save