forked from cheng/wallet
62 lines
2.6 KiB
C++
62 lines
2.6 KiB
C++
|
#include "stdafx.h"
|
|||
|
using ro::base58;
|
|||
|
display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
|
|||
|
wxPanel(parent, myID_WALLET_UI, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("Wallet")),
|
|||
|
m_db(nullptr)
|
|||
|
{
|
|||
|
wxLogMessage(_T("Loading %s"), walletfile.GetFullPath());
|
|||
|
if (!walletfile.IsOk() || !walletfile.HasName() || !walletfile.HasExt()) throw MyException("unexpected file name");
|
|||
|
if (!walletfile.FileExists())throw MyException(
|
|||
|
walletfile.GetFullPath().append(" does not exist.").ToUTF8()
|
|||
|
);
|
|||
|
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);
|
|||
|
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);
|
|||
|
// 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>(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 (m_MasterSecret(name).timesBase() != *pubkey)throw MyException(std::string(sz_public_key_of) + name + sz_fails_to_correspond);
|
|||
|
m_lSizer->Add(
|
|||
|
new wxStaticText(
|
|||
|
this,
|
|||
|
wxID_ANY,
|
|||
|
name,
|
|||
|
wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT|wxST_ELLIPSIZE_END
|
|||
|
),
|
|||
|
10,
|
|||
|
wxEXPAND | // make horizontally stretchable
|
|||
|
wxALL, // and make border all around
|
|||
|
2);
|
|||
|
m_rSizer->Add(
|
|||
|
new wxStaticText(
|
|||
|
this,
|
|||
|
wxID_ANY,
|
|||
|
"#" + base58(*pubkey).operator std::string(),
|
|||
|
wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxST_ELLIPSIZE_END
|
|||
|
),
|
|||
|
10,
|
|||
|
wxEXPAND | // make horizontally stretchable
|
|||
|
wxALL, // and make border all around
|
|||
|
2);
|
|||
|
}
|
|||
|
this->SetSize(this->GetParent()->GetClientSize());
|
|||
|
singletonFrame->m_LastUsedSqlite.Assign(walletfile);
|
|||
|
}
|
|||
|
display_wallet::~display_wallet() {
|
|||
|
}
|