]> Git Repo - VerusCoin.git/blobdiff - ui.cpp
JSON methods: listtransactions, gettransaction, move, sendfrom and getbalance <account>
[VerusCoin.git] / ui.cpp
diff --git a/ui.cpp b/ui.cpp
index 179b22d6b4602c2b7188c5a6df544020eb8c08c7..213cf7666d1c3e5e7c011d78597a238030c23cd2 100644 (file)
--- a/ui.cpp
+++ b/ui.cpp
@@ -103,6 +103,18 @@ int InsertLine(wxListCtrl* listCtrl, void* pdata, const wxString& str0, const wx
     return nIndex;
 }
 
+void SetItemTextColour(wxListCtrl* listCtrl, int nIndex, const wxColour& colour)
+{
+    // Repaint on Windows is more flickery if the colour has ever been set,
+    // so don't want to set it unless it's different.  Default colour has
+    // alpha 0 transparent, so our colours don't match using operator==.
+    wxColour c1 = listCtrl->GetItemTextColour(nIndex);
+    if (!c1.IsOk())
+        c1 = wxColour(0,0,0);
+    if (colour.Red() != c1.Red() || colour.Green() != c1.Green() || colour.Blue() != c1.Blue())
+        listCtrl->SetItemTextColour(nIndex, colour);
+}
+
 void SetSelection(wxListCtrl* listCtrl, int nIndex)
 {
     int nSize = listCtrl->GetItemCount();
@@ -184,7 +196,7 @@ int ThreadSafeMessageBox(const string& message, const string& caption, int style
 
 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)
 {
-    if (nFeeRequired == 0 || fDaemon)
+    if (nFeeRequired < CENT || nFeeRequired <= nTransactionFee || fDaemon)
         return true;
     string strMessage = strprintf(
         _("This transaction is over the size limit.  You can still send it for a fee of %s, "
@@ -434,7 +446,7 @@ int CMainFrame::GetSortIndex(const string& strSort)
 #endif
 }
 
-void CMainFrame::InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5, const wxString& str6)
+void CMainFrame::InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxColour& colour, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5, const wxString& str6)
 {
     strSort = " " + strSort;       // leading space to workaround wx2.9.0 ubuntu 9.10 bug
     long nData = *(long*)&hashKey; //  where first char of hidden column is displayed
@@ -470,6 +482,7 @@ void CMainFrame::InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSo
     m_listCtrl->SetItem(nIndex, 5, str5);
     m_listCtrl->SetItem(nIndex, 6, str6);
     m_listCtrl->SetItemData(nIndex, nData);
+    SetItemTextColour(m_listCtrl, nIndex, colour);
 }
 
 bool CMainFrame::DeleteLine(uint256 hashKey)
@@ -540,6 +553,8 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
     int64 nNet = nCredit - nDebit;
     uint256 hash = wtx.GetHash();
     string strStatus = FormatTxStatus(wtx);
+    bool fConfirmed = wtx.fConfirmedDisplayed = wtx.IsConfirmed();
+    wxColour colour = (fConfirmed ? wxColour(0,0,0) : wxColour(128,128,128));
     map<string, string> mapValue = wtx.mapValue;
     wtx.nLinesDisplayed = 1;
     nListViewUpdated++;
@@ -658,12 +673,16 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
             }
         }
 
-        InsertLine(fNew, nIndex, hash, strSort,
+        string strCredit = FormatMoney(nNet, true);
+        if (!fConfirmed)
+            strCredit = "[" + strCredit + "]";
+
+        InsertLine(fNew, nIndex, hash, strSort, colour,
                    strStatus,
                    nTime ? DateTimeStr(nTime) : "",
                    SingleLine(strDescription),
                    "",
-                   FormatMoney(nNet, true));
+                   strCredit);
     }
     else
     {
@@ -678,16 +697,13 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
         if (fAllFromMe && fAllToMe)
         {
             // Payment to self
-            int64 nValue = wtx.vout[0].nValue;
-            InsertLine(fNew, nIndex, hash, strSort,
+            int64 nChange = wtx.GetChange();
+            InsertLine(fNew, nIndex, hash, strSort, colour,
                        strStatus,
                        nTime ? DateTimeStr(nTime) : "",
                        _("Payment to yourself"),
-                       "",
-                       "");
-            /// issue: can't tell which is the payment and which is the change anymore
-            //           FormatMoney(nNet - nValue, true),
-            //           FormatMoney(nValue, true));
+                       FormatMoney(-(nDebit - nChange), true),
+                       FormatMoney(nCredit - nChange, true));
         }
         else if (fAllFromMe)
         {
@@ -738,12 +754,13 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
                     nTxFee = 0;
                 }
 
-                InsertLine(fNew, nIndex, hash, strprintf("%s-%d", strSort.c_str(), nOut),
+                InsertLine(fNew, nIndex, hash, strprintf("%s-%d", strSort.c_str(), nOut), colour,
                            strStatus,
                            nTime ? DateTimeStr(nTime) : "",
                            SingleLine(strDescription),
                            FormatMoney(-nValue, true),
                            "");
+                nIndex = -1;
                 wtx.nLinesDisplayed++;
             }
         }
@@ -758,7 +775,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
             foreach(const CTxIn& txin, wtx.vin)
                 fAllMine = fAllMine && txin.IsMine();
 
-            InsertLine(fNew, nIndex, hash, strSort,
+            InsertLine(fNew, nIndex, hash, strSort, colour,
                        strStatus,
                        nTime ? DateTimeStr(nTime) : "",
                        "",
@@ -885,13 +902,17 @@ void CMainFrame::RefreshStatusColumn()
                 continue;
             }
             CWalletTx& wtx = (*mi).second;
-            if (wtx.IsCoinBase() || wtx.GetTxTime() != wtx.nTimeDisplayed)
+            if (wtx.IsCoinBase() ||
+                wtx.GetTxTime() != wtx.nTimeDisplayed ||
+                wtx.IsConfirmed() != wtx.fConfirmedDisplayed)
             {
                 if (!InsertTransaction(wtx, false, nIndex))
                     m_listCtrl->DeleteItem(nIndex--);
             }
             else
+            {
                 m_listCtrl->SetItem(nIndex, 2, FormatTxStatus(wtx));
+            }
         }
     }
 }
@@ -1031,9 +1052,6 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
     string strStatus = strprintf(_("     %d connections     %d blocks     %d transactions"), vNodes.size(), nBestHeight, nTransactionCount);
     m_statusBar->SetStatusText(strStatus, 2);
 
-    if (fDebug && GetTime() - nThreadSocketHandlerHeartbeat > 60)
-        m_statusBar->SetStatusText("     ERROR: ThreadSocketHandler has stopped", 0);
-
     // Update receiving address
     string strDefaultAddress = PubKeyToAddress(vchDefaultKey);
     if (m_textCtrlAddress->GetValue() != strDefaultAddress)
@@ -1150,7 +1168,7 @@ void CMainFrame::OnButtonNew(wxCommandEvent& event)
     string strName = dialog.GetValue();
 
     // Generate new key
-    string strAddress = PubKeyToAddress(GenerateNewKey());
+    string strAddress = PubKeyToAddress(GetKeyFromKeyPool());
 
     // Save
     SetAddressBookName(strAddress, strName);
@@ -1355,10 +1373,10 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
                 if (fAllToMe)
                 {
                     // Payment to self
-                    /// issue: can't tell which is the payment and which is the change anymore
-                    //int64 nValue = wtx.vout[0].nValue;
-                    //strHTML += _("<b>Debit:</b> ") + FormatMoney(-nValue) + "<br>";
-                    //strHTML += _("<b>Credit:</b> ") + FormatMoney(nValue) + "<br>";
+                    int64 nChange = wtx.GetChange();
+                    int64 nValue = nCredit - nChange;
+                    strHTML += _("<b>Debit:</b> ") + FormatMoney(-nValue) + "<br>";
+                    strHTML += _("<b>Credit:</b> ") + FormatMoney(nValue) + "<br>";
                 }
 
                 int64 nTxFee = nDebit - wtx.GetValueOut();
@@ -1405,7 +1423,10 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
                 if (txout.IsMine())
                     strHTML += "<b>Credit:</b> " + FormatMoney(txout.GetCredit()) + "<br>";
 
