From 4fcbe8fbdd35dde6721502c39e0736dc3abf9b6f Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 17 Apr 2020 22:14:00 +0200 Subject: [PATCH] added more return codes to wallet --- src/wallet/view_iface.h | 1 + src/wallet/wallet2.cpp | 2 +- src/wallet/wallet_errors.h | 8 ++++++++ src/wallet/wallets_manager.cpp | 12 ++++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 6ce27063..4aae6bd2 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -793,6 +793,7 @@ public: #define API_RETURN_CODE_OVERFLOW "OVERFLOW" #define API_RETURN_CODE_BUSY "BUSY" #define API_RETURN_CODE_INVALID_FILE "INVALID_FILE" +#define API_RETURN_CODE_WRONG_SEED "WRONG_SEED" #define API_MAX_ALIASES_COUNT 10000 diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 08c5d8ec..5aaf395f 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2020,7 +2020,7 @@ void wallet2::restore(const std::wstring& path, const std::string& pass, const s m_password = pass; bool r = m_account.restore_keys_from_braindata(restore_key); init_log_prefix(); - THROW_IF_TRUE_WALLET_EX(!r, error::wallet_internal_error, epee::string_encoding::convert_to_ansii(m_wallet_file)); + THROW_IF_TRUE_WALLET_EX(!r, error::wallet_wrong_seed_error, epee::string_encoding::convert_to_ansii(m_wallet_file)); boost::system::error_code ignored_ec; THROW_IF_TRUE_WALLET_EX(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, epee::string_encoding::convert_to_ansii(m_wallet_file)); store(); diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 2b7a94a4..1430b35d 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -124,6 +124,14 @@ namespace tools } }; //---------------------------------------------------------------------------------------------------- + struct wallet_wrong_seed_error : public wallet_runtime_error + { + explicit wallet_wrong_seed_error(std::string&& loc, const std::string& message) + : wallet_runtime_error(std::move(loc), message) + { + } + }; + //---------------------------------------------------------------------------------------------------- struct wallet_common_error : public wallet_runtime_error { explicit wallet_common_error(std::string&& loc, const std::string& message) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 7aaa0427..ec505ff6 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -773,9 +773,13 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st return_code = API_RETURN_CODE_FILE_RESTORED; break; } + catch (const tools::error::invalid_password& ) + { + return std::string(API_RETURN_CODE_WRONG_PASSWORD); + } catch (const std::exception& e) { - return std::string(API_RETURN_CODE_WRONG_PASSWORD) + ":" + e.what(); + return std::string(API_RETURN_CODE_INTERNAL_ERROR) + ", DESCRIPTION: " + e.what(); } } EXCLUSIVE_CRITICAL_REGION_LOCAL(m_wallets_lock); @@ -929,7 +933,11 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: { return API_RETURN_CODE_ALREADY_EXISTS; } - + catch (const tools::error::wallet_wrong_seed_error&) + { + return API_RETURN_CODE_WRONG_SEED; + } + catch (const std::exception& e) { return std::string(API_RETURN_CODE_FAIL) + ":" + e.what();