From 914205541a05f7d46828911b910f055577387468 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 6 Apr 2023 15:04:12 +0200 Subject: [PATCH] Update from libeosio v0.1.7 to libantelope v0.2.0 --- cli/src/benchmark.cpp | 6 +-- cli/src/cli_key_search_result.cpp | 10 ++-- cli/src/cli_key_search_result.hpp | 10 ++-- cli/src/main.cpp | 26 ++++----- common/CMakeLists.txt | 6 +-- common/cmake/libantelope.cmake | 53 +++++++++++++++++++ common/cmake/libeosio.cmake | 53 ------------------- common/include/eoskeygen/key_search.hpp | 4 +- .../include/eoskeygen/key_search_result.hpp | 2 +- common/src/key_search.cpp | 12 ++--- common/src/key_search_mt.cpp | 6 +-- gui/src/GenerateWindow.cpp | 14 ++--- gui/src/MainWindow.cpp | 12 ++--- gui/src/SearchWindow.cpp | 10 ++-- gui/src/SearchWindow.hpp | 2 +- gui/src/Settings.cpp | 6 +-- gui/src/Settings.hpp | 6 +-- 17 files changed, 119 insertions(+), 119 deletions(-) create mode 100644 common/cmake/libantelope.cmake delete mode 100644 common/cmake/libeosio.cmake diff --git a/cli/src/benchmark.cpp b/cli/src/benchmark.cpp index 9c65375..b0a32b9 100644 --- a/cli/src/benchmark.cpp +++ b/cli/src/benchmark.cpp @@ -22,7 +22,7 @@ * SOFTWARE. */ #include -#include +#include #include "benchmark.hpp" namespace eoskeygen { @@ -30,8 +30,8 @@ namespace eoskeygen { std::chrono::duration _run_benchmark(size_t num_keys) { auto start = std::chrono::steady_clock::now(); for(size_t i = 0; i < num_keys; i++) { - struct libeosio::ec_keypair k; - libeosio::ec_generate_key(&k); + struct libantelope::ec_keypair k; + libantelope::ec_generate_key(&k); } return std::chrono::steady_clock::now() - start; } diff --git a/cli/src/cli_key_search_result.cpp b/cli/src/cli_key_search_result.cpp index d0cc9fd..aaa9f97 100644 --- a/cli/src/cli_key_search_result.cpp +++ b/cli/src/cli_key_search_result.cpp @@ -23,7 +23,7 @@ */ #include #include -#include +#include #include #include "console.hpp" #include "cli_key_search_result.hpp" @@ -38,15 +38,15 @@ static size_t highlight(console::Color color, const std::string& str, size_t pos return len; } -CliKeySearchResult::CliKeySearchResult(const Dictionary& dict, const libeosio::wif_codec_t& codec) : +CliKeySearchResult::CliKeySearchResult(const Dictionary& dict, const libantelope::wif_codec_t& codec) : m_dict (dict), m_codec (codec) { } -void CliKeySearchResult::onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result) { +void CliKeySearchResult::onResult(const struct libantelope::ec_keypair* key, const struct KeySearch::result& result) { - std::string pub = libeosio::wif_pub_encode(key->pub, m_codec.pub); + std::string pub = libantelope::wif_pub_encode(key->pub, m_codec.pub); Dictionary::search_result_t dict_res = m_dict.search(pub); int pub_prefix_len = (int) m_codec.pub.length(); @@ -71,7 +71,7 @@ void CliKeySearchResult::onResult(const struct libeosio::ec_keypair* key, const } std::cout << std::endl - << "Private: " << libeosio::wif_priv_encode(key->secret, m_codec.pvt) << std::endl; + << "Private: " << libantelope::wif_priv_encode(key->secret, m_codec.pvt) << std::endl; } } // namespace eoskeygen diff --git a/cli/src/cli_key_search_result.hpp b/cli/src/cli_key_search_result.hpp index 254ee8f..0d0a1a5 100644 --- a/cli/src/cli_key_search_result.hpp +++ b/cli/src/cli_key_search_result.hpp @@ -25,8 +25,8 @@ #define EOSIOKEYGEN_KEY_SEARCH_HELPERS_H #include -#include -#include +#include +#include #include #include #include @@ -38,15 +38,15 @@ class Dictionary; class CliKeySearchResult : public IKeySearchResult { public: - CliKeySearchResult(const Dictionary& dict, const libeosio::wif_codec_t& codec); + CliKeySearchResult(const Dictionary& dict, const libantelope::wif_codec_t& codec); - virtual void onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result); + virtual void onResult(const struct libantelope::ec_keypair* key, const struct KeySearch::result& result); protected : const Dictionary& m_dict; - libeosio::wif_codec_t m_codec; + libantelope::wif_codec_t m_codec; }; } // namespace eoskeygen diff --git a/cli/src/main.cpp b/cli/src/main.cpp index ddb8dc6..5351444 100644 --- a/cli/src/main.cpp +++ b/cli/src/main.cpp @@ -24,9 +24,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -40,7 +40,7 @@ // Command line options. bool option_l33t = false; -libeosio::wif_codec_t key_codec; +libantelope::wif_codec_t key_codec; #ifdef EOSIOKEYGEN_HAVE_THREADS size_t option_num_threads; @@ -71,7 +71,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 = libeosio::is_base58(*it); + size_t p = libantelope::is_base58(*it); if (p != std::string::npos) { std::cerr << "The word '" << *it << "' contains an invalid non-base58 character '" @@ -128,7 +128,7 @@ int main(int argc, char **argv) { size_t bench_count; int rc = 0; - libeosio::ec_init(); + libantelope::ec_init(); CLI::Option* version = cmd.add_flag("-v,--version", "Show version"); cmd.add_option("--format", key_format, "valid values: K1, fio, legacy")->default_val("K1"); @@ -174,11 +174,11 @@ int main(int argc, char **argv) { } if (key_format == "fio") { - key_codec = libeosio::wif_create_legacy_codec("FIO"); + key_codec = libantelope::wif_create_legacy_codec("FIO"); } else if (key_format == "legacy") { - key_codec = libeosio::WIF_CODEC_LEG; + key_codec = libantelope::WIF_CODEC_LEG; } else if (key_format == "K1") { - key_codec = libeosio::WIF_CODEC_K1; + key_codec = libantelope::WIF_CODEC_K1; } else { std::cerr << "invalid key format: " << key_format << std::endl; goto end; @@ -236,12 +236,12 @@ int main(int argc, char **argv) { } // No subcommand given, just generate and print a keypair. else { - struct libeosio::ec_keypair pair; - libeosio::ec_generate_key(&pair); - libeosio::wif_print_key(&pair, key_codec); + struct libantelope::ec_keypair pair; + libantelope::ec_generate_key(&pair); + libantelope::wif_print_key(&pair, key_codec); goto end; } -end: libeosio::ec_shutdown(); +end: libantelope::ec_shutdown(); return rc; } diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index e268a16..0acf3ec 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -40,10 +40,10 @@ add_library( ${COMMON_NAME} STATIC ${COMMON_SOURCE} ) target_include_directories( ${COMMON_NAME} PUBLIC include ) -# Link with libeosio and threads library. -include( libeosio ) +# Link with libantelope and threads library. +include( libantelope ) target_link_libraries( ${COMMON_NAME} PUBLIC - libeosio + libantelope ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/common/cmake/libantelope.cmake b/common/cmake/libantelope.cmake new file mode 100644 index 0000000..f70330b --- /dev/null +++ b/common/cmake/libantelope.cmake @@ -0,0 +1,53 @@ +# -------------------------------- +# Variables +# -------------------------------- +set( LIBANTELOPE_GIT_URL "https://github.com/eosswedenorg/libantelope.git" ) +set( LIBANTELOPE_WANTED_VERSION v0.2.0 ) + +# -------------------------------- +# Macros +# -------------------------------- +macro(fromGit tag) + + message ("Using libantelope from: ${LIBANTELOPE_GIT_URL}@${tag}") + + include(FetchContent) + FetchContent_Declare(libantelope + GIT_REPOSITORY ${LIBANTELOPE_GIT_URL} + GIT_TAG ${tag} + SOURCE_DIR ${DOWNLOAD_CACHE_DIR}/libeosio/src + STAMP_DIR ${DOWNLOAD_CACHE_DIR}/libeosio/stamp + ) + + FetchContent_GetProperties(libantelope) + if (NOT libantelope_POPULATED) + FetchContent_Populate(libantelope) + add_subdirectory(${libantelope_SOURCE_DIR} ${libantelope_BINARY_DIR} EXCLUDE_FROM_ALL) + endif() +endmacro() + +macro(buildLocal src) + message ("Using local libantelope at: ${src}") + add_subdirectory(${src} ${src}/build EXCLUDE_FROM_ALL) +endmacro() + +# If we have a local libantelope +if (LIBANTELOPE_SOURCE_DIR) + buildLocal( ${LIBANTELOPE_SOURCE_DIR} ) +else() + + # Check if version is in fact a version. + if (LIBANTELOPE_WANTED_VERSION MATCHES "^[0-9]+(.[0-9]+)?(.[0-9]+)(-[a-zA-Z0-9]+)?$") + # Try finding the package on the system. + find_package(libantelope ${LIBANTELOPE_WANTED_VERSION} QUIET) + if (libantelope_FOUND) + message ("Using libeosio in: ${libantelope_DIR}") + # Not found, download from git. + else() + fromGit( v${LIBANTELOPE_WANTED_VERSION} ) + endif() + # Assume version contains a git branch. + else() + fromGit( ${LIBANTELOPE_WANTED_VERSION} ) + endif() +endif() diff --git a/common/cmake/libeosio.cmake b/common/cmake/libeosio.cmake deleted file mode 100644 index 780f05f..0000000 --- a/common/cmake/libeosio.cmake +++ /dev/null @@ -1,53 +0,0 @@ -# -------------------------------- -# Variables -# -------------------------------- -set( LIBEOSIO_GIT_URL "https://github.com/eosswedenorg/libeosio.git" ) -set( LIBEOSIO_WANTED_VERSION v0.1.7 ) - -# -------------------------------- -# Macros -# -------------------------------- -macro(fromGit tag) - - message ("Using libeosio from: ${LIBEOSIO_GIT_URL}@${tag}") - - include(FetchContent) - FetchContent_Declare(libeosio - GIT_REPOSITORY ${LIBEOSIO_GIT_URL} - GIT_TAG ${tag} - SOURCE_DIR ${DOWNLOAD_CACHE_DIR}/libeosio/src - STAMP_DIR ${DOWNLOAD_CACHE_DIR}/libeosio/stamp - ) - - FetchContent_GetProperties(libeosio) - if (NOT libeosio_POPULATED) - FetchContent_Populate(libeosio) - add_subdirectory(${libeosio_SOURCE_DIR} ${libeosio_BINARY_DIR} EXCLUDE_FROM_ALL) - endif() -endmacro() - -macro(buildLocal src) - message ("Using local libeosio at: ${src}") - add_subdirectory(${src} ${src}/build EXCLUDE_FROM_ALL) -endmacro() - -# If we have a locallibeosio -if (LIBEOSIO_SOURCE_DIR) - buildLocal( ${LIBEOSIO_SOURCE_DIR} ) -else() - - # Check if version is in fact a version. - if (LIBEOSIO_WANTED_VERSION MATCHES "^[0-9]+(.[0-9]+)?(.[0-9]+)(-[a-zA-Z0-9]+)?$") - # Try finding the package on the system. - find_package(libeosio ${LIBEOSIO_WANTED_VERSION} QUIET) - if (libeoskeygen_FOUND) - message ("Using libeosio in: ${libeosio_DIR}") - # Not found, download from git. - else() - fromGit( v${LIBEOSIO_WANTED_VERSION} ) - endif() - # Assume version contains a git branch. - else() - fromGit( ${LIBEOSIO_WANTED_VERSION} ) - endif() -endif() diff --git a/common/include/eoskeygen/key_search.hpp b/common/include/eoskeygen/key_search.hpp index 040023a..0574575 100644 --- a/common/include/eoskeygen/key_search.hpp +++ b/common/include/eoskeygen/key_search.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -88,7 +88,7 @@ protected : // Check if any word in appears in 's public key. // returns true if a word was found (stored in ), false otherwise. - bool _contains_word(const struct libeosio::ec_keypair* key, struct result& result); + bool _contains_word(const struct libantelope::ec_keypair* key, struct result& result); #ifdef EOSIOKEYGEN_HAVE_THREADS void _thr_proc(); diff --git a/common/include/eoskeygen/key_search_result.hpp b/common/include/eoskeygen/key_search_result.hpp index e174d18..7abd975 100644 --- a/common/include/eoskeygen/key_search_result.hpp +++ b/common/include/eoskeygen/key_search_result.hpp @@ -32,7 +32,7 @@ class IKeySearchResult { public : - virtual void onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result) = 0; + virtual void onResult(const struct libantelope::ec_keypair* key, const struct KeySearch::result& result) = 0; }; } // namespace eoskeygen diff --git a/common/src/key_search.cpp b/common/src/key_search.cpp index 7b8c086..3e11303 100644 --- a/common/src/key_search.cpp +++ b/common/src/key_search.cpp @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include -#include +#include +#include #include #include #include @@ -77,11 +77,11 @@ void KeySearch::setCallback(IKeySearchResult* callback) void KeySearch::_search_linear() { - struct libeosio::ec_keypair pair; + struct libantelope::ec_keypair pair; while (m_count < m_max) { struct result res; - libeosio::ec_generate_key(&pair); + libantelope::ec_generate_key(&pair); if (_contains_word(&pair, res)) { m_callback->onResult(&pair, res); m_count++; @@ -111,10 +111,10 @@ void KeySearch::find(size_t num_results) _search_linear(); } -bool KeySearch::_contains_word(const struct libeosio::ec_keypair* key, struct result& result) { +bool KeySearch::_contains_word(const struct libantelope::ec_keypair* key, struct result& result) { size_t prefix_len = m_prefix.length(); - std::string pubstr = libeosio::wif_pub_encode(key->pub, m_prefix).substr(prefix_len); + std::string pubstr = libantelope::wif_pub_encode(key->pub, m_prefix).substr(prefix_len); strtolower(pubstr); for(auto const& w: m_words) { diff --git a/common/src/key_search_mt.cpp b/common/src/key_search_mt.cpp index b0773ba..25fa17e 100644 --- a/common/src/key_search_mt.cpp +++ b/common/src/key_search_mt.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include @@ -37,12 +37,12 @@ std::mutex g_count_mtx; // Thread process. void KeySearch::_thr_proc() { - struct libeosio::ec_keypair pair; + struct libantelope::ec_keypair pair; while (m_count < m_max) { struct result res; - libeosio::ec_generate_key(&pair); + libantelope::ec_generate_key(&pair); if (_contains_word(&pair, res)) { // Guard output with mutex, so we don't get diff --git a/gui/src/GenerateWindow.cpp b/gui/src/GenerateWindow.cpp index 48ce8f1..6d5e3f0 100644 --- a/gui/src/GenerateWindow.cpp +++ b/gui/src/GenerateWindow.cpp @@ -28,8 +28,8 @@ #include #include #include -#include -#include +#include +#include #include "Settings.hpp" #include "GenerateWindow.hpp" @@ -98,13 +98,13 @@ m_btn_copy_both ("Copy keys") void GenerateWindow::generate_key() { std::string pubstr, pvtstr; - struct libeosio::ec_keypair pair; - const libeosio::wif_codec_t& codec = Settings::getKeyCodec(); + struct libantelope::ec_keypair pair; + const libantelope::wif_codec_t& codec = Settings::getKeyCodec(); - libeosio::ec_generate_key(&pair); + libantelope::ec_generate_key(&pair); - pubstr = libeosio::wif_pub_encode(pair.pub, codec.pub); - pvtstr = libeosio::wif_priv_encode(pair.secret, codec.pvt); + pubstr = libantelope::wif_pub_encode(pair.pub, codec.pub); + pvtstr = libantelope::wif_priv_encode(pair.secret, codec.pvt); m_pub.setText(QString::fromStdString(pubstr)); m_priv.setText(QString::fromStdString(pvtstr)); } diff --git a/gui/src/MainWindow.cpp b/gui/src/MainWindow.cpp index 4001ef4..9b1a043 100644 --- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include "gui_text.h" #include "Settings.hpp" #include "GenerateWindow.hpp" @@ -38,7 +38,7 @@ m_format_fio_action (nullptr), m_format_legacy_action (nullptr), m_format_k1_action (nullptr) { - libeosio::ec_init(); + libantelope::ec_init(); // Create sub windows and stacked widget. m_stacked = new QStackedWidget(); @@ -83,7 +83,7 @@ m_format_k1_action (nullptr) MainWindow::~MainWindow() { - libeosio::ec_shutdown(); + libantelope::ec_shutdown(); } void MainWindow::switchToGenerate() @@ -106,20 +106,20 @@ void MainWindow::showAbout() void MainWindow::formatFioCheckboxChanged() { if (m_format_fio_action->isChecked()) { - Settings::setKeyCodec(libeosio::wif_create_legacy_codec("FIO")); + Settings::setKeyCodec(libantelope::wif_create_legacy_codec("FIO")); } } void MainWindow::formatLegacyCheckboxChanged() { if (m_format_legacy_action->isChecked()) { - Settings::setKeyCodec(libeosio::WIF_CODEC_LEG); + Settings::setKeyCodec(libantelope::WIF_CODEC_LEG); } } void MainWindow::formatK1CheckboxChanged() { if (m_format_k1_action->isChecked()) { - Settings::setKeyCodec(libeosio::WIF_CODEC_K1); + Settings::setKeyCodec(libantelope::WIF_CODEC_K1); } } diff --git a/gui/src/SearchWindow.cpp b/gui/src/SearchWindow.cpp index 7af886d..b2b4e60 100644 --- a/gui/src/SearchWindow.cpp +++ b/gui/src/SearchWindow.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include "Settings.hpp" @@ -146,12 +146,12 @@ void SearchWindow::loadDictionaries() } } -void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct eoskeygen::KeySearch::result& result) +void SearchWindow::onResult(const struct libantelope::ec_keypair* key, const struct eoskeygen::KeySearch::result& result) { int pos = (int) result.pos; int len = (int) result.len; - libeosio::wif_codec_t codec = Settings::getKeyCodec(); - QString pub = QString::fromStdString(libeosio::wif_pub_encode(key->pub, codec.pub)); + libantelope::wif_codec_t codec = Settings::getKeyCodec(); + QString pub = QString::fromStdString(libantelope::wif_pub_encode(key->pub, codec.pub)); int pub_prefix_len = (int) codec.pub.length(); QString mid = pub.mid(pos, len); QString left = pub.left(pos); @@ -180,7 +180,7 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct out += pub[i++]; } - out += "
Private: " + QString::fromStdString(libeosio::wif_priv_encode(key->secret, codec.pvt)); + out += "
Private: " + QString::fromStdString(libantelope::wif_priv_encode(key->secret, codec.pvt)); // As this function could be called from a non-gui thread. we use signals. emit addOutput("

