2022-02-16 00:53:01 -05:00
# 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 " ) ) ,
2022-04-02 22:07:41 -04:00
m_db ( nullptr ) ,
2022-05-07 00:40:17 -04:00
m_menuitem_close ( this , & display_wallet : : close_menu_event_handler ) ,
m_menuitem_add_name ( this , & display_wallet : : add_name_event_handler )
2022-02-16 00:53:01 -05:00
{
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 " ;)| " ) ;
2022-05-13 01:31:48 -04:00
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.
2022-02-16 00:53:01 -05:00
// 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 ) ;
}
2022-04-02 22:07:41 -04:00
Bind ( wxEVT_CLOSE_WINDOW , & display_wallet : : OnClose , this ) ;
2022-02-16 00:53:01 -05:00
this - > SetSize ( this - > GetParent ( ) - > GetClientSize ( ) ) ;
singletonFrame - > m_LastUsedSqlite . Assign ( walletfile ) ;
2022-04-02 22:07:41 -04:00
wxMenu * menuFile { singletonFrame - > GetMenuBar ( ) - > GetMenu ( 0 ) } ;
2022-05-07 00:40:17 -04:00
m_menuitem_close . Insert ( menuFile , 1 , " close " , " close wallet " ) ;
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 " ) ;
2022-02-16 00:53:01 -05:00
}
display_wallet : : ~ display_wallet ( ) {
2022-04-02 22:07:41 -04:00
assert ( true ) ;
2022-05-07 00:40:17 -04:00
singletonFrame - > GetMenuBar ( ) - > EnableTop ( 1 , false ) ; //disable edit menu.
2022-04-02 22:07:41 -04:00
}
void display_wallet : : close_menu_event_handler ( wxCommandEvent & event ) {
Close ( true ) ;
}
2022-05-07 00:40:17 -04:00
void display_wallet : : add_name_event_handler ( wxCommandEvent & event ) {
2022-05-13 01:31:48 -04:00
wxTextEntryDialog dialog ( this ,
" This is a small sample \n "
" A long, long string to test out the text entrybox " ,
" Please enter a string " ,
" Default value " ,
wxOK | wxCANCEL ) ;
if ( dialog . ShowModal ( ) = = wxID_OK )
{
wxMessageBox ( dialog . GetValue ( ) , " Got string " , wxOK | wxICON_INFORMATION , this ) ;
}
sql_insert_name insert_name ( m_db ) ;
insert_name ( dialog . GetValue ( ) . ToUTF8 ( ) , m_MasterSecret ( dialog . GetValue ( ) . ToUTF8 ( ) ) . timesBase ( ) ) ;
2022-05-07 00:40:17 -04:00
}
2022-04-02 22:07:41 -04:00
void display_wallet : : OnClose ( wxCloseEvent & event ) {
// This event gives you the opportunity to clean up anything that needs explicit cleanup, albeit if you have done your work right nothing should need explicit cleanup,
// and to object to the closing in a "file not saved" type situation.
// https://docs.wxwidgets.org/trunk/classwx_close_event.html
DestroyChildren ( ) ;
Destroy ( ) ; //Default handler will destroy the window. This is our handler for the user calling close,
// replacing the default handler.'
if ( singletonFrame - > m_panel = = this ) singletonFrame - > m_panel = nullptr ;
2022-02-16 00:53:01 -05:00
}