From 599558ef9b60cf349ea0a7db5f446165c9f9d928 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 2 May 2020 23:56:12 +0300 Subject: [PATCH] minor improvements --- src/common/mnemonic-encoding.cpp | 7 +++---- src/common/mnemonic-encoding.h | 2 ++ src/wallet/wallet_errors.h | 12 ++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/mnemonic-encoding.cpp b/src/common/mnemonic-encoding.cpp index e5f46641..b5a22c24 100644 --- a/src/common/mnemonic-encoding.cpp +++ b/src/common/mnemonic-encoding.cpp @@ -48,8 +48,6 @@ namespace tools { using namespace std; - const int NUMWORDS = 1626; - const map wordsMap = { {"like", 0}, {"just", 1}, @@ -3358,7 +3356,7 @@ namespace tools throw runtime_error("Invalid binary data size for mnemonic encoding"); // 4 bytes -> 3 words. 8 digits base 16 -> 3 digits base 1626 string res; - for (unsigned int i=0; i < binary.size() / 4; i++, res += ' ') + for (unsigned int i=0; i < binary.size() / 4; i++) { const uint32_t* val = reinterpret_cast(&binary[i * 4]); @@ -3369,8 +3367,9 @@ namespace tools res += wordsArray[w1] + " "; res += wordsArray[w2] + " "; - res += wordsArray[w3]; + res += wordsArray[w3] + " "; } + res.erase(--res.end()); // remove trailing space return res; } std::string word_by_num(uint32_t n) diff --git a/src/common/mnemonic-encoding.h b/src/common/mnemonic-encoding.h index 409a935b..2e92ffa4 100644 --- a/src/common/mnemonic-encoding.h +++ b/src/common/mnemonic-encoding.h @@ -40,6 +40,8 @@ namespace tools { namespace mnemonic_encoding { + constexpr int NUMWORDS = 1626; + std::vector text2binary(const std::string& text); std::string binary2text(const std::vector& binary); std::string word_by_num(uint32_t n); diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 1430b35d..a0b9834e 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -68,6 +68,12 @@ namespace tools return ss.str(); } + virtual char const* what() const + { + m_what = to_string(); + return m_what.c_str(); + } + protected: wallet_error_base(std::string&& loc, const std::string& message) : Base(message) @@ -77,6 +83,7 @@ namespace tools private: std::string m_loc; + mutable std::string m_what; }; //---------------------------------------------------------------------------------------------------- const char* const failed_rpc_request_messages[] = { @@ -113,8 +120,9 @@ namespace tools std::string m_status; }; //---------------------------------------------------------------------------------------------------- - typedef wallet_error_base wallet_logic_error; - typedef wallet_error_base wallet_runtime_error; + typedef wallet_error_base wallet_error; + typedef wallet_error wallet_logic_error; + typedef wallet_error wallet_runtime_error; //---------------------------------------------------------------------------------------------------- struct wallet_internal_error : public wallet_runtime_error {