|
|
|
@ -278,202 +278,6 @@ public:
|
|
|
|
|
no_of_mempool_tx_of_frontpage = 25;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Show recent blocks and mempool
|
|
|
|
|
*
|
|
|
|
|
* Not used currently. index2 method is used instead
|
|
|
|
|
*
|
|
|
|
|
* @param page_no block page to show
|
|
|
|
|
* @param refresh_page enable autorefresh
|
|
|
|
|
* @return rendered index page
|
|
|
|
|
*/
|
|
|
|
|
string
|
|
|
|
|
index(uint64_t page_no = 0, bool refresh_page = false)
|
|
|
|
|
{
|
|
|
|
|
// connect to the deamon if not yet connected
|
|
|
|
|
bool is_connected = rpc.connect_to_monero_deamon();
|
|
|
|
|
|
|
|
|
|
if (!is_connected)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Connection to the Monero demon does not exist or was lost!" << endl;
|
|
|
|
|
return "Connection to the Monero demon does not exist or was lost!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get current server timestamp
|
|
|
|
|
server_timestamp = std::time(nullptr);
|
|
|
|
|
|
|
|
|
|
// number of last blocks to show
|
|
|
|
|
uint64_t no_of_last_blocks {100 + 1};
|
|
|
|
|
|
|
|
|
|
uint64_t height = rpc.get_current_height() - 1;
|
|
|
|
|
|
|
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
|
mstch::map context {
|
|
|
|
|
{"refresh" , refresh_page},
|
|
|
|
|
{"height" , std::to_string(height)},
|
|
|
|
|
{"server_timestamp", xmreg::timestamp_to_str(server_timestamp)},
|
|
|
|
|
{"age_format" , string("[h:m:d]")},
|
|
|
|
|
{"page_no" , std::to_string(page_no)},
|
|
|
|
|
{"total_page_no" , std::to_string(height / (no_of_last_blocks))},
|
|
|
|
|
{"is_page_zero" , !bool(page_no)},
|
|
|
|
|
{"next_page" , std::to_string(page_no + 1)},
|
|
|
|
|
{"prev_page" , std::to_string((page_no > 0 ? page_no - 1 : 0))}
|
|
|
|
|
};
|
|
|
|
|
context.emplace("blocks", mstch::array());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get reference to blocks template map to be field below
|
|
|
|
|
mstch::array& blocks = boost::get<mstch::array>(context["blocks"]);
|
|
|
|
|
|
|
|
|
|
// calculate starting and ending block numbers to show
|
|
|
|
|
uint64_t start_height = height - no_of_last_blocks * (page_no + 1);
|
|
|
|
|
uint64_t end_height = height - no_of_last_blocks * (page_no);
|
|
|
|
|
|
|
|
|
|
// check few conditions to make sure we are whithin the avaliable range
|
|
|
|
|
//@TODO its too messed up. needs to find cleaner way.
|
|
|
|
|
start_height = start_height > 0 ? start_height : 0;
|
|
|
|
|
end_height = end_height < height ? end_height : height;
|
|
|
|
|
start_height = start_height > end_height ? 0 : start_height;
|
|
|
|
|
end_height = end_height - start_height > no_of_last_blocks
|
|
|
|
|
? no_of_last_blocks : end_height;
|
|
|
|
|
|
|
|
|
|
// previous blk timestamp, initalised to lowest possible value
|
|
|
|
|
double prev_blk_timestamp {std::numeric_limits<double>::lowest()};
|
|
|
|
|
|
|
|
|
|
// iterate over last no_of_last_blocks of blocks
|
|
|
|
|
for (uint64_t i = start_height; i <= end_height; ++i)
|
|
|
|
|
{
|
|
|
|
|
// get block at the given height i
|
|
|
|
|
block blk;
|
|
|
|
|
|
|
|
|
|
if (!mcore->get_block_by_height(i, blk))
|
|
|
|
|
{
|
|
|
|
|
cerr << "Cant get block: " << i << endl;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get block's hash
|
|
|
|
|
crypto::hash blk_hash = core_storage->get_block_id_by_height(i);
|
|
|
|
|
|
|
|
|
|
// remove "<" and ">" from the hash string
|
|
|
|
|
string blk_hash_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", blk_hash));
|
|
|
|
|
|
|
|
|
|
// get block timestamp in user friendly format
|
|
|
|
|
string timestamp_str = xmreg::timestamp_to_str(blk.timestamp);
|
|
|
|
|
|
|
|
|
|
pair<string, string> age = get_age(server_timestamp, blk.timestamp);
|
|
|
|
|
|
|
|
|
|
context["age_format"] = age.second;
|
|
|
|
|
|
|
|
|
|
// get time difference [m] between previous and current blocks
|
|
|
|
|
string time_delta_str {};
|
|
|
|
|
|
|
|
|
|
if (prev_blk_timestamp > std::numeric_limits<double>::lowest())
|
|
|
|
|
{
|
|
|
|
|
time_delta_str = fmt::format("{:0.2f}",
|
|
|
|
|
(double(blk.timestamp) - double(prev_blk_timestamp))/60.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get xmr in the block reward
|
|
|
|
|
array<uint64_t, 2> coinbase_tx = sum_money_in_tx(blk.miner_tx);
|
|
|
|
|
|
|
|
|
|
// get transactions in the block
|
|
|
|
|
const vector<cryptonote::transaction>& txs_in_blk =
|
|
|
|
|
core_storage->get_db().get_tx_list(blk.tx_hashes);
|
|
|
|
|
|
|
|
|
|
// sum xmr in the inputs and ouputs of all transactions
|
|
|
|
|
array<uint64_t, 2> sum_xmr_in_out = sum_money_in_txs(txs_in_blk);
|
|
|
|
|
|
|
|
|
|
// get sum of all transactions in the block
|
|
|
|
|
uint64_t sum_fees = sum_fees_in_txs(txs_in_blk);
|
|
|
|
|
|
|
|
|
|
// get mixin number in each transaction
|
|
|
|
|
vector<uint64_t> mixin_numbers = xmreg::get_mixin_no_in_txs(txs_in_blk);
|
|
|
|
|
|
|
|
|
|
// find minimum and maxium mixin numbers
|
|
|
|
|
int mixin_min {-1};
|
|
|
|
|
int mixin_max {-1};
|
|
|
|
|
|
|
|
|
|
if (!mixin_numbers.empty())
|
|
|
|
|
{
|
|
|
|
|
mixin_min = static_cast<int>(
|
|
|
|
|
*std::min_element(mixin_numbers.begin(), mixin_numbers.end()));
|
|
|
|
|
mixin_max = static_cast<int>(
|
|
|
|
|
*max_element(mixin_numbers.begin(), mixin_numbers.end()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mixing format for the templates
|
|
|
|
|
auto mixin_format = [=]() -> mstch::node
|
|
|
|
|
{
|
|
|
|
|
if (mixin_min < 0)
|
|
|
|
|
{
|
|
|
|
|
return string("N/A");
|
|
|
|
|
}
|
|
|
|
|
return fmt::format("{:d}-{:d}", mixin_min - 1, mixin_max - 1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// get block size in bytes
|
|
|
|
|
uint64_t blk_size = get_object_blobsize(blk);
|
|
|
|
|
|
|
|
|
|
// set output page template map
|
|
|
|
|
blocks.push_back(mstch::map {
|
|
|
|
|
{"height" , to_string(i)},
|
|
|
|
|
{"timestamp" , timestamp_str},
|
|
|
|
|
{"time_delta" , time_delta_str},
|
|
|
|
|
{"age" , age.first},
|
|
|
|
|
{"hash" , blk_hash_str},
|
|
|
|
|
{"block_reward", fmt::format("{:0.4f}/{:0.4f}",
|
|
|
|
|
XMR_AMOUNT(coinbase_tx[1] - sum_fees),
|
|
|
|
|
XMR_AMOUNT(sum_fees))},
|
|
|
|
|
{"fees" , fmt::format("{:0.3f}", XMR_AMOUNT(sum_fees))},
|
|
|
|
|
{"notx" , fmt::format("{:d}", blk.tx_hashes.size())},
|
|
|
|
|
{"xmr_inputs" , fmt::format("{:0.2f}",
|
|
|
|
|
XMR_AMOUNT(sum_xmr_in_out[0]))},
|
|
|
|
|
{"xmr_outputs" , fmt::format("{:0.2f}",
|
|
|
|
|
XMR_AMOUNT(sum_xmr_in_out[1]))},
|
|
|
|
|
{"mixin_range" , mstch::lambda {mixin_format}},
|
|
|
|
|
{"blksize" , fmt::format("{:0.2f}",
|
|
|
|
|
static_cast<double>(blk_size) / 1024.0)}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// save current's block timestamp as reference for the next one
|
|
|
|
|
prev_blk_timestamp = static_cast<double>(blk.timestamp);
|
|
|
|
|
|
|
|
|
|
} // for (uint64_t i = start_height; i <= end_height; ++i)
|
|
|
|
|
|
|
|
|
|
// reverse blocks and remove last (i.e., oldest)
|
|
|
|
|
// block. This is done so that time delats
|
|
|
|
|
// are easier to calcualte in the above for loop
|
|
|
|
|
std::reverse(blocks.begin(), blocks.end());
|
|
|
|
|
|
|
|
|
|
// if we look at the genesis time, we should not remove
|
|
|
|
|
// the last block, i.e. genesis one.
|
|
|
|
|
if (!(start_height < 2))
|
|
|
|
|
{
|
|
|
|
|
blocks.pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get memory pool rendered template
|
|
|
|
|
string mempool_html = mempool();
|
|
|
|
|
|
|
|
|
|
// append mempool_html to the index context map
|
|
|
|
|
context["mempool_info"] = mempool_html;
|
|
|
|
|
|
|
|
|
|
// read index.html
|
|
|
|
|
string index_html = xmreg::read(TMPL_INDEX);
|
|
|
|
|
|
|
|
|
|
// add header and footer
|
|
|
|
|
string full_page = get_full_page(index_html);
|
|
|
|
|
|
|
|
|
|
context["css_styles"] = this->css_styles;
|
|
|
|
|
|
|
|
|
|
// render the page
|
|
|
|
|
return mstch::render(full_page, context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief show recent transactions and mempool
|
|
|
|
|
* @param page_no block page to show
|
|
|
|
|