initializing monero blockchain access added to main.cpp

pull/1/head
moneroexamples 8 years ago
parent 3ec44a658c
commit f696e7114f

@ -5,6 +5,9 @@
#include "ext/restbed/source/restbed"
#include "src/CmdLineOptions.h"
#include "src/MicroCore.h"
#include "src/MySqlConnector.h"
#include "src/YourMoneroRequests.h"
#include "src/tools.h"
@ -13,68 +16,127 @@
using namespace std;
using namespace restbed;
using boost::filesystem::path;
// needed for log system of momero
namespace epee {
unsigned int g_test_dbg_lock_sleep = 0;
}
int
main()
main(int ac, const char* av[])
{
// get command line options
xmreg::CmdLineOptions opts {ac, av};
auto help_opt = opts.get_option<bool>("help");
auto testnet_opt = opts.get_option<bool>("testnet");
// if help was chosen, display help text and finish
if (*help_opt)
{
return EXIT_SUCCESS;
}
bool testnet {*testnet_opt};
xmreg::CurrentBlockchainStatus::set_blockchain_path("/home/mwo/.bitmonero/lmdb");
xmreg::CurrentBlockchainStatus::set_testnet(false);
xmreg::CurrentBlockchainStatus::refresh_block_status_every_seconds = 30;
auto port_opt = opts.get_option<string>("port");
auto bc_path_opt = opts.get_option<string>("bc-path");
xmreg::CurrentBlockchainStatus::start_monitor_blockchain_thread();
//cast port number in string to uint16
uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt);
xmreg::YourMoneroRequests::show_logs = true;
// get blockchain path
path blockchain_path;
if (!xmreg::get_blockchain_path(bc_path_opt, blockchain_path, testnet))
{
cerr << "Error getting blockchain path." << endl;
return EXIT_FAILURE;
}
xmreg::YourMoneroRequests your_xmr(
shared_ptr<xmreg::MySqlAccounts>(new xmreg::MySqlAccounts{}));
cout << "Blockchain path: " << blockchain_path.string() << endl;
// enable basic monero log output
xmreg::enable_monero_log();
auto login = your_xmr.make_resource(
&xmreg::YourMoneroRequests::login , "/login");
// create instance of our MicroCore
// and make pointer to the Blockchain
xmreg::MicroCore mcore;
cryptonote::Blockchain* core_storage;
auto get_address_txs = your_xmr.make_resource(
&xmreg::YourMoneroRequests::get_address_txs , "/get_address_txs");
// initialize mcore and core_storage
if (!xmreg::init_blockchain(blockchain_path.string(),
mcore, core_storage))
{
cerr << "Error accessing blockchain." << endl;
return EXIT_FAILURE;
}
auto get_address_info = your_xmr.make_resource(
&xmreg::YourMoneroRequests::get_address_info , "/get_address_info");
// 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;
auto import_wallet_request = your_xmr.make_resource(
&xmreg::YourMoneroRequests::import_wallet_request, "/import_wallet_request");
// 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();
bool use_ssl {false};
xmreg::YourMoneroRequests::show_logs = true;
auto settings = make_shared< Settings >( );
if (use_ssl)
{
auto ssl_settings = make_shared< SSLSettings >( );
xmreg::YourMoneroRequests your_xmr(
shared_ptr<xmreg::MySqlAccounts>(new xmreg::MySqlAccounts{}));
ssl_settings->set_http_disabled( true );
ssl_settings->set_port(1984);
ssl_settings->set_private_key( Uri( "file:///tmp/mwo.key" ) );
ssl_settings->set_certificate( Uri( "file:///tmp/mwo.crt" ) );
ssl_settings->set_temporary_diffie_hellman( Uri( "file:///tmp/dh2048.pem" ) );
settings->set_ssl_settings(ssl_settings);
}
else
{
settings->set_port(1984);
}
cout << "Start the service at http://localhost:1984" << endl;
auto login = your_xmr.make_resource(
&xmreg::YourMoneroRequests::login , "/login");
Service service;
auto get_address_txs = your_xmr.make_resource(
&xmreg::YourMoneroRequests::get_address_txs , "/get_address_txs");
service.publish(login);
service.publish(get_address_txs);
service.publish(get_address_info);
service.publish(import_wallet_request);
auto get_address_info = your_xmr.make_resource(
&xmreg::YourMoneroRequests::get_address_info , "/get_address_info");
service.start(settings);
auto import_wallet_request = your_xmr.make_resource(
&xmreg::YourMoneroRequests::import_wallet_request, "/import_wallet_request");
return EXIT_SUCCESS;
bool use_ssl {false};
auto settings = make_shared< Settings >( );
if (use_ssl)
{
auto ssl_settings = make_shared< SSLSettings >( );
ssl_settings->set_http_disabled( true );
ssl_settings->set_port(1984);
ssl_settings->set_private_key( Uri( "file:///tmp/mwo.key" ) );
ssl_settings->set_certificate( Uri( "file:///tmp/mwo.crt" ) );
ssl_settings->set_temporary_diffie_hellman( Uri( "file:///tmp/dh2048.pem" ) );
settings->set_ssl_settings(ssl_settings);
}
else
{
settings->set_port(1984);
}
cout << "Start the service at http://localhost:1984" << endl;
Service service;
service.publish(login);
service.publish(get_address_txs);
service.publish(get_address_info);
service.publish(import_wallet_request);
service.start(settings);
return EXIT_SUCCESS;
}

@ -18,15 +18,13 @@ namespace xmreg
p.add("txhash", -1);
options_description desc(
"xmrblocks, start Onion Monero Blockchain Explorer");
"yourmonero, start YourMonare backend service");
desc.add_options()
("help,h", value<bool>()->default_value(false)->implicit_value(true),
"produce help message")
("testnet,t", value<bool>()->default_value(false)->implicit_value(true),
"use testnet blockchain")
("enable-pusher", value<bool>()->default_value(false)->implicit_value(true),
"enable pushing signed tx")
("port,p", value<string>()->default_value("8081"),
"default port")
("bc-path,b", value<string>(),

@ -43,8 +43,6 @@ struct CurrentBlockchainStatus
static bool testnet;
static string blk_path;
static std::thread m_thread;
static bool is_running;

Loading…
Cancel
Save