diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f44fb6..1cb8d07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 2.8) #list(INSERT # CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake) diff --git a/src/monero_headers.h b/src/monero_headers.h index 51a4443..1ee0611 100644 --- a/src/monero_headers.h +++ b/src/monero_headers.h @@ -8,6 +8,12 @@ #define DB_LMDB 2 #define BLOCKCHAIN_DB DB_LMDB + +#include "net/http_base.h" +#include "net/http_server_handlers_map2.h" +#include "net/http_client.h" +#include "storages/http_abstract_invoke.h" + #include "cryptonote_core/cryptonote_basic.h" #include "cryptonote_core/blockchain_storage.h" #include "cryptonote_core/blockchain.h" diff --git a/src/page.h b/src/page.h index da3c500..6c75eb4 100644 --- a/src/page.h +++ b/src/page.h @@ -23,10 +23,11 @@ #include -#define TMPL_DIR "./templates" -#define TMPL_INDEX TMPL_DIR "/index.html" -#define TMPL_HEADER TMPL_DIR "/header.html" -#define TMPL_FOOTER TMPL_DIR "/footer.html" +#define TMPL_DIR "./templates" +#define TMPL_INDEX TMPL_DIR "/index.html" +#define TMPL_MEMPOOL TMPL_DIR "/mempool.html" +#define TMPL_HEADER TMPL_DIR "/header.html" +#define TMPL_FOOTER TMPL_DIR "/footer.html" @@ -36,6 +37,10 @@ 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; + class page { @@ -165,8 +170,14 @@ namespace xmreg { std::reverse(blocks.begin(), blocks.end()); blocks.pop_back(); + string mempool_html = mempool(); + + + context["mempool_info"] = mempool_html; + + // read index.html - std::string index_html = xmreg::read(TMPL_INDEX); + string index_html = xmreg::read(TMPL_INDEX); // add header and footer string full_page = get_full_page(index_html); @@ -176,6 +187,78 @@ namespace xmreg { } + string + mempool() + { + string deamon_url {"http:://127.0.0.1:18081"}; + + // perform RPC call to deamon to get + // its transaction pull + boost::mutex m_daemon_rpc_mutex; + + request req; + response res; + + http_simple_client m_http_client; + + m_daemon_rpc_mutex.lock(); + + bool r = epee::net_utils::invoke_http_json_remote_command2( + deamon_url + "/get_transaction_pool", + req, res, m_http_client, 200000); + + m_daemon_rpc_mutex.unlock(); + + if (!r) + { + cerr << "Error connecting to Monero deamon at " + << deamon_url << endl; + return "Error connecting to Monero deamon to get mempool"; + } + + // initalise page tempate map with basic info about blockchain + mstch::map context { + {"mempool_size", fmt::format("{:d}", res.transactions.size())}, + {"mempooltxs" , mstch::array()} + }; + + // get reference to blocks template map to be field below + mstch::array& txs = boost::get(context["mempooltxs"]); + + // for each transaction in the memory pool + for (size_t i = 0; i < res.transactions.size(); ++i) + { + // get transaction info of the tx in the mempool + cryptonote::tx_info _tx_info = res.transactions.at(i); + + // display basic info + fmt::print("Tx hash: {:s}\n", _tx_info.id_hash); + + fmt::print("Fee: {:0.10f} xmr, size {:d} bytes\n", + XMR_AMOUNT(_tx_info.fee), + _tx_info.blob_size); + + fmt::print("Receive time: {:s}\n", + xmreg::timestamp_to_str(_tx_info.receive_time)); + + // set output page template map + txs.push_back(mstch::map { + {"timestamp" , xmreg::timestamp_to_str(_tx_info.receive_time)}, + {"hash" , fmt::format("<{:s}>", _tx_info.id_hash)}, + {"fee" , fmt::format("{:0.4f}", XMR_AMOUNT(_tx_info.fee))}, + {"xmr_outputs" , fmt::format("{:0.4f}", 0.0)}, + {"mixin_range" , 0} + }); + } + + // read index.html + string mempool_html = xmreg::read(TMPL_MEMPOOL); + + // render the page + return mstch::render(mempool_html, context); + } + + private: string diff --git a/src/templates/css/style.css b/src/templates/css/style.css index 7189e3e..9c8abc6 100644 --- a/src/templates/css/style.css +++ b/src/templates/css/style.css @@ -1,3 +1,15 @@ +body { + margin: 0; + padding: 0; +} + +.center { + margin: auto; + width: 96%; + border: 1px solid #73AD21; + padding: 10px; +} + tr { font-family: "Lucida Console", Monaco, monospace; font-size : 12px; diff --git a/src/templates/index.html b/src/templates/index.html index 8dd554a..679d3eb 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -9,9 +9,16 @@ Autorefresh OFF {{/refresh}} -
-
    - + + + {{{mempool_info}}} + + +

    100 recent blocks

    + +
    + +
    @@ -34,6 +41,4 @@ {{/blocks}}
    height timestamp_(Δ mm:ss)
    -
-
diff --git a/src/templates/mempool.html b/src/templates/mempool.html new file mode 100644 index 0000000..de4416d --- /dev/null +++ b/src/templates/mempool.html @@ -0,0 +1,29 @@ +

+ Memory pool (size: {{mempool_size}}) +

+
+ + + + + + + + + + + + {{#mempooltxs}} + + + + + + + + + {{/mempooltxs}} +
heighttimestamptx hashtx feeno_of_txsxmr_outputsmixin_range
N/A{{timestamp}}{{hash}}{{fee}}{{xmr_outputs}}{{mixin_range}}
+ + +