From 240f3fbe2faca50a99e171afade28104cd7b0e30 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Wed, 19 May 2010 00:26:56 +0000 Subject: [PATCH] Mac OS build fixes by laszlo -- version 0.2.8 --- init.cpp | 8 +++++++- main.cpp | 6 +++--- net.cpp | 4 +--- net.h | 43 +++++++++++++++++++++++++++---------------- rpc.cpp | 23 ++++++++++++++--------- serialize.h | 4 ++-- ui.cpp | 15 ++++++++++++--- uibase.cpp | 14 +++++++------- uibase.h | 45 ++++++++++++++++++++++----------------------- uiproject.fbp | 14 +++++++------- util.cpp | 6 ++++++ util.h | 1 + 12 files changed, 109 insertions(+), 74 deletions(-) diff --git a/init.cpp b/init.cpp index 06d8f4c9..db8886e1 100644 --- a/init.cpp +++ b/init.cpp @@ -284,6 +284,10 @@ bool CMyApp::OnInit2() _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0)); #endif +#if _MSC_VER >= 1400 + // Disable confusing "helpful" text message on abort, ctrl-c + _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); +#endif #if defined(__WXMSW__) && defined(__WXDEBUG__) && wxUSE_GUI // Disable malfunctioning wxWidgets debug assertion g_isPainting = 10000; @@ -291,10 +295,12 @@ bool CMyApp::OnInit2() #if wxUSE_GUI wxImage::AddHandler(new wxPNGHandler); #endif -#ifdef __WXMSW__ +#if defined(__WXMSW__ ) || defined(__WXMAC__) SetAppName("Bitcoin"); #else SetAppName("bitcoin"); +#endif +#ifndef __WXMSW__ umask(077); #endif #ifdef __WXMSW__ diff --git a/main.cpp b/main.cpp index f7416230..ad0208a2 100644 --- a/main.cpp +++ b/main.cpp @@ -1338,7 +1338,7 @@ bool CBlock::AcceptBlock() // Don't relay old inventory during initial block download. // Please keep this number updated to a few thousand below current block count. - if (hashBestChain == hash && nBestHeight > 40000) + if (hashBestChain == hash && nBestHeight > 55000) RelayInventory(CInv(MSG_BLOCK, hash)); // // Add atoms to user reviews for coins created @@ -2255,9 +2255,9 @@ bool SendMessages(CNode* pto) // Delay tx inv messages to protect privacy, // trickle them out to a few nodes at a time. bool fSendTxInv = false; - if (GetTimeMillis() - pto->nLastSentTxInv > 1800 + GetRand(200)) + if (GetTimeMillis() > pto->nNextSendTxInv) { - pto->nLastSentTxInv = GetTimeMillis(); + pto->nNextSendTxInv = GetTimeMillis() + 3000 + GetRand(2000); fSendTxInv = true; } diff --git a/net.cpp b/net.cpp index 8e8127d7..fbfa7462 100644 --- a/net.cpp +++ b/net.cpp @@ -927,9 +927,7 @@ void ThreadOpenConnections2(void* parg) continue; // Only try the old stuff if we don't have enough connections - if (vNodes.size() >= 2 && nSinceLastSeen > 7 * 24 * 60 * 60) - continue; - if (vNodes.size() >= 5 && nSinceLastSeen > 24 * 60 * 60) + if (vNodes.size() >= 8 && nSinceLastSeen > 24 * 60 * 60) continue; // If multiple addresses are ready, prioritize by time since diff --git a/net.h b/net.h index c7d15460..1593a975 100644 --- a/net.h +++ b/net.h @@ -45,6 +45,7 @@ bool StopNode(); // (4) message start // (12) command // (4) size +// (4) checksum // The message start string is designed to be unlikely to occur in normal data. // The characters are rarely used upper ascii, not valid as UTF-8, and produce @@ -58,6 +59,7 @@ public: char pchMessageStart[sizeof(::pchMessageStart)]; char pchCommand[COMMAND_SIZE]; unsigned int nMessageSize; + //unsigned int nChecksum; CMessageHeader() { @@ -65,6 +67,7 @@ public: memset(pchCommand, 0, sizeof(pchCommand)); pchCommand[1] = 1; nMessageSize = -1; + //nChecksum = 0; } CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) @@ -79,6 +82,8 @@ public: READWRITE(FLATDATA(pchMessageStart)); READWRITE(FLATDATA(pchCommand)); READWRITE(nMessageSize); + //if (nVersion >= 209 && GetCommand() != "version") + // READWRITE(nChecksum); ) string GetCommand() @@ -484,7 +489,8 @@ public: int64 nLastRecv; int64 nLastSendEmpty; int64 nTimeConnected; - unsigned int nPushPos; + unsigned int nHeaderStart; + unsigned int nMessageStart; CAddress addr; int nVersion; bool fClient; @@ -512,7 +518,7 @@ public: vector vInventoryToSend; CCriticalSection cs_inventory; multimap mapAskFor; - int64 nLastSentTxInv; + int64 nNextSendTxInv; // publish and subscription vector vfSubscribe; @@ -528,7 +534,8 @@ public: nLastRecv = 0; nLastSendEmpty = GetTime(); nTimeConnected = GetTime(); - nPushPos = -1; + nHeaderStart = -1; + nMessageStart = -1; addr = addrIn; nVersion = 0; fClient = false; // set by version message @@ -542,6 +549,7 @@ public: pindexLastGetBlocksBegin = 0; hashLastGetBlocksEnd = 0; fGetAddr = false; + nNextSendTxInv = 0; vfSubscribe.assign(256, false); // Push a version message @@ -639,10 +647,11 @@ public: void BeginMessage(const char* pszCommand) { cs_vSend.Enter(); - if (nPushPos != -1) + if (nHeaderStart != -1) AbortMessage(); - nPushPos = vSend.size(); + nHeaderStart = vSend.size(); vSend << CMessageHeader(pszCommand, 0); + nMessageStart = vSend.size(); if (fDebug) printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str()); printf("sending: %s ", pszCommand); @@ -650,10 +659,11 @@ public: void AbortMessage() { - if (nPushPos == -1) + if (nHeaderStart == -1) return; - vSend.resize(nPushPos); - nPushPos = -1; + vSend.resize(nHeaderStart); + nHeaderStart = -1; + nMessageStart = -1; cs_vSend.Leave(); printf("(aborted)\n"); } @@ -667,25 +677,26 @@ public: return; } - if (nPushPos == -1) + if (nHeaderStart == -1) return; // Patch in the size - unsigned int nSize = vSend.size() - nPushPos - sizeof(CMessageHeader); - memcpy((char*)&vSend[nPushPos] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize)); + unsigned int nSize = vSend.size() - nMessageStart; + memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize)); printf("(%d bytes) ", nSize); printf("\n"); - nPushPos = -1; + nHeaderStart = -1; + nMessageStart = -1; cs_vSend.Leave(); } void EndMessageAbortIfEmpty() { - if (nPushPos == -1) + if (nHeaderStart == -1) return; - int nSize = vSend.size() - nPushPos - sizeof(CMessageHeader); + int nSize = vSend.size() - nMessageStart; if (nSize > 0) EndMessage(); else @@ -694,9 +705,9 @@ public: const char* GetMessageCommand() const { - if (nPushPos == -1) + if (nHeaderStart == -1) return ""; - return &vSend[nPushPos] + offsetof(CMessageHeader, pchCommand); + return &vSend[nHeaderStart] + offsetof(CMessageHeader, pchCommand); } diff --git a/rpc.cpp b/rpc.cpp index f298137a..c56ce263 100644 --- a/rpc.cpp +++ b/rpc.cpp @@ -77,24 +77,28 @@ Value getconnectioncount(const Array& params) } -Value getdifficulty(const Array& params) +double GetDifficulty() { - if (params.size() != 0) - throw runtime_error( - "getdifficulty (no parameters)\n" - "Returns the proof-of-work difficulty as a multiple of the minimum difficulty."); - - if (pindexBest == NULL) - throw runtime_error("block chain not loaded"); - // Floating point number that is a multiple of the minimum difficulty, // minimum difficulty = 1.0. + if (pindexBest == NULL) + return 1.0; int nShift = 256 - 32 - 31; // to fit in a uint double dMinimum = (CBigNum().SetCompact(bnProofOfWorkLimit.GetCompact()) >> nShift).getuint(); double dCurrently = (CBigNum().SetCompact(pindexBest->nBits) >> nShift).getuint(); return dMinimum / dCurrently; } +Value getdifficulty(const Array& params) +{ + if (params.size() != 0) + throw runtime_error( + "getdifficulty (no parameters)\n" + "Returns the proof-of-work difficulty as a multiple of the minimum difficulty."); + + return GetDifficulty(); +} + Value getbalance(const Array& params) { @@ -157,6 +161,7 @@ Value getinfo(const Array& params) obj.push_back(Pair("proxy", (fUseProxy ? addrProxy.ToStringIPPort() : string()))); obj.push_back(Pair("generate", (bool)fGenerateBitcoins)); obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1))); + obj.push_back(Pair("difficulty", (double)GetDifficulty())); return obj; } diff --git a/serialize.h b/serialize.h index 77dfa95b..c47dddc8 100644 --- a/serialize.h +++ b/serialize.h @@ -19,8 +19,8 @@ class CScript; class CDataStream; class CAutoFile; -static const int VERSION = 207; -static const char* pszSubVer = ".1"; +static const int VERSION = 208; +static const char* pszSubVer = ".0"; diff --git a/ui.cpp b/ui.cpp index efb05385..5c7311f9 100644 --- a/ui.cpp +++ b/ui.cpp @@ -256,11 +256,20 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent) m_staticTextBalance->SetLabel(FormatMoney(GetBalance()) + " "); m_listCtrl->SetFocus(); ptaskbaricon = new CMyTaskBarIcon(); +#ifdef __WXMAC__ + // Mac automatically moves wxID_EXIT, wxID_PREFERENCES and wxID_ABOUT + // to their standard places, leaving these menus empty. + GetMenuBar()->Remove(2); // remove Help menu + GetMenuBar()->Remove(0); // remove File menu +#endif // Init column headers int nDateWidth = DateTimeStr(1229413914).size() * 6 + 8; if (!strstr(DateTimeStr(1229413914).c_str(), "2008")) nDateWidth += 12; +#ifdef __WXMAC__ + nDateWidth += 2; +#endif wxListCtrl* pplistCtrl[] = {m_listCtrlAll, m_listCtrlSentReceived, m_listCtrlSent, m_listCtrlReceived}; foreach(wxListCtrl* p, pplistCtrl) { @@ -274,7 +283,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent) } // Init status bar - int pnWidths[3] = { -100, 88, 290 }; + int pnWidths[3] = { -100, 88, 300 }; #ifndef __WXMSW__ pnWidths[1] = pnWidths[1] * 1.1 * dResize; pnWidths[2] = pnWidths[2] * 1.1 * dResize; @@ -2157,7 +2166,7 @@ CAddressBookDialog::CAddressBookDialog(wxWindow* parent, const wxString& strInit bool fMine = (AddressToHash160(strAddress, hash160) && mapPubKeys.count(hash160)); wxListCtrl* plistCtrl = fMine ? m_listCtrlReceiving : m_listCtrlSending; int nIndex = InsertLine(plistCtrl, strName, strAddress); - if (strAddress == (fMine ? strDefaultReceiving : strInitSelected)) + if (strAddress == (fMine ? strDefaultReceiving : string(strInitSelected))) plistCtrl->SetItemState(nIndex, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); } } @@ -2444,7 +2453,7 @@ void CMyTaskBarIcon::OnMenuRestore(wxCommandEvent& event) void CMyTaskBarIcon::OnMenuOptions(wxCommandEvent& event) { // Since it's modal, get the main window to do it - wxCommandEvent event2(wxEVT_COMMAND_MENU_SELECTED, wxID_MENUOPTIONSOPTIONS); + wxCommandEvent event2(wxEVT_COMMAND_MENU_SELECTED, wxID_PREFERENCES); pframeMain->GetEventHandler()->AddPendingEvent(event2); } diff --git a/uibase.cpp b/uibase.cpp index 03ca13db..5fd83ee4 100644 --- a/uibase.cpp +++ b/uibase.cpp @@ -24,7 +24,7 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString& m_menuFile = new wxMenu(); wxMenuItem* m_menuFileExit; - m_menuFileExit = new wxMenuItem( m_menuFile, wxID_ANY, wxString( _("E&xit") ) , wxEmptyString, wxITEM_NORMAL ); + m_menuFileExit = new wxMenuItem( m_menuFile, wxID_EXIT, wxString( _("E&xit") ) , wxEmptyString, wxITEM_NORMAL ); m_menuFile->Append( m_menuFileExit ); m_menubar->Append( m_menuFile, _("&File") ); @@ -39,14 +39,14 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString& m_menuOptions->Append( m_menuOptionsChangeYourAddress ); wxMenuItem* m_menuOptionsOptions; - m_menuOptionsOptions = new wxMenuItem( m_menuOptions, wxID_MENUOPTIONSOPTIONS, wxString( _("&Options...") ) , wxEmptyString, wxITEM_NORMAL ); + m_menuOptionsOptions = new wxMenuItem( m_menuOptions, wxID_PREFERENCES, wxString( _("&Options...") ) , wxEmptyString, wxITEM_NORMAL ); m_menuOptions->Append( m_menuOptionsOptions ); m_menubar->Append( m_menuOptions, _("&Settings") ); m_menuHelp = new wxMenu(); wxMenuItem* m_menuHelpAbout; - m_menuHelpAbout = new wxMenuItem( m_menuHelp, wxID_ANY, wxString( _("&About...") ) , wxEmptyString, wxITEM_NORMAL ); + m_menuHelpAbout = new wxMenuItem( m_menuHelp, wxID_ABOUT, wxString( _("&About...") ) , wxEmptyString, wxITEM_NORMAL ); m_menuHelp->Append( m_menuHelpAbout ); m_menubar->Append( m_menuHelp, _("&Help") ); @@ -133,7 +133,7 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString& wxBoxSizer* bSizer11; bSizer11 = new wxBoxSizer( wxVERTICAL ); - m_listCtrlAll = new wxListCtrl( m_panel9, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT|wxLC_SORT_DESCENDING|wxVSCROLL ); + m_listCtrlAll = new wxListCtrl( m_panel9, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT|wxLC_SORT_DESCENDING ); bSizer11->Add( m_listCtrlAll, 1, wxEXPAND, 5 ); m_panel9->SetSizer( bSizer11 ); @@ -144,7 +144,7 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString& wxBoxSizer* bSizer111; bSizer111 = new wxBoxSizer( wxVERTICAL ); - m_listCtrlSentReceived = new wxListCtrl( m_panel91, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT|wxLC_SORT_DESCENDING|wxVSCROLL ); + m_listCtrlSentReceived = new wxListCtrl( m_panel91, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT|wxLC_SORT_DESCENDING ); bSizer111->Add( m_listCtrlSentReceived, 1, wxEXPAND, 5 ); m_panel91->SetSizer( bSizer111 ); @@ -155,7 +155,7 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString& wxBoxSizer* bSizer112; bSizer112 = new wxBoxSizer( wxVERTICAL ); - m_listCtrlSent = new wxListCtrl( m_panel92, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT|wxLC_SORT_DESCENDING|wxVSCROLL ); + m_listCtrlSent = new wxListCtrl( m_panel92, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT|wxLC_SORT_DESCENDING ); bSizer112->Add( m_listCtrlSent, 1, wxEXPAND, 5 ); m_panel92->SetSizer( bSizer112 ); @@ -166,7 +166,7 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString& wxBoxSizer* bSizer113; bSizer113 = new wxBoxSizer( wxVERTICAL ); - m_listCtrlReceived = new wxListCtrl( m_panel93, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT|wxLC_SORT_DESCENDING|wxVSCROLL ); + m_listCtrlReceived = new wxListCtrl( m_panel93, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT|wxLC_SORT_DESCENDING ); bSizer113->Add( m_listCtrlReceived, 1, wxEXPAND, 5 ); m_panel93->SetSizer( bSizer113 ); diff --git a/uibase.h b/uibase.h index 1686cbfa..e2f0a1c0 100644 --- a/uibase.h +++ b/uibase.h @@ -42,29 +42,28 @@ #define wxID_MAINFRAME 1000 #define wxID_OPTIONSGENERATEBITCOINS 1001 -#define wxID_MENUOPTIONSOPTIONS 1002 -#define wxID_BUTTONSEND 1003 -#define wxID_BUTTONRECEIVE 1004 -#define wxID_TEXTCTRLADDRESS 1005 -#define wxID_BUTTONNEW 1006 -#define wxID_BUTTONCOPY 1007 -#define wxID_TRANSACTIONFEE 1008 -#define wxID_PROXYIP 1009 -#define wxID_PROXYPORT 1010 -#define wxID_TEXTCTRLPAYTO 1011 -#define wxID_BUTTONPASTE 1012 -#define wxID_BUTTONADDRESSBOOK 1013 -#define wxID_TEXTCTRLAMOUNT 1014 -#define wxID_CHOICETRANSFERTYPE 1015 -#define wxID_LISTCTRL 1016 -#define wxID_BUTTONRENAME 1017 -#define wxID_PANELSENDING 1018 -#define wxID_LISTCTRLSENDING 1019 -#define wxID_PANELRECEIVING 1020 -#define wxID_LISTCTRLRECEIVING 1021 -#define wxID_BUTTONDELETE 1022 -#define wxID_BUTTONEDIT 1023 -#define wxID_TEXTCTRL 1024 +#define wxID_BUTTONSEND 1002 +#define wxID_BUTTONRECEIVE 1003 +#define wxID_TEXTCTRLADDRESS 1004 +#define wxID_BUTTONNEW 1005 +#define wxID_BUTTONCOPY 1006 +#define wxID_TRANSACTIONFEE 1007 +#define wxID_PROXYIP 1008 +#define wxID_PROXYPORT 1009 +#define wxID_TEXTCTRLPAYTO 1010 +#define wxID_BUTTONPASTE 1011 +#define wxID_BUTTONADDRESSBOOK 1012 +#define wxID_TEXTCTRLAMOUNT 1013 +#define wxID_CHOICETRANSFERTYPE 1014 +#define wxID_LISTCTRL 1015 +#define wxID_BUTTONRENAME 1016 +#define wxID_PANELSENDING 1017 +#define wxID_LISTCTRLSENDING 1018 +#define wxID_PANELRECEIVING 1019 +#define wxID_LISTCTRLRECEIVING 1020 +#define wxID_BUTTONDELETE 1021 +#define wxID_BUTTONEDIT 1022 +#define wxID_TEXTCTRL 1023 /////////////////////////////////////////////////////////////////////////////// /// Class CMainFrameBase diff --git a/uiproject.fbp b/uiproject.fbp index 8643fbab..990af521 100644 --- a/uiproject.fbp +++ b/uiproject.fbp @@ -123,7 +123,7 @@ 0 1 - wxID_ANY + wxID_EXIT wxITEM_NORMAL E&xit m_menuFileExit @@ -173,7 +173,7 @@ 0 1 - wxID_MENUOPTIONSOPTIONS + wxID_PREFERENCES wxITEM_NORMAL &Options... m_menuOptionsOptions @@ -193,7 +193,7 @@ 0 1 - wxID_ANY + wxID_ABOUT wxITEM_NORMAL &About... m_menuHelpAbout @@ -924,7 +924,7 @@ - wxVSCROLL + @@ -1047,7 +1047,7 @@ - wxVSCROLL + @@ -1170,7 +1170,7 @@ - wxVSCROLL + @@ -1293,7 +1293,7 @@ - wxVSCROLL + diff --git a/util.cpp b/util.cpp index acfbcd6c..8f6bf38c 100644 --- a/util.cpp +++ b/util.cpp @@ -314,6 +314,12 @@ string FormatMoney(int64 n, bool fPlus) return str; } + +bool ParseMoney(const string& str, int64& nRet) +{ + return ParseMoney(str.c_str(), nRet); +} + bool ParseMoney(const char* pszIn, int64& nRet) { string strWhole; diff --git a/util.h b/util.h index 75f0956f..1a25c7dd 100644 --- a/util.h +++ b/util.h @@ -133,6 +133,7 @@ void PrintException(std::exception* pex, const char* pszThread); void LogException(std::exception* pex, const char* pszThread); void ParseString(const string& str, char c, vector& v); string FormatMoney(int64 n, bool fPlus=false); +bool ParseMoney(const string& str, int64& nRet); bool ParseMoney(const char* pszIn, int64& nRet); vector ParseHex(const char* psz); vector ParseHex(const std::string& str);