1
0
forked from cheng/wallet

still broken

This commit is contained in:
Cheng 2022-04-14 02:17:18 -07:00
parent d7464ef04b
commit dc438a22eb
No known key found for this signature in database
GPG Key ID: D51301E176B31828
2 changed files with 36 additions and 80 deletions

View File

@ -223,55 +223,16 @@ void Frame::OnDeleteConfiguration(wxCommandEvent&)
}
using ro::bin2hex, ro::to_base64_string;
void Frame::NewWalletNewSecret(wxCommandEvent&) {
wxMessageBox(_T("new wallet new secret event"), _T(""));
/* If LastUsed is the empty string, check if default filename exists. If it exists, set Last Used to default file name
If LastUsed is not the empty string, or no longer the empty string, attempt to open indicated file. If open fails, or reading the opened file produces bad results, abort with exception
If LastUsed is still the empty string, attempt to create default filename. If creation fails, abort with exception. If it succeeds, set LastUsed to default filename.
The exception in unit test should simply generate an error message, but if run during initialization, should bring up the more complex UI for constructing or selecting your wallet file.*/
ILogMessage("\tWallet file");
/*
bool fWalletNameOk{ false };
wxStandardPaths& StandardPaths(wxStandardPaths::Get());
StandardPaths.UseAppInfo(3);
std::unique_ptr<ISqlite3> db;
if (fWalletNameOk) {
if (!m_LastUsedSqlite.FileExists())
throw MyException((std::string("Expected wallet:\n") + LastUsedSqlite.GetFullPath() + "\nfile not found").c_str());
db.reset(Sqlite3_open(m_LastUsedSqlite.GetFullPath().ToUTF8()));
sql_read_from_misc read_from_misc(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)
throw MyException(sz_unrecognized_wallet_schema);
if (!read_from_misc(4))
throw MyException(sz_mastersecret_missing);
ristretto255::CMasterSecret MasterSecret(*read_from_misc.value<ristretto255::scalar>());
ro::sql read_keys(db, R"|(SELECT * FROM "Keys" LIMIT 5;)|");
sql_read_name read_name(db);
// db.reset(nullptr);// Force error of premature destruction of Isqlite3
while (read_keys.step() == Icompiled_sql::ROW) {
auto pubkey = read_keys.column<ristretto255::point>(0);
auto id = read_keys.column<int>(1);
auto use = read_keys.column<int>(2);
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 (MasterSecret(name).timesBase() != *pubkey)throw MyException(sz_name_does_not_correspond);
wxLogMessage(_T("\t\t\"%s\" has expected public key 0x%s"), name, (wxString)bin2hex(*pubkey));
}
}
else {
// At this point in the code the filename LastUsedSqlite is a bad filename, normally the empty string, and the default wallet file does not exist in the default location.
// Construct default wallet and filename*//*
wxFileName path{ StandardPaths.GetUserLocalDataDir() };
void Frame::NewWallet(wxFileName& filename, ristretto255::hash<256>& secret) {
/*If creation fails, abort with exception. If it succeeds, set LastUsed to default filename.
The exception in unit test should simply generate an error message, but if run during initialization,
should bring up the more complex UI for constructing or selecting your wallet file.*/
wxLogMessage(_wx("New wallet file %s"), filename.GetFullPath());
std::unique_ptr<ISqlite3> db{ nullptr };
try {
// Disk operations to create wallet, which may throw.
// This try/catch block exists to catch disk io issues.
if (!path.DirExists())path.Mkdir();
if (!DefaultSqlite.DirExists())DefaultSqlite.Mkdir();
db.reset(Sqlite3_create(DefaultSqlite.GetFullPath().ToUTF8()));
db.reset(Sqlite3_create(filename.GetFullPath().ToUTF8()));
db->exec(R"|(
PRAGMA journal_mode = WAL;
PRAGMA synchronous = 1;
@ -290,11 +251,8 @@ CREATE TABLE "Misc"(
"m" BLOB
);
COMMIT;)|");
LastUsedSqlite = DefaultSqlite;
singletonApp->pConfig->Write(_T("LastUsed"), DefaultSqlite.GetFullPath());
wxLogMessage("\t\tConstructing default wallet %s", DefaultSqlite.GetFullPath());
wxLogMessage("\t\tConstructing default wallet %s", filename.GetFullPath());
// We now have a working wallet file with no valid data. Attempting to create a strong random secret, a name, and public and private keys for that name.
wxLogMessage("\t\tGenerating random 128 bit wallet secret");
auto text_secret{ DeriveTextSecret(ristretto255::scalar::random(), 1) };
ro::msec start_time{ ro::msec_since_epoch() };
@ -307,7 +265,7 @@ COMMIT;)|");
update_to_misc(3, &text_secret[0]);
update_to_misc(4, MasterSecret);
sql_insert_name insert_name(db);
const char* const cpsz("Unit Tester");
const char* const cpsz("fred");
insert_name(cpsz, MasterSecret(cpsz).timesBase());
}
catch (const MyException& e) {
@ -316,8 +274,6 @@ COMMIT;)|");
szError = e.what();
ILogError(szError.c_str());
}
} // End of wallet creation branch*/
}
@ -339,7 +295,7 @@ void Frame::OnSaveNew(wxCommandEvent& WXUNUSED(event))
}
auto wallet{ dialog.GetDirectory() + "/" + dialog.GetFilename() };
wxLogMessage("new wallet created: %s", wallet);
wxConfigBase::Get()->Write("Wallet", wallet);
// wxConfigBase::Get()->Write("Wallet", wallet);
}
void Frame::OnFileOpen(wxCommandEvent&) {

View File

@ -77,7 +77,7 @@ private:
public:
void OnSaveNew(wxCommandEvent&);
void NewWalletNewSecret(wxCommandEvent&);
void NewWallet(wxFileName&, ristretto255::hash<256>&);
void RecreateWalletFromExistingSecret(wxCommandEvent&);
void OnFileOpen(wxCommandEvent&);