diff --git a/CMakeLists.txt b/CMakeLists.txt index d5c1d1d..197a292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,6 @@ option(FORCE_ANSI "Force ANSI console colors even on windows" OFF) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") -include(libeoskeygen) - # Use installpath from GNUInstallDirs as default. include(GNUInstallDirs) @@ -39,6 +37,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") add_definitions( "-D_CRT_SECURE_NO_WARNINGS=1" ) endif() +# -------------------------------- +# Common code +# -------------------------------- +add_subdirectory( common ) + # -------------------------------- # Program # -------------------------------- @@ -66,7 +69,7 @@ include_directories(${PROJECT_BINARY_DIR}) add_executable( ${PROGRAM_EXE} ${PROGRAM_SOURCE} ) -target_link_libraries( ${PROGRAM_EXE} PUBLIC eoskeygen ) +target_link_libraries( ${PROGRAM_EXE} PUBLIC common ) # -------------------------------- # Install diff --git a/CMakeModules/libeoskeygen.cmake b/CMakeModules/libeoskeygen.cmake deleted file mode 100644 index d58803f..0000000 --- a/CMakeModules/libeoskeygen.cmake +++ /dev/null @@ -1,52 +0,0 @@ - -# -------------------------------- -# Variables -# -------------------------------- -set( LIBEOSKEYGEN_GIT_URL "https://github.com/eosswedenorg/libeoskeygen.git" ) -set( LIBEOSKEYGEN_WANTED_VERSION 0.1.1 ) - -# -------------------------------- -# Macros -# -------------------------------- -macro(fromGit tag) - - message ("Using libeoskeygen from: ${LIBEOSKEYGEN_GIT_URL}@${tag}") - - include(FetchContent) - FetchContent_Declare(libeoskeygen - GIT_REPOSITORY ${LIBEOSKEYGEN_GIT_URL} - GIT_TAG ${tag} - ) - - FetchContent_GetProperties(libeoskeygen) - if (NOT libeoskeygen_POPULATED) - FetchContent_Populate(libeoskeygen) - add_subdirectory(${libeoskeygen_SOURCE_DIR} ${libeoskeygen_BINARY_DIR} EXCLUDE_FROM_ALL) - endif() -endmacro() - -macro(buildLocal src) - message ("Using local libeoskeygen at: ${src}") - add_subdirectory(${src} ${src}/build EXCLUDE_FROM_ALL) -endmacro() - -# If we have a local libeoskeygen -if (LIBEOSKEYGEN_SOURCE_DIR) - buildLocal( ${LIBEOSKEYGEN_SOURCE_DIR} ) -else() - - # Check if version is in fact a version. - if (LIBEOSKEYGEN_WANTED_VERSION MATCHES "^[0-9]+(.[0-9]+)?(.[0-9]+)(-[a-zA-Z0-9]+)?$") - # Try finding the package on the system. - find_package(libeoskeygen ${LIBEOSKEYGEN_WANTED_VERSION} QUIET) - if (libeoskeygen_FOUND) - message ("Using libeoskeygen in: ${libeoskeygen_DIR}") - # Not found, download from git. - else() - fromGit( v${LIBEOSKEYGEN_WANTED_VERSION} ) - endif() - # Assume version contains a git branch. - else() - fromGit( ${LIBEOSKEYGEN_WANTED_VERSION} ) - endif() -endif() diff --git a/src/benchmark.cpp b/src/benchmark.cpp index 43d8b35..da384a4 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -22,7 +22,7 @@ * SOFTWARE. */ #include -#include +#include #include "benchmark.h" using std::chrono::steady_clock; @@ -43,8 +43,8 @@ void benchmark(size_t num_keys, struct benchmark_result* res) { start = steady_clock::now(); for(size_t i = 0; i < num_keys; i++) { - struct ec_keypair k; - ec_generate_key(&k); + struct libeosio::ec_keypair k; + libeosio::ec_generate_key(&k); } res->sec = duration(steady_clock::now() - start).count(); diff --git a/src/cli_key_search_result.cpp b/src/cli_key_search_result.cpp index b61ea3a..05d5b57 100644 --- a/src/cli_key_search_result.cpp +++ b/src/cli_key_search_result.cpp @@ -22,8 +22,8 @@ * SOFTWARE. */ #include +#include #include -#include #include "console.h" #include "cli_key_search_result.h" @@ -42,9 +42,9 @@ m_dict (dict) { } -void CliKeySearchResult::onResult(const struct ec_keypair* key, const struct KeySearch::result& result) { +void CliKeySearchResult::onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result) { - std::string pub = wif_pub_encode(key->pub); + std::string pub = libeosio::wif_pub_encode(key->pub); Dictionary::search_result_t dict_res = m_dict.search(pub); std::cout << "----" << std::endl; @@ -68,7 +68,7 @@ void CliKeySearchResult::onResult(const struct ec_keypair* key, const struct Key } std::cout << std::endl - << "Private: " << wif_priv_encode(key->secret) << std::endl; + << "Private: " << libeosio::wif_priv_encode(key->secret) << std::endl; } } // namespace eoskeygen diff --git a/src/cli_key_search_result.h b/src/cli_key_search_result.h index 2645aeb..0d7e6b2 100644 --- a/src/cli_key_search_result.h +++ b/src/cli_key_search_result.h @@ -24,8 +24,8 @@ #ifndef EOSIOKEYGEN_KEY_SEARCH_HELPERS_H #define EOSIOKEYGEN_KEY_SEARCH_HELPERS_H +#include #include -#include #include #include @@ -38,7 +38,7 @@ class CliKeySearchResult : public IKeySearchResult public: CliKeySearchResult(const Dictionary& dict); - virtual void onResult(const struct ec_keypair* key, const struct KeySearch::result& result); + virtual void onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result); protected : diff --git a/src/main.cpp b/src/main.cpp index d7834a7..eb74b8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,13 +23,13 @@ */ #include #include +#include +#include +#include #include #include #include #include -#include -#include -#include #include #include #include "cli_key_search_result.h" @@ -40,9 +40,9 @@ // Command line options. bool option_l33t = false; -#ifdef LIBEOSKEYGEN_HAVE_THREADS +#ifdef EOSIOKEYGEN_HAVE_THREADS size_t option_num_threads = eoskeygen::KeySearch::max_threads(); -#endif /* LIBEOSKEYGEN_HAVE_THREADS */ +#endif /* EOSIOKEYGEN_HAVE_THREADS */ int cmd_search(const eoskeygen::strlist_t& words, const eoskeygen::Dictionary& dict, int count) { @@ -52,7 +52,7 @@ int cmd_search(const eoskeygen::strlist_t& words, const eoskeygen::Dictionary& d ks.setCallback(&rs); for(auto it = words.begin(); it != words.end(); it++) { - size_t p = eoskeygen::is_base58(*it); + size_t p = libeosio::is_base58(*it); if (p != std::string::npos) { std::cerr << "The word '" << *it << "' contains an invalid non-base58 character '" @@ -69,15 +69,15 @@ int cmd_search(const eoskeygen::strlist_t& words, const eoskeygen::Dictionary& d ks.addList(words); } -#ifdef LIBEOSKEYGEN_HAVE_THREADS +#ifdef EOSIOKEYGEN_HAVE_THREADS ks.setThreadCount(option_num_threads); -#endif /* LIBEOSKEYGEN_HAVE_THREADS */ +#endif /* EOSIOKEYGEN_HAVE_THREADS */ std::cout << "Searching for " << count << " keys containing: " << eoskeygen::strlist::join(ks.getList(), ",") -#ifdef LIBEOSKEYGEN_HAVE_THREADS +#ifdef EOSIOKEYGEN_HAVE_THREADS << ", Using: " << option_num_threads << " threads" -#endif /* LIBEOSKEYGEN_HAVE_THREADS */ +#endif /* EOSIOKEYGEN_HAVE_THREADS */ << std::endl; ks.find(count); @@ -89,9 +89,9 @@ void usage(const char *name) { std::cout << name << " [ -h | --help | -v | search [ -m | --l33t" -#ifdef LIBEOSKEYGEN_HAVE_THREADS +#ifdef EOSIOKEYGEN_HAVE_THREADS << " | --threads=" -#endif /* LIBEOSKEYGEN_HAVE_THREADS */ +#endif /* EOSIOKEYGEN_HAVE_THREADS */ << " | --dict= ... " << " | --lang= ... ] |file: [ ]" << " | benchmark [ ]" @@ -119,11 +119,11 @@ void usage(const char *name) { << std::endl << std::endl << " --l33t: Takes each word in and find all l33tspeak" << std::endl << " combinations of that word and uses the new list for the search." -#ifdef LIBEOSKEYGEN_HAVE_THREADS +#ifdef EOSIOKEYGEN_HAVE_THREADS << std::endl << std::endl << " --threads=: Use of parallel threads for searching." << std::endl << " Default is what the operating system recomend." -#endif /* LIBEOSKEYGEN_HAVE_THREADS */ +#endif /* EOSIOKEYGEN_HAVE_THREADS */ << std::endl << std::endl << " --dict=: Use words found in (separated by newline) to" << std::endl << " highlight words in the keys found (note that the words in this" << std::endl @@ -163,9 +163,9 @@ int main(int argc, char **argv) { // No args, just print a key. if (argc <= 1) { - struct eoskeygen::ec_keypair pair; - eoskeygen::ec_generate_key(&pair); - eoskeygen::wif_print_key(&pair); + struct libeosio::ec_keypair pair; + libeosio::ec_generate_key(&pair); + libeosio::wif_print_key(&pair); return 0; } @@ -191,7 +191,7 @@ int main(int argc, char **argv) { } else if (!strcmp(argv[p], "--l33t")) { option_l33t = true; } else if (!memcmp(argv[p], "--threads=", 10)) { -#ifdef LIBEOSKEYGEN_HAVE_THREADS +#ifdef EOSIOKEYGEN_HAVE_THREADS option_num_threads = atoi(argv[p] + 10); if (option_num_threads < 2) { std::cerr << "NOTICE: Number of threads less than 2 does not make sense." @@ -203,7 +203,7 @@ int main(int argc, char **argv) { // otherwise we might break scripts. Print a nice message instead. std::cerr << "NOTICE: eosio-keygen is not compiled with" << " thread support. this option is ignored." << std::endl; -#endif /* LIBEOSKEYGEN_HAVE_THREADS */ +#endif /* EOSIOKEYGEN_HAVE_THREADS */ } // Dictionary. else if (!memcmp(argv[p], "--dict=", 7)) {