testnet option added to xmrblocks

master
moneroexamples 8 years ago
parent f9925d6c3b
commit c23213cd89

@ -25,6 +25,7 @@ int main(int ac, const char* av[]) {
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)
@ -32,6 +33,8 @@ int main(int ac, const char* av[]) {
return EXIT_SUCCESS;
}
bool testnet {*testnet_opt};
auto port_opt = opts.get_option<string>("port");
auto bc_path_opt = opts.get_option<string>("bc-path");
auto custom_db_path_opt = opts.get_option<string>("custom-db-path");
@ -43,12 +46,14 @@ int main(int ac, const char* av[]) {
// get blockchain path
path blockchain_path;
if (!xmreg::get_blockchain_path(bc_path_opt, blockchain_path))
if (!xmreg::get_blockchain_path(bc_path_opt, blockchain_path, testnet))
{
cerr << "Error getting blockchain path." << endl;
return EXIT_FAILURE;
}
cout << blockchain_path << endl;
// enable basic monero log output
xmreg::enable_monero_log();
@ -94,10 +99,18 @@ int main(int ac, const char* av[]) {
custom_db_path_str = xmreg::remove_trailing_path_separator(custom_db_path_str);
string deamon_url {*deamon_url_opt};
if (testnet)
deamon_url = "http:://127.0.0.1:28081";
// create instance of page class which
// contains logic for the website
xmreg::page xmrblocks(&mcore, core_storage,
*deamon_url_opt, custom_db_path_str);
deamon_url,
custom_db_path_str,
testnet);
// crow instance
crow::SimpleApp app;

@ -23,6 +23,8 @@ namespace xmreg
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")
("port,p", value<string>()->default_value("8081"),
"default port")
("bc-path,b", value<string>(),

@ -234,16 +234,19 @@ namespace xmreg {
string lmdb2_path;
bool testnet;
public:
page(MicroCore* _mcore, Blockchain* _core_storage,
string _deamon_url, string _lmdb2_path)
string _deamon_url, string _lmdb2_path, bool _testnet)
: mcore {_mcore},
core_storage {_core_storage},
rpc {_deamon_url},
server_timestamp {std::time(nullptr)},
lmdb2_path {_lmdb2_path}
lmdb2_path {_lmdb2_path},
testnet {_testnet}
{
}
@ -972,6 +975,7 @@ namespace xmreg {
{"tx_size" , fmt::format("{:0.4f}",
static_cast<double>(txd.size) / 1024.0)},
{"tx_fee" , fmt::format("{:0.12f}", XMR_AMOUNT(txd.fee))},
{"tx_version" , fmt::format("{:d}", txd.version)},
{"blk_timestamp" , blk_timestamp},
{"blk_timestamp_uint" , blk.timestamp},
{"delta_time" , age.first},

@ -35,6 +35,9 @@
<td>Fee: {{tx_fee}}</td>
<td>Tx size: {{tx_size}} kB</td>
</tr>
<tr>
<td>Tx version: {{tx_version}}</td>
</tr>
<tr>
<td colspan="5">Extra: {{extra}}</td>

@ -223,12 +223,16 @@ namespace xmreg
string
get_default_lmdb_folder()
get_default_lmdb_folder(bool testnet)
{
// default path to monero folder
// on linux this is /home/<username>/.bitmonero
string default_monero_dir = tools::get_default_data_dir();
if (testnet)
default_monero_dir += "/testnet";
// the default folder of the lmdb blockchain database
// is therefore as follows
return default_monero_dir + string("/lmdb");
@ -241,17 +245,17 @@ namespace xmreg
* If not given, provide default path
*/
bool
get_blockchain_path(const boost::optional<string>& bc_path, bf::path& blockchain_path )
get_blockchain_path(const boost::optional<string>& bc_path,
bf::path& blockchain_path,
bool testnet)
{
// the default folder of the lmdb blockchain database
string default_lmdb_dir = xmreg::get_default_lmdb_folder();
string default_lmdb_dir = xmreg::get_default_lmdb_folder(testnet);
blockchain_path = bc_path
? bf::path(*bc_path)
: bf::path(default_lmdb_dir);
if (!bf::is_directory(blockchain_path))
{
cerr << "Given path \"" << blockchain_path << "\" "

@ -118,7 +118,7 @@ namespace xmreg
string
get_default_lmdb_folder();
get_default_lmdb_folder(bool testnet = false);
bool
generate_key_image(const crypto::key_derivation& derivation,
@ -129,7 +129,8 @@ namespace xmreg
bool
get_blockchain_path(const boost::optional<string>& bc_path,
bf::path& blockchain_path);
bf::path& blockchain_path,
bool testnet = false);
uint64_t
sum_money_in_outputs(const transaction& tx);

Loading…
Cancel
Save