mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-17 03:50:03 +02:00
key_search: refactor into a KeySearch class.
This commit is contained in:
parent
418949f26f
commit
35bb2302dd
4 changed files with 96 additions and 29 deletions
|
|
@ -5,7 +5,32 @@
|
|||
#include "key_search_helpers.h"
|
||||
#include "key_search.h"
|
||||
|
||||
void key_search(const strlist_t& word_list, size_t n) {
|
||||
void KeySearch::addWord(const std::string& str)
|
||||
{
|
||||
std::string tmp = str;
|
||||
base58_strip(tmp);
|
||||
strtolower(tmp);
|
||||
m_words.push_back(tmp);
|
||||
}
|
||||
|
||||
void KeySearch::addList(const strlist_t& list)
|
||||
{
|
||||
for(const std::string& item : list) {
|
||||
addWord(item);
|
||||
}
|
||||
}
|
||||
|
||||
const strlist_t& KeySearch::getList()
|
||||
{
|
||||
return m_words;
|
||||
}
|
||||
|
||||
void KeySearch::clear()
|
||||
{
|
||||
m_words.clear();
|
||||
}
|
||||
|
||||
void KeySearch::_search_linear(size_t n) {
|
||||
|
||||
size_t count = 0;
|
||||
struct ec_keypair pair;
|
||||
|
|
@ -13,9 +38,22 @@ void key_search(const strlist_t& word_list, size_t n) {
|
|||
while (count < n) {
|
||||
std::string word;
|
||||
ec_generate_key(&pair);
|
||||
if (key_contains_word(&pair, word_list, word)) {
|
||||
if (key_contains_word(&pair, m_words, word)) {
|
||||
key_search_result(word, &pair);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeySearch::find(size_t num_results) {
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
// Only do multithread if number of threads makes sense.
|
||||
if (m_threads >= 2) {
|
||||
_search_mt(num_results);
|
||||
return;
|
||||
}
|
||||
#endif /* HAVE_THREADS */
|
||||
|
||||
_search_linear(num_results);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue