diff --git a/ext/mstch/include/mstch/mstch.hpp b/ext/mstch/include/mstch/mstch.hpp index 58d3330..68a3cfd 100644 --- a/ext/mstch/include/mstch/mstch.hpp +++ b/ext/mstch/include/mstch/mstch.hpp @@ -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, std::shared_ptr>, std::map, diff --git a/ext/mstch/src/visitor/render_node.hpp b/ext/mstch/src/visitor/render_node.hpp index 633dd4d..88f115f 100644 --- a/ext/mstch/src/visitor/render_node.hpp +++ b/ext/mstch/src/visitor/render_node.hpp @@ -32,6 +32,18 @@ class render_node: public boost::static_visitor { 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"; } diff --git a/main.cpp b/main.cpp index 4a734e8..50fa37d 100644 --- a/main.cpp +++ b/main.cpp @@ -30,7 +30,6 @@ int main(int ac, const char* av[]) { return 0; } - auto port_opt = opts.get_option("port"); auto bc_path_opt = opts.get_option("bc-path"); auto deamon_url_opt = opts.get_option("deamon-url"); diff --git a/src/page.h b/src/page.h index 99e2247..56968df 100644 --- a/src/page.h +++ b/src/page.h @@ -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 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(blk_size) / 1024.0)}, - {"blk_txs" , mstch::array()} + static_cast(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(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(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); diff --git a/src/templates/block.html b/src/templates/block.html index 0d9d0fc..33284c0 100644 --- a/src/templates/block.html +++ b/src/templates/block.html @@ -21,39 +21,60 @@ Δ [h:m:s]:{{delta_time}} - Major version:{{major_ver}} - Minor version:{{minor_ver}} + Major.minor version:{{major_ver}}.{{minor_ver}} + Block reward:{{blk_reward}} Block size [kB]:{{blk_size}} nonce:{{blk_nonce}} - Minor version:{{minor_ver}} + Total fees:{{sum_fees}} No of txs:{{no_txs}} - -

Transactions ({{no_txs}})

+

Miner reward transaction

- - - + - {{#blk_txs}} + {{#coinbase_txs}} - - - + - {{/blk_txs}} + {{/coinbase_txs}}
hashinputs/outputsfeemixin nooutputs size [kB] version
{{hash}}{{sum_inputs}}/{{sum_outputs}}{{tx_fee}}{{mixin}}{{sum_outputs}} {{tx_size}} {{version}}
+ + +

Transactions ({{no_txs}})

+ {{#have_txs}} + + + + + + + + + + {{#blk_txs}} + + + + + + + + + {{/blk_txs}} +
hashinputs/outputsfeemixin nosize [kB]version
{{hash}}{{sum_inputs}}/{{sum_outputs}}{{tx_fee}}{{mixin}}{{tx_size}}{{version}}
+ {{/have_txs}} +