fix display of new generated coins, fix assertion in bitcoinminer
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Sun, 25 Oct 2009 04:35:01 +0000 (04:35 +0000)
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Sun, 25 Oct 2009 04:35:01 +0000 (04:35 +0000)
main.cpp
serialize.h
ui.cpp
ui.h

index de5a593..dbdee70 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1129,9 +1129,6 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos)
             }\r
         }\r
 \r
-        // Notify UI to update prev block coinbase if it was ours\r
-        vWalletUpdated.push_back(hashBestChain);\r
-\r
         // New best link\r
         hashBestChain = hash;\r
         pindexBest = pindexNew;\r
@@ -1143,10 +1140,18 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos)
     txdb.TxnCommit();\r
     txdb.Close();\r
 \r
-    // Relay wallet transactions that haven't gotten in yet\r
     if (pindexNew == pindexBest)\r
+    {\r
+        // Relay wallet transactions that haven't gotten in yet\r
         RelayWalletTransactions();\r
 \r
+        // Notify UI to display prev block's coinbase if it was ours\r
+        static uint256 hashPrevBestCoinBase;\r
+        CRITICAL_BLOCK(cs_mapWallet)\r
+            vWalletUpdated.push_back(hashPrevBestCoinBase);\r
+        hashPrevBestCoinBase = vtx[0].GetHash();\r
+    }\r
+\r
     MainFrameRepaint();\r
     return true;\r
 }\r
@@ -2074,13 +2079,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
     else\r
     {\r
         // Ignore unknown commands for extensibility\r
-        printf("ProcessMessage(%s) : Ignored unknown message\n", strCommand.c_str());\r
     }\r
 \r
-\r
-    if (!vRecv.empty())\r
-        printf("ProcessMessage(%s) : %d extra bytes\n", strCommand.c_str(), vRecv.size());\r
-\r
     return true;\r
 }\r
 \r
@@ -2349,7 +2349,7 @@ bool BitcoinMiner()
         }\r
         pblock->nBits = nBits;\r
         pblock->vtx[0].vout[0].nValue = pblock->GetBlockValue(nFees);\r
-        printf("\n\nRunning BitcoinMiner with %d transactions in block\n", pblock->vtx.size());\r
+        printf("Running BitcoinMiner with %d transactions in block\n", pblock->vtx.size());\r
 \r
 \r
         //\r
@@ -2408,20 +2408,17 @@ bool BitcoinMiner()
                 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);\r
                 CRITICAL_BLOCK(cs_main)\r
                 {\r
-                    if (pindexPrev != pindexBest)\r
+                    if (pindexPrev == pindexBest)\r
                     {\r
-                        SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);\r
-                        break;\r
+                        // Save key\r
+                        if (!AddKey(key))\r
+                            return false;\r
+                        key.MakeNewKey();\r
+\r
+                        // Process this block the same as if we had received it from another node\r
+                        if (!ProcessBlock(NULL, pblock.release()))\r
+                            printf("ERROR in BitcoinMiner, ProcessBlock, block not accepted\n");\r
                     }\r
-\r
-                    // Save key\r
-                    if (!AddKey(key))\r
-                        return false;\r
-                    key.MakeNewKey();\r
-\r
-                    // Process this block the same as if we had received it from another node\r
-                    if (!ProcessBlock(NULL, pblock.release()))\r
-                        printf("ERROR in BitcoinMiner, ProcessBlock, block not accepted\n");\r
                 }\r
                 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);\r
 \r
@@ -2439,8 +2436,10 @@ bool BitcoinMiner()
                     break;\r
                 if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)\r
                     break;\r
-                if (!fGenerateBitcoins)\r
+                if (vNodes.empty())\r
                     break;\r
+                if (!fGenerateBitcoins)\r
+                    return true;\r
                 if (fLimitProcessors && vnThreadsRunning[3] > nLimitProcessors)\r
                     return true;\r
                 tmp.block.nTime = pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());\r
index 9b20e2a..b7ab86d 100644 (file)
@@ -19,7 +19,7 @@ class CScript;
 class CDataStream;\r
 class CAutoFile;\r
 \r
-static const int VERSION = 106;\r
+static const int VERSION = 105;\r
 \r
 \r
 \r
diff --git a/ui.cpp b/ui.cpp
index ce43a78..4283047 100644 (file)
--- a/ui.cpp
+++ b/ui.cpp
@@ -306,6 +306,8 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
 \r
     // Init column headers\r
     int nDateWidth = DateTimeStr(1229413914).size() * 6 + 8;\r
+    if (!strstr(DateTimeStr(1229413914).c_str(), "2008"))\r
+        nDateWidth += 12;\r
     m_listCtrl->InsertColumn(0, "",             wxLIST_FORMAT_LEFT,     0);\r
     m_listCtrl->InsertColumn(1, "",             wxLIST_FORMAT_LEFT,     0);\r
     m_listCtrl->InsertColumn(2, "Status",       wxLIST_FORMAT_LEFT,    90);\r
