1
0
Fork 0
forked from lthn/blockchain

minor improvements

This commit is contained in:
sowle 2020-05-02 23:56:12 +03:00
parent b9569ce89b
commit 599558ef9b
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 15 additions and 6 deletions

View file

@ -48,8 +48,6 @@ namespace tools
{
using namespace std;
const int NUMWORDS = 1626;
const map<string,uint32_t> 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<const uint32_t*>(&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)

View file

@ -40,6 +40,8 @@ namespace tools
{
namespace mnemonic_encoding
{
constexpr int NUMWORDS = 1626;
std::vector<unsigned char> text2binary(const std::string& text);
std::string binary2text(const std::vector<unsigned char>& binary);
std::string word_by_num(uint32_t n);

View file

@ -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<std::logic_error> wallet_logic_error;
typedef wallet_error_base<std::runtime_error> wallet_runtime_error;
typedef wallet_error_base<std::runtime_error> wallet_error;
typedef wallet_error wallet_logic_error;
typedef wallet_error wallet_runtime_error;
//----------------------------------------------------------------------------------------------------
struct wallet_internal_error : public wallet_runtime_error
{