@ -35,13 +35,54 @@ int fMinimizeOnClose = true;
// Util
// Util
//
//
void ExitTimeout ( void * parg )
{
# ifdef __WXMSW__
Sleep ( 5000 ) ;
ExitProcess ( 0 ) ;
# endif
}
void Shutdown ( void * parg )
{
static CCriticalSection cs_Shutdown ;
static bool fTaken ;
bool fFirstThread ;
CRITICAL_BLOCK ( cs_Shutdown )
{
fFirstThread = ! fTaken ;
fTaken = true ;
}
static bool fExit ;
if ( fFirstThread )
{
fShutdown = true ;
nTransactionsUpdated + + ;
DBFlush ( false ) ;
StopNode ( ) ;
DBFlush ( true ) ;
CreateThread ( ExitTimeout , NULL ) ;
Sleep ( 50 ) ;
printf ( " Bitcoin exiting \n \n " ) ;
fExit = true ;
exit ( 0 ) ;
}
else
{
while ( ! fExit )
Sleep ( 500 ) ;
Sleep ( 100 ) ;
ExitThread ( 0 ) ;
}
}
void HandleCtrlA ( wxKeyEvent & event )
void HandleCtrlA ( wxKeyEvent & event )
{
{
// Ctrl-a select all
// Ctrl-a select all
event . Skip ( ) ;
wxTextCtrl * textCtrl = ( wxTextCtrl * ) event . GetEventObject ( ) ;
wxTextCtrl * textCtrl = ( wxTextCtrl * ) event . GetEventObject ( ) ;
if ( event . GetModifiers ( ) = = wxMOD_CONTROL & & event . GetKeyCode ( ) = = ' A ' )
if ( event . GetModifiers ( ) = = wxMOD_CONTROL & & event . GetKeyCode ( ) = = ' A ' )
textCtrl - > SetSelection ( - 1 , - 1 ) ;
textCtrl - > SetSelection ( - 1 , - 1 ) ;
event . Skip ( ) ;
}
}
bool Is24HourTime ( )
bool Is24HourTime ( )
@ -194,6 +235,35 @@ int ThreadSafeMessageBox(const string& message, const string& caption, int style
# endif
# endif
}
}
bool ThreadSafeAskFee ( int64 nFeeRequired , const string & strCaption , wxWindow * parent )
{
if ( nFeeRequired = = 0 | | fDaemon )
return true ;
string strMessage = strprintf (
_ ( " This transaction is over the size limit. You can still send it for a fee of %s, "
" which goes to the nodes that process your transaction and helps to support the network. "
" Do you want to pay the fee? " ) ,
FormatMoney ( nFeeRequired ) . c_str ( ) ) ;
return ( ThreadSafeMessageBox ( strMessage , strCaption , wxYES_NO , parent ) = = wxYES ) ;
}
void SetDefaultReceivingAddress ( const string & strAddress )
{
// Update main window address and database
if ( pframeMain = = NULL )
return ;
if ( strAddress ! = pframeMain - > m_textCtrlAddress - > GetValue ( ) )
{
uint160 hash160 ;
if ( ! AddressToHash160 ( strAddress , hash160 ) )
return ;
if ( ! mapPubKeys . count ( hash160 ) )
return ;
CWalletDB ( ) . WriteDefaultKey ( mapPubKeys [ hash160 ] ) ;
pframeMain - > m_textCtrlAddress - > SetValue ( strAddress ) ;
}
}
@ -227,11 +297,6 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
fontTmp . SetFamily ( wxFONTFAMILY_TELETYPE ) ;
fontTmp . SetFamily ( wxFONTFAMILY_TELETYPE ) ;
m_staticTextBalance - > SetFont ( fontTmp ) ;
m_staticTextBalance - > SetFont ( fontTmp ) ;
m_staticTextBalance - > SetSize ( 140 , 17 ) ;
m_staticTextBalance - > SetSize ( 140 , 17 ) ;
// & underlines don't work on the toolbar buttons on gtk
m_toolBar - > ClearTools ( ) ;
m_toolBar - > AddTool ( wxID_BUTTONSEND , _ ( " Send Coins " ) , wxBitmap ( send20_xpm ) , wxNullBitmap , wxITEM_NORMAL , wxEmptyString , wxEmptyString ) ;
m_toolBar - > AddTool ( wxID_BUTTONRECEIVE , _ ( " Address Book " ) , wxBitmap ( addressbook20_xpm ) , wxNullBitmap , wxITEM_NORMAL , wxEmptyString , wxEmptyString ) ;
m_toolBar - > Realize ( ) ;
// resize to fit ubuntu's huge default font
// resize to fit ubuntu's huge default font
dResize = 1.20 ;
dResize = 1.20 ;
SetSize ( ( dResize + 0.02 ) * GetSize ( ) . GetWidth ( ) , 1.09 * GetSize ( ) . GetHeight ( ) ) ;
SetSize ( ( dResize + 0.02 ) * GetSize ( ) . GetWidth ( ) , 1.09 * GetSize ( ) . GetHeight ( ) ) ;
@ -276,47 +341,6 @@ CMainFrame::~CMainFrame()
ptaskbaricon = NULL ;
ptaskbaricon = NULL ;
}
}
void ExitTimeout ( void * parg )
{
# ifdef __WXMSW__
Sleep ( 5000 ) ;
ExitProcess ( 0 ) ;
# endif
}
void Shutdown ( void * parg )
{
static CCriticalSection cs_Shutdown ;
static bool fTaken ;
bool fFirstThread ;
CRITICAL_BLOCK ( cs_Shutdown )
{
fFirstThread = ! fTaken ;
fTaken = true ;
}
static bool fExit ;
if ( fFirstThread )
{
fShutdown = true ;
nTransactionsUpdated + + ;
DBFlush ( false ) ;
StopNode ( ) ;
DBFlush ( true ) ;
CreateThread ( ExitTimeout , NULL ) ;
Sleep ( 50 ) ;
printf ( " Bitcoin exiting \n \n " ) ;
fExit = true ;
exit ( 0 ) ;
}
else
{
while ( ! fExit )
Sleep ( 500 ) ;
Sleep ( 100 ) ;
ExitThread ( 0 ) ;
}
}
void CMainFrame : : OnClose ( wxCloseEvent & event )
void CMainFrame : : OnClose ( wxCloseEvent & event )
{
{
if ( fMinimizeOnClose & & event . CanVeto ( ) & & ! IsIconized ( ) )
if ( fMinimizeOnClose & & event . CanVeto ( ) & & ! IsIconized ( ) )
@ -335,6 +359,7 @@ void CMainFrame::OnClose(wxCloseEvent& event)
void CMainFrame : : OnIconize ( wxIconizeEvent & event )
void CMainFrame : : OnIconize ( wxIconizeEvent & event )
{
{
event . Skip ( ) ;
// Hide the task bar button when minimized.
// Hide the task bar button when minimized.
// Event is sent when the frame is minimized or restored.
// Event is sent when the frame is minimized or restored.
// wxWidgets 2.8.9 doesn't have IsIconized() so there's no way
// wxWidgets 2.8.9 doesn't have IsIconized() so there's no way
@ -342,7 +367,7 @@ void CMainFrame::OnIconize(wxIconizeEvent& event)
if ( ! event . Iconized ( ) )
if ( ! event . Iconized ( ) )
fClosedToTray = false ;
fClosedToTray = false ;
# ifndef __WXMSW__
# ifndef __WXMSW__
// Tray is not reliable on Linux gnome
// Tray is not reliable on ubuntu 9.10 gnome
fClosedToTray = false ;
fClosedToTray = false ;
# endif
# endif
if ( fMinimizeToTray & & event . Iconized ( ) )
if ( fMinimizeToTray & & event . Iconized ( ) )
@ -353,6 +378,7 @@ void CMainFrame::OnIconize(wxIconizeEvent& event)
void CMainFrame : : OnMouseEvents ( wxMouseEvent & event )
void CMainFrame : : OnMouseEvents ( wxMouseEvent & event )
{
{
event . Skip ( ) ;
RandAddSeed ( ) ;
RandAddSeed ( ) ;
RAND_add ( & event . m_x , sizeof ( event . m_x ) , 0.25 ) ;
RAND_add ( & event . m_x , sizeof ( event . m_x ) , 0.25 ) ;
RAND_add ( & event . m_y , sizeof ( event . m_y ) , 0.25 ) ;
RAND_add ( & event . m_y , sizeof ( event . m_y ) , 0.25 ) ;
@ -363,6 +389,8 @@ void CMainFrame::OnListColBeginDrag(wxListEvent& event)
// Hidden columns not resizeable
// Hidden columns not resizeable
if ( event . GetColumn ( ) < = 1 & & ! fDebug )
if ( event . GetColumn ( ) < = 1 & & ! fDebug )
event . Veto ( ) ;
event . Veto ( ) ;
else
event . Skip ( ) ;
}
}
int CMainFrame : : GetSortIndex ( const string & strSort )
int CMainFrame : : GetSortIndex ( const string & strSort )
@ -546,7 +574,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
if ( wtx . IsCoinBase ( ) )
if ( wtx . IsCoinBase ( ) )
{
{
// Coinbase
// Generated
strDescription = _ ( " Generated " ) ;
strDescription = _ ( " Generated " ) ;
if ( nCredit = = 0 )
if ( nCredit = = 0 )
{
{
@ -569,7 +597,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
}
}
else if ( ! mapValue [ " from " ] . empty ( ) | | ! mapValue [ " message " ] . empty ( ) )
else if ( ! mapValue [ " from " ] . empty ( ) | | ! mapValue [ " message " ] . empty ( ) )
{
{
// Online transa ction
// Received by IP conne ction
if ( ! mapValue [ " from " ] . empty ( ) )
if ( ! mapValue [ " from " ] . empty ( ) )
strDescription + = _ ( " From: " ) + mapValue [ " from " ] ;
strDescription + = _ ( " From: " ) + mapValue [ " from " ] ;
if ( ! mapValue [ " message " ] . empty ( ) )
if ( ! mapValue [ " message " ] . empty ( ) )
@ -581,7 +609,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
}
}
else
else
{
{
// Offline transaction
// Received by Bitcoin Address
foreach ( const CTxOut & txout , wtx . vout )
foreach ( const CTxOut & txout , wtx . vout )
{
{
if ( txout . IsMine ( ) )
if ( txout . IsMine ( ) )
@ -590,21 +618,20 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
if ( ExtractPubKey ( txout . scriptPubKey , true , vchPubKey ) )
if ( ExtractPubKey ( txout . scriptPubKey , true , vchPubKey ) )
{
{
CRITICAL_BLOCK ( cs_mapAddressBook )
CRITICAL_BLOCK ( cs_mapAddressBook )
{
string strAddress = PubKeyToAddress ( vchPubKey ) ;
if ( mapAddressBook . count ( strAddress ) )
{
{
//strDescription += _("Received payment to ");
//strDescription += _("Received payment to ");
//strDescription += _("Received with address ");
//strDescription += _("Received with address ");
strDescription + = _ ( " From: unknown, To : " ) ;
strDescription + = _ ( " From: unknown, Received with : " ) ;
strDescription + = strAddress ;
string strAddress = PubKeyToAddress ( vchPubKey ) ;
/// The labeling feature is just too confusing, so I hid it
map < string , string > : : iterator mi = mapAddressBook . find ( strAddress ) ;
/// by putting it at the end where it runs off the screen.
if ( mi ! = mapAddressBook . end ( ) & & ! ( * mi ) . second . empty ( ) )
/// It can still be seen by widening the column, or in the
{
/// details dialog.
string strLabel = ( * mi ) . second ;
if ( ! mapAddressBook [ strAddress ] . empty ( ) )
strDescription + = strAddress . substr ( 0 , 12 ) + " ... " ;
strDescription + = " (" + mapAddressBook [ strAddress ] + " ) " ;
strDescription + = " ( " + strLabel + " ) " ;
}
}
else
strDescription + = strAddress ;
}
}
}
}
break ;
break ;
@ -659,12 +686,12 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
string strAddress ;
string strAddress ;
if ( ! mapValue [ " to " ] . empty ( ) )
if ( ! mapValue [ " to " ] . empty ( ) )
{
{
// Online transaction
// Sent to IP
strAddress = mapValue [ " to " ] ;
strAddress = mapValue [ " to " ] ;
}
}
else
else
{
{
// Offline transaction
// Sent to Bitcoin Address
uint160 hash160 ;
uint160 hash160 ;
if ( ExtractHash160 ( txout . scriptPubKey , hash160 ) )
if ( ExtractHash160 ( txout . scriptPubKey , hash160 ) )
strAddress = Hash160ToAddress ( hash160 ) ;
strAddress = Hash160ToAddress ( hash160 ) ;
@ -683,8 +710,11 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
}
}
int64 nValue = txout . nValue ;
int64 nValue = txout . nValue ;
if ( nOut = = 0 & & nTxFee > 0 )
if ( nTxFee > 0 )
{
nValue + = nTxFee ;
nValue + = nTxFee ;
nTxFee = 0 ;
}
InsertLine ( fNew , nIndex , hash , strprintf ( " %s-%d " , strSort . c_str ( ) , nOut ) ,
InsertLine ( fNew , nIndex , hash , strprintf ( " %s-%d " , strSort . c_str ( ) , nOut ) ,
strStatus ,
strStatus ,
@ -846,12 +876,12 @@ void CMainFrame::RefreshStatusColumn()
void CMainFrame : : OnPaint ( wxPaintEvent & event )
void CMainFrame : : OnPaint ( wxPaintEvent & event )
{
{
event . Skip ( ) ;
if ( fRefresh )
if ( fRefresh )
{
{
fRefresh = false ;
fRefresh = false ;
Refresh ( ) ;
Refresh ( ) ;
}
}
event . Skip ( ) ;
}
}
@ -903,6 +933,9 @@ void MainFrameRepaint()
void CMainFrame : : OnPaintListCtrl ( wxPaintEvent & event )
void CMainFrame : : OnPaintListCtrl ( wxPaintEvent & event )
{
{
// Skip lets the listctrl do the paint, we're just hooking the message
event . Skip ( ) ;
if ( ptaskbaricon )
if ( ptaskbaricon )
ptaskbaricon - > UpdateTooltip ( ) ;
ptaskbaricon - > UpdateTooltip ( ) ;
@ -970,11 +1003,6 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
if ( fDebug & & GetTime ( ) - nThreadSocketHandlerHeartbeat > 60 )
if ( fDebug & & GetTime ( ) - nThreadSocketHandlerHeartbeat > 60 )
m_statusBar - > SetStatusText ( " ERROR: ThreadSocketHandler has stopped " , 0 ) ;
m_statusBar - > SetStatusText ( " ERROR: ThreadSocketHandler has stopped " , 0 ) ;
// Pass through to listctrl to actually do the paint, we're just hooking the message
m_listCtrl - > Disconnect ( wxEVT_PAINT , ( wxObjectEventFunction ) NULL , NULL , this ) ;
m_listCtrl - > GetEventHandler ( ) - > ProcessEvent ( event ) ;
m_listCtrl - > Connect ( wxEVT_PAINT , wxPaintEventHandler ( CMainFrame : : OnPaintListCtrl ) , NULL , this ) ;
}
}
@ -1033,8 +1061,10 @@ void CMainFrame::OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event)
void CMainFrame : : OnMenuOptionsChangeYourAddress ( wxCommandEvent & event )
void CMainFrame : : OnMenuOptionsChangeYourAddress ( wxCommandEvent & event )
{
{
// Options->Change Your Address
// Options->Your Receiving Addresses
OnButtonChange ( event ) ;
CAddressBookDialog dialog ( this , " " , CAddressBookDialog : : RECEIVING , false ) ;
if ( ! dialog . ShowModal ( ) )
return ;
}
}
void CMainFrame : : OnMenuOptionsOptions ( wxCommandEvent & event )
void CMainFrame : : OnMenuOptionsOptions ( wxCommandEvent & event )
@ -1061,11 +1091,11 @@ void CMainFrame::OnButtonSend(wxCommandEvent& event)
void CMainFrame : : OnButtonAddressBook ( wxCommandEvent & event )
void CMainFrame : : OnButtonAddressBook ( wxCommandEvent & event )
{
{
// Toolbar: Address Book
// Toolbar: Address Book
CAddressBookDialog dialogAddr ( this , " " , false ) ;
CAddressBookDialog dialogAddr ( this , " " , CAddressBookDialog : : SENDING , false ) ;
if ( dialogAddr . ShowModal ( ) = = 2 )
if ( dialogAddr . ShowModal ( ) = = 2 )
{
{
// Send
// Send
CSendDialog dialogSend ( this , dialogAddr . GetAddress ( ) ) ;
CSendDialog dialogSend ( this , dialogAddr . GetSelected Address ( ) ) ;
dialogSend . ShowModal ( ) ;
dialogSend . ShowModal ( ) ;
}
}
}
}
@ -1073,35 +1103,36 @@ void CMainFrame::OnButtonAddressBook(wxCommandEvent& event)
void CMainFrame : : OnSetFocusAddress ( wxFocusEvent & event )
void CMainFrame : : OnSetFocusAddress ( wxFocusEvent & event )
{
{
// Automatically select-all when entering window
// Automatically select-all when entering window
event . Skip ( ) ;
m_textCtrlAddress - > SetSelection ( - 1 , - 1 ) ;
m_textCtrlAddress - > SetSelection ( - 1 , - 1 ) ;
fOnSetFocusAddress = true ;
fOnSetFocusAddress = true ;
event . Skip ( ) ;
}
}
void CMainFrame : : OnMouseEventsAddress ( wxMouseEvent & event )
void CMainFrame : : OnMouseEventsAddress ( wxMouseEvent & event )
{
{
event . Skip ( ) ;
if ( fOnSetFocusAddress )
if ( fOnSetFocusAddress )
m_textCtrlAddress - > SetSelection ( - 1 , - 1 ) ;
m_textCtrlAddress - > SetSelection ( - 1 , - 1 ) ;
fOnSetFocusAddress = false ;
fOnSetFocusAddress = false ;
event . Skip ( ) ;
}
}
void CMainFrame : : OnButtonChange ( wxCommandEvent & event )
void CMainFrame : : OnButtonNew ( wxCommandEvent & event )
{
{
CYourAddressDialog dialog ( this , string ( m_textCtrlAddress - > GetValue ( ) ) ) ;
// Ask name
CGetTextFromUserDialog dialog ( this ,
_ ( " New Receiving Address " ) ,
_ ( " It's good policy to use a new address for each payment you receive. \n \n Label " ) ,
" " ) ;
if ( ! dialog . ShowModal ( ) )
if ( ! dialog . ShowModal ( ) )
return ;
return ;
string strAddress = ( string ) dialog . GetAddress ( ) ;
string strName = dialog . GetValue ( ) ;
if ( strAddress ! = m_textCtrlAddress - > GetValue ( ) )
{
// Generate new key
uint160 hash160 ;
string strAddress = PubKeyToAddress ( GenerateNewKey ( ) ) ;
if ( ! AddressToHash160 ( strAddress , hash160 ) )
return ;
// Save
if ( ! mapPubKeys . count ( hash160 ) )
SetAddressBookName ( strAddress , strName ) ;
return ;
SetDefaultReceivingAddress ( strAddress ) ;
CWalletDB ( ) . WriteDefaultKey ( mapPubKeys [ hash160 ] ) ;
m_textCtrlAddress - > SetValue ( strAddress ) ;
}
}
}
void CMainFrame : : OnButtonCopy ( wxCommandEvent & event )
void CMainFrame : : OnButtonCopy ( wxCommandEvent & event )
@ -1139,7 +1170,6 @@ void CMainFrame::OnListItemActivated(wxListEvent& event)
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
//
// CTxDetailsDialog
// CTxDetailsDialog
@ -1452,6 +1482,7 @@ void COptionsDialog::OnListBox(wxCommandEvent& event)
void COptionsDialog : : OnKillFocusTransactionFee ( wxFocusEvent & event )
void COptionsDialog : : OnKillFocusTransactionFee ( wxFocusEvent & event )
{
{
event . Skip ( ) ;
int64 nTmp = nTransactionFee ;
int64 nTmp = nTransactionFee ;
ParseMoney ( m_textCtrlTransactionFee - > GetValue ( ) , nTmp ) ;
ParseMoney ( m_textCtrlTransactionFee - > GetValue ( ) , nTmp ) ;
m_textCtrlTransactionFee - > SetValue ( FormatMoney ( nTmp ) ) ;
m_textCtrlTransactionFee - > SetValue ( FormatMoney ( nTmp ) ) ;
@ -1485,6 +1516,7 @@ CAddress COptionsDialog::GetProxyAddr()
void COptionsDialog : : OnKillFocusProxy ( wxFocusEvent & event )
void COptionsDialog : : OnKillFocusProxy ( wxFocusEvent & event )
{
{
event . Skip ( ) ;
m_textCtrlProxyIP - > SetValue ( GetProxyAddr ( ) . ToStringIP ( ) ) ;
m_textCtrlProxyIP - > SetValue ( GetProxyAddr ( ) . ToStringIP ( ) ) ;
m_textCtrlProxyPort - > SetValue ( GetProxyAddr ( ) . ToStringPort ( ) ) ;
m_textCtrlProxyPort - > SetValue ( GetProxyAddr ( ) . ToStringPort ( ) ) ;
}
}
@ -1632,6 +1664,7 @@ CSendDialog::CSendDialog(wxWindow* parent, const wxString& strAddress) : CSendDi
void CSendDialog : : OnTextAddress ( wxCommandEvent & event )
void CSendDialog : : OnTextAddress ( wxCommandEvent & event )
{
{
// Check mark
// Check mark
event . Skip ( ) ;
bool fBitcoinAddress = IsValidBitcoinAddress ( m_textCtrlAddress - > GetValue ( ) ) ;
bool fBitcoinAddress = IsValidBitcoinAddress ( m_textCtrlAddress - > GetValue ( ) ) ;
m_bitmapCheckMark - > Show ( fBitcoinAddress ) ;
m_bitmapCheckMark - > Show ( fBitcoinAddress ) ;
@ -1660,6 +1693,7 @@ void CSendDialog::OnTextAddress(wxCommandEvent& event)
void CSendDialog : : OnKillFocusAmount ( wxFocusEvent & event )
void CSendDialog : : OnKillFocusAmount ( wxFocusEvent & event )
{
{
// Reformat the amount
// Reformat the amount
event . Skip ( ) ;
if ( m_textCtrlAmount - > GetValue ( ) . Trim ( ) . empty ( ) )
if ( m_textCtrlAmount - > GetValue ( ) . Trim ( ) . empty ( ) )
return ;
return ;
int64 nTmp ;
int64 nTmp ;
@ -1670,9 +1704,9 @@ void CSendDialog::OnKillFocusAmount(wxFocusEvent& event)
void CSendDialog : : OnButtonAddressBook ( wxCommandEvent & event )
void CSendDialog : : OnButtonAddressBook ( wxCommandEvent & event )
{
{
// Open address book
// Open address book
CAddressBookDialog dialog ( this , m_textCtrlAddress - > GetValue ( ) , true ) ;
CAddressBookDialog dialog ( this , m_textCtrlAddress - > GetValue ( ) , CAddressBookDialog : : SENDING , true ) ;
if ( dialog . ShowModal ( ) )
if ( dialog . ShowModal ( ) )
m_textCtrlAddress - > SetValue ( dialog . GetAddress ( ) ) ;
m_textCtrlAddress - > SetValue ( dialog . GetSelected Address ( ) ) ;
}
}
void CSendDialog : : OnButtonPaste ( wxCommandEvent & event )
void CSendDialog : : OnButtonPaste ( wxCommandEvent & event )
@ -1723,11 +1757,11 @@ void CSendDialog::OnButtonSend(wxCommandEvent& event)
CScript scriptPubKey ;
CScript scriptPubKey ;
scriptPubKey < < OP_DUP < < OP_HASH160 < < hash160 < < OP_EQUALVERIFY < < OP_CHECKSIG ;
scriptPubKey < < OP_DUP < < OP_HASH160 < < hash160 < < OP_EQUALVERIFY < < OP_CHECKSIG ;
string strError = SendMoney ( scriptPubKey , nValue , wtx ) ;
string strError = SendMoney ( scriptPubKey , nValue , wtx , true ) ;
if ( strError ! = " " )
if ( strError = = " " )
wxMessageBox ( strError + " " , _ ( " Sending... " ) ) ;
else
wxMessageBox ( _ ( " Payment sent " ) , _ ( " Sending... " ) ) ;
wxMessageBox ( _ ( " Payment sent " ) , _ ( " Sending... " ) ) ;
else if ( strError ! = " ABORTED " )
wxMessageBox ( strError + " " , _ ( " Sending... " ) ) ;
}
}
else
else
{
{
@ -1846,6 +1880,7 @@ void CSendingDialog::OnButtonCancel(wxCommandEvent& event)
void CSendingDialog : : OnPaint ( wxPaintEvent & event )
void CSendingDialog : : OnPaint ( wxPaintEvent & event )
{
{
event . Skip ( ) ;
if ( strlen ( pszStatus ) > 130 )
if ( strlen ( pszStatus ) > 130 )
m_textCtrlStatus - > SetValue ( string ( " \n " ) + pszStatus ) ;
m_textCtrlStatus - > SetValue ( string ( " \n " ) + pszStatus ) ;
else
else
@ -1869,7 +1904,6 @@ void CSendingDialog::OnPaint(wxPaintEvent& event)
Close ( ) ;
Close ( ) ;
wxMessageBox ( _ ( " Transfer cancelled " ) , _ ( " Sending... " ) , wxOK , this ) ;
wxMessageBox ( _ ( " Transfer cancelled " ) , _ ( " Sending... " ) , wxOK , this ) ;
}
}
event . Skip ( ) ;
}
}
@ -2016,6 +2050,13 @@ void CSendingDialog::OnReply2(CDataStream& vRecv)
return ;
return ;
}
}
// Transaction fee
if ( ! ThreadSafeAskFee ( nFeeRequired , _ ( " Sending... " ) , this ) )
{
Error ( _ ( " Transaction aborted " ) ) ;
return ;
}
// Make sure we're still connected
// Make sure we're still connected
CNode * pnode = ConnectNode ( addr , 2 * 60 * 60 ) ;
CNode * pnode = ConnectNode ( addr , 2 * 60 * 60 ) ;
if ( ! pnode )
if ( ! pnode )
@ -2040,20 +2081,15 @@ void CSendingDialog::OnReply2(CDataStream& vRecv)
return ;
return ;
// Commit
// Commit
if ( ! CommitTransactionSpent ( wtx , key ) )
if ( ! CommitTransaction ( wtx , key ) )
{
{
Error ( _ ( " Error finalizing payment " ) ) ;
Error ( _ ( " The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here. " ) ) ;
return ;
return ;
}
}
// Send payment tx to seller, with response going to OnReply3 via event handler
// Send payment tx to seller, with response going to OnReply3 via event handler
pnode - > PushRequest ( " submitorder " , wtx , SendingDialogOnReply3 , this ) ;
pnode - > PushRequest ( " submitorder " , wtx , SendingDialogOnReply3 , this ) ;
// Accept and broadcast transaction
if ( ! wtx . AcceptTransaction ( ) )
printf ( " ERROR: CSendingDialog : wtxNew.AcceptTransaction() %s failed \n " , wtx . GetHash ( ) . ToString ( ) . c_str ( ) ) ;
wtx . RelayWalletTransaction ( ) ;
Status ( _ ( " Waiting for confirmation... " ) ) ;
Status ( _ ( " Waiting for confirmation... " ) ) ;
MainFrameRepaint ( ) ;
MainFrameRepaint ( ) ;
}
}
@ -2097,37 +2133,54 @@ void CSendingDialog::OnReply3(CDataStream& vRecv)
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
//
// CYour AddressDialog
// CAddressBook Dialog
//
//
CYour AddressDialog : : CYour AddressDialog ( wxWindow * parent , const s tring& strInitSelected ) : CYour AddressDialogBase ( parent )
CAddressBook Dialog : : CAddressBook Dialog ( wxWindow * parent , const wxS tring& strInitSelected , int nPageIn , bool fDuringSendIn ) : CAddressBook DialogBase ( parent )
{
{
// Set initially selected page
wxNotebookEvent event ;
event . SetSelection ( nPageIn ) ;
OnNotebookPageChanged ( event ) ;
m_notebook - > ChangeSelection ( nPageIn ) ;
fDuringSend = fDuringSendIn ;
if ( ! fDuringSend )
m_buttonCancel - > Show ( false ) ;
// Set Icon
wxIcon iconAddressBook ;
iconAddressBook . CopyFromBitmap ( wxBitmap ( addressbook16_xpm ) ) ;
SetIcon ( iconAddressBook ) ;
// Init column headers
// Init column headers
m_listCtrl - > InsertColumn ( 0 , _ ( " Label " ) , wxLIST_FORMAT_LEFT , 200 ) ;
m_listCtrlSending - > InsertColumn ( 0 , _ ( " Name " ) , wxLIST_FORMAT_LEFT , 200 ) ;
m_listCtrl - > InsertColumn ( 1 , _ ( " Bitcoin Address " ) , wxLIST_FORMAT_LEFT , 350 ) ;
m_listCtrlSending - > InsertColumn ( 1 , _ ( " Address " ) , wxLIST_FORMAT_LEFT , 350 ) ;
m_listCtrl - > SetFocus ( ) ;
m_listCtrlSending - > SetFocus ( ) ;
m_listCtrlReceiving - > InsertColumn ( 0 , _ ( " Label " ) , wxLIST_FORMAT_LEFT , 200 ) ;
m_listCtrlReceiving - > InsertColumn ( 1 , _ ( " Bitcoin Address " ) , wxLIST_FORMAT_LEFT , 350 ) ;
m_listCtrlReceiving - > SetFocus ( ) ;
// Fill listctrl with address book data
// Fill listctrl with address book data
CRITICAL_BLOCK ( cs_mapKeys )
CRITICAL_BLOCK ( cs_mapKeys )
CRITICAL_BLOCK ( cs_mapAddressBook )
CRITICAL_BLOCK ( cs_mapAddressBook )
{
{
string strDefaultReceiving = ( string ) pframeMain - > m_textCtrlAddress - > GetValue ( ) ;
foreach ( const PAIRTYPE ( string , string ) & item , mapAddressBook )
foreach ( const PAIRTYPE ( string , string ) & item , mapAddressBook )
{
{
string strAddress = item . first ;
string strAddress = item . first ;
string strName = item . second ;
string strName = item . second ;
uint160 hash160 ;
uint160 hash160 ;
bool fMine = ( AddressToHash160 ( strAddress , hash160 ) & & mapPubKeys . count ( hash160 ) ) ;
bool fMine = ( AddressToHash160 ( strAddress , hash160 ) & & mapPubKeys . count ( hash160 ) ) ;
if ( fMine )
wxListCtrl * plistCtrl = fMine ? m_listCtrlReceiving : m_listCtrlSending ;
{
int nIndex = InsertLine ( plistCtrl , strName , strAddress ) ;
int nIndex = InsertLine ( m_listCtrl , strName , strAddress ) ;
if ( strAddress = = ( fMine ? strDefaultReceiving : strInitSelected ) )
if ( strAddress = = strInitSelected )
plistCtrl - > SetItemState ( nIndex , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED ) ;
m_listCtrl - > SetItemState ( nIndex , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED ) ;
}
}
}
}
}
}
}
wxString CYour AddressDialog : : GetAddress ( )
wxString CAddressBook Dialog : : GetSelected Address ( )
{
{
int nIndex = GetSelection ( m_listCtrl ) ;
int nIndex = GetSelection ( m_listCtrl ) ;
if ( nIndex = = - 1 )
if ( nIndex = = - 1 )
@ -2135,149 +2188,40 @@ wxString CYourAddressDialog::GetAddress()
return GetItemText ( m_listCtrl , nIndex , 1 ) ;
return GetItemText ( m_listCtrl , nIndex , 1 ) ;
}
}
void CYourAddressDialog : : OnListEndLabelEdit ( wxListEvent & event )
wxString CAddressBookDialog : : GetSelectedSendingAddress ( )
{
{
// Update address book with edited name
int nIndex = GetSelection ( m_listCtrlSending ) ;
if ( event . IsEditCancelled ( ) )
return ;
string strAddress = ( string ) GetItemText ( m_listCtrl , event . GetIndex ( ) , 1 ) ;
SetAddressBookName ( strAddress , string ( event . GetText ( ) ) ) ;
pframeMain - > RefreshListCtrl ( ) ;
}
void CYourAddressDialog : : OnListItemSelected ( wxListEvent & event )
{
}
void CYourAddressDialog : : OnListItemActivated ( wxListEvent & event )
{
// Doubleclick edits item
wxCommandEvent event2 ;
OnButtonRename ( event2 ) ;
}
void CYourAddressDialog : : OnButtonRename ( wxCommandEvent & event )
{
// Ask new name
int nIndex = GetSelection ( m_listCtrl ) ;
if ( nIndex = = - 1 )
if ( nIndex = = - 1 )
return ;
return " " ;
string strName = ( string ) m_listCtrl - > GetItemText ( nIndex ) ;
return GetItemText ( m_listCtrlSending , nIndex , 1 ) ;
string strAddress = ( string ) GetItemText ( m_listCtrl , nIndex , 1 ) ;
CGetTextFromUserDialog dialog ( this , _ ( " Edit Address Label " ) , _ ( " New Label " ) , strName ) ;
if ( ! dialog . ShowModal ( ) )
return ;
strName = dialog . GetValue ( ) ;
// Change name
SetAddressBookName ( strAddress , strName ) ;
m_listCtrl - > SetItemText ( nIndex , strName ) ;
pframeMain - > RefreshListCtrl ( ) ;
}
void CYourAddressDialog : : OnButtonNew ( wxCommandEvent & event )
{
// Ask name
CGetTextFromUserDialog dialog ( this , _ ( " New Bitcoin Address " ) , _ ( " Label " ) , " " ) ;
if ( ! dialog . ShowModal ( ) )
return ;
string strName = dialog . GetValue ( ) ;
// Generate new key
string strAddress = PubKeyToAddress ( GenerateNewKey ( ) ) ;
SetAddressBookName ( strAddress , strName ) ;
// Add to list and select it
int nIndex = InsertLine ( m_listCtrl , strName , strAddress ) ;
SetSelection ( m_listCtrl , nIndex ) ;
m_listCtrl - > SetFocus ( ) ;
}
void CYourAddressDialog : : OnButtonCopy ( wxCommandEvent & event )
{
// Copy address box to clipboard
if ( wxTheClipboard - > Open ( ) )
{
wxTheClipboard - > SetData ( new wxTextDataObject ( GetAddress ( ) ) ) ;
wxTheClipboard - > Close ( ) ;
}
}
void CYourAddressDialog : : OnButtonOK ( wxCommandEvent & event )
{
// OK
EndModal ( true ) ;
}
}
void CYourAddressDialog : : OnButtonCancel ( wxCommandEvent & event )
wxString CAddressBookDialog : : GetSelectedReceivingAddress ( )
{
{
// Cancel
int nIndex = GetSelection ( m_listCtrlReceiving ) ;
EndModal ( false ) ;
if ( nIndex = = - 1 )
return " " ;
return GetItemText ( m_listCtrlReceiving , nIndex , 1 ) ;
}
}
void CYour AddressDialog : : OnClose ( wxClose Event & event )
void CAddressBookDialog : : OnNotebookPageChanged ( wxNotebookEvent & event )
{
{
// Close
event . Skip ( ) ;
EndModal ( false ) ;
nPage = event . GetSelection ( ) ;
}
if ( nPage = = SENDING )
m_listCtrl = m_listCtrlSending ;
else if ( nPage = = RECEIVING )
m_listCtrl = m_listCtrlReceiving ;
m_buttonDelete - > Show ( nPage = = SENDING ) ;
m_buttonCopy - > Show ( nPage = = RECEIVING ) ;
this - > Layout ( ) ;
//////////////////////////////////////////////////////////////////////////////
//
// CAddressBookDialog
//
CAddressBookDialog : : CAddressBookDialog ( wxWindow * parent , const wxString & strInitSelected , bool fSendingIn ) : CAddressBookDialogBase ( parent )
{
fSending = fSendingIn ;
if ( ! fSending )
m_buttonCancel - > Show ( false ) ;
// Init column headers
m_listCtrl - > InsertColumn ( 0 , _ ( " Name " ) , wxLIST_FORMAT_LEFT , 200 ) ;
m_listCtrl - > InsertColumn ( 1 , _ ( " Address " ) , wxLIST_FORMAT_LEFT , 350 ) ;
m_listCtrl - > SetFocus ( ) ;
m_listCtrl - > SetFocus ( ) ;
// Set Icon
wxIcon iconAddressBook ;
iconAddressBook . CopyFromBitmap ( wxBitmap ( addressbook16_xpm ) ) ;
SetIcon ( iconAddressBook ) ;
// Fill listctrl with address book data
CRITICAL_BLOCK ( cs_mapKeys )
CRITICAL_BLOCK ( cs_mapAddressBook )
{
foreach ( const PAIRTYPE ( string , string ) & item , mapAddressBook )
{
string strAddress = item . first ;
string strName = item . second ;
uint160 hash160 ;
bool fMine = ( AddressToHash160 ( strAddress , hash160 ) & & mapPubKeys . count ( hash160 ) ) ;
if ( ! fMine )
{
int nIndex = InsertLine ( m_listCtrl , strName , strAddress ) ;
if ( strAddress = = strInitSelected )
m_listCtrl - > SetItemState ( nIndex , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED ) ;
}
}
}
}
wxString CAddressBookDialog : : GetAddress ( )
{
int nIndex = GetSelection ( m_listCtrl ) ;
if ( nIndex = = - 1 )
return " " ;
return GetItemText ( m_listCtrl , nIndex , 1 ) ;
}
}
void CAddressBookDialog : : OnListEndLabelEdit ( wxListEvent & event )
void CAddressBookDialog : : OnListEndLabelEdit ( wxListEvent & event )
{
{
// Update address book with edited name
// Update address book with edited name
event . Skip ( ) ;
if ( event . IsEditCancelled ( ) )
if ( event . IsEditCancelled ( ) )
return ;
return ;
string strAddress = ( string ) GetItemText ( m_listCtrl , event . GetIndex ( ) , 1 ) ;
string strAddress = ( string ) GetItemText ( m_listCtrl , event . GetIndex ( ) , 1 ) ;
@ -2287,21 +2231,50 @@ void CAddressBookDialog::OnListEndLabelEdit(wxListEvent& event)
void CAddressBookDialog : : OnListItemSelected ( wxListEvent & event )
void CAddressBookDialog : : OnListItemSelected ( wxListEvent & event )
{
{
event . Skip ( ) ;
if ( nPage = = RECEIVING )
SetDefaultReceivingAddress ( ( string ) GetSelectedReceivingAddress ( ) ) ;
}
}
void CAddressBookDialog : : OnListItemActivated ( wxListEvent & event )
void CAddressBookDialog : : OnListItemActivated ( wxListEvent & event )
{
{
if ( fSending )
event . Skip ( ) ;
if ( fDuringSend )
{
{
// Doubleclick returns selection
// Doubleclick returns selection
EndModal ( GetAddress ( ) ! = " " ? 2 : 0 ) ;
EndModal ( GetSelectedAddress ( ) ! = " " ? 2 : 0 ) ;
return ;
}
}
else
{
// Doubleclick edits item
// Doubleclick edits item
wxCommandEvent event2 ;
wxCommandEvent event2 ;
OnButtonEdit ( event2 ) ;
OnButtonEdit ( event2 ) ;
}
}
void CAddressBookDialog : : OnButtonDelete ( wxCommandEvent & event )
{
if ( nPage ! = SENDING )
return ;
for ( int nIndex = m_listCtrl - > GetItemCount ( ) - 1 ; nIndex > = 0 ; nIndex - - )
{
if ( m_listCtrl - > GetItemState ( nIndex , wxLIST_STATE_SELECTED ) )
{
string strAddress = ( string ) GetItemText ( m_listCtrl , nIndex , 1 ) ;
CWalletDB ( ) . EraseName ( strAddress ) ;
m_listCtrl - > DeleteItem ( nIndex ) ;
}
}
pframeMain - > RefreshListCtrl ( ) ;
}
void CAddressBookDialog : : OnButtonCopy ( wxCommandEvent & event )
{
// Copy address box to clipboard
if ( wxTheClipboard - > Open ( ) )
{
wxTheClipboard - > SetData ( new wxTextDataObject ( GetSelectedAddress ( ) ) ) ;
wxTheClipboard - > Close ( ) ;
}
}
}
bool CAddressBookDialog : : CheckIfMine ( const string & strAddress , const string & strTitle )
bool CAddressBookDialog : : CheckIfMine ( const string & strAddress , const string & strTitle )
@ -2315,13 +2288,16 @@ bool CAddressBookDialog::CheckIfMine(const string& strAddress, const string& str
void CAddressBookDialog : : OnButtonEdit ( wxCommandEvent & event )
void CAddressBookDialog : : OnButtonEdit ( wxCommandEvent & event )
{
{
// Ask new name
int nIndex = GetSelection ( m_listCtrl ) ;
int nIndex = GetSelection ( m_listCtrl ) ;
if ( nIndex = = - 1 )
if ( nIndex = = - 1 )
return ;
return ;
string strName = ( string ) m_listCtrl - > GetItemText ( nIndex ) ;
string strName = ( string ) m_listCtrl - > GetItemText ( nIndex ) ;
string strAddress = ( string ) GetItemText ( m_listCtrl , nIndex , 1 ) ;
string strAddress = ( string ) GetItemText ( m_listCtrl , nIndex , 1 ) ;
string strAddressOrg = strAddress ;
string strAddressOrg = strAddress ;
if ( nPage = = SENDING )
{
// Ask name and address
do
do
{
{
CGetTextFromUserDialog dialog ( this , _ ( " Edit Address " ) , _ ( " Name " ) , strName , _ ( " Address " ) , strAddress ) ;
CGetTextFromUserDialog dialog ( this , _ ( " Edit Address " ) , _ ( " Name " ) , strName , _ ( " Address " ) , strAddress ) ;
@ -2332,7 +2308,17 @@ void CAddressBookDialog::OnButtonEdit(wxCommandEvent& event)
}
}
while ( CheckIfMine ( strAddress , _ ( " Edit Address " ) ) ) ;
while ( CheckIfMine ( strAddress , _ ( " Edit Address " ) ) ) ;
// Change name
}
else if ( nPage = = RECEIVING )
{
// Ask name
CGetTextFromUserDialog dialog ( this , _ ( " Edit Address Label " ) , _ ( " Label " ) , strName ) ;
if ( ! dialog . ShowModal ( ) )
return ;
strName = dialog . GetValue ( ) ;
}
// Write back
if ( strAddress ! = strAddressOrg )
if ( strAddress ! = strAddressOrg )
CWalletDB ( ) . EraseName ( strAddressOrg ) ;
CWalletDB ( ) . EraseName ( strAddressOrg ) ;
SetAddressBookName ( strAddress , strName ) ;
SetAddressBookName ( strAddress , strName ) ;
@ -2343,55 +2329,50 @@ void CAddressBookDialog::OnButtonEdit(wxCommandEvent& event)
void CAddressBookDialog : : OnButtonNew ( wxCommandEvent & event )
void CAddressBookDialog : : OnButtonNew ( wxCommandEvent & event )
{
{
// Ask name
string strName ;
string strName ;
string strAddress ;
string strAddress ;
if ( nPage = = SENDING )
{
// Ask name and address
do
do
{
{
CGetTextFromUserDialog dialog ( this , _ ( " New Address " ) , _ ( " Name " ) , strName , _ ( " Address " ) , strAddress ) ;
CGetTextFromUserDialog dialog ( this , _ ( " Add Address" ) , _ ( " Name " ) , strName , _ ( " Address " ) , strAddress ) ;
if ( ! dialog . ShowModal ( ) )
if ( ! dialog . ShowModal ( ) )
return ;
return ;
strName = dialog . GetValue1 ( ) ;
strName = dialog . GetValue1 ( ) ;
strAddress = dialog . GetValue2 ( ) ;
strAddress = dialog . GetValue2 ( ) ;
}
}
while ( CheckIfMine ( strAddress , _ ( " New Address " ) ) ) ;
while ( CheckIfMine ( strAddress , _ ( " Add Address " ) ) ) ;
}
else if ( nPage = = RECEIVING )
{
// Ask name
CGetTextFromUserDialog dialog ( this ,
_ ( " New Receiving Address " ) ,
_ ( " It's good policy to use a new address for each payment you receive. \n \n Label " ) ,
" " ) ;
if ( ! dialog . ShowModal ( ) )
return ;
strName = dialog . GetValue ( ) ;
// Generate new key
strAddress = PubKeyToAddress ( GenerateNewKey ( ) ) ;
}
// Add to list and select it
// Add to list and select it
SetAddressBookName ( strAddress , strName ) ;
SetAddressBookName ( strAddress , strName ) ;
int nIndex = InsertLine ( m_listCtrl , strName , strAddress ) ;
int nIndex = InsertLine ( m_listCtrl , strName , strAddress ) ;
SetSelection ( m_listCtrl , nIndex ) ;
SetSelection ( m_listCtrl , nIndex ) ;
m_listCtrl - > SetFocus ( ) ;
m_listCtrl - > SetFocus ( ) ;
if ( nPage = = SENDING )
pframeMain - > RefreshListCtrl ( ) ;
pframeMain - > RefreshListCtrl ( ) ;
}
}
void CAddressBookDialog : : OnButtonDelete ( wxCommandEvent & event )
{
for ( int nIndex = m_listCtrl - > GetItemCount ( ) - 1 ; nIndex > = 0 ; nIndex - - )
{
if ( m_listCtrl - > GetItemState ( nIndex , wxLIST_STATE_SELECTED ) )
{
string strAddress = ( string ) GetItemText ( m_listCtrl , nIndex , 1 ) ;
CWalletDB ( ) . EraseName ( strAddress ) ;
m_listCtrl - > DeleteItem ( nIndex ) ;
}
}
pframeMain - > RefreshListCtrl ( ) ;
}
void CAddressBookDialog : : OnButtonCopy ( wxCommandEvent & event )
{
// Copy address box to clipboard
if ( wxTheClipboard - > Open ( ) )
{
wxTheClipboard - > SetData ( new wxTextDataObject ( GetAddress ( ) ) ) ;
wxTheClipboard - > Close ( ) ;
}
}
void CAddressBookDialog : : OnButtonOK ( wxCommandEvent & event )
void CAddressBookDialog : : OnButtonOK ( wxCommandEvent & event )
{
{
// OK
// OK
EndModal ( GetAddress ( ) ! = " " ? 1 : 0 ) ;
EndModal ( GetSelectedAddress ( ) ! = " " ? 1 : 0 ) ;
}
}
void CAddressBookDialog : : OnButtonCancel ( wxCommandEvent & event )
void CAddressBookDialog : : OnButtonCancel ( wxCommandEvent & event )
@ -2947,7 +2928,6 @@ bool CMyApp::OnExceptionInMainLoop()
Sleep ( 1000 ) ;
Sleep ( 1000 ) ;
throw ;
throw ;
}
}
return true ;
return true ;
}
}