diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ee65df..c055ede 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,7 @@ endmacro(configure_files) configure_files(${CMAKE_CURRENT_SOURCE_DIR}/src/templates ${CMAKE_CURRENT_BINARY_DIR}/templates) configure_files(${CMAKE_CURRENT_SOURCE_DIR}/src/templates/css ${CMAKE_CURRENT_BINARY_DIR}/templates/css) +configure_files(${CMAKE_CURRENT_SOURCE_DIR}/src/templates/partials ${CMAKE_CURRENT_BINARY_DIR}/templates/partials) target_link_libraries(${PROJECT_NAME} @@ -126,4 +127,4 @@ target_link_libraries(${PROJECT_NAME} lmdb ${Boost_LIBRARIES} pthread - unbound) \ No newline at end of file + unbound) diff --git a/src/MicroCore.cpp b/src/MicroCore.cpp index 713fbdb..d4121f2 100644 --- a/src/MicroCore.cpp +++ b/src/MicroCore.cpp @@ -135,6 +135,29 @@ namespace xmreg return true; } + bool + MicroCore::get_tx(const string& tx_hash_str, transaction& tx) + { + + // parse tx hash string to hash object + crypto::hash tx_hash; + + if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash)) + { + cerr << "Cant parse tx hash: " << tx_hash_str << endl; + return false; + } + + + if (!get_tx(tx_hash, tx)) + { + return false; + } + + + return true; + } + @@ -300,4 +323,4 @@ namespace xmreg } -} \ No newline at end of file +} diff --git a/src/MicroCore.h b/src/MicroCore.h index 9e694a8..ca55c07 100644 --- a/src/MicroCore.h +++ b/src/MicroCore.h @@ -46,6 +46,9 @@ namespace xmreg bool get_tx(const crypto::hash& tx_hash, transaction& tx); + bool + get_tx(const string& tx_hash, transaction& tx); + bool find_output_in_tx(const transaction& tx, const public_key& output_pubkey, diff --git a/src/page.h b/src/page.h index 962f72e..aee4fd9 100644 --- a/src/page.h +++ b/src/page.h @@ -25,6 +25,7 @@ #include #define TMPL_DIR "./templates" +#define TMPL_PARIALS_DIR TMPL_DIR "/partials" #define TMPL_INDEX TMPL_DIR "/index.html" #define TMPL_MEMPOOL TMPL_DIR "/mempool.html" #define TMPL_HEADER TMPL_DIR "/header.html" @@ -969,9 +970,9 @@ namespace xmreg { // initalise page tempate map with basic info about blockchain mstch::map context { {"search_text", search_text}, + {"no_results" , true}, }; - string out_tmp {"Searching for: " + search_text + string("
")}; for (const pair>& found_txs: all_possible_tx_hashes) { @@ -985,36 +986,46 @@ namespace xmreg { pair< mstch::map::iterator, bool> res = context.insert({found_txs.first, mstch::array{}}); - if (!found_txs.second.empty()) - { - out_tmp += found_txs.first + string("
"); - - cout << "found_txs.first: " << found_txs.first << endl; + { + // for each found tx_hash, get the corresponding tx + // and its details, and put into mstch for rendering for (const string& tx_hash: found_txs.second) { - boost::get((res.first)->second).push_back( - mstch::map {{"tx_hash", tx_hash}} - ); + transaction tx; - out_tmp += string(" - ") - + fmt::format("{:s}", tx_hash) - + string("
"); + if (!mcore->get_tx(tx_hash, tx)) + { + return string("Cant get tx of hash: " + tx_hash); + } + + tx_details txd = get_tx_details(tx); + + boost::get((res.first)->second).push_back(txd.get_mstch_map()); } + // if found something, set this flag to indicate this fact + context["no_results"] = false; + } } // read search_results.html string search_results_html = xmreg::read(TMPL_SEARCH_RESULTS); - // add header and footer + // add header and footer string full_page = get_full_page(search_results_html); + // read partial for showing details of tx(s) found + map partials { + {"tx_table_head", xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_table_header.html")}, + {"tx_table_row" , xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_table_row.html")} + }; + // render the page - return mstch::render(full_page, context); + return mstch::render(full_page, context, partials); } diff --git a/src/templates/partials/tx_table_header.html b/src/templates/partials/tx_table_header.html new file mode 100644 index 0000000..85f0e47 --- /dev/null +++ b/src/templates/partials/tx_table_header.html @@ -0,0 +1,8 @@ + + tx hash + outputs + fee + mixin + in/out + size [kB] + diff --git a/src/templates/partials/tx_table_row.html b/src/templates/partials/tx_table_row.html new file mode 100644 index 0000000..e2c317f --- /dev/null +++ b/src/templates/partials/tx_table_row.html @@ -0,0 +1,8 @@ + + {{hash}} + {{sum_outputs}} + {{tx_fee}} + {{mixin}} + {{no_inputs}}/{{no_outputs}} + {{tx_size}} + diff --git a/src/templates/search_results.html b/src/templates/search_results.html index 1cefc6d..18f123e 100644 --- a/src/templates/search_results.html +++ b/src/templates/search_results.html @@ -1,46 +1,75 @@ -

Search results

-
Looking for {{search_text}}
+

Search results for: {{search_text}}

+ + {{#no_results}} +

Nothing has been found that matches the search term :-(

+ {{/no_results}}
- {{#has_key_images}} -

This key image found in the following transactions

-
    - {{#key_images}} -
  • {{tx_hash}}
  • - {{/key_images}} -
+

The search term matches key image found in the following transactions

+ + + {{>tx_table_head}} + {{#key_images}} + {{>tx_table_row}} + {{/key_images}} +
{{/has_key_images}} +
+
+ + {{#has_tx_public_keys}} + +

The search term matches tx public key found in the following transactions

+ + + {{>tx_table_head}} + {{#tx_public_keys}} + {{>tx_table_row}} + {{/tx_public_keys}} +
+ + {{/has_tx_public_keys}}
- {{#tx_public_keys}} - {{tx_hash}}
- {{/tx_public_keys}} + {{#has_payments_id}} + +

The search term matches payment id found in the following transactions

+ + + {{>tx_table_head}} + {{#payments_id}} + {{>tx_table_row}} + {{/payments_id}} +
+ + {{/has_payments_id}}
- {{#payments_id}} - {{tx_hash}}
- {{/payments_id}} + {{#has_output_public_keys}} -
+

The search term matches output public key found in the following transactions

-
+ + {{>tx_table_head}} + {{#output_public_keys}} + {{>tx_table_row}} + {{/output_public_keys}} +
- {{#output_public_keys}} - {{tx_hash}}
- {{/output_public_keys}} + {{/has_output_public_keys}}