-            strHTML += "<b>Inputs:</b><br>";
+            strHTML += "<br><b>Transaction:</b><br>";
+            strHTML += HtmlEscape(wtx.ToString(), true);
+
+            strHTML += "<br><b>Inputs:</b><br>";
             CRITICAL_BLOCK(cs_mapWallet)
             {
                 foreach(const CTxIn& txin, wtx.vin)
@@ -1424,9 +1445,6 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
                     }
                 }
             }
-
-            strHTML += "<br><hr><br><b>Transaction:</b><br>";
-            strHTML += HtmlEscape(wtx.ToString(), true);
         }
 
 
@@ -1610,6 +1628,9 @@ COptionsDialog::COptionsDialog(wxWindow* parent) : COptionsDialogBase(parent)
     //m_listBox->Append(_("Test 2"));
     m_listBox->SetSelection(0);
     SelectPage(0);
+#ifndef __WXMSW__
+    SetSize(1.0 * GetSize().GetWidth(), 1.2 * GetSize().GetHeight());
+#endif
 #if defined(__WXGTK__) || defined(__WXMAC_OSX__)
     m_checkBoxStartOnSystemStartup->SetLabel(_("&Start Bitcoin on window system startup"));
     if (!mapArgs.count("-minimizetotray"))
@@ -1775,7 +1796,7 @@ void COptionsDialog::OnButtonApply(wxCommandEvent& event)
 
 CAboutDialog::CAboutDialog(wxWindow* parent) : CAboutDialogBase(parent)
 {
-    m_staticTextVersion->SetLabel(strprintf(_("version %d.%d.%d%s beta"), VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer));
+    m_staticTextVersion->SetLabel(strprintf(_("version %s%s beta"), FormatVersion(VERSION).c_str(), pszSubVer));
 
     // Change (c) into UTF-8 or ANSI copyright symbol
     wxString str = m_staticTextMain->GetLabel();
@@ -1908,69 +1929,78 @@ void CSendDialog::OnButtonPaste(wxCommandEvent& event)
 
 void CSendDialog::OnButtonSend(wxCommandEvent& event)
 {
-    CWalletTx wtx;
-    string strAddress = (string)m_textCtrlAddress->GetValue();
-
-    // Parse amount
-    int64 nValue = 0;
-    if (!ParseMoney(m_textCtrlAmount->GetValue(), nValue) || nValue <= 0)
-    {
-        wxMessageBox(_("Error in amount  "), _("Send Coins"));
-        return;
-    }
-    if (nValue > GetBalance())
-    {
-        wxMessageBox(_("Amount exceeds your balance  "), _("Send Coins"));
-        return;
-    }
-    if (nValue + nTransactionFee > GetBalance())
+    static CCriticalSection cs_sendlock;
+    TRY_CRITICAL_BLOCK(cs_sendlock)
     {
-        wxMessageBox(string(_("Total exceeds your balance when the ")) + FormatMoney(nTransactionFee) + _(" transaction fee is included  "), _("Send Coins"));
-        return;
-    }
+        CWalletTx wtx;
+        string strAddress = (string)m_textCtrlAddress->GetValue();
 
-    // Parse bitcoin address
-    uint160 hash160;
-    bool fBitcoinAddress = AddressToHash160(strAddress, hash160);
+        // Parse amount
+        int64 nValue = 0;
+        if (!ParseMoney(m_textCtrlAmount->GetValue(), nValue) || nValue <= 0)
+        {
+            wxMessageBox(_("Error in amount  "), _("Send Coins"));
+            return;
+        }
+        if (nValue > GetBalance())
+        {
+            wxMessageBox(_("Amount exceeds your balance  "), _("Send Coins"));
+            return;
+        }
+        if (nValue + nTransactionFee > GetBalance())
+        {
+            wxMessageBox(string(_("Total exceeds your balance when the ")) + FormatMoney(nTransactionFee) + _(" transaction fee is included  "), _("Send Coins"));
+            return;
+        }
 
-    if (fBitcoinAddress)
-    {
-        // Send to bitcoin address
-        CScript scriptPubKey;
-        scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
+        // Parse bitcoin address
+        uint160 hash160;
+        bool fBitcoinAddress = AddressToHash160(strAddress, hash160);
 
-        string strError = SendMoney(scriptPubKey, nValue, wtx, true);
-        if (strError == "")
-            wxMessageBox(_("Payment sent  "), _("Sending..."));
-        else if (strError != "ABORTED")
-            wxMessageBox(strError + "  ", _("Sending..."));
-    }
-    else
-    {
-        // Parse IP address
-        CAddress addr(strAddress);
-        if (!addr.IsValid())
+        if (fBitcoinAddress)
         {
-            wxMessageBox(_("Invalid address  "), _("Send Coins"));
-            return;
+            // Send to bitcoin address
+            CScript scriptPubKey;
+            scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
+
+            string strError = SendMoney(scriptPubKey, nValue, wtx, true);
+            if (strError == "")
+                wxMessageBox(_("Payment sent  "), _("Sending..."));
+            else if (strError == "ABORTED")
+                return; // leave send dialog open
+            else
+            {
+                wxMessageBox(strError + "  ", _("Sending..."));
+                EndModal(false);
+            }
         }
+        else
+        {
+            // Parse IP address
+            CAddress addr(strAddress);
+            if (!addr.IsValid())
+            {
+                wxMessageBox(_("Invalid address  "), _("Send Coins"));
+                return;
+            }
 
-        // Message
-        wtx.mapValue["to"] = strAddress;
-        wtx.mapValue["from"] = m_textCtrlFrom->GetValue();
-        wtx.mapValue["message"] = m_textCtrlMessage->GetValue();
+            // Message
+            wtx.mapValue["to"] = strAddress;
+            wtx.mapValue["from"] = m_textCtrlFrom->GetValue();
+            wtx.mapValue["message"] = m_textCtrlMessage->GetValue();
 
-        // Send to IP address
-        CSendingDialog* pdialog = new CSendingDialog(this, addr, nValue, wtx);
-        if (!pdialog->ShowModal())
-            return;
-    }
+            // Send to IP address
+            CSendingDialog* pdialog = new CSendingDialog(this, addr, nValue, wtx);
+            if (!pdialog->ShowModal())
+                return;
+        }
 
-    CRITICAL_BLOCK(cs_mapAddressBook)
-        if (!mapAddressBook.count(strAddress))
-            SetAddressBookName(strAddress, "");
+        CRITICAL_BLOCK(cs_mapAddressBook)
+            if (!mapAddressBook.count(strAddress))
+                SetAddressBookName(strAddress, "");
 
-    EndModal(true);
+        EndModal(true);
+    }
 }
 
 void CSendDialog::OnButtonCancel(wxCommandEvent& event)
