diff --git a/src/BlockchainSetup.cpp b/src/BlockchainSetup.cpp index 6ed97d3..b9bd0bb 100755 --- a/src/BlockchainSetup.cpp +++ b/src/BlockchainSetup.cpp @@ -3,6 +3,7 @@ // #include "BlockchainSetup.h" +#include "xmregcore/src/tools.h" namespace xmreg { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f442b80..44a589e 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,10 +19,8 @@ set(SOURCE_FILES utils.cpp RandomOutputs.cpp) -add_library(myxmr STATIC) - -target_sources(myxmr - PRIVATE ${SOURCE_FILES}) +add_library(myxmr STATIC + ${SOURCE_FILES}) target_link_libraries(myxmr PUBLIC diff --git a/src/utils.cpp b/src/utils.cpp index 0134e08..0c707d5 100755 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -9,42 +9,6 @@ namespace xmreg { -/** - * Parse key string, e.g., a viewkey in a string - * into crypto::secret_key or crypto::public_key - * depending on the template argument. - */ -template -bool -parse_str_secret_key(const string& key_str, T& secret_key) -{ - - // hash and keys have same structure, so to parse string of - // a key, e.g., a view key, we can first parse it into the hash - // object using parse_hash256 function, and then copy the reslting - // hash data into secret key. - crypto::hash hash_; - - if(!parse_hash256(key_str, hash_)) - { - cerr << "Cant parse a key (e.g. viewkey): " << key_str << endl; - return false; - } - - // crypto::hash and crypto::secret_key have basicly same - // structure. They both keep they key/hash as c-style char array - // of fixed size. Thus we can just copy data from hash - // to key - copy(begin(hash_.data), end(hash_.data), secret_key.data); - - return true; -} - -// explicit instantiations of get template function -template bool parse_str_secret_key(const string& key_str, crypto::secret_key& secret_key); -template bool parse_str_secret_key(const string& key_str, crypto::public_key& secret_key); -template bool parse_str_secret_key(const string& key_str, crypto::hash& secret_key); -template bool parse_str_secret_key(const string& key_str, crypto::hash8& secret_key); /** * Get transaction tx using given tx hash. Hash is represent as string here, @@ -76,20 +40,6 @@ get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, t * cryptonote::account_public_address object */ -bool -parse_str_address(const string& address_str, - address_parse_info& address_info, - network_type net_type) -{ - - if (!get_account_address_from_str(address_info, net_type, address_str)) - { - //cerr << "Error getting address: " << address_str << '\n'; - return false; - } - - return true; -} string @@ -116,27 +66,6 @@ is_separator(char c) } - -/** - * Remove trailinig path separator. - */ -string -remove_trailing_path_separator(const string& in_path) -{ - string new_string = in_path; - if (!new_string.empty() && is_separator(new_string[new_string.size() - 1])) - new_string.erase(new_string.size() - 1); - return new_string; -} - -bf::path -remove_trailing_path_separator(const bf::path& in_path) -{ - string path_str = in_path.native(); - return bf::path(remove_trailing_path_separator(path_str)); -} - - string timestamp_to_str_gm(time_t timestamp, const char* format) { @@ -236,70 +165,6 @@ generate_key_image(const crypto::key_derivation& derivation, } -string -get_default_lmdb_folder(network_type nettype) -{ - // default path to monero folder - // on linux this is /home//.bitmonero - string default_monero_dir = tools::get_default_data_dir(); - - if (nettype == cryptonote::network_type::TESTNET) - default_monero_dir += "/testnet"; - if (nettype == cryptonote::network_type::STAGENET) - default_monero_dir += "/stagenet"; - - - // the default folder of the lmdb blockchain database - // is therefore as follows - return default_monero_dir + string("/lmdb"); -} - - - -/* - * Ge blockchain exception from command line option - * - * If not given, provide default path - */ -bool -get_blockchain_path(bf::path& blockchain_path, - cryptonote::network_type nettype) -{ - // the default folder of the lmdb blockchain database - string default_lmdb_dir = xmreg::get_default_lmdb_folder(nettype); - - blockchain_path = !blockchain_path.empty() - ? blockchain_path - : bf::path(default_lmdb_dir); - - if (!bf::is_directory(blockchain_path)) - { - cerr << "Given path \"" << blockchain_path << "\" " - << "is not a folder or does not exist \n"; - - return false; - } - - blockchain_path = xmreg::remove_trailing_path_separator(blockchain_path); - - return true; -} - -bool -get_blockchain_path(string& blockchain_path, - cryptonote::network_type nettype) -{ - bf::path p {blockchain_path}; - - if (!get_blockchain_path(p, nettype)) - return false; - - blockchain_path = p.string(); - - return true; -} - - array summary_of_in_out_rct( const transaction& tx, @@ -1309,22 +1174,6 @@ make_hash(const string& in_str) } -bool -hex_to_tx(string const& tx_hex, transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash) -{ - std::string tx_blob; - - epee::string_tools::parse_hexstr_to_binbuff(tx_hex, tx_blob); - - return parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash); -} - -string -tx_to_hex(transaction const& tx) -{ - return epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx)); -} - bool hex_to_tx_blob(string const& tx_hex, string& tx_blob) { @@ -1405,22 +1254,6 @@ blocks_and_txs_from_complete_blocks( return true; } -bool -addr_and_viewkey_from_string(string const& addres_str, - string const& viewkey_str, - network_type net_type, - address_parse_info& address, - crypto::secret_key& viewkey) -{ - if (!xmreg::parse_str_address(addres_str, address, net_type)) - return false; - - if (!xmreg::parse_str_secret_key(viewkey_str, viewkey)) - return false; - - return true; -} - bool output_data_from_hex( string const& out_data_hex, diff --git a/src/utils.h b/src/utils.h index b409b3e..2e827bd 100755 --- a/src/utils.h +++ b/src/utils.h @@ -50,33 +50,18 @@ using json = nlohmann::json; using epee::string_tools::pod_to_hex; using epee::string_tools::hex_to_pod; -template -bool -parse_str_secret_key(const string& key_str, T& secret_key); - bool get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, transaction& tx); -bool -parse_str_address(const string& address_str, - address_parse_info& address_info, - cryptonote::network_type nettype = cryptonote::network_type::MAINNET); - inline bool is_separator(char c); string print_sig (const signature& sig); -string -remove_trailing_path_separator(const string& in_path); - -bf::path -remove_trailing_path_separator(const bf::path& in_path); - string timestamp_to_str_gm(time_t timestamp, const char* format = "%F %T"); @@ -85,9 +70,6 @@ ostream& operator<< (ostream& os, const address_parse_info& addr); -string -get_default_lmdb_folder(network_type nettype = network_type::MAINNET); - bool generate_key_image(const crypto::key_derivation& derivation, const std::size_t output_index, @@ -95,13 +77,7 @@ generate_key_image(const crypto::key_derivation& derivation, const crypto::public_key& pub_key, crypto::key_image& key_img); -bool -get_blockchain_path(bf::path& blockchain_path, - network_type nettype = network_type::MAINNET); -bool -get_blockchain_path(string& blockchain_path, - network_type nettype = network_type::MAINNET); array summary_of_in_out_rct( @@ -279,13 +255,6 @@ get_human_readable_timestamp(uint64_t ts); string make_hash(const string& in_str); -bool -hex_to_tx(string const& tx_hex, transaction& tx, - crypto::hash& tx_hash, crypto::hash& tx_prefix_hash); - -string -tx_to_hex(transaction const& tx); - bool hex_to_tx_blob(string const& tx_hex, string& tx_blob); @@ -304,13 +273,6 @@ blocks_and_txs_from_complete_blocks( vector& blocks, vector& txs); -bool -addr_and_viewkey_from_string(string const& addres_str, - string const& viewkey_str, - network_type net_type, - address_parse_info& address_info, - crypto::secret_key& viewkey); - // this function only useful in google test for mocking // ring member output info bool diff --git a/src/xmregcore b/src/xmregcore index efeff91..447ac6f 160000 --- a/src/xmregcore +++ b/src/xmregcore @@ -1 +1 @@ -Subproject commit efeff91fcfe767f5f0891879b7364e565ca52e69 +Subproject commit 447ac6fe53057a85f5468da030af24aacaa3fa61 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 270faa7..3d4a748 100755 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,6 @@ macro(add_om_test _TEST_NAME) - add_executable(${_TEST_NAME}_tests) - - target_sources(${_TEST_NAME}_tests - PRIVATE + add_executable(${_TEST_NAME}_tests "${_TEST_NAME}_tests.cpp" JsonTx.cpp) @@ -30,20 +27,20 @@ add_om_test(txsearch) ########## CODE COVERAGE ############# ###################################### -include(CodeCoverage) +#include(CodeCoverage) -APPEND_COVERAGE_COMPILER_FLAGS() +#APPEND_COVERAGE_COMPILER_FLAGS() -set(COVERAGE_LCOV_EXCLUDES - '*/ext/*' '*boost/*' '*c++/*' - '*/monero/*' '*googletest/*' '*googlemock/*' - '*restbed/*' '*/mysql++/*' '*tests/*' - '*src/xmregcore/*') +#set(COVERAGE_LCOV_EXCLUDES + #'*/ext/*' '*boost/*' '*c++/*' + #'*/monero/*' '*googletest/*' '*googlemock/*' + #'*restbed/*' '*/mysql++/*' '*tests/*' + #'*src/xmregcore/*') - SETUP_TARGET_FOR_COVERAGE_LCOV( - NAME coverage - EXECUTABLE mysql_tests - microcore_tests - bcstatus - txsearch) + #SETUP_TARGET_FOR_COVERAGE_LCOV( + #NAME coverage + #EXECUTABLE mysql_tests + #microcore_tests + #bcstatus + #txsearch) diff --git a/tests/JsonTx.cpp b/tests/JsonTx.cpp index 31600bd..0d301fc 100644 --- a/tests/JsonTx.cpp +++ b/tests/JsonTx.cpp @@ -1,4 +1,5 @@ #include "JsonTx.h" +#include "../src/xmregcore/src/tools.h" namespace xmreg {