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:
Cheng 2023-09-28 22:14:29 +00:00
parent d82d5218bc
commit bba593180e
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
4 changed files with 96 additions and 66 deletions

View File

@ -49,3 +49,10 @@ MyException::MyException(const char* sz, int i, const char* func__, const char*
err = std::format(R"|({} err = std::format(R"|({}
line {}, function {}, file {})|", sz, i, func__, FILE__); 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) {}

View File

@ -32,6 +32,9 @@ public:
virtual const int what_num() const { virtual const int what_num() const {
return err_number; 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 { class FatalException : public MyException {

View File

@ -1,72 +1,92 @@
#include "stdafx.h" #include "stdafx.h"
using ro::base58; using ro::base58;
static constexpr char SrcFilename[]{ "src/display_wallet.cpp" };
display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) : display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
wxPanel(parent, myID_WALLET_UI, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, wxT("Wallet")), wxPanel(parent, myID_WALLET_UI, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, wxT("Wallet")),
m_db(nullptr), m_db(nullptr),
m_menuitem_add_name(this, &display_wallet::add_name_event_handler) m_menuitem_add_name(this, &display_wallet::add_name_event_handler)
{ {
wxLogMessage(wxT("Loading %s"), walletfile.GetFullPath()); wxLogMessage(wxT("Loading %s"), walletfile.GetFullPath());
if (!walletfile.IsOk() || !walletfile.HasName() || !walletfile.HasExt()) throw MyException("unexpected file name"); try {
if (!walletfile.FileExists())throw MyException( if (!walletfile.IsOk() || !walletfile.HasName() || !walletfile.HasExt()) throw MyException("unexpected file name", __LINE__, __func__, SrcFilename);
walletfile.GetFullPath().append(" does not exist.").ToUTF8() if (!walletfile.FileExists())throw MyException(
); walletfile.GetFullPath().append(" does not exist.").ToUTF8(),
m_db.reset(Sqlite3_open(walletfile.GetFullPath().ToUTF8())); __LINE__, __func__, SrcFilename);
sql_read_from_misc read_from_misc(m_db); m_db.reset(Sqlite3_open(walletfile.GetFullPath().ToUTF8()));
if (!read_from_misc(1) || read_from_misc.value<int64_t>() != WALLET_FILE_IDENTIFIER)throw MyException(sz_unrecognizable_wallet_file_format); sql_read_from_misc read_from_misc(m_db);
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); if (!read_from_misc(1) || read_from_misc.value<int64_t>() != WALLET_FILE_IDENTIFIER)throw MyException(sz_unrecognizable_wallet_file_format);
read_from_misc.read(m_MasterSecret); 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);
if (!m_MasterSecret.valid()) throw MyException(sz_cold_wallets_not_yet_implemented); m_MasterSecret= *read_from_misc.value<ristretto255::scalar>();
auto sizer = new wxBoxSizer(wxHORIZONTAL); ILogMessage(std::format("\t\tmaster secret: #{}", ro::base58(m_MasterSecret).operator const char* ()).c_str());
m_lSizer = new wxBoxSizer(wxVERTICAL); if(!m_MasterSecret.valid()) throw MyException(sz_cold_wallets_not_yet_implemented, __LINE__, __func__, SrcFilename);
m_rSizer = new wxBoxSizer(wxVERTICAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_lSizer,0, wxGROW, 4); m_lSizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(m_rSizer, 50, wxGROW, 4); m_rSizer = new wxBoxSizer(wxVERTICAL);
SetSizer(sizer); sizer->Add(m_lSizer, 0, wxGROW, 4);
ro::sql read_keys(m_db, R"|(SELECT * FROM "Keys";)|"); sizer->Add(m_rSizer, 50, wxGROW, 4);
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. SetSizer(sizer);
/* ro::sql sql_read_names( try {
m_db, ro::sql read_names_and_keys(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;)|"){} */ 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;)|");
// m_db.reset(nullptr);// Force error of premature destruction of Isqlite3 while (read_names_and_keys.step() == Icompiled_sql::ROW) {
while (read_keys.step() == Icompiled_sql::ROW) { std::string name = read_names_and_keys.column<const char*>(0);
auto pubkey = read_keys.column<ristretto255::point>(1); auto pubkey = *read_names_and_keys.column<ristretto255::point>(1);
auto id = read_keys.column<int>(2); // if (m_MasterSecret(name).timesBase() != pubkey)throw MyException(std::string(sz_public_key_of) + name + sz_fails_to_correspond);
auto use = read_keys.column<int>(3); m_lSizer->Add(
if (use != 1)throw MyException(sz_unknown_secret_key_algorithm); new wxStaticText(
if (!read_name(id)) throw MyException(sz_no_corresponding_entry); this,
const char* name = read_name.name(); wxID_ANY,
if (m_MasterSecret(name).timesBase() != *pubkey)throw MyException(std::string(sz_public_key_of) + name + sz_fails_to_correspond); name,
m_lSizer->Add( wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_ELLIPSIZE_END
new wxStaticText( ),
this, 10,
wxID_ANY, wxEXPAND | // make horizontally stretchable
name, wxALL, // and make border all around
wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT|wxST_ELLIPSIZE_END 2);
), m_rSizer->Add(
10, new wxStaticText(
wxEXPAND | // make horizontally stretchable this,
wxALL, // and make border all around wxID_ANY,
2); "#" + base58(pubkey).operator std::string(),
m_rSizer->Add( wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxST_ELLIPSIZE_END
new wxStaticText( ),
this, 10,
wxID_ANY, wxEXPAND | // make horizontally stretchable
"#" + base58(*pubkey).operator std::string(), wxALL, // and make border all around
wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxST_ELLIPSIZE_END 2);
), }
10, }
wxEXPAND | // make horizontally stretchable catch (const MyException& e) {
wxALL, // and make border all around throw MyException(e, __LINE__, __func__, SrcFilename);
2); // sql exceptions tend to be unintelligible and excessively generic
} // because unclear what statement provoked them.
Bind(wxEVT_CLOSE_WINDOW, &display_wallet::OnClose, this); }
this->SetSize(this->GetParent()->GetClientSize()); catch (const std::exception& e) {
singletonFrame->m_LastUsedSqlite.Assign(walletfile); 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);
wxMenu* menuFile{ singletonFrame->GetMenuBar()->GetMenu(0) }; wxMenu* menuFile{ singletonFrame->GetMenuBar()->GetMenu(0) };
singletonFrame->GetMenuBar()->EnableTop(1, true); //enable edit menu. singletonFrame->GetMenuBar()->EnableTop(1, true); //enable edit menu.
wxMenu* menuEdit{ singletonFrame->GetMenuBar()->GetMenu(1) }; wxMenu* menuEdit{ singletonFrame->GetMenuBar()->GetMenu(1) };
m_menuitem_add_name.Insert(menuEdit, 0, "add name", "create new Zooko identity"); 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);
}
} }