@@ -2189,8 +2219,12 @@ void CSendingDialog::OnReply2(CDataStream& vRecv)
         if (nRet > 0)
         {
             string strMessage;
-            vRecv >> strMessage;
-            Error(_("Transfer was not accepted"));
+            if (!vRecv.empty())
+                vRecv >> strMessage;
+            if (nRet == 2)
+                Error(_("Recipient is not accepting transactions sent by IP address"));
+            else
+                Error(_("Transfer was not accepted"));
             //// todo: enlarge the window and enable a hidden white box to put seller's message
             return;
         }
@@ -2221,9 +2255,9 @@ void CSendingDialog::OnReply2(CDataStream& vRecv)
             Error(_("Insufficient funds"));
             return;
         }
-        CKey key;
+        CReserveKey reservekey;
         int64 nFeeRequired;
-        if (!CreateTransaction(scriptPubKey, nPrice, wtx, key, nFeeRequired))
+        if (!CreateTransaction(scriptPubKey, nPrice, wtx, reservekey, nFeeRequired))
         {
             if (nPrice + nFeeRequired > GetBalance())
                 Error(strprintf(_("This is an oversized transaction that requires a transaction fee of %s"), FormatMoney(nFeeRequired).c_str()));
@@ -2263,7 +2297,7 @@ void CSendingDialog::OnReply2(CDataStream& vRecv)
             return;
 
         // Commit
-        if (!CommitTransaction(wtx, key))
+        if (!CommitTransaction(wtx, reservekey))
         {
             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;
@@ -2541,7 +2575,7 @@ void CAddressBookDialog::OnButtonNew(wxCommandEvent& event)
         strName = dialog.GetValue();
 
         // Generate new key
-        strAddress = PubKeyToAddress(GenerateNewKey());
+        strAddress = PubKeyToAddress(GetKeyFromKeyPool());
     }
 
     // Add to list and select it
This page took 0.039315 seconds and 4 git commands to generate.