@@ -441,12 +443,33 @@ void CMainFrame::InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSo
     m_listCtrl->SetItemData(nIndex, nData);\r
 }\r
 \r
+bool CMainFrame::DeleteLine(uint256 hashKey)\r
+{\r
+    long nData = *(long*)&hashKey;\r
+\r
+    // Find item\r
+    int nIndex = -1;\r
+    while ((nIndex = m_listCtrl->FindItem(nIndex, nData)) != -1)\r
+        if (GetItemText(m_listCtrl, nIndex, 1) == hashKey.ToString())\r
+            break;\r
+\r
+    if (nIndex != -1)\r
+        m_listCtrl->DeleteItem(nIndex);\r
+\r
+    return nIndex != -1;\r
+}\r
+\r
 string FormatTxStatus(const CWalletTx& wtx)\r
 {\r
     // Status\r
     int nDepth = wtx.GetDepthInMainChain();\r
     if (!wtx.IsFinal())\r
-        return strprintf("Open for %d blocks", nBestHeight - wtx.nLockTime);\r
+    {\r
+        if (wtx.nLockTime < 500000000)\r
+            return strprintf("Open for %d blocks", nBestHeight - wtx.nLockTime);\r
+        else\r
+            return strprintf("Open until %s", DateTimeStr(wtx.nLockTime).c_str());\r
+    }\r
     else if (nDepth < 6)\r
         return strprintf("%d/unconfirmed", nDepth);\r
     else\r
@@ -503,7 +526,11 @@ void CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
         // are special because if their block is not accepted, they are not valid.\r
         //\r
         if (wtx.GetDepthInMainChain() < 2)\r
+        {\r
+            // In case it was previously displayed\r
+            DeleteLine(hash);\r
             return;\r
+        }\r
     }\r
 \r
     // Find the block the tx is in\r
@@ -800,6 +827,17 @@ void CMainFrame::OnPaint(wxPaintEvent& event)
     event.Skip();\r
 }\r
 \r
+void DelayedRepaint(void* parg)\r
+{\r
+    static bool fOneThread;\r
+    if (fOneThread)\r
+        return;\r
+    fOneThread = true;\r
+    Sleep(1000);\r
+    MainFrameRepaint();\r
+    fOneThread = false;\r
+}\r
+\r
 void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)\r
 {\r
     // Update listctrl contents\r
@@ -824,7 +862,7 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
     // Update status bar\r
     string strGen = "";\r
     if (fGenerateBitcoins)\r
-        strGen = "     Generating";\r
+        strGen = "    Generating";\r
     if (fGenerateBitcoins && vNodes.empty())\r
         strGen = "(not connected)";\r
     m_statusBar->SetStatusText(strGen, 1);\r
@@ -833,8 +871,16 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
     m_statusBar->SetStatusText(strStatus, 2);\r
 \r
     // Balance total\r
+    bool fRefreshed = false;\r
     TRY_CRITICAL_BLOCK(cs_mapWallet)\r
+    {\r
         m_staticTextBalance->SetLabel(FormatMoney(GetBalance()) + "  ");\r
+        fRefreshed = true;\r
+    }\r
+\r
+    // mapWallet was locked, try again later\r
+    if (!vWalletUpdated.empty() || !fRefreshed)\r
+        _beginthread(DelayedRepaint, 0, NULL);\r
 \r
     m_listCtrl->OnPaint(event);\r
 }\r
@@ -1414,7 +1460,7 @@ void COptionsDialog::OnButtonApply(wxCommandEvent& event)
 \r
 CAboutDialog::CAboutDialog(wxWindow* parent) : CAboutDialogBase(parent)\r
 {\r
-    m_staticTextVersion->SetLabel(strprintf("version 0.%d.%d Alpha", VERSION/100, VERSION%100));\r
+    m_staticTextVersion->SetLabel(strprintf("version 0.%d.%d Beta", VERSION/100, VERSION%100));\r
 \r
     // Workaround until upgrade to wxWidgets supporting UTF-8\r
     wxString str = m_staticTextMain->GetLabel();\r
@@ -3358,6 +3404,8 @@ bool CMyApp::OnInit2()
         return false;\r
     }\r
 \r
+    //RandAddSeedPerfmon();\r
+\r
     if (!StartNode(strErrors))\r
         wxMessageBox(strErrors, "Bitcoin");\r
 \r
@@ -3517,7 +3565,6 @@ void SetStartOnSystemStartup(bool fAutoStart)
             // Get the current executable path\r
             char pszExePath[MAX_PATH];\r
             GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));\r
-            _strlwr(pszExePath);\r
 \r
             // Set the path to the shortcut target\r
             psl->SetPath(pszExePath);\r
diff --git a/ui.h b/ui.h
index f89456b..f451d93 100644 (file)
--- a/ui.h
+++ b/ui.h
@@ -88,6 +88,7 @@ public:
 \r
     void OnCrossThreadCall(wxCommandEvent& event);\r
     void InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxString& str1, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5);\r
+    bool DeleteLine(uint256 hashKey);\r
     void InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);\r
     void RefreshListCtrl();\r
     void RefreshStatus();\r