remove years from copyrights

validate language on wallet creation and standardize error message
This commit is contained in:
woodser
2020-06-18 13:42:14 -04:00
parent 8f91f48a10
commit 557a81d875
15 changed files with 48 additions and 19 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+15 -2
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -54,6 +54,8 @@
#include "rpc/core_rpc_server_commands_defs.h"
#include "storages/portable_storage_template_helper.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "mnemonics/electrum-words.h"
#include "mnemonics/english.h"
#include "string_tools.h"
using namespace cryptonote;
@@ -230,8 +232,19 @@ void monero_utils::deserialize(const std::string& json, boost::property_tree::pt
// ----------------------------------------------------------------------------
// TODO: this is unused
bool monero_utils::is_valid_language(const std::string& language) {
std::vector<std::string> languages;
crypto::ElectrumWords::get_language_list(languages, false);
std::vector<std::string>::iterator it = std::find(languages.begin(), languages.end(), language);
if (it == languages.end()) {
crypto::ElectrumWords::get_language_list(languages, true);
it = std::find(languages.begin(), languages.end(), language);
}
if (it == languages.end()) return false;
return true;
}
// TODO: this is unused
std::shared_ptr<monero_block> monero_utils::cn_block_to_block(const cryptonote::block& cn_block) {
cryptonote::block temp = cn_block;
std::cout << cryptonote::obj_to_json_str(temp) << std::endl;
+8 -2
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -119,7 +119,13 @@ namespace monero_utils
// --------------------------------------------------------------------------
void deserialize(const std::string& json, boost::property_tree::ptree& root);
/**
* Indicates if the given language is valid.
*
* @param language is the language to validate
* @return true if the language is valid, false otherwise
*/
bool is_valid_language(const std::string& language);
/**
* Convert a Monero Core cryptonote::block to a block in this library's native model.
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+5 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -853,6 +853,7 @@ namespace monero {
monero_wallet_core* monero_wallet_core::create_wallet_random(const std::string& path, const std::string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const std::string& language, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory) {
MTRACE("create_wallet_random(...)");
if (!monero_utils::is_valid_language(language)) throw std::runtime_error("Unknown language: " + language);
monero_wallet_core* wallet = new monero_wallet_core();
if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true));
else wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true, std::move(http_client_factory)));
@@ -936,6 +937,9 @@ namespace monero {
if (info.address.m_view_public_key != pkey) throw std::runtime_error("view key does not match address");
}
// validate language
if (!monero_utils::is_valid_language(language)) throw std::runtime_error("Unknown language: " + language);
// initialize wallet
if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true));
else wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true, std::move(http_client_factory)));
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+8 -2
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -75,6 +75,9 @@ namespace monero {
monero_wallet_keys* monero_wallet_keys::create_wallet_random(const monero_network_type network_type, const std::string& language) {
// validate language
if (!monero_utils::is_valid_language(language)) throw std::runtime_error("Unknown language: " + language);
// initialize random wallet account
monero_wallet_keys* wallet = new monero_wallet_keys();
crypto::secret_key spend_key_sk = wallet->m_account.generate();
@@ -166,6 +169,9 @@ namespace monero {
if (info.address.m_view_public_key != pkey) throw std::runtime_error("view key does not match address");
}
// validate language
if (!monero_utils::is_valid_language(language)) throw std::runtime_error("Unknown language: " + language);
// initialize wallet account
monero_wallet_keys* wallet = new monero_wallet_keys();
if (has_spend_key && has_view_key) {
@@ -194,7 +200,7 @@ namespace monero {
std::vector<std::string> monero_wallet_keys::get_mnemonic_languages() {
std::vector<std::string> languages;
crypto::ElectrumWords::get_language_list(languages, true);
crypto::ElectrumWords::get_language_list(languages, true); // TODO: support getting names in language
return languages;
}
+2 -2
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -77,7 +77,7 @@ namespace monero {
* @param network_type is the wallet's network type (default = monero_network_type.MAINNET)
* @param language is the wallet and mnemonic's language (default = "English")
*/
static monero_wallet_keys* create_wallet_random(const monero_network_type network_type, const std::string& language);
static monero_wallet_keys* create_wallet_random(const monero_network_type network_type, const std::string& language = "English");
/**
* Create a wallet from an existing mnemonic phrase.
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2019 woodser
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal