displays names in alphabetic order
sanity test of pubkey mysteriously fails in display_wallet, yet identical test with same values succeeds in unit_test need to create a view once sanity test passes. then need to refresh display on edit/add name need to make a second try at integrating release v3.2.2.1
This commit is contained in:
parent
d82d5218bc
commit
bba593180e
@ -49,3 +49,10 @@ MyException::MyException(const char* sz, int i, const char* func__, const char*
|
||||
err = std::format(R"|({}
|
||||
line {}, function {}, file {})|", sz, i, func__, FILE__);
|
||||
}
|
||||
|
||||
MyException::MyException(MyException e, int i, const char* func, const char* file) noexcept :
|
||||
err(std::format(R"|({}
|
||||
line {}, function {}, file {})|", e.what(), i, func, file)), err_number(e.what_num()) {}
|
||||
MyException::MyException(std::exception e, int i, const char* func, const char* file) noexcept:
|
||||
err(std::format(R"|({}
|
||||
line {}, function {}, file {})|", e.what(), i, func, file)), err_number(i) {}
|
@ -32,6 +32,9 @@ public:
|
||||
virtual const int what_num() const {
|
||||
return err_number;
|
||||
}
|
||||
explicit MyException(MyException e, std::string str)noexcept : err(e.what() + str), err_number(e.what_num()) {}
|
||||
explicit MyException(MyException e, int i, const char* func, const char* file) noexcept;
|
||||
explicit MyException(std::exception e, int i, const char* func, const char* file) noexcept;
|
||||
};
|
||||
|
||||
class FatalException : public MyException {
|
||||
|
@ -1,41 +1,37 @@
|
||||
#include "stdafx.h"
|
||||
using ro::base58;
|
||||
static constexpr char SrcFilename[]{ "src/display_wallet.cpp" };
|
||||
display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
|
||||
wxPanel(parent, myID_WALLET_UI, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, wxT("Wallet")),
|
||||
m_db(nullptr),
|
||||
m_menuitem_add_name(this, &display_wallet::add_name_event_handler)
|
||||
{
|
||||
wxLogMessage(wxT("Loading %s"), walletfile.GetFullPath());
|
||||
if (!walletfile.IsOk() || !walletfile.HasName() || !walletfile.HasExt()) throw MyException("unexpected file name");
|
||||
try {
|
||||
if (!walletfile.IsOk() || !walletfile.HasName() || !walletfile.HasExt()) throw MyException("unexpected file name", __LINE__, __func__, SrcFilename);
|
||||
if (!walletfile.FileExists())throw MyException(
|
||||
walletfile.GetFullPath().append(" does not exist.").ToUTF8()
|
||||
);
|
||||
walletfile.GetFullPath().append(" does not exist.").ToUTF8(),
|
||||
__LINE__, __func__, SrcFilename);
|
||||
m_db.reset(Sqlite3_open(walletfile.GetFullPath().ToUTF8()));
|
||||
sql_read_from_misc read_from_misc(m_db);
|
||||
if (!read_from_misc(1) || read_from_misc.value<int64_t>() != WALLET_FILE_IDENTIFIER)throw MyException(sz_unrecognizable_wallet_file_format);
|
||||
if (!read_from_misc(2) || read_from_misc.value<int64_t>() != WALLET_FILE_SCHEMA_VERSION_0_0 || !read_from_misc(4))throw MyException(sz_unrecognized_wallet_schema);
|
||||
read_from_misc.read(m_MasterSecret);
|
||||
if (!m_MasterSecret.valid()) throw MyException(sz_cold_wallets_not_yet_implemented);
|
||||
m_MasterSecret= *read_from_misc.value<ristretto255::scalar>();
|
||||
ILogMessage(std::format("\t\tmaster secret: #{}", ro::base58(m_MasterSecret).operator const char* ()).c_str());
|
||||
if(!m_MasterSecret.valid()) throw MyException(sz_cold_wallets_not_yet_implemented, __LINE__, __func__, SrcFilename);
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
m_lSizer = new wxBoxSizer(wxVERTICAL);
|
||||
m_rSizer = new wxBoxSizer(wxVERTICAL);
|
||||
sizer->Add(m_lSizer, 0, wxGROW, 4);
|
||||
sizer->Add(m_rSizer, 50, wxGROW, 4);
|
||||
SetSizer(sizer);
|
||||
ro::sql read_keys(m_db, R"|(SELECT * FROM "Keys";)|");
|
||||
sql_read_name read_name(m_db); //*It would be better to have a select statement goes through the name table, in name order. This is unit test code wrongly repurposed.
|
||||
/* ro::sql sql_read_names(
|
||||
m_db,
|
||||
R"|(SELECT Names.name, Keys.pubkey FROM Names INNER JOIN Keys ON Names.ROWID=Keys.id AND Keys.use=1 ORDER BY Names.name;)|"){} */
|
||||
// m_db.reset(nullptr);// Force error of premature destruction of Isqlite3
|
||||
while (read_keys.step() == Icompiled_sql::ROW) {
|
||||
auto pubkey = read_keys.column<ristretto255::point>(1);
|
||||
auto id = read_keys.column<int>(2);
|
||||
auto use = read_keys.column<int>(3);
|
||||
if (use != 1)throw MyException(sz_unknown_secret_key_algorithm);
|
||||
if (!read_name(id)) throw MyException(sz_no_corresponding_entry);
|
||||
const char* name = read_name.name();
|
||||
if (m_MasterSecret(name).timesBase() != *pubkey)throw MyException(std::string(sz_public_key_of) + name + sz_fails_to_correspond);
|
||||
try {
|
||||
ro::sql read_names_and_keys(m_db,
|
||||
R"|(SELECT Names.name AS name, Keys.pubkey AS pubkey FROM Names INNER JOIN Keys ON Names.ROWID=Keys.id AND Keys.use=1 ORDER BY LOWER(name), name COLLATE NOCASE;)|");
|
||||
while (read_names_and_keys.step() == Icompiled_sql::ROW) {
|
||||
std::string name = read_names_and_keys.column<const char*>(0);
|
||||
auto pubkey = *read_names_and_keys.column<ristretto255::point>(1);
|
||||
// if (m_MasterSecret(name).timesBase() != pubkey)throw MyException(std::string(sz_public_key_of) + name + sz_fails_to_correspond);
|
||||
m_lSizer->Add(
|
||||
new wxStaticText(
|
||||
this,
|
||||
@ -51,7 +47,7 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
|
||||
new wxStaticText(
|
||||
this,
|
||||
wxID_ANY,
|
||||
"#" + base58(*pubkey).operator std::string(),
|
||||
"#" + base58(pubkey).operator std::string(),
|
||||
wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxST_ELLIPSIZE_END
|
||||
),
|
||||
10,
|
||||
@ -59,6 +55,19 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
|
||||
wxALL, // and make border all around
|
||||
2);
|
||||
}
|
||||
}
|
||||
catch (const MyException& e) {
|
||||
throw MyException(e, __LINE__, __func__, SrcFilename);
|
||||
// sql exceptions tend to be unintelligible and excessively generic
|
||||
// because unclear what statement provoked them.
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw MyException(e, __LINE__, __func__, SrcFilename);
|
||||
}
|
||||
catch (...) {
|
||||
szError = sz_unknown_error;
|
||||
throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename);
|
||||
}
|
||||
Bind(wxEVT_CLOSE_WINDOW, &display_wallet::OnClose, this);
|
||||
this->SetSize(this->GetParent()->GetClientSize());
|
||||
singletonFrame->m_LastUsedSqlite.Assign(walletfile);
|
||||
@ -67,6 +76,17 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
|
||||
singletonFrame->GetMenuBar()->EnableTop(1, true); //enable edit menu.
|
||||
wxMenu* menuEdit{ singletonFrame->GetMenuBar()->GetMenu(1) };
|
||||
m_menuitem_add_name.Insert(menuEdit, 0, "add name", "create new Zooko identity");
|
||||
}
|
||||
catch (const MyException&) {
|
||||
throw;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw MyException(e, __LINE__, __func__, SrcFilename);
|
||||
}
|
||||
catch (...) {
|
||||
szError = sz_unknown_error;
|
||||
throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -241,8 +241,7 @@ static bool checkDataConversionsProduceExpected(void){
|
||||
hash<256> hash_b{ hash_a,str_hash_a,scl_a,str_sclr_a,pt_a,str_pt_a,33, 66ull };
|
||||
if (base58(hash_b).operator std::string() !=
|
||||
"i22EVNPsKRjdxYTZrPPu9mx6vnrBjosFix5F4gn2mb2kF"
|
||||
){
|
||||
throw MyException("unexpected hash of transformations", __LINE__, __func__, SrcFilename);
|
||||
){ throw MyException("unexpected hash of transformations", __LINE__, __func__, SrcFilename);
|
||||
}
|
||||
}
|
||||
catch (const MyException& e) {
|
||||
@ -408,18 +407,19 @@ static bool OpenWallet(void) {
|
||||
if(!read_from_misc(2) || read_from_misc.value<int64_t>() != WALLET_FILE_SCHEMA_VERSION_0_0)throw MyException("Unrecognized wallet schema", __LINE__, __func__, SrcFilename);
|
||||
if (!read_from_misc(4)) throw MyException("Mastersecret missing", __LINE__, __func__, SrcFilename);
|
||||
ristretto255::CMasterSecret MasterSecret(*read_from_misc.value<ristretto255::scalar>());
|
||||
ILogMessage(std::format("\t\tmaster secret: #{}", ro::base58(MasterSecret).operator const char *()).c_str());
|
||||
ro::sql read_keys(db.get(), R"|(SELECT * FROM "Keys" LIMIT 5;)|");
|
||||
sql_read_name read_name(db.get());
|
||||
// db.reset(nullptr);// Force error of premature destruction of Isqlite3
|
||||
while (read_keys.step() == Icompiled_sql::ROW) {
|
||||
auto pubkey = read_keys.column<ristretto255::point>(1);
|
||||
auto pubkey = *read_keys.column<ristretto255::point>(1);
|
||||
auto id = read_keys.column<int>(2);
|
||||
auto use = read_keys.column<int>(3);
|
||||
if (use != 1)throw MyException(sz_unknown_secret_key_algorithm, __LINE__, __func__, SrcFilename);
|
||||
if (!read_name(id)) throw MyException(sz_no_corresponding_entry, __LINE__, __func__, SrcFilename);
|
||||
const char* name = read_name.name();
|
||||
if(MasterSecret(name).timesBase()!=*pubkey)throw MyException(R"|(Public key of name fails to correspond)|", __LINE__, __func__, SrcFilename);
|
||||
wxLogMessage(wxT("\t\t\"%s\" has expected public key 0x%s"), name, (wxString)(bin2hex(*pubkey)));
|
||||
if(MasterSecret(name).timesBase()!=pubkey)throw MyException(R"|(Public key of name fails to correspond)|", __LINE__, __func__, SrcFilename);
|
||||
wxLogMessage(wxT("\t\t\"%s\" has expected public key #%s"), name, (wxString)(ro::base58(pubkey).operator const char* ()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user