Merge pull request #3426

8ea3c4d5 simplewallet: new --use-english-language-names flag (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2018-03-18 15:58:12 +02:00
commit df91d7bcbd
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD
18 changed files with 70 additions and 26 deletions

View File

@ -72,7 +72,7 @@ namespace Language
class Chinese_Simplified: public Base class Chinese_Simplified: public Base
{ {
public: public:
Chinese_Simplified(): Base("简体中文 (中国)", std::vector<std::string>({ Chinese_Simplified(): Base("简体中文 (中国)", "Chinese (simplified)", std::vector<std::string>({
"", "",
"", "",
"", "",

View File

@ -49,7 +49,7 @@ namespace Language
class Dutch: public Base class Dutch: public Base
{ {
public: public:
Dutch(): Base("Nederlands", std::vector<std::string>({ Dutch(): Base("Nederlands", "Dutch", std::vector<std::string>({
"aalglad", "aalglad",
"aalscholver", "aalscholver",
"aambeeld", "aambeeld",

View File

@ -445,13 +445,9 @@ namespace crypto
return bytes_to_words(src.data, sizeof(src), words, language_name); return bytes_to_words(src.data, sizeof(src), words, language_name);
} }
/*! std::vector<const Language::Base*> get_language_list()
* \brief Gets a list of seed languages that are supported.
* \param languages The vector is set to the list of languages.
*/
void get_language_list(std::vector<std::string> &languages)
{ {
std::vector<Language::Base*> language_instances({ static const std::vector<const Language::Base*> language_instances({
Language::Singleton<Language::German>::instance(), Language::Singleton<Language::German>::instance(),
Language::Singleton<Language::English>::instance(), Language::Singleton<Language::English>::instance(),
Language::Singleton<Language::Spanish>::instance(), Language::Singleton<Language::Spanish>::instance(),
@ -465,10 +461,20 @@ namespace crypto
Language::Singleton<Language::Esperanto>::instance(), Language::Singleton<Language::Esperanto>::instance(),
Language::Singleton<Language::Lojban>::instance() Language::Singleton<Language::Lojban>::instance()
}); });
for (std::vector<Language::Base*>::iterator it = language_instances.begin(); return language_instances;
}
/*!
* \brief Gets a list of seed languages that are supported.
* \param languages The vector is set to the list of languages.
*/
void get_language_list(std::vector<std::string> &languages, bool english)
{
const std::vector<const Language::Base*> language_instances = get_language_list();
for (std::vector<const Language::Base*>::const_iterator it = language_instances.begin();
it != language_instances.end(); it++) it != language_instances.end(); it++)
{ {
languages.push_back((*it)->get_language_name()); languages.push_back(english ? (*it)->get_english_language_name() : (*it)->get_language_name());
} }
} }
@ -485,6 +491,18 @@ namespace crypto
return word_list.size() != (seed_length + 1); return word_list.size() != (seed_length + 1);
} }
std::string get_english_name_for(const std::string &name)
{
const std::vector<const Language::Base*> language_instances = get_language_list();
for (std::vector<const Language::Base*>::const_iterator it = language_instances.begin();
it != language_instances.end(); it++)
{
if ((*it)->get_language_name() == name)
return (*it)->get_english_language_name();
}
return "<language not found>";
}
} }
} }

View File

@ -106,8 +106,9 @@ namespace crypto
/*! /*!
* \brief Gets a list of seed languages that are supported. * \brief Gets a list of seed languages that are supported.
* \param languages A vector is set to the list of languages. * \param languages A vector is set to the list of languages.
* \param english whether to get the names in English or the language language
*/ */
void get_language_list(std::vector<std::string> &languages); void get_language_list(std::vector<std::string> &languages, bool english = false);
/*! /*!
* \brief Tells if the seed passed is an old style seed or not. * \brief Tells if the seed passed is an old style seed or not.
@ -115,6 +116,13 @@ namespace crypto
* \return true if the seed passed is a old style seed false if not. * \return true if the seed passed is a old style seed false if not.
*/ */
bool get_is_old_style_seed(std::string seed); bool get_is_old_style_seed(std::string seed);
/*!
* \brief Returns the name of a language in English
* \param name the name of the language in its own language
* \return the name of the language in English
*/
std::string get_english_name_for(const std::string &name);
} }
} }

View File

@ -49,7 +49,7 @@ namespace Language
class English: public Base class English: public Base
{ {
public: public:
English(): Base("English", std::vector<std::string>({ English(): Base("English", "English", std::vector<std::string>({
"abbey", "abbey",
"abducts", "abducts",
"ability", "ability",

View File

@ -51,7 +51,7 @@ namespace Language
class EnglishOld: public Base class EnglishOld: public Base
{ {
public: public:
EnglishOld(): Base("EnglishOld", std::vector<std::string>({ EnglishOld(): Base("EnglishOld", "English (old)", std::vector<std::string>({
"like", "like",
"just", "just",
"love", "love",

View File

@ -58,7 +58,7 @@ namespace Language
class Esperanto: public Base class Esperanto: public Base
{ {
public: public:
Esperanto(): Base("Esperanto", std::vector<std::string>({ Esperanto(): Base("Esperanto", "Esperanto", std::vector<std::string>({
"abako", "abako",
"abdiki", "abdiki",
"abelo", "abelo",

View File

@ -49,7 +49,7 @@ namespace Language
class French: public Base class French: public Base
{ {
public: public:
French(): Base("Français", std::vector<std::string>({ French(): Base("Français", "French", std::vector<std::string>({
"abandon", "abandon",
"abattre", "abattre",
"aboi", "aboi",

View File

@ -51,7 +51,7 @@ namespace Language
class German: public Base class German: public Base
{ {
public: public:
German(): Base("Deutsch", std::vector<std::string>({ German(): Base("Deutsch", "German", std::vector<std::string>({
"Abakus", "Abakus",
"Abart", "Abart",
"abbilden", "abbilden",

View File

@ -51,7 +51,7 @@ namespace Language
class Italian: public Base class Italian: public Base
{ {
public: public:
Italian(): Base("Italiano", std::vector<std::string>({ Italian(): Base("Italiano", "Italian", std::vector<std::string>({
"abbinare", "abbinare",
"abbonato", "abbonato",
"abisso", "abisso",

View File

@ -71,7 +71,7 @@ namespace Language
class Japanese: public Base class Japanese: public Base
{ {
public: public:
Japanese(): Base("日本語", std::vector<std::string>({ Japanese(): Base("日本語", "Japanese", std::vector<std::string>({
"あいこくしん", "あいこくしん",
"あいさつ", "あいさつ",
"あいだ", "あいだ",

View File

@ -82,6 +82,7 @@ namespace Language
std::unordered_map<std::string, uint32_t> word_map; /*!< hash table to find word's index */ std::unordered_map<std::string, uint32_t> word_map; /*!< hash table to find word's index */
std::unordered_map<std::string, uint32_t> trimmed_word_map; /*!< hash table to find word's trimmed index */ std::unordered_map<std::string, uint32_t> trimmed_word_map; /*!< hash table to find word's trimmed index */
std::string language_name; /*!< Name of language */ std::string language_name; /*!< Name of language */
std::string english_language_name; /*!< Name of language */
uint32_t unique_prefix_length; /*!< Number of unique starting characters to trim the wordlist to when matching */ uint32_t unique_prefix_length; /*!< Number of unique starting characters to trim the wordlist to when matching */
/*! /*!
* \brief Populates the word maps after the list is ready. * \brief Populates the word maps after the list is ready.
@ -122,10 +123,11 @@ namespace Language
} }
} }
public: public:
Base(const char *language_name, const std::vector<std::string> &words, uint32_t prefix_length): Base(const char *language_name, const char *english_language_name, const std::vector<std::string> &words, uint32_t prefix_length):
word_list(words), word_list(words),
unique_prefix_length(prefix_length), unique_prefix_length(prefix_length),
language_name(language_name) language_name(language_name),
english_language_name(english_language_name)
{ {
} }
virtual ~Base() virtual ~Base()
@ -163,6 +165,14 @@ namespace Language
{ {
return language_name; return language_name;
} }
/*!
* \brief Returns the name of the language in English.
* \return Name of the language.
*/
const std::string &get_english_language_name() const
{
return english_language_name;
}
/*! /*!
* \brief Returns the number of unique starting characters to be used for matching. * \brief Returns the number of unique starting characters to be used for matching.
* \return Number of unique starting characters. * \return Number of unique starting characters.

View File

@ -56,7 +56,7 @@ namespace Language
class Lojban: public Base class Lojban: public Base
{ {
public: public:
Lojban(): Base("Lojban", std::vector<std::string>({ Lojban(): Base("Lojban", "Lojban", std::vector<std::string>({
"backi", "backi",
"bacru", "bacru",
"badna", "badna",

View File

@ -72,7 +72,7 @@ namespace Language
class Portuguese: public Base class Portuguese: public Base
{ {
public: public:
Portuguese(): Base("Português", std::vector<std::string>({ Portuguese(): Base("Português", "Portuguese", std::vector<std::string>({
"abaular", "abaular",
"abdominal", "abdominal",
"abeto", "abeto",

View File

@ -51,7 +51,7 @@ namespace Language
class Russian: public Base class Russian: public Base
{ {
public: public:
Russian(): Base("русский язык", std::vector<std::string>({ Russian(): Base("русский язык", "Russian", std::vector<std::string>({
"абажур", "абажур",
"абзац", "абзац",
"абонент", "абонент",

View File

@ -72,7 +72,7 @@ namespace Language
class Spanish: public Base class Spanish: public Base
{ {
public: public:
Spanish(): Base("Español", std::vector<std::string>({ Spanish(): Base("Español", "Spanish", std::vector<std::string>({
"ábaco", "ábaco",
"abdomen", "abdomen",
"abeja", "abeja",

View File

@ -135,6 +135,7 @@ namespace
const command_line::arg_descriptor<bool> arg_do_not_relay = {"do-not-relay", sw::tr("The newly created transaction will not be relayed to the monero network"), false}; const command_line::arg_descriptor<bool> arg_do_not_relay = {"do-not-relay", sw::tr("The newly created transaction will not be relayed to the monero network"), false};
const command_line::arg_descriptor<bool> arg_create_address_file = {"create-address-file", sw::tr("Create an address file for new wallets"), false}; const command_line::arg_descriptor<bool> arg_create_address_file = {"create-address-file", sw::tr("Create an address file for new wallets"), false};
const command_line::arg_descriptor<std::string> arg_subaddress_lookahead = {"subaddress-lookahead", tools::wallet2::tr("Set subaddress lookahead sizes to <major>:<minor>"), ""}; const command_line::arg_descriptor<std::string> arg_subaddress_lookahead = {"subaddress-lookahead", tools::wallet2::tr("Set subaddress lookahead sizes to <major>:<minor>"), ""};
const command_line::arg_descriptor<bool> arg_use_english_language_names = {"use-english-language-names", sw::tr("Display English language names"), false};
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""}; const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
@ -2341,7 +2342,10 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
{ {
if (args.empty()) if (args.empty())
{ {
success_msg_writer() << "seed = " << m_wallet->get_seed_language(); std::string seed_language = m_wallet->get_seed_language();
if (m_use_english_language_names)
seed_language = crypto::ElectrumWords::get_english_name_for(seed_language);
success_msg_writer() << "seed = " << seed_language;
success_msg_writer() << "always-confirm-transfers = " << m_wallet->always_confirm_transfers(); success_msg_writer() << "always-confirm-transfers = " << m_wallet->always_confirm_transfers();
success_msg_writer() << "print-ring-members = " << m_wallet->print_ring_members(); success_msg_writer() << "print-ring-members = " << m_wallet->print_ring_members();
success_msg_writer() << "store-tx-info = " << m_wallet->store_tx_info(); success_msg_writer() << "store-tx-info = " << m_wallet->store_tx_info();
@ -3130,6 +3134,7 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
m_restore_height = command_line::get_arg(vm, arg_restore_height); m_restore_height = command_line::get_arg(vm, arg_restore_height);
m_do_not_relay = command_line::get_arg(vm, arg_do_not_relay); m_do_not_relay = command_line::get_arg(vm, arg_do_not_relay);
m_subaddress_lookahead = command_line::get_arg(vm, arg_subaddress_lookahead); m_subaddress_lookahead = command_line::get_arg(vm, arg_subaddress_lookahead);
m_use_english_language_names = command_line::get_arg(vm, arg_use_english_language_names);
m_restoring = !m_generate_from_view_key.empty() || m_restoring = !m_generate_from_view_key.empty() ||
!m_generate_from_spend_key.empty() || !m_generate_from_spend_key.empty() ||
!m_generate_from_keys.empty() || !m_generate_from_keys.empty() ||
@ -3176,8 +3181,9 @@ std::string simple_wallet::get_mnemonic_language()
std::vector<std::string> language_list; std::vector<std::string> language_list;
std::string language_choice; std::string language_choice;
int language_number = -1; int language_number = -1;
crypto::ElectrumWords::get_language_list(language_list); crypto::ElectrumWords::get_language_list(language_list, m_use_english_language_names);
std::cout << tr("List of available languages for your wallet's seed:") << std::endl; std::cout << tr("List of available languages for your wallet's seed:") << std::endl;
std::cout << tr("If your display freezes, exit blind with ^C, then run again with --use-english-language-names") << std::endl;
int ii; int ii;
std::vector<std::string>::iterator it; std::vector<std::string>::iterator it;
for (it = language_list.begin(), ii = 0; it != language_list.end(); it++, ii++) for (it = language_list.begin(), ii = 0; it != language_list.end(); it++, ii++)
@ -7444,6 +7450,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_do_not_relay); command_line::add_arg(desc_params, arg_do_not_relay);
command_line::add_arg(desc_params, arg_create_address_file); command_line::add_arg(desc_params, arg_create_address_file);
command_line::add_arg(desc_params, arg_subaddress_lookahead); command_line::add_arg(desc_params, arg_subaddress_lookahead);
command_line::add_arg(desc_params, arg_use_english_language_names);
po::positional_options_description positional_options; po::positional_options_description positional_options;
positional_options.add(arg_command.name, -1); positional_options.add(arg_command.name, -1);

View File

@ -335,6 +335,7 @@ namespace cryptonote
bool m_restoring; // are we restoring, by whatever method? bool m_restoring; // are we restoring, by whatever method?
uint64_t m_restore_height; // optional uint64_t m_restore_height; // optional
bool m_do_not_relay; bool m_do_not_relay;
bool m_use_english_language_names;
epee::console_handlers_binder m_cmd_binder; epee::console_handlers_binder m_cmd_binder;