added mnemonic_language_from_code and convenience__new_wallet_with_language_code, updating newly_created_wallet to take language code and return mnemonic_language

pull/29/head
Paul Shapiro 6 years ago
parent 9a9d9cb8f0
commit 33be2feb26

@ -92,10 +92,24 @@ bool monero_wallet_utils::bytes_to_words(
);
}
//
bool monero_wallet_utils::convenience__new_wallet_with_language_code(
const string &locale_language_code,
WalletDescriptionRetVals &retVals,
network_type nettype
) {
auto mnemonic_language = mnemonic_language_from_code(locale_language_code);
if (mnemonic_language == none) {
retVals.did_error = true;
retVals.err_string = "Unrecognized locale language code";
return false;
}
return new_wallet(*mnemonic_language, retVals, nettype);
}
//
bool monero_wallet_utils::new_wallet(
const string &mnemonic_language,
WalletDescriptionRetVals &retVals,
cryptonote::network_type nettype
network_type nettype
) {
retVals = {};
//

@ -114,12 +114,47 @@ namespace monero_wallet_utils
public_key pub_viewKey;
//
string mnemonic_string;
string mnemonic_language; // this might be redundant if the function returning this WalletDescription itself required the language, such as new_wallet
string mnemonic_language;
};
struct WalletDescriptionRetVals: RetVals_base
{
optional<WalletDescription> optl__desc = boost::none;
};
inline optional<string> mnemonic_language_from_code(const string &language_code)
{
if (language_code == "en") {
return string("English");
} else if (language_code == "nl") { // Dutch language
return string("Nederlands");
} else if (language_code == "fr") {
return string("Français");
} else if (language_code == "es") {
return string("Español");
} else if (language_code == "pt") {
return string("Português");
} else if (language_code == "ja") {
return string("日本語");
} else if (language_code == "it") {
return string("Italiano");
} else if (language_code == "de") {
return string("Deutsch");
} else if (language_code == "ru") {
return string("русский язык");
} else if (language_code == "zh") { // Chinese language, simplified
return string("简体中文 (中国)");
} else if (language_code == "eo" || language_code == "epo") {
return string("Esperanto");
} else if (language_code == "jbo") {
return string("Lojban");
} else {
return none; // error .. possibly throw?
}
};
bool convenience__new_wallet_with_language_code(
const string &locale_language_code,
WalletDescriptionRetVals &retVals,
network_type nettype
);
bool new_wallet(
const string &mnemonic_language,
WalletDescriptionRetVals &retVals,

@ -232,8 +232,8 @@ string serial_bridge::newly_created_wallet(const string &args_string)
return error_ret_json_from_message("Invalid JSON");
}
monero_wallet_utils::WalletDescriptionRetVals retVals;
bool r = monero_wallet_utils::new_wallet(
json_root.get<string>("wordset_name"),
bool r = monero_wallet_utils::convenience__new_wallet_with_language_code(
json_root.get<string>("locale_language_code"),
retVals,
nettype_from_string(json_root.get<string>("nettype_string"))
);
@ -246,6 +246,7 @@ string serial_bridge::newly_created_wallet(const string &args_string)
//
boost::property_tree::ptree root;
root.put(ret_json_key__mnemonic_string(), (*(retVals.optl__desc)).mnemonic_string);
root.put(ret_json_key__mnemonic_language(), (*(retVals.optl__desc)).mnemonic_language);
root.put(ret_json_key__sec_seed_string(), (*(retVals.optl__desc)).sec_seed_string);
root.put(ret_json_key__address_string(), (*(retVals.optl__desc)).address_string);
root.put(ret_json_key__pub_viewKey_string(), epee::string_tools::pod_to_hex((*(retVals.optl__desc)).pub_viewKey));

@ -42,17 +42,17 @@ namespace serial_bridge
using namespace cryptonote;
//
// Bridging Functions - these take and return JSON strings
string create_transaction(const string &args_string); // TODO: maybe expose tx key as arg
string create_transaction(const string &args_string);
//
string decode_address(const string &args_string);
string is_subaddress(const string &args_string);
string is_integrated_address(const string &args_string);
//
string new_integrated_address(const string &args_string);
string new_fake_address_for_rct_tx(const string &args_string); // TODO: maybe expose random scalar as arg
string new_fake_address_for_rct_tx(const string &args_string);
string new_payment_id(const string &args_string);
//
string newly_created_wallet(const string &args_string); // TODO: maybe expose random scalar as arg
string newly_created_wallet(const string &args_string);
string are_equal_mnemonics(const string &args_string);
string mnemonic_from_seed(const string &args_string);
string seed_and_keys_from_mnemonic(const string &args_string);

@ -619,7 +619,7 @@ BOOST_AUTO_TEST_CASE(bridged__new_wallet)
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET));
root.put("wordset_name", "English");
root.put("locale_language_code", "en");
//
auto ret_string = serial_bridge::newly_created_wallet(args_string_from_root(root));
stringstream ret_stream;
@ -634,6 +634,10 @@ BOOST_AUTO_TEST_CASE(bridged__new_wallet)
BOOST_REQUIRE(mnemonic_string != none);
BOOST_REQUIRE((*mnemonic_string).size() > 0);
cout << "bridged__new_wallet: mnemonic: " << *mnemonic_string << endl;
optional<string> mnemonic_language = ret_tree.get_optional<string>(ret_json_key__mnemonic_language());
BOOST_REQUIRE(mnemonic_language != none);
BOOST_REQUIRE((*mnemonic_language).size() > 0);
cout << "bridged__new_wallet: mnemonic_language: " << *mnemonic_language << endl;
optional<string> sec_seed_string = ret_tree.get_optional<string>(ret_json_key__sec_seed_string());
BOOST_REQUIRE(sec_seed_string != none);
BOOST_REQUIRE((*sec_seed_string).size() > 0);

Loading…
Cancel
Save