View File

@ -241,9 +241,8 @@ 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 }; 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() != if (base58(hash_b).operator std::string() !=
"i22EVNPsKRjdxYTZrPPu9mx6vnrBjosFix5F4gn2mb2kF" "i22EVNPsKRjdxYTZrPPu9mx6vnrBjosFix5F4gn2mb2kF"
){ ){ throw MyException("unexpected hash of transformations", __LINE__, __func__, SrcFilename);
throw MyException("unexpected hash of transformations", __LINE__, __func__, SrcFilename); }
}
} }
catch (const MyException& e) { catch (const MyException& e) {
errorCode = e.what_num(); errorCode = e.what_num();
@ -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(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); if (!read_from_misc(4)) throw MyException("Mastersecret missing", __LINE__, __func__, SrcFilename);
ristretto255::CMasterSecret MasterSecret(*read_from_misc.value<ristretto255::scalar>()); 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;)|"); ro::sql read_keys(db.get(), R"|(SELECT * FROM "Keys" LIMIT 5;)|");
sql_read_name read_name(db.get()); sql_read_name read_name(db.get());
// db.reset(nullptr);// Force error of premature destruction of Isqlite3 // db.reset(nullptr);// Force error of premature destruction of Isqlite3
while (read_keys.step() == Icompiled_sql::ROW) { 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 id = read_keys.column<int>(2);
auto use = read_keys.column<int>(3); auto use = read_keys.column<int>(3);
if (use != 1)throw MyException(sz_unknown_secret_key_algorithm, __LINE__, __func__, SrcFilename); 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); if (!read_name(id)) throw MyException(sz_no_corresponding_entry, __LINE__, __func__, SrcFilename);
const char* name = read_name.name(); const char* name = read_name.name();
if(MasterSecret(name).timesBase()!=*pubkey)throw MyException(R"|(Public key of name fails to correspond)|", __LINE__, __func__, SrcFilename); 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))); wxLogMessage(wxT("\t\t\"%s\" has expected public key #%s"), name, (wxString)(ro::base58(pubkey).operator const char* ()));
} }
} }
else { else {