# HG changeset patch # User s_nakamoto # Date 1274228816 0 # Node ID 48fda46fed2ba0f7aded5f733f2e51b6623ee1d7 # Parent 1bf4f0e9e04c1da43113551506e5518d9966b124 Mac OS build fixes by laszlo -- version 0.2.8 diff --git a/init.cpp b/init.cpp --- a/init.cpp +++ b/init.cpp @@ -284,6 +284,10 @@ _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 @@ #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 --- a/main.cpp +++ b/main.cpp @@ -1338,7 +1338,7 @@ // 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 @@ // 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 --- a/net.cpp +++ b/net.cpp @@ -927,9 +927,7 @@ 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 --- a/net.h +++ b/net.h @@ -45,6 +45,7 @@ // (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 @@ char pchMessageStart[sizeof(::pchMessageStart)]; char pchCommand[COMMAND_SIZE]; unsigned int nMessageSize; + //unsigned int nChecksum; CMessageHeader() { @@ -65,6 +67,7 @@ memset(pchCommand, 0, sizeof(pchCommand)); pchCommand[1] = 1; nMessageSize = -1; + //nChecksum = 0; } CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) @@ -79,6 +82,8 @@ READWRITE(FLATDATA(pchMessageStart)); READWRITE(FLATDATA(pchCommand)); READWRITE(nMessageSize); + //if (nVersion >= 209 && GetCommand() != "version") + // READWRITE(nChecksum); ) string GetCommand() @@ -484,7 +489,8 @@ 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 @@ vector vInventoryToSend; CCriticalSection cs_inventory; multimap mapAskFor; - int64 nLastSentTxInv; + int64 nNextSendTxInv; // publish and subscription vector vfSubscribe; @@ -528,7 +534,8 @@ 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 @@ pindexLastGetBlocksBegin = 0; hashLastGetBlocksEnd = 0; fGetAddr = false; + nNextSendTxInv = 0; vfSubscribe.assign(256, false); // Push a version message @@ -639,10 +647,11 @@ 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 @@ 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 @@ 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 @@ 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 --- a/rpc.cpp +++ b/rpc.cpp @@ -77,6 +77,18 @@ } +double GetDifficulty() +{ + // 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) @@ -84,15 +96,7 @@ "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. - 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; + return GetDifficulty(); } @@ -157,6 +161,7 @@ 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 --- a/serialize.h +++ b/serialize.h @@ -19,8 +19,8 @@ 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 --- a/ui.cpp +++ b/ui.cpp @@ -256,11 +256,20 @@ 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 @@ } // 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 @@ 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::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 --- a/uibase.cpp +++ b/uibase.cpp @@ -24,7 +24,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 --- 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 --- 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 --- a/util.cpp +++ b/util.cpp @@ -314,6 +314,12 @@ 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 --- a/util.h +++ b/util.h @@ -133,6 +133,7 @@ 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);