From f52905f08ca5a4df873591a701dc49a4d1852bec Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sat, 28 May 2016 13:05:51 +0800 Subject: [PATCH] Checking if lmdb2 exists or not, before trying to use the custom lmdb database for searching things. --- src/CMakeLists.txt | 4 +- src/page.cpp | 5 - src/page.h | 259 ++++++++++++++++++++++++--------------------- 3 files changed, 143 insertions(+), 125 deletions(-) delete mode 100644 src/page.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a81890..6745425 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,9 @@ set(SOURCE_FILES MicroCore.cpp tools.cpp CmdLineOptions.cpp - tx_details.cpp page.cpp page.h rpccalls.cpp rpccalls.h) + tx_details.cpp + page.h + rpccalls.cpp rpccalls.h) # make static library called libmyxrm # that we are going to link to diff --git a/src/page.cpp b/src/page.cpp deleted file mode 100644 index 56698ee..0000000 --- a/src/page.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by mwo on 8/04/16. -// - -#include "page.h" diff --git a/src/page.h b/src/page.h index 8e1996a..095fa87 100644 --- a/src/page.h +++ b/src/page.h @@ -1447,178 +1447,199 @@ namespace xmreg { vector>> all_possible_tx_hashes; - xmreg::MyLMDB mylmdb {lmdb2_path}; - // search the custum lmdb for key_images and append the result - // to those from the mempool search if found - mylmdb.search(search_text, - tx_search_results["key_images"], - "key_images"); + try + { + unique_ptr mylmdb; - cout << "size: " << tx_search_results["key_images"].size() << endl; + if (!bf::is_directory(lmdb2_path)) + { + throw std::runtime_error(lmdb2_path + " does not exist"); + } - all_possible_tx_hashes.push_back( - make_pair("key_images", - tx_search_results["key_images"])); + mylmdb = make_unique(lmdb2_path); - // search the custum lmdb for tx_public_keys and append the result - // to those from the mempool search if found + mylmdb->search(search_text, + tx_search_results["key_images"], + "key_images"); - mylmdb.search(search_text, - tx_search_results["tx_public_keys"], - "tx_public_keys"); + cout << "size: " << tx_search_results["key_images"].size() << endl; - all_possible_tx_hashes.push_back( - make_pair("tx_public_keys", - tx_search_results["tx_public_keys"])); + all_possible_tx_hashes.push_back( + make_pair("key_images", + tx_search_results["key_images"])); - // search the custum lmdb for payments_id and append the result - // to those from the mempool search if found - mylmdb.search(search_text, - tx_search_results["payments_id"], - "payments_id"); + // search the custum lmdb for tx_public_keys and append the result + // to those from the mempool search if found - all_possible_tx_hashes.push_back( - make_pair("payments_id", - tx_search_results["payments_id"])); + mylmdb->search(search_text, + tx_search_results["tx_public_keys"], + "tx_public_keys"); - // search the custum lmdb for encrypted_payments_id and append the result - // to those from the mempool search if found + all_possible_tx_hashes.push_back( + make_pair("tx_public_keys", + tx_search_results["tx_public_keys"])); - mylmdb.search(search_text, - tx_search_results["encrypted_payments_id"], - "encrypted_payments_id"); + // search the custum lmdb for payments_id and append the result + // to those from the mempool search if found - all_possible_tx_hashes.push_back( - make_pair("encrypted_payments_id", - tx_search_results["encrypted_payments_id"])); + mylmdb->search(search_text, + tx_search_results["payments_id"], + "payments_id"); - // search the custum lmdb for output_public_keys and append the result - // to those from the mempool search if found + all_possible_tx_hashes.push_back( + make_pair("payments_id", + tx_search_results["payments_id"])); - mylmdb.search(search_text, - tx_search_results["output_public_keys"], - "output_public_keys"); + // search the custum lmdb for encrypted_payments_id and append the result + // to those from the mempool search if found - all_possible_tx_hashes.push_back( - make_pair("output_public_keys", - tx_search_results["output_public_keys"])); + mylmdb->search(search_text, + tx_search_results["encrypted_payments_id"], + "encrypted_payments_id"); + all_possible_tx_hashes.push_back( + make_pair("encrypted_payments_id", + tx_search_results["encrypted_payments_id"])); - // seach for output using output global index + // search the custum lmdb for output_public_keys and append the result + // to those from the mempool search if found - if (search_for_global_output_idx) - { - try + mylmdb->search(search_text, + tx_search_results["output_public_keys"], + "output_public_keys"); + + all_possible_tx_hashes.push_back( + make_pair("output_public_keys", + tx_search_results["output_public_keys"])); + + + // seach for output using output global index + + if (search_for_global_output_idx) { - uint64_t global_idx = boost::lexical_cast( - search_text.substr(4)); + try + { + uint64_t global_idx = boost::lexical_cast( + search_text.substr(4)); - //cout << "global_idx: " << global_idx << endl; + //cout << "global_idx: " << global_idx << endl; - // get info about output of a given global index - output_data_t output_data = core_storage->get_db() - .get_output_key(global_idx); + // get info about output of a given global index + output_data_t output_data = core_storage->get_db() + .get_output_key(global_idx); - //tx_out_index tx_out = core_storage->get_db() - // .get_output_tx_and_index_from_global(global_idx); + //tx_out_index tx_out = core_storage->get_db() + // .get_output_tx_and_index_from_global(global_idx); - //cout << "tx_out.first: " << tx_out.first << endl; - //cout << "tx_out.second: " << tx_out.second << endl; + //cout << "tx_out.first: " << tx_out.first << endl; + //cout << "tx_out.second: " << tx_out.second << endl; - string output_pub_key = pod_to_hex(output_data.pubkey); + string output_pub_key = pod_to_hex(output_data.pubkey); - //cout << "output_pub_key: " << output_pub_key << endl; + //cout << "output_pub_key: " << output_pub_key << endl; - vector found_outputs; + vector found_outputs; - mylmdb.search(output_pub_key, - found_outputs, - "output_public_keys"); + mylmdb->search(output_pub_key, + found_outputs, + "output_public_keys"); - //cout << "found_outputs.size(): " << found_outputs.size() << endl; + //cout << "found_outputs.size(): " << found_outputs.size() << endl; - all_possible_tx_hashes.push_back( - make_pair("output_public_keys_based_on_global_idx", - found_outputs)); + all_possible_tx_hashes.push_back( + make_pair("output_public_keys_based_on_global_idx", + found_outputs)); - } - catch(boost::bad_lexical_cast &e) - { - cerr << "Cant cast global_idx string: " - << search_text.substr(4) << endl; - } - } + } + catch(boost::bad_lexical_cast &e) + { + cerr << "Cant cast global_idx string: " + << search_text.substr(4) << endl; + } + } // if (search_for_global_output_idx) - // seach for output using output amount index and amount + // seach for output using output amount index and amount - if (search_for_amount_output_idx) - { - try + if (search_for_amount_output_idx) { + try + { - string str_to_split = search_text.substr(4); + string str_to_split = search_text.substr(4); - vector string_parts; + vector string_parts; - boost::split(string_parts, str_to_split, - boost::is_any_of("-")); + boost::split(string_parts, str_to_split, + boost::is_any_of("-")); - if (string_parts.size() != 2) - { - throw; - } + if (string_parts.size() != 2) + { + throw; + } - uint64_t amount_idx = boost::lexical_cast( - string_parts[0]); + uint64_t amount_idx = boost::lexical_cast( + string_parts[0]); - uint64_t amount = static_cast - (boost::lexical_cast( - string_parts[1]) * 1e12); + uint64_t amount = static_cast + (boost::lexical_cast( + string_parts[1]) * 1e12); - //cout << "amount_idx: " << amount_idx << endl; - //cout << "amount: " << amount << endl; + //cout << "amount_idx: " << amount_idx << endl; + //cout << "amount: " << amount << endl; - // get info about output of a given global index - output_data_t output_data = core_storage->get_db() - .get_output_key( - amount, amount_idx); + // get info about output of a given global index + output_data_t output_data = core_storage->get_db() + .get_output_key( + amount, amount_idx); - string output_pub_key = pod_to_hex(output_data.pubkey); + string output_pub_key = pod_to_hex(output_data.pubkey); - //cout << "output_pub_key: " << output_pub_key << endl; + //cout << "output_pub_key: " << output_pub_key << endl; - vector found_outputs; + vector found_outputs; - mylmdb.search(output_pub_key, - found_outputs, - "output_public_keys"); + mylmdb->search(output_pub_key, + found_outputs, + "output_public_keys"); - //cout << "found_outputs.size(): " << found_outputs.size() << endl; + //cout << "found_outputs.size(): " << found_outputs.size() << endl; - all_possible_tx_hashes.push_back( - make_pair("output_public_keys_based_on_amount_idx", - found_outputs)); + all_possible_tx_hashes.push_back( + make_pair("output_public_keys_based_on_amount_idx", + found_outputs)); - } - catch(boost::bad_lexical_cast& e) - { - cerr << "Cant parse amout index and amout string: " - << search_text.substr(4) << endl; - } - catch(OUTPUT_DNE& e) - { - cerr << "Output not found in the blockchain: " - << search_text.substr(4) << endl; + } + catch(boost::bad_lexical_cast& e) + { + cerr << "Cant parse amout index and amout string: " + << search_text.substr(4) << endl; + } + catch(OUTPUT_DNE& e) + { + cerr << "Output not found in the blockchain: " + << search_text.substr(4) << endl; - return(string("Output not found in the blockchain: ") - + search_text.substr(4)); - } + return(string("Output not found in the blockchain: ") + + search_text.substr(4)); + } + } // if (search_for_amount_output_idx) + } + catch (const lmdb::runtime_error& e) + { + cerr << "Error opening/accessing custom lmdb database: " + << e.what() << endl; + } + catch (...) + { + std::exception_ptr p = std::current_exception(); + cerr << "Error opening/accessing custom lmdb database: " + << p.__cxa_exception_type()->name() << endl; }