" + out + "

"); diff --git a/gui/src/SearchWindow.hpp b/gui/src/SearchWindow.hpp index a161628..479edf2 100644 --- a/gui/src/SearchWindow.hpp +++ b/gui/src/SearchWindow.hpp @@ -43,7 +43,7 @@ class SearchWindow : public QWidget, public eoskeygen::IKeySearchResult public: explicit SearchWindow(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags()); - void onResult(const struct libeosio::ec_keypair* key, const struct eoskeygen::KeySearch::result& result); + void onResult(const struct libantelope::ec_keypair* key, const struct eoskeygen::KeySearch::result& result); private : void initSignals(); diff --git a/gui/src/Settings.cpp b/gui/src/Settings.cpp index 733e028..aa8dad9 100644 --- a/gui/src/Settings.cpp +++ b/gui/src/Settings.cpp @@ -25,13 +25,13 @@ namespace priv { - libeosio::wif_codec_t key_format = libeosio::WIF_CODEC_K1; + libantelope::wif_codec_t key_format = libantelope::WIF_CODEC_K1; } // namespace priv -void Settings::setKeyCodec(const libeosio::wif_codec_t& format) { +void Settings::setKeyCodec(const libantelope::wif_codec_t& format) { priv::key_format = format; } -const libeosio::wif_codec_t& Settings::getKeyCodec() { +const libantelope::wif_codec_t& Settings::getKeyCodec() { return priv::key_format; } diff --git a/gui/src/Settings.hpp b/gui/src/Settings.hpp index 4cf04be..08a56cd 100644 --- a/gui/src/Settings.hpp +++ b/gui/src/Settings.hpp @@ -24,13 +24,13 @@ #ifndef SETTINGS_H #define SETTINGS_H -#include +#include namespace Settings { - void setKeyCodec(const libeosio::wif_codec_t& format); + void setKeyCodec(const libantelope::wif_codec_t& format); - const libeosio::wif_codec_t& getKeyCodec(); + const libantelope::wif_codec_t& getKeyCodec(); }; #endif /* SEARCH_WINDOW_H */