Kagome
Polkadot Runtime Engine in C++17
dictionary.cpp
Go to the documentation of this file.
1 
7 
8 #include <gsl/gsl>
11 
12 namespace kagome::crypto::bip39 {
13 
15  for (size_t i = 0; i < english::dictionary.size(); ++i) {
16  auto token = EntropyToken(i);
17  std::string_view word = gsl::at(english::dictionary, i);
18  entropy_map_[word] = token;
19  }
20  }
21 
22  outcome::result<EntropyToken> Dictionary::findValue(
23  std::string_view word) const {
24  auto loc = entropy_map_.find(word);
25  if (entropy_map_.end() != loc) {
26  return loc->second;
27  }
28 
30  }
31 
32 } // namespace kagome::crypto::bip39
33 
36  switch (error) {
37  case E::ENTRY_NOT_FOUND:
38  return "word not found";
39  }
40  return "unknown DictionaryError error";
41 }
outcome::result< EntropyToken > findValue(std::string_view word) const
looks for word in dictionary
Definition: dictionary.cpp:22
OUTCOME_CPP_DEFINE_CATEGORY(kagome::crypto::bip39, DictionaryError, error)
Definition: dictionary.cpp:34
std::unordered_map< std::string_view, EntropyToken > entropy_map_
Definition: dictionary.hpp:39
constexpr std::array< std::string_view, 2048 > dictionary
words are taken from https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md
Definition: english.hpp:14
void initialize()
initializes dictionary
Definition: dictionary.cpp:14