More block info added

master
moneroexamples 9 years ago
parent e9dcc0fc42
commit 72279c5340

@ -94,7 +94,7 @@ class lambda_t {
}
using node = boost::make_recursive_variant<
std::nullptr_t, std::string, int, double, bool,
std::nullptr_t, std::string, int, double, bool, uint64_t, uint32_t,
internal::lambda_t<boost::recursive_variant_>,
std::shared_ptr<internal::object_t<boost::recursive_variant_>>,
std::map<const std::string, boost::recursive_variant_>,

@ -32,6 +32,18 @@ class render_node: public boost::static_visitor<std::string> {
return ss.str();
}
std::string operator()(const uint64_t& value) const {
std::stringstream ss;
ss << value;
return ss.str();
}
std::string operator()(const uint32_t& value) const {
std::stringstream ss;
ss << value;
return ss.str();
}
std::string operator()(const bool& value) const {
return value ? "true" : "false";
}

@ -30,7 +30,6 @@ int main(int ac, const char* av[]) {
return 0;
}
auto port_opt = opts.get_option<string>("port");
auto bc_path_opt = opts.get_option<string>("bc-path");
auto deamon_url_opt = opts.get_option<string>("deamon-url");

@ -37,11 +37,6 @@ namespace xmreg {
using namespace crypto;
using namespace std;
using request = cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::request;
using response = cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::response;
using http_simple_client = epee::net_utils::http::http_simple_client;
/**
* @brief The tx_details struct
*
@ -72,9 +67,9 @@ namespace xmreg {
return mstch::map {
{"hash" , tx_hash_str},
{"pub_key" , tx_pk_str},
{"tx_fee" , fmt::format("{:0.4f}", XMR_AMOUNT(fee))},
{"sum_inputs" , fmt::format("{:0.4f}", XMR_AMOUNT(xmr_inputs))},
{"sum_outputs" , fmt::format("{:0.4f}", XMR_AMOUNT(xmr_outputs))},
{"tx_fee" , fmt::format("{:0.6f}", XMR_AMOUNT(fee))},
{"sum_inputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_inputs))},
{"sum_outputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_outputs))},
{"mixin" , std::to_string(mixin_no - 1)},
{"version" , std::to_string(version)},
{"unlock_time" , std::to_string(unlock_time)},
@ -389,12 +384,19 @@ namespace xmreg {
// transcation in the block
vector<crypto::hash> tx_hashes = blk.tx_hashes;
bool have_txs = !blk.tx_hashes.empty();
// sum of all transactions in the block
uint64_t sum_fees = 0;
// get tx details for the coinbase tx, i.e., miners reward
tx_details txd_coinbase = get_tx_details(blk.miner_tx, true);
// initalise page tempate map with basic info about blockchain
mstch::map context {
{"blk_hash" , blk_hash_str},
{"blk_height" , fmt::format("{:d}", _blk_height)},
{"blk_height" , _blk_height},
{"blk_timestamp" , blk_timestamp},
{"prev_hash" , prev_hash_str},
{"next_hash" , next_hash_str},
@ -404,16 +406,21 @@ namespace xmreg {
{"no_txs" , std::to_string(blk.tx_hashes.size())},
{"blk_age" , age.first},
{"delta_time" , delta_time},
{"blk_nonce" , std::to_string(blk.nonce)},
{"blk_nonce" , blk.nonce},
{"age_format" , age.second},
{"major_ver" , std::to_string(blk.major_version)},
{"minor_ver" , std::to_string(blk.minor_version)},
{"blk_size" , fmt::format("{:0.4f}",
static_cast<double>(blk_size) / 1024.0)},
{"blk_txs" , mstch::array()}
static_cast<double>(blk_size) / 1024.0)},
{"coinbase_txs" , mstch::array{{txd_coinbase.get_mstch_map()}}},
{"blk_txs" , mstch::array()}
};
// .push_back(txd_coinbase.get_mstch_map()
// boost::get<mstch::array>(context["blk_txs"]).push_back(txd_coinbase.get_mstch_map());
// now process nomral transactions
// get reference to blocks template map to be field below
mstch::array& txs = boost::get<mstch::array>(context["blk_txs"]);
@ -438,10 +445,22 @@ namespace xmreg {
tx_details txd = get_tx_details(tx);
// add fee to the rest
sum_fees += txd.fee;
// add tx details mstch map to context
txs.push_back(txd.get_mstch_map());
}
// add total fees in the block to the context
context["sum_fees"] = fmt::format("{:0.6f}",
XMR_AMOUNT(sum_fees));
// get xmr in the block reward
context["blk_reward"] = fmt::format("{:0.6f}",
XMR_AMOUNT(txd_coinbase.xmr_outputs - sum_fees));
// read block.html
string block_html = xmreg::read(TMPL_BLOCK);
@ -452,6 +471,7 @@ namespace xmreg {
return mstch::render(full_page, context);
}
string
show_block(string _blk_hash)
{
@ -488,7 +508,7 @@ namespace xmreg {
tx_details
get_tx_details(const transaction& tx)
get_tx_details(const transaction& tx, bool coinbase = false)
{
tx_details txd;
@ -505,8 +525,11 @@ namespace xmreg {
// get mixin number
txd.mixin_no = get_mixin_no(tx);
// get tx fee
txd.fee = get_tx_fee(tx);
if (!coinbase)
{
// get tx fee
txd.fee = get_tx_fee(tx);
}
// get tx size in bytes
txd.size = get_object_blobsize(tx);

@ -21,39 +21,60 @@
<td>Δ [h:m:s]:</td><td>{{delta_time}}</td>
</tr>
<tr>
<td>Major version:</td><td>{{major_ver}}</td>
<td>Minor version:</td><td>{{minor_ver}}</td>
<td>Major.minor version:</td><td>{{major_ver}}.{{minor_ver}}</td>
<td>Block reward:</td><td>{{blk_reward}}</td>
<td>Block size [kB]:</td><td>{{blk_size}}</td>
</tr>
<tr>
<td>nonce:</td><td>{{blk_nonce}}</td>
<td>Minor version:</td><td>{{minor_ver}}</td>
<td>Total fees:</td><td>{{sum_fees}}</td>
<td>No of txs:</td><td>{{no_txs}}</td>
</tr>
</table>
<h3>Transactions ({{no_txs}})</h3>
<h3>Miner reward transaction</h3>
<table class="center" style="width:80%">
<tr>
<td>hash</td>
<td>inputs/outputs</td>
<td>fee</td>
<td>mixin no</td>
<td>outputs</td>
<td>size [kB]</td>
<td>version</td>
</tr>
{{#blk_txs}}
{{#coinbase_txs}}
<tr>
<td>{{hash}}</td>
<td>{{sum_inputs}}/{{sum_outputs}}</td>
<td>{{tx_fee}}</td>
<td>{{mixin}}</td>
<td>{{sum_outputs}}</td>
<td>{{tx_size}}</td>
<td>{{version}}</td>
</tr>
{{/blk_txs}}
{{/coinbase_txs}}
</table>
<h3>Transactions ({{no_txs}})</h3>
{{#have_txs}}
<table class="center" style="width:80%">
<tr>
<td>hash</td>
<td>inputs/outputs</td>
<td>fee</td>
<td>mixin no</td>
<td>size [kB]</td>
<td>version</td>
</tr>
{{#blk_txs}}
<tr>
<td>{{hash}}</td>
<td>{{sum_inputs}}/{{sum_outputs}}</td>
<td>{{tx_fee}}</td>
<td>{{mixin}}</td>
<td>{{tx_size}}</td>
<td>{{version}}</td>
</tr>
{{/blk_txs}}
</table>
{{/have_txs}}
</div>

Loading…
Cancel
Save