1
0
forked from cheng/wallet

Moved the compiled sql statments from the stack to unique

pointers that are members of the window
This commit is contained in:
Cheng 2023-09-29 11:16:13 +00:00
parent 883d8c5b51
commit 5f4fe3104b
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
3 changed files with 13 additions and 10 deletions

View File

@ -13,10 +13,13 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
walletfile.GetFullPath().append(" does not exist.").ToUTF8(), walletfile.GetFullPath().append(" does not exist.").ToUTF8(),
__LINE__, __func__, SrcFilename); __LINE__, __func__, SrcFilename);
m_db.reset(Sqlite3_open(walletfile.GetFullPath().ToUTF8())); m_db.reset(Sqlite3_open(walletfile.GetFullPath().ToUTF8()));
sql_read_from_misc read_from_misc(m_db); m_read_from_misc.reset(new sql_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); m_read_names_and_keys.reset(new ro::sql(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); R"|(SELECT "Names".name AS name, "Keys".pubkey AS pubkey FROM "Names" INNER JOIN "Keys" )|"
m_MasterSecret= *read_from_misc.value<ristretto255::scalar>(); R"|(ON "Names"."ROWID"="Keys".id AND "Keys".use=1 ORDER BY LOWER(name), name COLLATE BINARY;)|"));
if (!(*m_read_from_misc)(1) || m_read_from_misc->value<int64_t>() != WALLET_FILE_IDENTIFIER)throw MyException(sz_unrecognizable_wallet_file_format);
if (!(*m_read_from_misc)(2) || m_read_from_misc->value<int64_t>() != WALLET_FILE_SCHEMA_VERSION_0_0 || !(*m_read_from_misc)(4))throw MyException(sz_unrecognized_wallet_schema);
m_MasterSecret= *(m_read_from_misc->value<ristretto255::scalar>());
ILogMessage(std::format("\t\tmaster secret: #{}", ro::base58(m_MasterSecret).operator const char* ()).c_str()); 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); if(!m_MasterSecret.valid()) throw MyException(sz_cold_wallets_not_yet_implemented, __LINE__, __func__, SrcFilename);
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
@ -26,11 +29,9 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
sizer->Add(m_rSizer, 50, wxGROW, 4); sizer->Add(m_rSizer, 50, wxGROW, 4);
SetSizer(sizer); SetSizer(sizer);
try { try {
ro::sql read_names_and_keys(m_db, while (m_read_names_and_keys->step() == Icompiled_sql::ROW) {
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 BINARY;)|"); std::string name = m_read_names_and_keys->column<const char*>(0);
while (read_names_and_keys.step() == Icompiled_sql::ROW) { auto pubkey = *(m_read_names_and_keys->column<ristretto255::point>(1));
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); if (m_MasterSecret(name).timesBase() != pubkey)throw MyException(std::string(sz_public_key_of) + name + sz_fails_to_correspond);
m_lSizer->Add( m_lSizer->Add(
new wxStaticText( new wxStaticText(

View File

@ -7,6 +7,8 @@ public:
private: private:
typedef MenuLink<display_wallet> MenuLink; typedef MenuLink<display_wallet> MenuLink;
std::unique_ptr<ISqlite3> m_db; std::unique_ptr<ISqlite3> m_db;
std::unique_ptr <sql_read_from_misc> m_read_from_misc;
std::unique_ptr <ro::sql> m_read_names_and_keys;
ristretto255::CMasterSecret m_MasterSecret; ristretto255::CMasterSecret m_MasterSecret;
wxBoxSizer* m_lSizer; wxBoxSizer* m_lSizer;
wxBoxSizer* m_rSizer; wxBoxSizer* m_rSizer;

View File

@ -75,7 +75,7 @@
l = std::size(a); l = std::size(a);
pt = &a[0]; pt = &a[0];
} }
return std::span<const byte>(static_cast<const byte *>(pt), l); return std::span(static_cast<const byte *>(pt), l);
} }
// Compile time test to see if a type has a blob array member // Compile time test to see if a type has a blob array member