What changed
Bitcoin v0.3.3 → v0.3.6
Release commit message: reverted makefile.unix wx-config -- version 0.3.6
Previous diff: v0.3.2 → v0.3.3. Next: v0.3.6 → v0.3.7.
- bignum.h modified · +2 −1
- db.cpp modified · +1 −1
- headers.h modified · +14 −3
- init.cpp modified · +56 −348
- init.h modified · +2 −2
- main.cpp modified · +96 −111
- makefile.mingw modified · +28 −27
- makefile.osx modified · +21 −18
- makefile.unix modified · +28 −23
- makefile.vc modified · +37 −28
- net.cpp modified · +2 −2
- noui.h added · +34 −0
- rpc.cpp modified · +5 −4
- script.cpp modified · +761 −733
- script.h modified · +26 −1
- serialize.h modified · +1 −1
- setup.nsi modified · +3 −3
- sha.cpp removed · +0 −554
- sha.h removed · +0 −177
- ui.cpp modified · +343 −10
- ui.h modified · +23 −56
- util.cpp modified · +12 −9
- util.h modified · +26 −5
bignum.h (modified)
1--- v0.3.3/bignum.h2+++ v0.3.6/bignum.h3@@ -401,7 +401,8 @@4 5 CBigNum& operator>>=(unsigned int shift)6 {7- // Note: BN_rshift segfaults on 64-bit ubuntu 9.10 if 2^shift is greater than the number8+ // Note: BN_rshift segfaults on 64-bit ubuntu 9.10 if 2^shift is greater than the number,9+ // tested OK on 64-bit ubuntu 10.410 if (!BN_rshift(this, this, shift))11 throw bignum_error("CBigNum:operator>>= : BN_rshift failed");12 return *this;
db.cpp (modified)
1--- v0.3.3/db.cpp2+++ v0.3.6/db.cpp3@@ -60,7 +60,7 @@4 return;5 string strDataDir = GetDataDir();6 string strLogDir = strDataDir + "/database";7- _mkdir(strLogDir.c_str());8+ filesystem::create_directory(strLogDir.c_str());9 string strErrorFile = strDataDir + "/db.log";10 printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());11
headers.h (modified)
1--- v0.3.3/headers.h2+++ v0.3.6/headers.h3@@ -18,13 +18,19 @@4 #define _WIN32_IE 0x04005 #define WIN32_LEAN_AND_MEAN 16 #define __STDC_LIMIT_MACROS // to enable UINT64_MAX from stdint.h7+#ifdef GUI8 #include <wx/wx.h>9 #include <wx/stdpaths.h>10 #include <wx/snglinst.h>11-#if wxUSE_GUI12 #include <wx/utils.h>13 #include <wx/clipbrd.h>14 #include <wx/taskbar.h>15+#else16+#ifdef __WXMAC_OSX__17+#define __WXMAC__ 118+#define __WXOSX__ 119+#define __BSD__ 120+#endif21 #endif22 #include <openssl/buffer.h>23 #include <openssl/ecdsa.h>24@@ -61,6 +67,7 @@25 #include <boost/filesystem.hpp>26 #include <boost/filesystem/fstream.hpp>27 #include <boost/algorithm/string.hpp>28+#include <boost/thread.hpp>29 #include <boost/interprocess/sync/interprocess_mutex.hpp>30 #include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>31 #include <boost/date_time/gregorian/gregorian_types.hpp>32@@ -82,12 +89,14 @@33 #include <sys/time.h>34 #include <sys/resource.h>35 #include <sys/socket.h>36+#include <sys/stat.h>37 #include <arpa/inet.h>38 #include <netdb.h>39 #include <unistd.h>40 #include <errno.h>41 #include <net/if.h>42 #include <ifaddrs.h>43+#include <fcntl.h>44 #endif45 #ifdef __BSD__46 #include <netinet/in.h>47@@ -111,10 +120,12 @@48 #include "irc.h"49 #include "main.h"50 #include "rpc.h"51-#if wxUSE_GUI52+#ifdef GUI53 #include "uibase.h"54+#include "ui.h"55+#else56+#include "noui.h"57 #endif58-#include "ui.h"59 #include "init.h"60 61 #include "xpm/addressbook16.xpm"
init.cpp (modified)
1--- v0.3.3/init.cpp2+++ v0.3.6/init.cpp3@@ -6,6 +6,15 @@4 5 6 7+8+9+10+11+12+//////////////////////////////////////////////////////////////////////////////13+//14+// Shutdown15+//16 17 void ExitTimeout(void* parg)18 {19@@ -55,273 +64,59 @@20 21 //////////////////////////////////////////////////////////////////////////////22 //23-// Startup folder24+// Start25 //26 27-#ifdef __WXMSW__28-string StartupShortcutPath()29-{30- return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";31-}32-33-bool GetStartOnSystemStartup()34-{35- return filesystem::exists(StartupShortcutPath().c_str());36-}37-38-void SetStartOnSystemStartup(bool fAutoStart)39-{40- // If the shortcut exists already, remove it for updating41- remove(StartupShortcutPath().c_str());42-43- if (fAutoStart)44- {45- CoInitialize(NULL);46-47- // Get a pointer to the IShellLink interface.48- IShellLink* psl = NULL;49- HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,50- CLSCTX_INPROC_SERVER, IID_IShellLink,51- reinterpret_cast<void**>(&psl));52-53- if (SUCCEEDED(hres))54- {55- // Get the current executable path56- TCHAR pszExePath[MAX_PATH];57- GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));58-59- // Set the path to the shortcut target60- psl->SetPath(pszExePath);61- PathRemoveFileSpec(pszExePath);62- psl->SetWorkingDirectory(pszExePath);63- psl->SetShowCmd(SW_SHOWMINNOACTIVE);64-65- // Query IShellLink for the IPersistFile interface for66- // saving the shortcut in persistent storage.67- IPersistFile* ppf = NULL;68- hres = psl->QueryInterface(IID_IPersistFile,69- reinterpret_cast<void**>(&ppf));70- if (SUCCEEDED(hres))71- {72- WCHAR pwsz[MAX_PATH];73- // Ensure that the string is ANSI.74- MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().c_str(), -1, pwsz, MAX_PATH);75- // Save the link by calling IPersistFile::Save.76- hres = ppf->Save(pwsz, TRUE);77- ppf->Release();78- }79- psl->Release();80- }81- CoUninitialize();82- }83-}84-85-#elif defined(__WXGTK__)86-87-//88-// Follow the Desktop Application Autostart Spec:89-// http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html90-//91-92-boost::filesystem::path GetAutostartDir()93-{94- namespace fs = boost::filesystem;95-96- char* pszConfigHome = getenv("XDG_CONFIG_HOME");97- if (pszConfigHome) return fs::path(pszConfigHome) / fs::path("autostart");98- char* pszHome = getenv("HOME");99- if (pszHome) return fs::path(pszHome) / fs::path(".config/autostart");100- return fs::path();101-}102-103-boost::filesystem::path GetAutostartFilePath()104-{105- return GetAutostartDir() / boost::filesystem::path("bitcoin.desktop");106-}107-108-bool GetStartOnSystemStartup()109-{110- boost::filesystem::ifstream optionFile(GetAutostartFilePath());111- if (!optionFile.good())112- return false;113- // Scan through file for "Hidden=true":114- string line;115- while (!optionFile.eof())116- {117- getline(optionFile, line);118- if (line.find("Hidden") != string::npos &&119- line.find("true") != string::npos)120- return false;121- }122- optionFile.close();123-124- return true;125-}126-127-void SetStartOnSystemStartup(bool fAutoStart)128-{129- if (!fAutoStart)130- {131- unlink(GetAutostartFilePath().native_file_string().c_str());132- }133- else134- {135- boost::filesystem::create_directories(GetAutostartDir());136-137- boost::filesystem::ofstream optionFile(GetAutostartFilePath(), ios_base::out|ios_base::trunc);138- if (!optionFile.good())139- {140- wxMessageBox(_("Cannot write autostart/bitcoin.desktop file"), "Bitcoin");141- return;142- }143- // Write a bitcoin.desktop file to the autostart directory:144- char pszExePath[MAX_PATH+1];145- memset(pszExePath, 0, sizeof(pszExePath));146- readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1);147- optionFile << "[Desktop Entry]\n";148- optionFile << "Type=Application\n";149- optionFile << "Name=Bitcoin\n";150- optionFile << "Exec=" << pszExePath << "\n";151- optionFile << "Terminal=false\n";152- optionFile << "Hidden=false\n";153- optionFile.close();154- }155-}156-#else157-158-// TODO: OSX startup stuff; see:159-// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html160-161-bool GetStartOnSystemStartup() { return false; }162-void SetStartOnSystemStartup(bool fAutoStart) { }163-164-#endif165-166-167-168-169-170-171-172-//////////////////////////////////////////////////////////////////////////////173-//174-// CMyApp175-//176-177-// Define a new application178-class CMyApp : public wxApp179-{180-public:181- wxLocale m_locale;182-183- CMyApp(){};184- ~CMyApp(){};185- bool OnInit();186- bool OnInit2();187- int OnExit();188-189- // Hook Initialize so we can start without GUI190- virtual bool Initialize(int& argc, wxChar** argv);191-192- // 2nd-level exception handling: we get all the exceptions occurring in any193- // event handler here194- virtual bool OnExceptionInMainLoop();195-196- // 3rd, and final, level exception handling: whenever an unhandled197- // exception is caught, this function is called198- virtual void OnUnhandledException();199-200- // and now for something different: this function is called in case of a201- // crash (e.g. dereferencing null pointer, division by 0, ...)202- virtual void OnFatalException();203-};204-205-IMPLEMENT_APP(CMyApp)206-207-bool CMyApp::Initialize(int& argc, wxChar** argv)208+#ifndef GUI209+int main(int argc, char* argv[])210 {211 for (int i = 1; i < argc; i++)212 if (!IsSwitchChar(argv[i][0]))213 fCommandLine = true;214-215+ fDaemon = !fCommandLine;216+217+#ifdef __WXGTK__218 if (!fCommandLine)219 {220- if (!fGUI)221- {222- fDaemon = true;223- }224- else225- {226- // wxApp::Initialize will remove environment-specific parameters,227- // so it's too early to call ParseParameters yet228- for (int i = 1; i < argc; i++)229- {230- wxString str = argv[i];231- #ifdef __WXMSW__232- if (str.size() >= 1 && str[0] == '/')233- str[0] = '-';234- char pszLower[MAX_PATH];235- strlcpy(pszLower, str.c_str(), sizeof(pszLower));236- strlwr(pszLower);237- str = pszLower;238- #endif239- if (str == "-daemon")240- fDaemon = true;241- }242- }243- }244-245-#ifdef __WXGTK__246- if (fDaemon || fCommandLine)247- {248- // Call the original Initialize while suppressing error messages249- // and ignoring failure. If unable to initialize GTK, it fails250- // near the end so hopefully the last few things don't matter.251- {252- wxLogNull logNo;253- wxApp::Initialize(argc, argv);254- }255-256- if (fDaemon)257- {258- // Daemonize259- pid_t pid = fork();260- if (pid < 0)261- {262- fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);263- return false;264- }265- if (pid > 0)266- pthread_exit((void*)0);267- }268-269- return true;270- }271-#endif272-273- return wxApp::Initialize(argc, argv);274-}275-276-bool CMyApp::OnInit()277+ // Daemonize278+ pid_t pid = fork();279+ if (pid < 0)280+ {281+ fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);282+ return 1;283+ }284+ if (pid > 0)285+ pthread_exit((void*)0);286+ }287+#endif288+289+ if (!AppInit(argc, argv))290+ return 1;291+292+ while (!fShutdown)293+ Sleep(1000000);294+ return 0;295+}296+#endif297+298+bool AppInit(int argc, char* argv[])299 {300 bool fRet = false;301 try302 {303- fRet = OnInit2();304+ fRet = AppInit2(argc, argv);305 }306 catch (std::exception& e) {307- PrintException(&e, "OnInit()");308+ PrintException(&e, "AppInit()");309 } catch (...) {310- PrintException(NULL, "OnInit()");311+ PrintException(NULL, "AppInit()");312 }313 if (!fRet)314 Shutdown(NULL);315 return fRet;316 }317 318-extern int g_isPainting;319-320-bool CMyApp::OnInit2()321+bool AppInit2(int argc, char* argv[])322 {323 #ifdef _MSC_VER324 // Turn off microsoft heap dump noise325@@ -332,46 +127,9 @@326 // Disable confusing "helpful" text message on abort, ctrl-c327 _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);328 #endif329-#if defined(__WXMSW__) && defined(__WXDEBUG__) && wxUSE_GUI330- // Disable malfunctioning wxWidgets debug assertion331- g_isPainting = 10000;332-#endif333-#if wxUSE_GUI334- wxImage::AddHandler(new wxPNGHandler);335-#endif336-#if defined(__WXMSW__ ) || defined(__WXMAC__)337- SetAppName("Bitcoin");338-#else339- SetAppName("bitcoin");340-#endif341 #ifndef __WXMSW__342 umask(077);343 #endif344-#ifdef __WXMSW__345-#if wxUSE_UNICODE346- // Hack to set wxConvLibc codepage to UTF-8 on Windows,347- // may break if wxMBConv_win32 implementation in strconv.cpp changes.348- class wxMBConv_win32 : public wxMBConv349- {350- public:351- long m_CodePage;352- size_t m_minMBCharWidth;353- };354- if (((wxMBConv_win32*)&wxConvLibc)->m_CodePage == CP_ACP)355- ((wxMBConv_win32*)&wxConvLibc)->m_CodePage = CP_UTF8;356-#endif357-#endif358-359- // Load locale/<lang>/LC_MESSAGES/bitcoin.mo language file360- m_locale.Init(wxLANGUAGE_DEFAULT, 0);361- m_locale.AddCatalogLookupPathPrefix("locale");362- if (!fWindows)363- {364- m_locale.AddCatalogLookupPathPrefix("/usr/share/locale");365- m_locale.AddCatalogLookupPathPrefix("/usr/local/share/locale");366- }367- m_locale.AddCatalog("wxstd"); // wxWidgets standard translations, if any368- m_locale.AddCatalog("bitcoin");369 370 //371 // Parameters372@@ -385,7 +143,7 @@373 374 if (mapArgs.count("-?") || mapArgs.count("--help"))375 {376- wxString strUsage = string() +377+ string strUsage = string() +378 _("Usage:") + "\t\t\t\t\t\t\t\t\t\t\n" +379 " bitcoin [options] \t " + "\n" +380 " bitcoin [options] <command> [params]\t " + _("Send command to -server or bitcoind\n") +381@@ -404,13 +162,13 @@382 " -daemon \t " + _("Run in the background as a daemon and accept commands\n") +383 " -? \t " + _("This help message\n");384 385-#if defined(__WXMSW__) && wxUSE_GUI386+#if defined(__WXMSW__) && defined(GUI)387 // Tabs make the columns line up in the message box388 wxMessageBox(strUsage, "Bitcoin", wxOK);389 #else390 // Remove tabs391- strUsage.Replace("\t", "");392- fprintf(stderr, "%s", ((string)strUsage).c_str());393+ strUsage.erase(std::remove(strUsage.begin(), strUsage.end(), '\t'), strUsage.end());394+ fprintf(stderr, "%s", strUsage.c_str());395 #endif396 return false;397 }398@@ -430,9 +188,12 @@399 if (!fDebug && !pszSetDataDir[0])400 ShrinkDebugFile();401 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");402- printf("Bitcoin version %d.%d.%d%s beta, OS version %s\n", VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer, ((string)wxGetOsDescription()).c_str());403- printf("System default language is %d %s\n", m_locale.GetSystemLanguage(), ((string)m_locale.GetSysName()).c_str());404- printf("Language file %s (%s)\n", (string("locale/") + (string)m_locale.GetCanonicalName() + "/LC_MESSAGES/bitcoin.mo").c_str(), ((string)m_locale.GetLocale()).c_str());405+ printf("Bitcoin version %d.%d.%d%s beta\n", VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer);406+#ifdef GUI407+ printf("OS version %s\n", ((string)wxGetOsDescription()).c_str());408+ printf("System default language is %d %s\n", g_locale.GetSystemLanguage(), ((string)g_locale.GetSysName()).c_str());409+ printf("Language file %s (%s)\n", (string("locale/") + (string)g_locale.GetCanonicalName() + "/LC_MESSAGES/bitcoin.mo").c_str(), ((string)g_locale.GetLocale()).c_str());410+#endif411 printf("Default data directory %s\n", GetDefaultDataDir().c_str());412 413 if (mapArgs.count("-loadblockindextest"))414@@ -447,7 +208,7 @@415 // Limit to single instance per user416 // Required to protect the database files if we're going to keep deleting log.*417 //418-#ifdef __WXMSW__419+#if defined(__WXMSW__) && defined(GUI)420 // todo: wxSingleInstanceChecker wasn't working on Linux, never deleted its lock file421 // maybe should go by whether successfully bind port 8333 instead422 wxString strMutexName = wxString("bitcoin_running.") + getenv("HOMEPATH");423@@ -605,8 +366,10 @@424 //425 // Create the main window and start the node426 //427+#ifdef GUI428 if (!fDaemon)429 CreateMainWindow();430+#endif431 432 if (!CheckDiskSpace())433 return false;434@@ -619,66 +382,11 @@435 if (mapArgs.count("-server") || fDaemon)436 CreateThread(ThreadRPCServer, NULL);437 438+#ifdef GUI439 if (fFirstRun)440 SetStartOnSystemStartup(true);441+#endif442 443 return true;444 }445 446-int CMyApp::OnExit()447-{448- Shutdown(NULL);449- return wxApp::OnExit();450-}451-452-bool CMyApp::OnExceptionInMainLoop()453-{454- try455- {456- throw;457- }458- catch (std::exception& e)459- {460- PrintException(&e, "CMyApp::OnExceptionInMainLoop()");461- wxLogWarning("Exception %s %s", typeid(e).name(), e.what());462- Sleep(1000);463- throw;464- }465- catch (...)466- {467- PrintException(NULL, "CMyApp::OnExceptionInMainLoop()");468- wxLogWarning("Unknown exception");469- Sleep(1000);470- throw;471- }472- return true;473-}474-475-void CMyApp::OnUnhandledException()476-{477- // this shows how we may let some exception propagate uncaught478- try479- {480- throw;481- }482- catch (std::exception& e)483- {484- PrintException(&e, "CMyApp::OnUnhandledException()");485- wxLogWarning("Exception %s %s", typeid(e).name(), e.what());486- Sleep(1000);487- throw;488- }489- catch (...)490- {491- PrintException(NULL, "CMyApp::OnUnhandledException()");492- wxLogWarning("Unknown exception");493- Sleep(1000);494- throw;495- }496-}497-498-void CMyApp::OnFatalException()499-{500- wxMessageBox(_("Program has crashed and will terminate. "), "Bitcoin", wxOK | wxICON_ERROR);501-}502-
init.h (modified)
1--- v0.3.3/init.h2+++ v0.3.6/init.h3@@ -3,6 +3,6 @@4 // file license.txt or http://www.opensource.org/licenses/mit-license.php.5 6 void Shutdown(void* parg);7-bool GetStartOnSystemStartup();8-void SetStartOnSystemStartup(bool fAutoStart);9+bool AppInit(int argc, char* argv[]);10+bool AppInit2(int argc, char* argv[]);11
main.cpp (modified)
1--- v0.3.3/main.cpp2+++ v0.3.6/main.cpp3@@ -3,7 +3,7 @@4 // file license.txt or http://www.opensource.org/licenses/mit-license.php.5 6 #include "headers.h"7-#include "sha.h"8+#include "cryptopp/sha.h"9 10 11 12@@ -83,6 +83,7 @@13 14 vector<unsigned char> GenerateNewKey()15 {16+ RandAddSeedPerfmon();17 CKey key;18 key.MakeNewKey();19 if (!AddKey(key))20@@ -805,9 +806,9 @@21 22 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast)23 {24- const unsigned int nTargetTimespan = 14 * 24 * 60 * 60; // two weeks25- const unsigned int nTargetSpacing = 10 * 60;26- const unsigned int nInterval = nTargetTimespan / nTargetSpacing;27+ const int64 nTargetTimespan = 14 * 24 * 60 * 60; // two weeks28+ const int64 nTargetSpacing = 10 * 60;29+ const int64 nInterval = nTargetTimespan / nTargetSpacing;30 31 // Genesis block32 if (pindexLast == NULL)33@@ -824,8 +825,8 @@34 assert(pindexFirst);35 36 // Limit adjustment step37- unsigned int nActualTimespan = pindexLast->nTime - pindexFirst->nTime;38- printf(" nActualTimespan = %d before bounds\n", nActualTimespan);39+ int64 nActualTimespan = (int64)pindexLast->nTime - (int64)pindexFirst->nTime;40+ printf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan);41 if (nActualTimespan < nTargetTimespan/4)42 nActualTimespan = nTargetTimespan/4;43 if (nActualTimespan > nTargetTimespan*4)44@@ -842,29 +843,26 @@45 46 /// debug print47 printf("GetNextWorkRequired RETARGET\n");48- printf("nTargetTimespan = %d nActualTimespan = %d\n", nTargetTimespan, nActualTimespan);49+ printf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan);50 printf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str());51 printf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());52 53 return bnNew.GetCompact();54 }55 56-vector<int> vStartingHeight;57-void AddStartingHeight(int nStartingHeight)58-{59- if (nStartingHeight != -1)60- {61- vStartingHeight.push_back(nStartingHeight);62- sort(vStartingHeight.begin(), vStartingHeight.end());63- }64-}65-66 bool IsInitialBlockDownload()67 {68- int nMedian = 69000;69- if (vStartingHeight.size() >= 5)70- nMedian = vStartingHeight[vStartingHeight.size()/2];71- return nBestHeight < nMedian-1000;72+ if (pindexBest == NULL)73+ return true;74+ static int64 nLastUpdate;75+ static CBlockIndex* pindexLastBest;76+ if (pindexBest != pindexLastBest)77+ {78+ pindexLastBest = pindexBest;79+ nLastUpdate = GetTime();80+ }81+ return (GetTime() - nLastUpdate < 10 &&82+ pindexBest->nTime < GetTime() - 24 * 60 * 60);83 }84 85 86@@ -1368,6 +1366,8 @@87 return error("AcceptBlock() : rejected by checkpoint lockin at 33333");88 if (pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a"))89 return error("AcceptBlock() : rejected by checkpoint lockin at 68555");90+ if (pindexPrev->nHeight+1 == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a"))91+ return error("AcceptBlock() : rejected by checkpoint lockin at 70567");92 93 // Write block to history file94 if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK)))95@@ -1506,7 +1506,7 @@96 {97 fShutdown = true;98 printf("*** %s***\n", _("Warning: Disk space is low "));99-#if wxUSE_GUI100+#ifdef GUI101 ThreadSafeMessageBox(_("Warning: Disk space is low "), "Bitcoin", wxOK | wxICON_EXCLAMATION);102 #endif103 CreateThread(Shutdown, NULL);104@@ -1920,7 +1920,6 @@105 }106 107 AddTimeData(pfrom->addr.ip, nTime);108- AddStartingHeight(pfrom->nStartingHeight);109 110 // Change version111 if (pfrom->nVersion >= 209)112@@ -2494,7 +2493,7 @@113 }114 if (fGenerateBitcoins)115 {116- int nProcessors = wxThread::GetCPUCount();117+ int nProcessors = boost::thread::hardware_concurrency();118 printf("%d processors\n", nProcessors);119 if (nProcessors < 1)120 nProcessors = 1;121@@ -2546,33 +2545,18 @@122 }123 124 using CryptoPP::ByteReverse;125-static int detectlittleendian = 1;126-127-void BlockSHA256(const void* pin, unsigned int nBlocks, void* pout)128-{129- unsigned int* pinput = (unsigned int*)pin;130- unsigned int* pstate = (unsigned int*)pout;131-132- CryptoPP::SHA256::InitState(pstate);133-134- if (*(char*)&detectlittleendian != 0)135- {136- for (int n = 0; n < nBlocks; n++)137- {138- unsigned int pbuf[16];139- for (int i = 0; i < 16; i++)140- pbuf[i] = ByteReverse(pinput[n * 16 + i]);141- CryptoPP::SHA256::Transform(pstate, pbuf);142- }143- for (int i = 0; i < 8; i++)144- pstate[i] = ByteReverse(pstate[i]);145- }146- else147- {148- for (int n = 0; n < nBlocks; n++)149- CryptoPP::SHA256::Transform(pstate, pinput + n * 16);150- }151-}152+153+static const unsigned int pSHA256InitState[8] =154+{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};155+156+inline void SHA256Transform(void* pstate, void* pinput, const void* pinit)157+{158+ memcpy(pstate, pinit, 32);159+ CryptoPP::SHA256::Transform((CryptoPP::word32*)pstate, (CryptoPP::word32*)pinput);160+}161+162+163+164 165 166 void BitcoinMiner()167@@ -2588,7 +2572,7 @@168 Sleep(50);169 if (fShutdown)170 return;171- while (vNodes.empty())172+ while (vNodes.empty() || IsInitialBlockDownload())173 {174 Sleep(1000);175 if (fShutdown)176@@ -2671,7 +2655,7 @@177 //178 // Prebuild hash buffer179 //180- struct unnamed1181+ struct tmpworkspace182 {183 struct unnamed2184 {185@@ -2686,18 +2670,28 @@186 unsigned char pchPadding0[64];187 uint256 hash1;188 unsigned char pchPadding1[64];189- }190- tmp;191+ };192+ char tmpbuf[sizeof(tmpworkspace)+16];193+ tmpworkspace& tmp = *(tmpworkspace*)alignup<16>(tmpbuf);194 195 tmp.block.nVersion = pblock->nVersion;196 tmp.block.hashPrevBlock = pblock->hashPrevBlock = (pindexPrev ? pindexPrev->GetBlockHash() : 0);197 tmp.block.hashMerkleRoot = pblock->hashMerkleRoot = pblock->BuildMerkleTree();198 tmp.block.nTime = pblock->nTime = max((pindexPrev ? pindexPrev->GetMedianTimePast()+1 : 0), GetAdjustedTime());199 tmp.block.nBits = pblock->nBits = nBits;200- tmp.block.nNonce = pblock->nNonce = 1;201+ tmp.block.nNonce = pblock->nNonce = 0;202 203 unsigned int nBlocks0 = FormatHashBlocks(&tmp.block, sizeof(tmp.block));204 unsigned int nBlocks1 = FormatHashBlocks(&tmp.hash1, sizeof(tmp.hash1));205+206+ // Byte swap all the input buffer207+ for (int i = 0; i < sizeof(tmp)/4; i++)208+ ((unsigned int*)&tmp)[i] = ByteReverse(((unsigned int*)&tmp)[i]);209+210+ // Precalc the first half of the first hash, which stays constant211+ uint256 midstatebuf[2];212+ uint256& midstate = *alignup<16>(midstatebuf);213+ SHA256Transform(&midstate, &tmp.block, pSHA256InitState);214 215 216 //217@@ -2705,47 +2699,55 @@218 //219 int64 nStart = GetTime();220 uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();221- uint256 hash;222+ uint256 hashbuf[2];223+ uint256& hash = *alignup<16>(hashbuf);224 loop225 {226- BlockSHA256(&tmp.block, nBlocks0, &tmp.hash1);227- BlockSHA256(&tmp.hash1, nBlocks1, &hash);228-229- if (hash <= hashTarget)230- {231- pblock->nNonce = tmp.block.nNonce;232- assert(hash == pblock->GetHash());233-234- //// debug print235- printf("BitcoinMiner:\n");236- printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());237- pblock->print();238- printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str());239- printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());240-241- SetThreadPriority(THREAD_PRIORITY_NORMAL);242- CRITICAL_BLOCK(cs_main)243+ SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate);244+ SHA256Transform(&hash, &tmp.hash1, pSHA256InitState);245+246+ if (((unsigned short*)&hash)[14] == 0)247+ {248+ // Byte swap the result after preliminary check249+ for (int i = 0; i < sizeof(hash)/4; i++)250+ ((unsigned int*)&hash)[i] = ByteReverse(((unsigned int*)&hash)[i]);251+252+ if (hash <= hashTarget)253 {254- if (pindexPrev == pindexBest)255+ pblock->nNonce = ByteReverse(tmp.block.nNonce);256+ assert(hash == pblock->GetHash());257+258+ //// debug print259+ printf("BitcoinMiner:\n");260+ printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());261+ pblock->print();262+ printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str());263+ printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());264+265+ SetThreadPriority(THREAD_PRIORITY_NORMAL);266+ CRITICAL_BLOCK(cs_main)267 {268- // Save key269- if (!AddKey(key))270- return;271- key.MakeNewKey();272-273- // Track how many getdata requests this block gets274- CRITICAL_BLOCK(cs_mapRequestCount)275- mapRequestCount[pblock->GetHash()] = 0;276-277- // Process this block the same as if we had received it from another node278- if (!ProcessBlock(NULL, pblock.release()))279- printf("ERROR in BitcoinMiner, ProcessBlock, block not accepted\n");280+ if (pindexPrev == pindexBest)281+ {282+ // Save key283+ if (!AddKey(key))284+ return;285+ key.MakeNewKey();286+287+ // Track how many getdata requests this block gets288+ CRITICAL_BLOCK(cs_mapRequestCount)289+ mapRequestCount[pblock->GetHash()] = 0;290+291+ // Process this block the same as if we had received it from another node292+ if (!ProcessBlock(NULL, pblock.release()))293+ printf("ERROR in BitcoinMiner, ProcessBlock, block not accepted\n");294+ }295 }296+ SetThreadPriority(THREAD_PRIORITY_LOWEST);297+298+ Sleep(500);299+ break;300 }301- SetThreadPriority(THREAD_PRIORITY_LOWEST);302-303- Sleep(500);304- break;305 }306 307 // Update nTime every few seconds308@@ -2796,27 +2798,10 @@309 if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)310 break;311 if (pindexPrev != pindexBest)312- {313- // Pause generating during initial download314- if (GetTime() - nStart < 20)315- {316- CBlockIndex* pindexTmp;317- do318- {319- pindexTmp = pindexBest;320- for (int i = 0; i < 10; i++)321- {322- Sleep(1000);323- if (fShutdown)324- return;325- }326- }327- while (pindexTmp != pindexBest);328- }329 break;330- }331-332- tmp.block.nTime = pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());333+334+ pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());335+ tmp.block.nTime = ByteReverse(pblock->nTime);336 }337 }338 }
makefile.mingw (modified)
1--- v0.3.3/makefile.mingw2+++ v0.3.6/makefile.mingw3@@ -2,8 +2,6 @@4 # Distributed under the MIT/X11 software license, see the accompanying5 # file license.txt or http://www.opensource.org/licenses/mit-license.php.6 7-8-# for wxWidgets-2.8.x, search and replace "mswud"->"mswd" and "29u"->"28"9 10 INCLUDEPATHS= \11 -I"/boost" \12@@ -22,32 +20,19 @@13 -l wxmsw29ud_html -l wxmsw29ud_core -l wxmsw29ud_adv -l wxbase29ud -l wxtiffd -l wxjpegd -l wxpngd -l wxzlibd14 15 LIBS= \16- -l libboost_system-mgw34-mt-d -l libboost_filesystem-mgw34-mt-d -l libboost_program_options-mgw34-mt-d \17+ -l libboost_system-mgw34-mt-d \18+ -l libboost_filesystem-mgw34-mt-d \19+ -l libboost_program_options-mgw34-mt-d \20+ -l libboost_thread-mgw34-mt-d \21 -l db_cxx \22 -l eay32 \23 -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell32 -l comctl32 -l ole32 -l oleaut32 -l uuid -l rpcrt4 -l advapi32 -l ws2_32 -l shlwapi24 25-WXDEFS=-DWIN32 -D__WXMSW__ -D_WINDOWS -DNOPCH26+DEFS=-DWIN32 -D__WXMSW__ -D_WINDOWS -DNOPCH27 DEBUGFLAGS=-g -D__WXDEBUG__28-CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)29+CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)30 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \31- script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h32-33-34-all: bitcoin.exe35-36-37-headers.h.gch: headers.h $(HEADERS)38- g++ -c $(CFLAGS) -o $@ $<39-40-obj/%.o: %.cpp $(HEADERS) headers.h.gch41- g++ -c $(CFLAGS) -o $@ $<42-43-obj/sha.o: sha.cpp sha.h44- g++ -c $(CFLAGS) -O3 -o $@ $<45-46-obj/ui_res.o: ui.rc rc/bitcoin.ico rc/check.ico rc/send16.bmp rc/send16mask.bmp rc/send16masknoshadow.bmp rc/send20.bmp rc/send20mask.bmp rc/addressbook16.bmp rc/addressbook16mask.bmp rc/addressbook20.bmp rc/addressbook20mask.bmp47- windres $(WXDEFS) $(INCLUDEPATHS) -o $@ -i $<48+ script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h noui.h init.h49 50 OBJS= \51 obj/util.o \52@@ -57,21 +42,37 @@53 obj/irc.o \54 obj/main.o \55 obj/rpc.o \56- obj/init.o57+ obj/init.o \58+ cryptopp/obj/sha.o \59+ cryptopp/obj/cpu.o60 61-bitcoin.exe: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o obj/ui_res.o62+63+all: bitcoin.exe64+65+66+obj/%.o: %.cpp $(HEADERS)67+ g++ -c $(CFLAGS) -DGUI -o $@ $<68+69+cryptopp/obj/%.o: cryptopp/%.cpp70+ g++ -c $(CFLAGS) -O3 -DCRYPTOPP_X86_ASM_AVAILABLE -DCRYPTOPP_DISABLE_SSE2 -o $@ $<71+72+obj/ui_res.o: ui.rc rc/bitcoin.ico rc/check.ico rc/send16.bmp rc/send16mask.bmp rc/send16masknoshadow.bmp rc/send20.bmp rc/send20mask.bmp rc/addressbook16.bmp rc/addressbook16mask.bmp rc/addressbook20.bmp rc/addressbook20mask.bmp73+ windres $(DEFS) $(INCLUDEPATHS) -o $@ -i $<74+75+bitcoin.exe: $(OBJS) obj/ui.o obj/uibase.o obj/ui_res.o76 g++ $(CFLAGS) -mwindows -Wl,--subsystem,windows -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)77 78 79 obj/nogui/%.o: %.cpp $(HEADERS)80- g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<81+ g++ -c $(CFLAGS) -o $@ $<82 83-bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) obj/sha.o obj/ui_res.o84- g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -l wxbase29ud $(LIBS)85+bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) obj/ui_res.o86+ g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)87 88 89 clean:90 -del /Q obj\*91 -del /Q obj\nogui\*92+ -del /Q cryptopp\obj\*93 -del /Q headers.h.gch94
makefile.osx (modified)
1--- v0.3.3/makefile.osx2+++ v0.3.6/makefile.osx3@@ -20,25 +20,16 @@4 $(DEPSDIR)/lib/libboost_system.a \5 $(DEPSDIR)/lib/libboost_filesystem.a \6 $(DEPSDIR)/lib/libboost_program_options.a \7+ $(DEPSDIR)/lib/libboost_thread.a \8 $(DEPSDIR)/lib/libcrypto.a 9 10-WXDEFS=$(shell $(DEPSDIR)/bin/wx-config --cxxflags) -DNOPCH -DMSG_NOSIGNAL=011+DEFS=$(shell $(DEPSDIR)/bin/wx-config --cxxflags) -D__WXMAC_OSX__ -DNOPCH -DMSG_NOSIGNAL=012 13 DEBUGFLAGS=-g -DwxDEBUG_LEVEL=014 # ppc doesn't work because we don't support big-endian15-CFLAGS=-mmacosx-version-min=10.5 -arch i386 -arch x86_64 -O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)16+CFLAGS=-mmacosx-version-min=10.5 -arch i386 -arch x86_64 -O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)17 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \18- script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h19-20-21-all: bitcoin22-23-24-obj/%.o: %.cpp $(HEADERS)25- g++ -c $(CFLAGS) -o $@ $<26-27-obj/sha.o: sha.cpp sha.h28- g++ -c $(CFLAGS) -O3 -o $@ $<29+ script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h noui.h init.h30 31 OBJS= \32 obj/util.o \33@@ -48,17 +39,29 @@34 obj/irc.o \35 obj/main.o \36 obj/rpc.o \37- obj/init.o38+ obj/init.o \39+ cryptopp/obj/sha.o \40+ cryptopp/obj/cpu.o41 42-bitcoin: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o43+44+all: bitcoin45+46+47+obj/%.o: %.cpp $(HEADERS)48+ g++ -c $(CFLAGS) -DGUI -o $@ $<49+50+cryptopp/obj/%.o: cryptopp/%.cpp51+ g++ -c $(CFLAGS) -O3 -DCRYPTOPP_DISABLE_ASM -o $@ $<52+53+bitcoin: $(OBJS) obj/ui.o obj/uibase.o54 g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)55 56 57 obj/nogui/%.o: %.cpp $(HEADERS)58- g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<59+ g++ -c $(CFLAGS) -o $@ $<60 61-bitcoind: $(OBJS:obj/%=obj/nogui/%) obj/sha.o62- g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)63+bitcoind: $(OBJS:obj/%=obj/nogui/%)64+ g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)65 66 67 clean:
makefile.unix (modified)
1--- v0.3.3/makefile.unix2+++ v0.3.6/makefile.unix3@@ -1,7 +1,6 @@4 # Copyright (c) 2009-2010 Satoshi Nakamoto5 # Distributed under the MIT/X11 software license, see the accompanying6 # file license.txt or http://www.opensource.org/licenses/mit-license.php.7-8 9 10 INCLUDEPATHS= \11@@ -21,30 +20,20 @@12 13 LIBS= \14 -Wl,-Bstatic \15- -l boost_system -l boost_filesystem -l boost_program_options \16+ -l boost_system \17+ -l boost_filesystem \18+ -l boost_program_options \19+ -l boost_thread \20 -l db_cxx \21 -l crypto \22 -Wl,-Bdynamic \23 -l gthread-2.024 25-WXDEFS=-D__WXGTK__ -DNOPCH26+DEFS=-D__WXGTK__ -DNOPCH27 DEBUGFLAGS=-g -D__WXDEBUG__28-CFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)29+CFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)30 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \31- script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h32-33-34-all: bitcoin35-36-37-headers.h.gch: headers.h $(HEADERS)38- g++ -c $(CFLAGS) -o $@ $<39-40-obj/%.o: %.cpp $(HEADERS) headers.h.gch41- g++ -c $(CFLAGS) -o $@ $<42-43-obj/sha.o: sha.cpp sha.h44- g++ -c $(CFLAGS) -O3 -o $@ $<45+ script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h noui.h init.h46 47 OBJS= \48 obj/util.o \49@@ -54,21 +43,37 @@50 obj/irc.o \51 obj/main.o \52 obj/rpc.o \53- obj/init.o54+ obj/init.o \55+ cryptopp/obj/sha.o \56+ cryptopp/obj/cpu.o57 58-bitcoin: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o59+60+all: bitcoin61+62+63+headers.h.gch: headers.h $(HEADERS)64+ g++ -c $(CFLAGS) -DGUI -o $@ $<65+66+obj/%.o: %.cpp $(HEADERS) headers.h.gch67+ g++ -c $(CFLAGS) -DGUI -o $@ $<68+69+cryptopp/obj/%.o: cryptopp/%.cpp70+ g++ -c $(CFLAGS) -O3 -DCRYPTOPP_DISABLE_SSE2 -o $@ $<71+72+bitcoin: $(OBJS) obj/ui.o obj/uibase.o73 g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)74 75 76 obj/nogui/%.o: %.cpp $(HEADERS)77- g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<78+ g++ -c $(CFLAGS) -o $@ $<79 80-bitcoind: $(OBJS:obj/%=obj/nogui/%) obj/sha.o81- g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -l wx_baseud-2.9 $(LIBS)82+bitcoind: $(OBJS:obj/%=obj/nogui/%)83+ g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)84 85 86 clean:87 -rm -f obj/*.o88 -rm -f obj/nogui/*.o89+ -rm -f cryptopp/obj/*.o90 -rm -f headers.h.gch91
makefile.vc (modified)
1--- v0.3.3/makefile.vc2+++ v0.3.6/makefile.vc3@@ -2,8 +2,6 @@4 # Distributed under the MIT/X11 software license, see the accompanying5 # file license.txt or http://www.opensource.org/licenses/mit-license.php.6 7-8-# for wxWidgets-2.8.x, search and replace "mswud"->"mswd" and "29u"->"28"9 10 INCLUDEPATHS= \11 /I"/boost" \12@@ -18,25 +16,41 @@13 /LIBPATH:"/openssl/out" \14 /LIBPATH:"/wxwidgets/lib/vc_lib"15 16+WXLIBS=wxmsw29ud_html.lib wxmsw29ud_core.lib wxmsw29ud_adv.lib wxbase29ud.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib17+18 LIBS= \19- libboost_system-vc80-mt-gd.lib libboost_filesystem-vc80-mt-gd.lib libboost_program_options-vc80-mt-gd.lib \20+ libboost_system-vc80-mt-gd.lib \21+ libboost_filesystem-vc80-mt-gd.lib \22+ libboost_program_options-vc80-mt-gd.lib \23+ libboost_thread-vc80-mt-gd.lib \24 libdb47sd.lib \25 libeay32.lib \26- wxmsw29ud_html.lib wxmsw29ud_core.lib wxmsw29ud_adv.lib wxbase29ud.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib \27 kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib ws2_32.lib shlwapi.lib28 29-WXDEFS=/DWIN32 /D__WXMSW__ /D_WINDOWS /DNOPCH30-DEBUGFLAGS=/Zi /Od /D__WXDEBUG__31-CFLAGS=/c /nologo /Ob0 /MDd /EHsc /GR /Zm300 $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)32+DEFS=/DWIN32 /D__WXMSW__ /D_WINDOWS /DNOPCH33+DEBUGFLAGS=/Zi /D__WXDEBUG__34+CFLAGS=/c /nologo /MDd /EHsc /GR /Zm300 $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)35 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \36- script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h37+ script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h noui.h init.h38+39+OBJS= \40+ obj\util.obj \41+ obj\script.obj \42+ obj\db.obj \43+ obj\net.obj \44+ obj\irc.obj \45+ obj\main.obj \46+ obj\rpc.obj \47+ obj\init.obj \48+ cryptopp\obj\sha.obj \49+ cryptopp\obj\cpu.obj50 51 52 all: bitcoin.exe53 54 55 .cpp{obj}.obj:56- cl $(CFLAGS) /Fo$@ %s57+ cl $(CFLAGS) /DGUI /Fo$@ %s58 59 obj\util.obj: $(HEADERS)60 61@@ -58,28 +72,21 @@62 63 obj\uibase.obj: $(HEADERS)64 65-obj\sha.obj: sha.cpp sha.h66- cl $(CFLAGS) /O2 /Fo$@ %s67+cryptopp\obj\sha.obj: cryptopp\sha.cpp68+ cl $(CFLAGS) /O2 /DCRYPTOPP_DISABLE_ASM /Fo$@ %s69+70+cryptopp\obj\cpu.obj: cryptopp\cpu.cpp71+ cl $(CFLAGS) /O2 /DCRYPTOPP_DISABLE_ASM /Fo$@ %s72 73 obj\ui.res: ui.rc rc/bitcoin.ico rc/check.ico rc/send16.bmp rc/send16mask.bmp rc/send16masknoshadow.bmp rc/send20.bmp rc/send20mask.bmp rc/addressbook16.bmp rc/addressbook16mask.bmp rc/addressbook20.bmp rc/addressbook20mask.bmp74- rc $(INCLUDEPATHS) $(WXDEFS) /Fo$@ %s75+ rc $(INCLUDEPATHS) $(DEFS) /Fo$@ %s76 77-OBJS= \78- obj\util.obj \79- obj\script.obj \80- obj\db.obj \81- obj\net.obj \82- obj\irc.obj \83- obj\main.obj \84- obj\rpc.obj \85- obj\init.obj86-87-bitcoin.exe: $(OBJS) obj\ui.obj obj\uibase.obj obj\sha.obj obj\ui.res88- link /nologo /DEBUG /SUBSYSTEM:WINDOWS /OUT:$@ $(LIBPATHS) $** $(LIBS)89+bitcoin.exe: $(OBJS) obj\ui.obj obj\uibase.obj obj\ui.res90+ link /nologo /DEBUG /SUBSYSTEM:WINDOWS /OUT:$@ $(LIBPATHS) $** $(WXLIBS) $(LIBS)91 92 93 .cpp{obj\nogui}.obj:94- cl $(CFLAGS) /DwxUSE_GUI=0 /Fo$@ %s95+ cl $(CFLAGS) /Fo$@ %s96 97 obj\nogui\util.obj: $(HEADERS)98 99@@ -97,12 +104,14 @@100 101 obj\nogui\init.obj: $(HEADERS)102 103-bitcoind.exe: $(OBJS:obj\=obj\nogui\) obj\sha.obj obj\ui.res104+bitcoind.exe: $(OBJS:obj\=obj\nogui\) obj\ui.res105 link /nologo /DEBUG /OUT:$@ $(LIBPATHS) $** $(LIBS)106 107 108 clean:109 -del /Q obj\*110- -del *.ilk111- -del *.pdb112+ -del /Q obj\nogui\*113+ -del /Q cryptopp\obj\*114+ -del /Q *.ilk115+ -del /Q *.pdb116
net.cpp (modified)
1--- v0.3.3/net.cpp2+++ v0.3.6/net.cpp3@@ -64,7 +64,7 @@4 SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);5 if (hSocket == INVALID_SOCKET)6 return false;7-#if defined(__BSD__) || defined(__WXOSX__)8+#if defined(__BSD__) || defined(__WXMAC_OSX__)9 int set = 1;10 setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));11 #endif12@@ -1163,7 +1163,7 @@13 return false;14 }15 16-#if defined(__BSD__) || defined(__WXOSX__)17+#if defined(__BSD__) || defined(__WXMAC_OSX__)18 // Different way of disabling SIGPIPE on BSD19 setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));20 #endif
noui.h (added)
1--- /dev/null2+++ v0.3.6/noui.h3@@ -1 +1,35 @@4+// Copyright (c) 2010 Satoshi Nakamoto5+// Distributed under the MIT/X11 software license, see the accompanying6+// file license.txt or http://www.opensource.org/licenses/mit-license.php.7 8+9+inline int MyMessageBox(const string& message, const string& caption="Message", int style=4, void* parent=NULL, int x=-1, int y=-1)10+{11+ printf("%s: %s\n", caption.c_str(), message.c_str());12+ fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());13+ return 4;14+}15+#define wxMessageBox MyMessageBox16+17+inline int ThreadSafeMessageBox(const string& message, const string& caption, int style, void* parent, int x, int y)18+{19+ return MyMessageBox(message, caption, style, parent, x, y);20+}21+22+inline bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, void* parent)23+{24+ return true;25+}26+27+inline void CalledSetStatusBar(const string& strText, int nField)28+{29+}30+31+inline void UIThreadCall(boost::function0<void> fn)32+{33+}34+35+inline void MainFrameRepaint()36+{37+}38+
rpc.cpp (modified)
1--- v0.3.3/rpc.cpp2+++ v0.3.6/rpc.cpp3@@ -36,7 +36,7 @@4 ret = limit - 1;5 buffer[limit-1] = 0;6 }7-#if defined(__WXMSW__) && wxUSE_GUI8+#if defined(__WXMSW__) && defined(GUI)9 MyMessageBox(buffer, "Bitcoin", wxOK | wxICON_EXCLAMATION);10 #else11 fprintf(stdout, "%s", buffer);12@@ -765,13 +765,14 @@13 BUF_MEM *bptr;14 15 b64 = BIO_new(BIO_f_base64());16+ BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);17 bmem = BIO_new(BIO_s_mem());18 b64 = BIO_push(b64, bmem);19 BIO_write(b64, s.c_str(), s.size());20 BIO_flush(b64);21 BIO_get_mem_ptr(b64, &bptr);22 23- string result(bptr->data, bptr->length-1);24+ string result(bptr->data, bptr->length);25 BIO_free_all(b64);26 27 return result;28@@ -1110,7 +1111,7 @@29 string strResult = (result.type() == str_type ? result.get_str() : write_string(result, true));30 if (result.type() != null_type)31 {32-#if defined(__WXMSW__) && wxUSE_GUI33+#if defined(__WXMSW__) && defined(GUI)34 // Windows GUI apps can't print to command line,35 // so settle for a message box yuck36 MyMessageBox(strResult.c_str(), "Bitcoin", wxOK);37@@ -1121,7 +1122,7 @@38 return 0;39 }40 catch (std::exception& e) {41-#if defined(__WXMSW__) && wxUSE_GUI42+#if defined(__WXMSW__) && defined(GUI)43 MyMessageBox(strprintf("error: %s\n", e.what()).c_str(), "Bitcoin", wxOK);44 #else45 fprintf(stderr, "error: %s\n", e.what());
script.cpp (modified)
1--- v0.3.3/script.cpp2+++ v0.3.6/script.cpp3@@ -16,6 +16,7 @@4 static const CBigNum bnOne(1);5 static const CBigNum bnFalse(0);6 static const CBigNum bnTrue(1);7+static const size_t nMaxNumSize = 258;8 9 10 bool CastToBool(const valtype& vch)11@@ -53,752 +54,779 @@12 vector<valtype> altstack;13 if (pvStackRet)14 pvStackRet->clear();15-16-17- while (pc < pend)18+ if (script.size() > 20000)19+ return false;20+21+22+ try23 {24- bool fExec = !count(vfExec.begin(), vfExec.end(), false);25-26- //27- // Read instruction28- //29- opcodetype opcode;30- valtype vchPushValue;31- if (!script.GetOp(pc, opcode, vchPushValue))32- return false;33-34- if (fExec && opcode <= OP_PUSHDATA4)35- stack.push_back(vchPushValue);36- else if (fExec || (OP_IF <= opcode && opcode <= OP_ENDIF))37- switch (opcode)38+ while (pc < pend)39 {40+ bool fExec = !count(vfExec.begin(), vfExec.end(), false);41+42 //43- // Push value44+ // Read instruction45 //46- case OP_1NEGATE:47- case OP_1:48- case OP_2:49- case OP_3:50- case OP_4:51- case OP_5:52- case OP_6:53- case OP_7:54- case OP_8:55- case OP_9:56- case OP_10:57- case OP_11:58- case OP_12:59- case OP_13:60- case OP_14:61- case OP_15:62- case OP_16:63+ opcodetype opcode;64+ valtype vchPushValue;65+ if (!script.GetOp(pc, opcode, vchPushValue))66+ return false;67+ if (vchPushValue.size() > 5000)68+ return false;69+70+ if (fExec && opcode <= OP_PUSHDATA4)71+ stack.push_back(vchPushValue);72+ else if (fExec || (OP_IF <= opcode && opcode <= OP_ENDIF))73+ switch (opcode)74 {75- // ( -- value)76- CBigNum bn((int)opcode - (int)(OP_1 - 1));77- stack.push_back(bn.getvch());78- }79- break;80-81-82- //83- // Control84- //85- case OP_NOP:86- break;87-88- case OP_VER:89- {90- CBigNum bn(VERSION);91- stack.push_back(bn.getvch());92- }93- break;94-95- case OP_IF:96- case OP_NOTIF:97- case OP_VERIF:98- case OP_VERNOTIF:99- {100- // <expression> if [statements] [else [statements]] endif101- bool fValue = false;102- if (fExec)103- {104+ //105+ // Push value106+ //107+ case OP_1NEGATE:108+ case OP_1:109+ case OP_2:110+ case OP_3:111+ case OP_4:112+ case OP_5:113+ case OP_6:114+ case OP_7:115+ case OP_8:116+ case OP_9:117+ case OP_10:118+ case OP_11:119+ case OP_12:120+ case OP_13:121+ case OP_14:122+ case OP_15:123+ case OP_16:124+ {125+ // ( -- value)126+ CBigNum bn((int)opcode - (int)(OP_1 - 1));127+ stack.push_back(bn.getvch());128+ }129+ break;130+131+132+ //133+ // Control134+ //135+ case OP_NOP:136+ case OP_NOP1: case OP_NOP2: case OP_NOP3: case OP_NOP4: case OP_NOP5:137+ case OP_NOP6: case OP_NOP7: case OP_NOP8: case OP_NOP9: case OP_NOP10:138+ break;139+140+ case OP_VER:141+ case OP_VERIF:142+ case OP_VERNOTIF:143+ {144+ return false;145+ }146+ break;147+148+ case OP_IF:149+ case OP_NOTIF:150+ {151+ // <expression> if [statements] [else [statements]] endif152+ bool fValue = false;153+ if (fExec)154+ {155+ if (stack.size() < 1)156+ return false;157+ valtype& vch = stacktop(-1);158+ fValue = CastToBool(vch);159+ if (opcode == OP_NOTIF)160+ fValue = !fValue;161+ stack.pop_back();162+ }163+ vfExec.push_back(fValue);164+ }165+ break;166+167+ case OP_ELSE:168+ {169+ if (vfExec.empty())170+ return false;171+ vfExec.back() = !vfExec.back();172+ }173+ break;174+175+ case OP_ENDIF:176+ {177+ if (vfExec.empty())178+ return false;179+ vfExec.pop_back();180+ }181+ break;182+183+ case OP_VERIFY:184+ {185+ // (true -- ) or186+ // (false -- false) and return187 if (stack.size() < 1)188 return false;189- valtype& vch = stacktop(-1);190- if (opcode == OP_VERIF || opcode == OP_VERNOTIF)191- fValue = (CBigNum(VERSION) >= CBigNum(vch));192- else193- fValue = CastToBool(vch);194- if (opcode == OP_NOTIF || opcode == OP_VERNOTIF)195- fValue = !fValue;196- stack.pop_back();197- }198- vfExec.push_back(fValue);199- }200- break;201-202- case OP_ELSE:203- {204- if (vfExec.empty())205- return false;206- vfExec.back() = !vfExec.back();207- }208- break;209-210- case OP_ENDIF:211- {212- if (vfExec.empty())213- return false;214- vfExec.pop_back();215- }216- break;217-218- case OP_VERIFY:219- {220- // (true -- ) or221- // (false -- false) and return222- if (stack.size() < 1)223- return false;224- bool fValue = CastToBool(stacktop(-1));225- if (fValue)226- stack.pop_back();227- else228- pc = pend;229- }230- break;231-232- case OP_RETURN:233- {234- pc = pend;235- }236- break;237-238-239- //240- // Stack ops241- //242- case OP_TOALTSTACK:243- {244- if (stack.size() < 1)245- return false;246- altstack.push_back(stacktop(-1));247- stack.pop_back();248- }249- break;250-251- case OP_FROMALTSTACK:252- {253- if (altstack.size() < 1)254- return false;255- stack.push_back(altstacktop(-1));256- altstack.pop_back();257- }258- break;259-260- case OP_2DROP:261- {262- // (x1 x2 -- )263- stack.pop_back();264- stack.pop_back();265- }266- break;267-268- case OP_2DUP:269- {270- // (x1 x2 -- x1 x2 x1 x2)271- if (stack.size() < 2)272- return false;273- valtype vch1 = stacktop(-2);274- valtype vch2 = stacktop(-1);275- stack.push_back(vch1);276- stack.push_back(vch2);277- }278- break;279-280- case OP_3DUP:281- {282- // (x1 x2 x3 -- x1 x2 x3 x1 x2 x3)283- if (stack.size() < 3)284- return false;285- valtype vch1 = stacktop(-3);286- valtype vch2 = stacktop(-2);287- valtype vch3 = stacktop(-1);288- stack.push_back(vch1);289- stack.push_back(vch2);290- stack.push_back(vch3);291- }292- break;293-294- case OP_2OVER:295- {296- // (x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2)297- if (stack.size() < 4)298- return false;299- valtype vch1 = stacktop(-4);300- valtype vch2 = stacktop(-3);301- stack.push_back(vch1);302- stack.push_back(vch2);303- }304- break;305-306- case OP_2ROT:307- {308- // (x1 x2 x3 x4 x5 x6 -- x3 x4 x5 x6 x1 x2)309- if (stack.size() < 6)310- return false;311- valtype vch1 = stacktop(-6);312- valtype vch2 = stacktop(-5);313- stack.erase(stack.end()-6, stack.end()-4);314- stack.push_back(vch1);315- stack.push_back(vch2);316- }317- break;318-319- case OP_2SWAP:320- {321- // (x1 x2 x3 x4 -- x3 x4 x1 x2)322- if (stack.size() < 4)323- return false;324- swap(stacktop(-4), stacktop(-2));325- swap(stacktop(-3), stacktop(-1));326- }327- break;328-329- case OP_IFDUP:330- {331- // (x - 0 | x x)332- if (stack.size() < 1)333- return false;334- valtype vch = stacktop(-1);335- if (CastToBool(vch))336- stack.push_back(vch);337- }338- break;339-340- case OP_DEPTH:341- {342- // -- stacksize343- CBigNum bn(stack.size());344- stack.push_back(bn.getvch());345- }346- break;347-348- case OP_DROP:349- {350- // (x -- )351- if (stack.size() < 1)352- return false;353- stack.pop_back();354- }355- break;356-357- case OP_DUP:358- {359- // (x -- x x)360- if (stack.size() < 1)361- return false;362- valtype vch = stacktop(-1);363- stack.push_back(vch);364- }365- break;366-367- case OP_NIP:368- {369- // (x1 x2 -- x2)370- if (stack.size() < 2)371- return false;372- stack.erase(stack.end() - 2);373- }374- break;375-376- case OP_OVER:377- {378- // (x1 x2 -- x1 x2 x1)379- if (stack.size() < 2)380- return false;381- valtype vch = stacktop(-2);382- stack.push_back(vch);383- }384- break;385-386- case OP_PICK:387- case OP_ROLL:388- {389- // (xn ... x2 x1 x0 n - xn ... x2 x1 x0 xn)390- // (xn ... x2 x1 x0 n - ... x2 x1 x0 xn)391- if (stack.size() < 2)392- return false;393- int n = CBigNum(stacktop(-1)).getint();394- stack.pop_back();395- if (n < 0 || n >= stack.size())396- return false;397- valtype vch = stacktop(-n-1);398- if (opcode == OP_ROLL)399- stack.erase(stack.end()-n-1);400- stack.push_back(vch);401- }402- break;403-404- case OP_ROT:405- {406- // (x1 x2 x3 -- x2 x3 x1)407- // x2 x1 x3 after first swap408- // x2 x3 x1 after second swap409- if (stack.size() < 3)410- return false;411- swap(stacktop(-3), stacktop(-2));412- swap(stacktop(-2), stacktop(-1));413- }414- break;415-416- case OP_SWAP:417- {418- // (x1 x2 -- x2 x1)419- if (stack.size() < 2)420- return false;421- swap(stacktop(-2), stacktop(-1));422- }423- break;424-425- case OP_TUCK:426- {427- // (x1 x2 -- x2 x1 x2)428- if (stack.size() < 2)429- return false;430- valtype vch = stacktop(-1);431- stack.insert(stack.end()-2, vch);432- }433- break;434-435-436- //437- // Splice ops438- //439- case OP_CAT:440- {441- // (x1 x2 -- out)442- if (stack.size() < 2)443- return false;444- valtype& vch1 = stacktop(-2);445- valtype& vch2 = stacktop(-1);446- vch1.insert(vch1.end(), vch2.begin(), vch2.end());447- stack.pop_back();448- }449- break;450-451- case OP_SUBSTR:452- {453- // (in begin size -- out)454- if (stack.size() < 3)455- return false;456- valtype& vch = stacktop(-3);457- int nBegin = CBigNum(stacktop(-2)).getint();458- int nEnd = nBegin + CBigNum(stacktop(-1)).getint();459- if (nBegin < 0 || nEnd < nBegin)460- return false;461- if (nBegin > vch.size())462- nBegin = vch.size();463- if (nEnd > vch.size())464- nEnd = vch.size();465- vch.erase(vch.begin() + nEnd, vch.end());466- vch.erase(vch.begin(), vch.begin() + nBegin);467- stack.pop_back();468- stack.pop_back();469- }470- break;471-472- case OP_LEFT:473- case OP_RIGHT:474- {475- // (in size -- out)476- if (stack.size() < 2)477- return false;478- valtype& vch = stacktop(-2);479- int nSize = CBigNum(stacktop(-1)).getint();480- if (nSize < 0)481- return false;482- if (nSize > vch.size())483- nSize = vch.size();484- if (opcode == OP_LEFT)485- vch.erase(vch.begin() + nSize, vch.end());486- else487- vch.erase(vch.begin(), vch.end() - nSize);488- stack.pop_back();489- }490- break;491-492- case OP_SIZE:493- {494- // (in -- in size)495- if (stack.size() < 1)496- return false;497- CBigNum bn(stacktop(-1).size());498- stack.push_back(bn.getvch());499- }500- break;501-502-503- //504- // Bitwise logic505- //506- case OP_INVERT:507- {508- // (in - out)509- if (stack.size() < 1)510- return false;511- valtype& vch = stacktop(-1);512- for (int i = 0; i < vch.size(); i++)513- vch[i] = ~vch[i];514- }515- break;516-517- case OP_AND:518- case OP_OR:519- case OP_XOR:520- {521- // (x1 x2 - out)522- if (stack.size() < 2)523- return false;524- valtype& vch1 = stacktop(-2);525- valtype& vch2 = stacktop(-1);526- MakeSameSize(vch1, vch2);527- if (opcode == OP_AND)528- {529- for (int i = 0; i < vch1.size(); i++)530- vch1[i] &= vch2[i];531- }532- else if (opcode == OP_OR)533- {534- for (int i = 0; i < vch1.size(); i++)535- vch1[i] |= vch2[i];536- }537- else if (opcode == OP_XOR)538- {539- for (int i = 0; i < vch1.size(); i++)540- vch1[i] ^= vch2[i];541- }542- stack.pop_back();543- }544- break;545-546- case OP_EQUAL:547- case OP_EQUALVERIFY:548- //case OP_NOTEQUAL: // use OP_NUMNOTEQUAL549- {550- // (x1 x2 - bool)551- if (stack.size() < 2)552- return false;553- valtype& vch1 = stacktop(-2);554- valtype& vch2 = stacktop(-1);555- bool fEqual = (vch1 == vch2);556- // OP_NOTEQUAL is disabled because it would be too easy to say557- // something like n != 1 and have some wiseguy pass in 1 with extra558- // zero bytes after it (numerically, 0x01 == 0x0001 == 0x000001)559- //if (opcode == OP_NOTEQUAL)560- // fEqual = !fEqual;561- stack.pop_back();562- stack.pop_back();563- stack.push_back(fEqual ? vchTrue : vchFalse);564- if (opcode == OP_EQUALVERIFY)565- {566- if (fEqual)567+ bool fValue = CastToBool(stacktop(-1));568+ if (fValue)569 stack.pop_back();570 else571- pc = pend;572- }573+ return false;574+ }575+ break;576+577+ case OP_RETURN:578+ {579+ return false;580+ }581+ break;582+583+584+ //585+ // Stack ops586+ //587+ case OP_TOALTSTACK:588+ {589+ if (stack.size() < 1)590+ return false;591+ altstack.push_back(stacktop(-1));592+ stack.pop_back();593+ }594+ break;595+596+ case OP_FROMALTSTACK:597+ {598+ if (altstack.size() < 1)599+ return false;600+ stack.push_back(altstacktop(-1));601+ altstack.pop_back();602+ }603+ break;604+605+ case OP_2DROP:606+ {607+ // (x1 x2 -- )608+ stack.pop_back();609+ stack.pop_back();610+ }611+ break;612+613+ case OP_2DUP:614+ {615+ // (x1 x2 -- x1 x2 x1 x2)616+ if (stack.size() < 2)617+ return false;618+ valtype vch1 = stacktop(-2);619+ valtype vch2 = stacktop(-1);620+ stack.push_back(vch1);621+ stack.push_back(vch2);622+ }623+ break;624+625+ case OP_3DUP:626+ {627+ // (x1 x2 x3 -- x1 x2 x3 x1 x2 x3)628+ if (stack.size() < 3)629+ return false;630+ valtype vch1 = stacktop(-3);631+ valtype vch2 = stacktop(-2);632+ valtype vch3 = stacktop(-1);633+ stack.push_back(vch1);634+ stack.push_back(vch2);635+ stack.push_back(vch3);636+ }637+ break;638+639+ case OP_2OVER:640+ {641+ // (x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2)642+ if (stack.size() < 4)643+ return false;644+ valtype vch1 = stacktop(-4);645+ valtype vch2 = stacktop(-3);646+ stack.push_back(vch1);647+ stack.push_back(vch2);648+ }649+ break;650+651+ case OP_2ROT:652+ {653+ // (x1 x2 x3 x4 x5 x6 -- x3 x4 x5 x6 x1 x2)654+ if (stack.size() < 6)655+ return false;656+ valtype vch1 = stacktop(-6);657+ valtype vch2 = stacktop(-5);658+ stack.erase(stack.end()-6, stack.end()-4);659+ stack.push_back(vch1);660+ stack.push_back(vch2);661+ }662+ break;663+664+ case OP_2SWAP:665+ {666+ // (x1 x2 x3 x4 -- x3 x4 x1 x2)667+ if (stack.size() < 4)668+ return false;669+ swap(stacktop(-4), stacktop(-2));670+ swap(stacktop(-3), stacktop(-1));671+ }672+ break;673+674+ case OP_IFDUP:675+ {676+ // (x - 0 | x x)677+ if (stack.size() < 1)678+ return false;679+ valtype vch = stacktop(-1);680+ if (CastToBool(vch))681+ stack.push_back(vch);682+ }683+ break;684+685+ case OP_DEPTH:686+ {687+ // -- stacksize688+ CBigNum bn(stack.size());689+ stack.push_back(bn.getvch());690+ }691+ break;692+693+ case OP_DROP:694+ {695+ // (x -- )696+ if (stack.size() < 1)697+ return false;698+ stack.pop_back();699+ }700+ break;701+702+ case OP_DUP:703+ {704+ // (x -- x x)705+ if (stack.size() < 1)706+ return false;707+ valtype vch = stacktop(-1);708+ stack.push_back(vch);709+ }710+ break;711+712+ case OP_NIP:713+ {714+ // (x1 x2 -- x2)715+ if (stack.size() < 2)716+ return false;717+ stack.erase(stack.end() - 2);718+ }719+ break;720+721+ case OP_OVER:722+ {723+ // (x1 x2 -- x1 x2 x1)724+ if (stack.size() < 2)725+ return false;726+ valtype vch = stacktop(-2);727+ stack.push_back(vch);728+ }729+ break;730+731+ case OP_PICK:732+ case OP_ROLL:733+ {734+ // (xn ... x2 x1 x0 n - xn ... x2 x1 x0 xn)735+ // (xn ... x2 x1 x0 n - ... x2 x1 x0 xn)736+ if (stack.size() < 2)737+ return false;738+ int n = CBigNum(stacktop(-1)).getint();739+ stack.pop_back();740+ if (n < 0 || n >= stack.size())741+ return false;742+ valtype vch = stacktop(-n-1);743+ if (opcode == OP_ROLL)744+ stack.erase(stack.end()-n-1);745+ stack.push_back(vch);746+ }747+ break;748+749+ case OP_ROT:750+ {751+ // (x1 x2 x3 -- x2 x3 x1)752+ // x2 x1 x3 after first swap753+ // x2 x3 x1 after second swap754+ if (stack.size() < 3)755+ return false;756+ swap(stacktop(-3), stacktop(-2));757+ swap(stacktop(-2), stacktop(-1));758+ }759+ break;760+761+ case OP_SWAP:762+ {763+ // (x1 x2 -- x2 x1)764+ if (stack.size() < 2)765+ return false;766+ swap(stacktop(-2), stacktop(-1));767+ }768+ break;769+770+ case OP_TUCK:771+ {772+ // (x1 x2 -- x2 x1 x2)773+ if (stack.size() < 2)774+ return false;775+ valtype vch = stacktop(-1);776+ stack.insert(stack.end()-2, vch);777+ }778+ break;779+780+781+ //782+ // Splice ops783+ //784+ case OP_CAT:785+ {786+ // (x1 x2 -- out)787+ if (stack.size() < 2)788+ return false;789+ valtype& vch1 = stacktop(-2);790+ valtype& vch2 = stacktop(-1);791+ vch1.insert(vch1.end(), vch2.begin(), vch2.end());792+ stack.pop_back();793+ if (stacktop(-1).size() > 5000)794+ return false;795+ }796+ break;797+798+ case OP_SUBSTR:799+ {800+ // (in begin size -- out)801+ if (stack.size() < 3)802+ return false;803+ valtype& vch = stacktop(-3);804+ int nBegin = CBigNum(stacktop(-2)).getint();805+ int nEnd = nBegin + CBigNum(stacktop(-1)).getint();806+ if (nBegin < 0 || nEnd < nBegin)807+ return false;808+ if (nBegin > vch.size())809+ nBegin = vch.size();810+ if (nEnd > vch.size())811+ nEnd = vch.size();812+ vch.erase(vch.begin() + nEnd, vch.end());813+ vch.erase(vch.begin(), vch.begin() + nBegin);814+ stack.pop_back();815+ stack.pop_back();816+ }817+ break;818+819+ case OP_LEFT:820+ case OP_RIGHT:821+ {822+ // (in size -- out)823+ if (stack.size() < 2)824+ return false;825+ valtype& vch = stacktop(-2);826+ int nSize = CBigNum(stacktop(-1)).getint();827+ if (nSize < 0)828+ return false;829+ if (nSize > vch.size())830+ nSize = vch.size();831+ if (opcode == OP_LEFT)832+ vch.erase(vch.begin() + nSize, vch.end());833+ else834+ vch.erase(vch.begin(), vch.end() - nSize);835+ stack.pop_back();836+ }837+ break;838+839+ case OP_SIZE:840+ {841+ // (in -- in size)842+ if (stack.size() < 1)843+ return false;844+ CBigNum bn(stacktop(-1).size());845+ stack.push_back(bn.getvch());846+ }847+ break;848+849+850+ //851+ // Bitwise logic852+ //853+ case OP_INVERT:854+ {855+ // (in - out)856+ if (stack.size() < 1)857+ return false;858+ valtype& vch = stacktop(-1);859+ for (int i = 0; i < vch.size(); i++)860+ vch[i] = ~vch[i];861+ }862+ break;863+864+ case OP_AND:865+ case OP_OR:866+ case OP_XOR:867+ {868+ // (x1 x2 - out)869+ if (stack.size() < 2)870+ return false;871+ valtype& vch1 = stacktop(-2);872+ valtype& vch2 = stacktop(-1);873+ MakeSameSize(vch1, vch2);874+ if (opcode == OP_AND)875+ {876+ for (int i = 0; i < vch1.size(); i++)877+ vch1[i] &= vch2[i];878+ }879+ else if (opcode == OP_OR)880+ {881+ for (int i = 0; i < vch1.size(); i++)882+ vch1[i] |= vch2[i];883+ }884+ else if (opcode == OP_XOR)885+ {886+ for (int i = 0; i < vch1.size(); i++)887+ vch1[i] ^= vch2[i];888+ }889+ stack.pop_back();890+ }891+ break;892+893+ case OP_EQUAL:894+ case OP_EQUALVERIFY:895+ //case OP_NOTEQUAL: // use OP_NUMNOTEQUAL896+ {897+ // (x1 x2 - bool)898+ if (stack.size() < 2)899+ return false;900+ valtype& vch1 = stacktop(-2);901+ valtype& vch2 = stacktop(-1);902+ bool fEqual = (vch1 == vch2);903+ // OP_NOTEQUAL is disabled because it would be too easy to say904+ // something like n != 1 and have some wiseguy pass in 1 with extra905+ // zero bytes after it (numerically, 0x01 == 0x0001 == 0x000001)906+ //if (opcode == OP_NOTEQUAL)907+ // fEqual = !fEqual;908+ stack.pop_back();909+ stack.pop_back();910+ stack.push_back(fEqual ? vchTrue : vchFalse);911+ if (opcode == OP_EQUALVERIFY)912+ {913+ if (fEqual)914+ stack.pop_back();915+ else916+ return false;917+ }918+ }919+ break;920+921+922+ //923+ // Numeric924+ //925+ case OP_1ADD:926+ case OP_1SUB:927+ case OP_2MUL:928+ case OP_2DIV:929+ case OP_NEGATE:930+ case OP_ABS:931+ case OP_NOT:932+ case OP_0NOTEQUAL:933+ {934+ // (in -- out)935+ if (stack.size() < 1)936+ return false;937+ if (stacktop(-1).size() > nMaxNumSize)938+ return false;939+ CBigNum bn(stacktop(-1));940+ switch (opcode)941+ {942+ case OP_1ADD: bn += bnOne; break;943+ case OP_1SUB: bn -= bnOne; break;944+ case OP_2MUL: bn <<= 1; break;945+ case OP_2DIV: bn >>= 1; break;946+ case OP_NEGATE: bn = -bn; break;947+ case OP_ABS: if (bn < bnZero) bn = -bn; break;948+ case OP_NOT: bn = (bn == bnZero); break;949+ case OP_0NOTEQUAL: bn = (bn != bnZero); break;950+ }951+ stack.pop_back();952+ stack.push_back(bn.getvch());953+ }954+ break;955+956+ case OP_ADD:957+ case OP_SUB:958+ case OP_MUL:959+ case OP_DIV:960+ case OP_MOD:961+ case OP_LSHIFT:962+ case OP_RSHIFT:963+ case OP_BOOLAND:964+ case OP_BOOLOR:965+ case OP_NUMEQUAL:966+ case OP_NUMEQUALVERIFY:967+ case OP_NUMNOTEQUAL:968+ case OP_LESSTHAN:969+ case OP_GREATERTHAN:970+ case OP_LESSTHANOREQUAL:971+ case OP_GREATERTHANOREQUAL:972+ case OP_MIN:973+ case OP_MAX:974+ {975+ // (x1 x2 -- out)976+ if (stack.size() < 2)977+ return false;978+ if (stacktop(-2).size() > nMaxNumSize ||979+ stacktop(-1).size() > nMaxNumSize)980+ return false;981+ CBigNum bn1(stacktop(-2));982+ CBigNum bn2(stacktop(-1));983+ CBigNum bn;984+ switch (opcode)985+ {986+ case OP_ADD:987+ bn = bn1 + bn2;988+ break;989+990+ case OP_SUB:991+ bn = bn1 - bn2;992+ break;993+994+ case OP_MUL:995+ if (!BN_mul(&bn, &bn1, &bn2, pctx))996+ return false;997+ break;998+999+ case OP_DIV:1000+ if (!BN_div(&bn, NULL, &bn1, &bn2, pctx))1001+ return false;1002+ break;1003+1004+ case OP_MOD:1005+ if (!BN_mod(&bn, &bn1, &bn2, pctx))1006+ return false;1007+ break;1008+1009+ case OP_LSHIFT:1010+ if (bn2 < bnZero || bn2 > CBigNum(2048))1011+ return false;1012+ bn = bn1 << bn2.getulong();1013+ break;1014+1015+ case OP_RSHIFT:1016+ if (bn2 < bnZero || bn2 > CBigNum(2048))1017+ return false;1018+ bn = bn1 >> bn2.getulong();1019+ break;1020+1021+ case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero); break;1022+ case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero); break;1023+ case OP_NUMEQUAL: bn = (bn1 == bn2); break;1024+ case OP_NUMEQUALVERIFY: bn = (bn1 == bn2); break;1025+ case OP_NUMNOTEQUAL: bn = (bn1 != bn2); break;1026+ case OP_LESSTHAN: bn = (bn1 < bn2); break;1027+ case OP_GREATERTHAN: bn = (bn1 > bn2); break;1028+ case OP_LESSTHANOREQUAL: bn = (bn1 <= bn2); break;1029+ case OP_GREATERTHANOREQUAL: bn = (bn1 >= bn2); break;1030+ case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2); break;1031+ case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2); break;1032+ }1033+ stack.pop_back();1034+ stack.pop_back();1035+ stack.push_back(bn.getvch());1036+1037+ if (opcode == OP_NUMEQUALVERIFY)1038+ {1039+ if (CastToBool(stacktop(-1)))1040+ stack.pop_back();1041+ else1042+ return false;1043+ }1044+ }1045+ break;1046+1047+ case OP_WITHIN:1048+ {1049+ // (x min max -- out)1050+ if (stack.size() < 3)1051+ return false;1052+ if (stacktop(-3).size() > nMaxNumSize ||1053+ stacktop(-2).size() > nMaxNumSize ||1054+ stacktop(-1).size() > nMaxNumSize)1055+ return false;1056+ CBigNum bn1(stacktop(-3));1057+ CBigNum bn2(stacktop(-2));1058+ CBigNum bn3(stacktop(-1));1059+ bool fValue = (bn2 <= bn1 && bn1 < bn3);1060+ stack.pop_back();1061+ stack.pop_back();1062+ stack.pop_back();1063+ stack.push_back(fValue ? vchTrue : vchFalse);1064+ }1065+ break;1066+1067+1068+ //1069+ // Crypto1070+ //1071+ case OP_RIPEMD160:1072+ case OP_SHA1:1073+ case OP_SHA256:1074+ case OP_HASH160:1075+ case OP_HASH256:1076+ {1077+ // (in -- hash)1078+ if (stack.size() < 1)1079+ return false;1080+ valtype& vch = stacktop(-1);1081+ valtype vchHash((opcode == OP_RIPEMD160 || opcode == OP_SHA1 || opcode == OP_HASH160) ? 20 : 32);1082+ if (opcode == OP_RIPEMD160)1083+ RIPEMD160(&vch[0], vch.size(), &vchHash[0]);1084+ else if (opcode == OP_SHA1)1085+ SHA1(&vch[0], vch.size(), &vchHash[0]);1086+ else if (opcode == OP_SHA256)1087+ SHA256(&vch[0], vch.size(), &vchHash[0]);1088+ else if (opcode == OP_HASH160)1089+ {1090+ uint160 hash160 = Hash160(vch);1091+ memcpy(&vchHash[0], &hash160, sizeof(hash160));1092+ }1093+ else if (opcode == OP_HASH256)1094+ {1095+ uint256 hash = Hash(vch.begin(), vch.end());1096+ memcpy(&vchHash[0], &hash, sizeof(hash));1097+ }1098+ stack.pop_back();1099+ stack.push_back(vchHash);1100+ }1101+ break;1102+1103+ case OP_CODESEPARATOR:1104+ {1105+ // Hash starts after the code separator1106+ pbegincodehash = pc;1107+ }1108+ break;1109+1110+ case OP_CHECKSIG:1111+ case OP_CHECKSIGVERIFY:1112+ {1113+ // (sig pubkey -- bool)1114+ if (stack.size() < 2)1115+ return false;1116+1117+ valtype& vchSig = stacktop(-2);1118+ valtype& vchPubKey = stacktop(-1);1119+1120+ ////// debug print1121+ //PrintHex(vchSig.begin(), vchSig.end(), "sig: %s\n");1122+ //PrintHex(vchPubKey.begin(), vchPubKey.end(), "pubkey: %s\n");1123+1124+ // Subset of script starting at the most recent codeseparator1125+ CScript scriptCode(pbegincodehash, pend);1126+1127+ // Drop the signature, since there's no way for a signature to sign itself1128+ scriptCode.FindAndDelete(CScript(vchSig));1129+1130+ bool fSuccess = CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType);1131+1132+ stack.pop_back();1133+ stack.pop_back();1134+ stack.push_back(fSuccess ? vchTrue : vchFalse);1135+ if (opcode == OP_CHECKSIGVERIFY)1136+ {1137+ if (fSuccess)1138+ stack.pop_back();1139+ else1140+ return false;1141+ }1142+ }1143+ break;1144+1145+ case OP_CHECKMULTISIG:1146+ case OP_CHECKMULTISIGVERIFY:1147+ {1148+ // ([sig ...] num_of_signatures [pubkey ...] num_of_pubkeys -- bool)1149+1150+ int i = 1;1151+ if (stack.size() < i)1152+ return false;1153+1154+ int nKeysCount = CBigNum(stacktop(-i)).getint();1155+ if (nKeysCount < 0)1156+ return false;1157+ int ikey = ++i;1158+ i += nKeysCount;1159+ if (stack.size() < i)1160+ return false;1161+1162+ int nSigsCount = CBigNum(stacktop(-i)).getint();1163+ if (nSigsCount < 0 || nSigsCount > nKeysCount)1164+ return false;1165+ int isig = ++i;1166+ i += nSigsCount;1167+ if (stack.size() < i)1168+ return false;1169+1170+ // Subset of script starting at the most recent codeseparator1171+ CScript scriptCode(pbegincodehash, pend);1172+1173+ // Drop the signatures, since there's no way for a signature to sign itself1174+ for (int k = 0; k < nSigsCount; k++)1175+ {1176+ valtype& vchSig = stacktop(-isig-k);1177+ scriptCode.FindAndDelete(CScript(vchSig));1178+ }1179+1180+ bool fSuccess = true;1181+ while (fSuccess && nSigsCount > 0)1182+ {1183+ valtype& vchSig = stacktop(-isig);1184+ valtype& vchPubKey = stacktop(-ikey);1185+1186+ // Check signature1187+ if (CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType))1188+ {1189+ isig++;1190+ nSigsCount--;1191+ }1192+ ikey++;1193+ nKeysCount--;1194+1195+ // If there are more signatures left than keys left,1196+ // then too many signatures have failed1197+ if (nSigsCount > nKeysCount)1198+ fSuccess = false;1199+ }1200+1201+ while (i-- > 0)1202+ stack.pop_back();1203+ stack.push_back(fSuccess ? vchTrue : vchFalse);1204+1205+ if (opcode == OP_CHECKMULTISIGVERIFY)1206+ {1207+ if (fSuccess)1208+ stack.pop_back();1209+ else1210+ return false;1211+ }1212+ }1213+ break;1214+1215+ default:1216+ return false;1217 }1218- break;1219-1220-1221- //1222- // Numeric1223- //1224- case OP_1ADD:1225- case OP_1SUB:1226- case OP_2MUL:1227- case OP_2DIV:1228- case OP_NEGATE:1229- case OP_ABS:1230- case OP_NOT:1231- case OP_0NOTEQUAL:1232- {1233- // (in -- out)1234- if (stack.size() < 1)1235- return false;1236- CBigNum bn(stacktop(-1));1237- switch (opcode)1238- {1239- case OP_1ADD: bn += bnOne; break;1240- case OP_1SUB: bn -= bnOne; break;1241- case OP_2MUL: bn <<= 1; break;1242- case OP_2DIV: bn >>= 1; break;1243- case OP_NEGATE: bn = -bn; break;1244- case OP_ABS: if (bn < bnZero) bn = -bn; break;1245- case OP_NOT: bn = (bn == bnZero); break;1246- case OP_0NOTEQUAL: bn = (bn != bnZero); break;1247- }1248- stack.pop_back();1249- stack.push_back(bn.getvch());1250- }1251- break;1252-1253- case OP_ADD:1254- case OP_SUB:1255- case OP_MUL:1256- case OP_DIV:1257- case OP_MOD:1258- case OP_LSHIFT:1259- case OP_RSHIFT:1260- case OP_BOOLAND:1261- case OP_BOOLOR:1262- case OP_NUMEQUAL:1263- case OP_NUMEQUALVERIFY:1264- case OP_NUMNOTEQUAL:1265- case OP_LESSTHAN:1266- case OP_GREATERTHAN:1267- case OP_LESSTHANOREQUAL:1268- case OP_GREATERTHANOREQUAL:1269- case OP_MIN:1270- case OP_MAX:1271- {1272- // (x1 x2 -- out)1273- if (stack.size() < 2)1274- return false;1275- CBigNum bn1(stacktop(-2));1276- CBigNum bn2(stacktop(-1));1277- CBigNum bn;1278- switch (opcode)1279- {1280- case OP_ADD:1281- bn = bn1 + bn2;1282- break;1283-1284- case OP_SUB:1285- bn = bn1 - bn2;1286- break;1287-1288- case OP_MUL:1289- if (!BN_mul(&bn, &bn1, &bn2, pctx))1290- return false;1291- break;1292-1293- case OP_DIV:1294- if (!BN_div(&bn, NULL, &bn1, &bn2, pctx))1295- return false;1296- break;1297-1298- case OP_MOD:1299- if (!BN_mod(&bn, &bn1, &bn2, pctx))1300- return false;1301- break;1302-1303- case OP_LSHIFT:1304- if (bn2 < bnZero)1305- return false;1306- bn = bn1 << bn2.getulong();1307- break;1308-1309- case OP_RSHIFT:1310- if (bn2 < bnZero)1311- return false;1312- bn = bn1 >> bn2.getulong();1313- break;1314-1315- case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero); break;1316- case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero); break;1317- case OP_NUMEQUAL: bn = (bn1 == bn2); break;1318- case OP_NUMEQUALVERIFY: bn = (bn1 == bn2); break;1319- case OP_NUMNOTEQUAL: bn = (bn1 != bn2); break;1320- case OP_LESSTHAN: bn = (bn1 < bn2); break;1321- case OP_GREATERTHAN: bn = (bn1 > bn2); break;1322- case OP_LESSTHANOREQUAL: bn = (bn1 <= bn2); break;1323- case OP_GREATERTHANOREQUAL: bn = (bn1 >= bn2); break;1324- case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2); break;1325- case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2); break;1326- }1327- stack.pop_back();1328- stack.pop_back();1329- stack.push_back(bn.getvch());1330-1331- if (opcode == OP_NUMEQUALVERIFY)1332- {1333- if (CastToBool(stacktop(-1)))1334- stack.pop_back();1335- else1336- pc = pend;1337- }1338- }1339- break;1340-1341- case OP_WITHIN:1342- {1343- // (x min max -- out)1344- if (stack.size() < 3)1345- return false;1346- CBigNum bn1(stacktop(-3));1347- CBigNum bn2(stacktop(-2));1348- CBigNum bn3(stacktop(-1));1349- bool fValue = (bn2 <= bn1 && bn1 < bn3);1350- stack.pop_back();1351- stack.pop_back();1352- stack.pop_back();1353- stack.push_back(fValue ? vchTrue : vchFalse);1354- }1355- break;1356-1357-1358- //1359- // Crypto1360- //1361- case OP_RIPEMD160:1362- case OP_SHA1:1363- case OP_SHA256:1364- case OP_HASH160:1365- case OP_HASH256:1366- {1367- // (in -- hash)1368- if (stack.size() < 1)1369- return false;1370- valtype& vch = stacktop(-1);1371- valtype vchHash((opcode == OP_RIPEMD160 || opcode == OP_SHA1 || opcode == OP_HASH160) ? 20 : 32);1372- if (opcode == OP_RIPEMD160)1373- RIPEMD160(&vch[0], vch.size(), &vchHash[0]);1374- else if (opcode == OP_SHA1)1375- SHA1(&vch[0], vch.size(), &vchHash[0]);1376- else if (opcode == OP_SHA256)1377- SHA256(&vch[0], vch.size(), &vchHash[0]);1378- else if (opcode == OP_HASH160)1379- {1380- uint160 hash160 = Hash160(vch);1381- memcpy(&vchHash[0], &hash160, sizeof(hash160));1382- }1383- else if (opcode == OP_HASH256)1384- {1385- uint256 hash = Hash(vch.begin(), vch.end());1386- memcpy(&vchHash[0], &hash, sizeof(hash));1387- }1388- stack.pop_back();1389- stack.push_back(vchHash);1390- }1391- break;1392-1393- case OP_CODESEPARATOR:1394- {1395- // Hash starts after the code separator1396- pbegincodehash = pc;1397- }1398- break;1399-1400- case OP_CHECKSIG:1401- case OP_CHECKSIGVERIFY:1402- {1403- // (sig pubkey -- bool)1404- if (stack.size() < 2)1405- return false;1406-1407- valtype& vchSig = stacktop(-2);1408- valtype& vchPubKey = stacktop(-1);1409-1410- ////// debug print1411- //PrintHex(vchSig.begin(), vchSig.end(), "sig: %s\n");1412- //PrintHex(vchPubKey.begin(), vchPubKey.end(), "pubkey: %s\n");1413-1414- // Subset of script starting at the most recent codeseparator1415- CScript scriptCode(pbegincodehash, pend);1416-1417- // Drop the signature, since there's no way for a signature to sign itself1418- scriptCode.FindAndDelete(CScript(vchSig));1419-1420- bool fSuccess = CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType);1421-1422- stack.pop_back();1423- stack.pop_back();1424- stack.push_back(fSuccess ? vchTrue : vchFalse);1425- if (opcode == OP_CHECKSIGVERIFY)1426- {1427- if (fSuccess)1428- stack.pop_back();1429- else1430- pc = pend;1431- }1432- }1433- break;1434-1435- case OP_CHECKMULTISIG:1436- case OP_CHECKMULTISIGVERIFY:1437- {1438- // ([sig ...] num_of_signatures [pubkey ...] num_of_pubkeys -- bool)1439-1440- int i = 1;1441- if (stack.size() < i)1442- return false;1443-1444- int nKeysCount = CBigNum(stacktop(-i)).getint();1445- if (nKeysCount < 0)1446- return false;1447- int ikey = ++i;1448- i += nKeysCount;1449- if (stack.size() < i)1450- return false;1451-1452- int nSigsCount = CBigNum(stacktop(-i)).getint();1453- if (nSigsCount < 0 || nSigsCount > nKeysCount)1454- return false;1455- int isig = ++i;1456- i += nSigsCount;1457- if (stack.size() < i)1458- return false;1459-1460- // Subset of script starting at the most recent codeseparator1461- CScript scriptCode(pbegincodehash, pend);1462-1463- // Drop the signatures, since there's no way for a signature to sign itself1464- for (int k = 0; k < nSigsCount; k++)1465- {1466- valtype& vchSig = stacktop(-isig-k);1467- scriptCode.FindAndDelete(CScript(vchSig));1468- }1469-1470- bool fSuccess = true;1471- while (fSuccess && nSigsCount > 0)1472- {1473- valtype& vchSig = stacktop(-isig);1474- valtype& vchPubKey = stacktop(-ikey);1475-1476- // Check signature1477- if (CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType))1478- {1479- isig++;1480- nSigsCount--;1481- }1482- ikey++;1483- nKeysCount--;1484-1485- // If there are more signatures left than keys left,1486- // then too many signatures have failed1487- if (nSigsCount > nKeysCount)1488- fSuccess = false;1489- }1490-1491- while (i-- > 0)1492- stack.pop_back();1493- stack.push_back(fSuccess ? vchTrue : vchFalse);1494-1495- if (opcode == OP_CHECKMULTISIGVERIFY)1496- {1497- if (fSuccess)1498- stack.pop_back();1499- else1500- pc = pend;1501- }1502- }1503- break;1504-1505- default:1506+1507+ // Size limits1508+ if (stack.size() + altstack.size() > 1000)1509 return false;1510 }1511 }1512-1513+ catch (...)1514+ {1515+ return false;1516+ }1517+1518+1519+ if (!vfExec.empty())1520+ return false;1521 1522 if (pvStackRet)1523 *pvStackRet = stack;
script.h (modified)
1--- v0.3.3/script.h2+++ v0.3.6/script.h3@@ -135,6 +135,20 @@4 OP_CHECKSIGVERIFY,5 OP_CHECKMULTISIG,6 OP_CHECKMULTISIGVERIFY,7+8+ // expansion9+ OP_NOP1,10+ OP_NOP2,11+ OP_NOP3,12+ OP_NOP4,13+ OP_NOP5,14+ OP_NOP6,15+ OP_NOP7,16+ OP_NOP8,17+ OP_NOP9,18+ OP_NOP10,19+20+21 22 23 // multi-byte opcodes24@@ -276,6 +290,18 @@25 case OP_CHECKMULTISIG : return "OP_CHECKMULTISIG";26 case OP_CHECKMULTISIGVERIFY : return "OP_CHECKMULTISIGVERIFY";27 28+ // expanson29+ case OP_NOP1 : return "OP_NOP1";30+ case OP_NOP2 : return "OP_NOP2";31+ case OP_NOP3 : return "OP_NOP3";32+ case OP_NOP4 : return "OP_NOP4";33+ case OP_NOP5 : return "OP_NOP5";34+ case OP_NOP6 : return "OP_NOP6";35+ case OP_NOP7 : return "OP_NOP7";36+ case OP_NOP8 : return "OP_NOP8";37+ case OP_NOP9 : return "OP_NOP9";38+ case OP_NOP10 : return "OP_NOP10";39+40 41 42 // multi-byte opcodes43@@ -283,7 +309,6 @@44 case OP_DOUBLEBYTE_BEGIN : return "OP_DOUBLEBYTE_BEGIN";45 case OP_PUBKEY : return "OP_PUBKEY";46 case OP_PUBKEYHASH : return "OP_PUBKEYHASH";47-48 49 50 case OP_INVALIDOPCODE : return "OP_INVALIDOPCODE";
serialize.h (modified)
1--- v0.3.3/serialize.h2+++ v0.3.6/serialize.h3@@ -19,7 +19,7 @@4 class CDataStream;5 class CAutoFile;6 7-static const int VERSION = 303;8+static const int VERSION = 306;9 static const char* pszSubVer = "";10 11
setup.nsi (modified)
1--- v0.3.3/setup.nsi2+++ v0.3.6/setup.nsi3@@ -7,7 +7,7 @@4 5 # General Symbol Definitions6 !define REGKEY "SOFTWARE\$(^Name)"7-!define VERSION 0.3.38+!define VERSION 0.3.69 !define COMPANY "Bitcoin project"10 !define URL http://www.bitcoin.org/11 12@@ -42,12 +42,12 @@13 !insertmacro MUI_LANGUAGE English14 15 # Installer attributes16-OutFile bitcoin-0.3.3-win32-setup.exe17+OutFile bitcoin-0.3.6-win32-setup.exe18 InstallDir $PROGRAMFILES\Bitcoin19 CRCCheck on20 XPStyle on21 ShowInstDetails show22-VIProductVersion 0.3.3.023+VIProductVersion 0.3.6.024 VIAddVersionKey ProductName Bitcoin25 VIAddVersionKey ProductVersion "${VERSION}"26 VIAddVersionKey CompanyName "${COMPANY}"
sha.cpp (removed)
1--- v0.3.3/sha.cpp2+++ /dev/null3@@ -1,555 +1 @@4-// This file is public domain5-// SHA routines extracted as a standalone file from:6-// Crypto++: a C++ Class Library of Cryptographic Schemes7-// Version 5.5.2 (9/24/2007)8-// http://www.cryptopp.com9 10-// sha.cpp - modified by Wei Dai from Steve Reid's public domain sha1.c11-12-// Steve Reid implemented SHA-1. Wei Dai implemented SHA-2.13-// Both are in the public domain.14-15-#include <assert.h>16-#include <memory.h>17-#include "sha.h"18-19-namespace CryptoPP20-{21-22-// start of Steve Reid's code23-24-#define blk0(i) (W[i] = data[i])25-#define blk1(i) (W[i&15] = rotlFixed(W[(i+13)&15]^W[(i+8)&15]^W[(i+2)&15]^W[i&15],1))26-27-void SHA1::InitState(HashWordType *state)28-{29- state[0] = 0x67452301L;30- state[1] = 0xEFCDAB89L;31- state[2] = 0x98BADCFEL;32- state[3] = 0x10325476L;33- state[4] = 0xC3D2E1F0L;34-}35-36-#define f1(x,y,z) (z^(x&(y^z)))37-#define f2(x,y,z) (x^y^z)38-#define f3(x,y,z) ((x&y)|(z&(x|y)))39-#define f4(x,y,z) (x^y^z)40-41-/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */42-#define R0(v,w,x,y,z,i) z+=f1(w,x,y)+blk0(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30);43-#define R1(v,w,x,y,z,i) z+=f1(w,x,y)+blk1(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30);44-#define R2(v,w,x,y,z,i) z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rotlFixed(v,5);w=rotlFixed(w,30);45-#define R3(v,w,x,y,z,i) z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rotlFixed(v,5);w=rotlFixed(w,30);46-#define R4(v,w,x,y,z,i) z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rotlFixed(v,5);w=rotlFixed(w,30);47-48-void SHA1::Transform(word32 *state, const word32 *data)49-{50- word32 W[16];51- /* Copy context->state[] to working vars */52- word32 a = state[0];53- word32 b = state[1];54- word32 c = state[2];55- word32 d = state[3];56- word32 e = state[4];57- /* 4 rounds of 20 operations each. Loop unrolled. */58- R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);59- R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);60- R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);61- R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);62- R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);63- R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);64- R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);65- R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);66- R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);67- R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);68- R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);69- R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);70- R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);71- R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);72- R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);73- R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);74- R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);75- R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);76- R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);77- R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);78- /* Add the working vars back into context.state[] */79- state[0] += a;80- state[1] += b;81- state[2] += c;82- state[3] += d;83- state[4] += e;84-}85-86-// end of Steve Reid's code87-88-// *************************************************************89-90-void SHA224::InitState(HashWordType *state)91-{92- static const word32 s[8] = {0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4};93- memcpy(state, s, sizeof(s));94-}95-96-void SHA256::InitState(HashWordType *state)97-{98- static const word32 s[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};99- memcpy(state, s, sizeof(s));100-}101-102-static const word32 SHA256_K[64] = {103- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,104- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,105- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,106- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,107- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,108- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,109- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,110- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,111- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,112- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,113- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,114- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,115- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,116- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,117- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,118- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2119-};120-121-#define blk2(i) (W[i&15]+=s1(W[(i-2)&15])+W[(i-7)&15]+s0(W[(i-15)&15]))122-123-#define Ch(x,y,z) (z^(x&(y^z)))124-#define Maj(x,y,z) ((x&y)|(z&(x|y)))125-126-#define a(i) T[(0-i)&7]127-#define b(i) T[(1-i)&7]128-#define c(i) T[(2-i)&7]129-#define d(i) T[(3-i)&7]130-#define e(i) T[(4-i)&7]131-#define f(i) T[(5-i)&7]132-#define g(i) T[(6-i)&7]133-#define h(i) T[(7-i)&7]134-135-#define R(i) h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+SHA256_K[i+j]+(j?blk2(i):blk0(i));\136- d(i)+=h(i);h(i)+=S0(a(i))+Maj(a(i),b(i),c(i))137-138-// for SHA256139-#define S0(x) (rotrFixed(x,2)^rotrFixed(x,13)^rotrFixed(x,22))140-#define S1(x) (rotrFixed(x,6)^rotrFixed(x,11)^rotrFixed(x,25))141-#define s0(x) (rotrFixed(x,7)^rotrFixed(x,18)^(x>>3))142-#define s1(x) (rotrFixed(x,17)^rotrFixed(x,19)^(x>>10))143-144-void SHA256::Transform(word32 *state, const word32 *data)145-{146- word32 W[16];147- word32 T[8];148- /* Copy context->state[] to working vars */149- memcpy(T, state, sizeof(T));150- /* 64 operations, partially loop unrolled */151- for (unsigned int j=0; j<64; j+=16)152- {153- R( 0); R( 1); R( 2); R( 3);154- R( 4); R( 5); R( 6); R( 7);155- R( 8); R( 9); R(10); R(11);156- R(12); R(13); R(14); R(15);157- }158- /* Add the working vars back into context.state[] */159- state[0] += a(0);160- state[1] += b(0);161- state[2] += c(0);162- state[3] += d(0);163- state[4] += e(0);164- state[5] += f(0);165- state[6] += g(0);166- state[7] += h(0);167-}168-169-/*170-// smaller but slower171-void SHA256_Transform(word32 *state, const word32 *data)172-{173- word32 T[20];174- word32 W[32];175- unsigned int i = 0, j = 0;176- word32 *t = T+8;177-178- memcpy(t, state, 8*4);179- word32 e = t[4], a = t[0];180-181- do182- {183- word32 w = data[j];184- W[j] = w;185- w += K[j];186- w += t[7];187- w += S1(e);188- w += Ch(e, t[5], t[6]);189- e = t[3] + w;190- t[3] = t[3+8] = e;191- w += S0(t[0]);192- a = w + Maj(a, t[1], t[2]);193- t[-1] = t[7] = a;194- --t;195- ++j;196- if (j%8 == 0)197- t += 8;198- } while (j<16);199-200- do201- {202- i = j&0xf;203- word32 w = s1(W[i+16-2]) + s0(W[i+16-15]) + W[i] + W[i+16-7];204- W[i+16] = W[i] = w;205- w += K[j];206- w += t[7];207- w += S1(e);208- w += Ch(e, t[5], t[6]);209- e = t[3] + w;210- t[3] = t[3+8] = e;211- w += S0(t[0]);212- a = w + Maj(a, t[1], t[2]);213- t[-1] = t[7] = a;214-215- w = s1(W[(i+1)+16-2]) + s0(W[(i+1)+16-15]) + W[(i+1)] + W[(i+1)+16-7];216- W[(i+1)+16] = W[(i+1)] = w;217- w += K[j+1];218- w += (t-1)[7];219- w += S1(e);220- w += Ch(e, (t-1)[5], (t-1)[6]);221- e = (t-1)[3] + w;222- (t-1)[3] = (t-1)[3+8] = e;223- w += S0((t-1)[0]);224- a = w + Maj(a, (t-1)[1], (t-1)[2]);225- (t-1)[-1] = (t-1)[7] = a;226-227- t-=2;228- j+=2;229- if (j%8 == 0)230- t += 8;231- } while (j<64);232-233- state[0] += a;234- state[1] += t[1];235- state[2] += t[2];236- state[3] += t[3];237- state[4] += e;238- state[5] += t[5];239- state[6] += t[6];240- state[7] += t[7];241-}242-*/243-244-#undef S0245-#undef S1246-#undef s0247-#undef s1248-#undef R249-250-// *************************************************************251-252-#ifdef WORD64_AVAILABLE253-254-void SHA384::InitState(HashWordType *state)255-{256- static const word64 s[8] = {257- W64LIT(0xcbbb9d5dc1059ed8), W64LIT(0x629a292a367cd507),258- W64LIT(0x9159015a3070dd17), W64LIT(0x152fecd8f70e5939),259- W64LIT(0x67332667ffc00b31), W64LIT(0x8eb44a8768581511),260- W64LIT(0xdb0c2e0d64f98fa7), W64LIT(0x47b5481dbefa4fa4)};261- memcpy(state, s, sizeof(s));262-}263-264-void SHA512::InitState(HashWordType *state)265-{266- static const word64 s[8] = {267- W64LIT(0x6a09e667f3bcc908), W64LIT(0xbb67ae8584caa73b),268- W64LIT(0x3c6ef372fe94f82b), W64LIT(0xa54ff53a5f1d36f1),269- W64LIT(0x510e527fade682d1), W64LIT(0x9b05688c2b3e6c1f),270- W64LIT(0x1f83d9abfb41bd6b), W64LIT(0x5be0cd19137e2179)};271- memcpy(state, s, sizeof(s));272-}273-274-CRYPTOPP_ALIGN_DATA(16) static const word64 SHA512_K[80] CRYPTOPP_SECTION_ALIGN16 = {275- W64LIT(0x428a2f98d728ae22), W64LIT(0x7137449123ef65cd),276- W64LIT(0xb5c0fbcfec4d3b2f), W64LIT(0xe9b5dba58189dbbc),277- W64LIT(0x3956c25bf348b538), W64LIT(0x59f111f1b605d019),278- W64LIT(0x923f82a4af194f9b), W64LIT(0xab1c5ed5da6d8118),279- W64LIT(0xd807aa98a3030242), W64LIT(0x12835b0145706fbe),280- W64LIT(0x243185be4ee4b28c), W64LIT(0x550c7dc3d5ffb4e2),281- W64LIT(0x72be5d74f27b896f), W64LIT(0x80deb1fe3b1696b1),282- W64LIT(0x9bdc06a725c71235), W64LIT(0xc19bf174cf692694),283- W64LIT(0xe49b69c19ef14ad2), W64LIT(0xefbe4786384f25e3),284- W64LIT(0x0fc19dc68b8cd5b5), W64LIT(0x240ca1cc77ac9c65),285- W64LIT(0x2de92c6f592b0275), W64LIT(0x4a7484aa6ea6e483),286- W64LIT(0x5cb0a9dcbd41fbd4), W64LIT(0x76f988da831153b5),287- W64LIT(0x983e5152ee66dfab), W64LIT(0xa831c66d2db43210),288- W64LIT(0xb00327c898fb213f), W64LIT(0xbf597fc7beef0ee4),289- W64LIT(0xc6e00bf33da88fc2), W64LIT(0xd5a79147930aa725),290- W64LIT(0x06ca6351e003826f), W64LIT(0x142929670a0e6e70),291- W64LIT(0x27b70a8546d22ffc), W64LIT(0x2e1b21385c26c926),292- W64LIT(0x4d2c6dfc5ac42aed), W64LIT(0x53380d139d95b3df),293- W64LIT(0x650a73548baf63de), W64LIT(0x766a0abb3c77b2a8),294- W64LIT(0x81c2c92e47edaee6), W64LIT(0x92722c851482353b),295- W64LIT(0xa2bfe8a14cf10364), W64LIT(0xa81a664bbc423001),296- W64LIT(0xc24b8b70d0f89791), W64LIT(0xc76c51a30654be30),297- W64LIT(0xd192e819d6ef5218), W64LIT(0xd69906245565a910),298- W64LIT(0xf40e35855771202a), W64LIT(0x106aa07032bbd1b8),299- W64LIT(0x19a4c116b8d2d0c8), W64LIT(0x1e376c085141ab53),300- W64LIT(0x2748774cdf8eeb99), W64LIT(0x34b0bcb5e19b48a8),301- W64LIT(0x391c0cb3c5c95a63), W64LIT(0x4ed8aa4ae3418acb),302- W64LIT(0x5b9cca4f7763e373), W64LIT(0x682e6ff3d6b2b8a3),303- W64LIT(0x748f82ee5defb2fc), W64LIT(0x78a5636f43172f60),304- W64LIT(0x84c87814a1f0ab72), W64LIT(0x8cc702081a6439ec),305- W64LIT(0x90befffa23631e28), W64LIT(0xa4506cebde82bde9),306- W64LIT(0xbef9a3f7b2c67915), W64LIT(0xc67178f2e372532b),307- W64LIT(0xca273eceea26619c), W64LIT(0xd186b8c721c0c207),308- W64LIT(0xeada7dd6cde0eb1e), W64LIT(0xf57d4f7fee6ed178),309- W64LIT(0x06f067aa72176fba), W64LIT(0x0a637dc5a2c898a6),310- W64LIT(0x113f9804bef90dae), W64LIT(0x1b710b35131c471b),311- W64LIT(0x28db77f523047d84), W64LIT(0x32caab7b40c72493),312- W64LIT(0x3c9ebe0a15c9bebc), W64LIT(0x431d67c49c100d4c),313- W64LIT(0x4cc5d4becb3e42b6), W64LIT(0x597f299cfc657e2a),314- W64LIT(0x5fcb6fab3ad6faec), W64LIT(0x6c44198c4a475817)315-};316-317-#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && CRYPTOPP_BOOL_X86318-// put assembly version in separate function, otherwise MSVC 2005 SP1 doesn't generate correct code for the non-assembly version319-CRYPTOPP_NAKED static void CRYPTOPP_FASTCALL SHA512_SSE2_Transform(word64 *state, const word64 *data)320-{321-#ifdef __GNUC__322- __asm__ __volatile__323- (324- ".intel_syntax noprefix;"325- AS1( push ebx)326- AS2( mov ebx, eax)327-#else328- AS1( push ebx)329- AS1( push esi)330- AS1( push edi)331- AS2( lea ebx, SHA512_K)332-#endif333-334- AS2( mov eax, esp)335- AS2( and esp, 0xfffffff0)336- AS2( sub esp, 27*16) // 17*16 for expanded data, 20*8 for state337- AS1( push eax)338- AS2( xor eax, eax)339- AS2( lea edi, [esp+4+8*8]) // start at middle of state buffer. will decrement pointer each round to avoid copying340- AS2( lea esi, [esp+4+20*8+8]) // 16-byte alignment, then add 8341-342- AS2( movq mm4, [ecx+0*8])343- AS2( movq [edi+0*8], mm4)344- AS2( movq mm0, [ecx+1*8])345- AS2( movq [edi+1*8], mm0)346- AS2( movq mm0, [ecx+2*8])347- AS2( movq [edi+2*8], mm0)348- AS2( movq mm0, [ecx+3*8])349- AS2( movq [edi+3*8], mm0)350- AS2( movq mm5, [ecx+4*8])351- AS2( movq [edi+4*8], mm5)352- AS2( movq mm0, [ecx+5*8])353- AS2( movq [edi+5*8], mm0)354- AS2( movq mm0, [ecx+6*8])355- AS2( movq [edi+6*8], mm0)356- AS2( movq mm0, [ecx+7*8])357- AS2( movq [edi+7*8], mm0)358- ASJ( jmp, 0, f)359-360-#define SSE2_S0_S1(r, a, b, c) \361- AS2( movq mm6, r)\362- AS2( psrlq r, a)\363- AS2( movq mm7, r)\364- AS2( psllq mm6, 64-c)\365- AS2( pxor mm7, mm6)\366- AS2( psrlq r, b-a)\367- AS2( pxor mm7, r)\368- AS2( psllq mm6, c-b)\369- AS2( pxor mm7, mm6)\370- AS2( psrlq r, c-b)\371- AS2( pxor r, mm7)\372- AS2( psllq mm6, b-a)\373- AS2( pxor r, mm6)374-375-#define SSE2_s0(r, a, b, c) \376- AS2( movdqa xmm6, r)\377- AS2( psrlq r, a)\378- AS2( movdqa xmm7, r)\379- AS2( psllq xmm6, 64-c)\380- AS2( pxor xmm7, xmm6)\381- AS2( psrlq r, b-a)\382- AS2( pxor xmm7, r)\383- AS2( psrlq r, c-b)\384- AS2( pxor r, xmm7)\385- AS2( psllq xmm6, c-a)\386- AS2( pxor r, xmm6)387-388-#define SSE2_s1(r, a, b, c) \389- AS2( movdqa xmm6, r)\390- AS2( psrlq r, a)\391- AS2( movdqa xmm7, r)\392- AS2( psllq xmm6, 64-c)\393- AS2( pxor xmm7, xmm6)\394- AS2( psrlq r, b-a)\395- AS2( pxor xmm7, r)\396- AS2( psllq xmm6, c-b)\397- AS2( pxor xmm7, xmm6)\398- AS2( psrlq r, c-b)\399- AS2( pxor r, xmm7)400-401- ASL(SHA512_Round)402- // k + w is in mm0, a is in mm4, e is in mm5403- AS2( paddq mm0, [edi+7*8]) // h404- AS2( movq mm2, [edi+5*8]) // f405- AS2( movq mm3, [edi+6*8]) // g406- AS2( pxor mm2, mm3)407- AS2( pand mm2, mm5)408- SSE2_S0_S1(mm5,14,18,41)409- AS2( pxor mm2, mm3)410- AS2( paddq mm0, mm2) // h += Ch(e,f,g)411- AS2( paddq mm5, mm0) // h += S1(e)412- AS2( movq mm2, [edi+1*8]) // b413- AS2( movq mm1, mm2)414- AS2( por mm2, mm4)415- AS2( pand mm2, [edi+2*8]) // c416- AS2( pand mm1, mm4)417- AS2( por mm1, mm2)418- AS2( paddq mm1, mm5) // temp = h + Maj(a,b,c)419- AS2( paddq mm5, [edi+3*8]) // e = d + h420- AS2( movq [edi+3*8], mm5)421- AS2( movq [edi+11*8], mm5)422- SSE2_S0_S1(mm4,28,34,39) // S0(a)423- AS2( paddq mm4, mm1) // a = temp + S0(a)424- AS2( movq [edi-8], mm4)425- AS2( movq [edi+7*8], mm4)426- AS1( ret)427-428- // first 16 rounds429- ASL(0)430- AS2( movq mm0, [edx+eax*8])431- AS2( movq [esi+eax*8], mm0)432- AS2( movq [esi+eax*8+16*8], mm0)433- AS2( paddq mm0, [ebx+eax*8])434- ASC( call, SHA512_Round)435- AS1( inc eax)436- AS2( sub edi, 8)437- AS2( test eax, 7)438- ASJ( jnz, 0, b)439- AS2( add edi, 8*8)440- AS2( cmp eax, 16)441- ASJ( jne, 0, b)442-443- // rest of the rounds444- AS2( movdqu xmm0, [esi+(16-2)*8])445- ASL(1)446- // data expansion, W[i-2] already in xmm0447- AS2( movdqu xmm3, [esi])448- AS2( paddq xmm3, [esi+(16-7)*8])449- AS2( movdqa xmm2, [esi+(16-15)*8])450- SSE2_s1(xmm0, 6, 19, 61)451- AS2( paddq xmm0, xmm3)452- SSE2_s0(xmm2, 1, 7, 8)453- AS2( paddq xmm0, xmm2)454- AS2( movdq2q mm0, xmm0)455- AS2( movhlps xmm1, xmm0)456- AS2( paddq mm0, [ebx+eax*8])457- AS2( movlps [esi], xmm0)458- AS2( movlps [esi+8], xmm1)459- AS2( movlps [esi+8*16], xmm0)460- AS2( movlps [esi+8*17], xmm1)461- // 2 rounds462- ASC( call, SHA512_Round)463- AS2( sub edi, 8)464- AS2( movdq2q mm0, xmm1)465- AS2( paddq mm0, [ebx+eax*8+8])466- ASC( call, SHA512_Round)467- // update indices and loop468- AS2( add esi, 16)469- AS2( add eax, 2)470- AS2( sub edi, 8)471- AS2( test eax, 7)472- ASJ( jnz, 1, b)473- // do housekeeping every 8 rounds474- AS2( mov esi, 0xf)475- AS2( and esi, eax)476- AS2( lea esi, [esp+4+20*8+8+esi*8])477- AS2( add edi, 8*8)478- AS2( cmp eax, 80)479- ASJ( jne, 1, b)480-481-#define SSE2_CombineState(i) \482- AS2( movq mm0, [edi+i*8])\483- AS2( paddq mm0, [ecx+i*8])\484- AS2( movq [ecx+i*8], mm0)485-486- SSE2_CombineState(0)487- SSE2_CombineState(1)488- SSE2_CombineState(2)489- SSE2_CombineState(3)490- SSE2_CombineState(4)491- SSE2_CombineState(5)492- SSE2_CombineState(6)493- SSE2_CombineState(7)494-495- AS1( pop esp)496- AS1( emms)497-498-#if defined(__GNUC__)499- AS1( pop ebx)500- ".att_syntax prefix;"501- :502- : "a" (SHA512_K), "c" (state), "d" (data)503- : "%esi", "%edi", "memory", "cc"504- );505-#else506- AS1( pop edi)507- AS1( pop esi)508- AS1( pop ebx)509- AS1( ret)510-#endif511-}512-#endif // #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE513-514-void SHA512::Transform(word64 *state, const word64 *data)515-{516-#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && CRYPTOPP_BOOL_X86517- if (HasSSE2())518- {519- SHA512_SSE2_Transform(state, data);520- return;521- }522-#endif523-524-#define S0(x) (rotrFixed(x,28)^rotrFixed(x,34)^rotrFixed(x,39))525-#define S1(x) (rotrFixed(x,14)^rotrFixed(x,18)^rotrFixed(x,41))526-#define s0(x) (rotrFixed(x,1)^rotrFixed(x,8)^(x>>7))527-#define s1(x) (rotrFixed(x,19)^rotrFixed(x,61)^(x>>6))528-529-#define R(i) h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+SHA512_K[i+j]+(j?blk2(i):blk0(i));\530- d(i)+=h(i);h(i)+=S0(a(i))+Maj(a(i),b(i),c(i))531-532- word64 W[16];533- word64 T[8];534- /* Copy context->state[] to working vars */535- memcpy(T, state, sizeof(T));536- /* 80 operations, partially loop unrolled */537- for (unsigned int j=0; j<80; j+=16)538- {539- R( 0); R( 1); R( 2); R( 3);540- R( 4); R( 5); R( 6); R( 7);541- R( 8); R( 9); R(10); R(11);542- R(12); R(13); R(14); R(15);543- }544- /* Add the working vars back into context.state[] */545- state[0] += a(0);546- state[1] += b(0);547- state[2] += c(0);548- state[3] += d(0);549- state[4] += e(0);550- state[5] += f(0);551- state[6] += g(0);552- state[7] += h(0);553-}554-555-#endif556-557-}558-
sha.h (removed)
1--- v0.3.3/sha.h2+++ /dev/null3@@ -1,178 +1 @@4-// This file is public domain5-// SHA routines extracted as a standalone file from:6-// Crypto++: a C++ Class Library of Cryptographic Schemes7-// Version 5.5.2 (9/24/2007)8-// http://www.cryptopp.com9-#ifndef CRYPTOPP_SHA_H10-#define CRYPTOPP_SHA_H11-#include <stdlib.h>12 13-namespace CryptoPP14-{15-16-//17-// Dependencies18-//19-20-typedef unsigned char byte;21-typedef unsigned short word16;22-typedef unsigned int word32;23-#if defined(_MSC_VER) || defined(__BORLANDC__)24-typedef unsigned __int64 word64;25-#else26-typedef unsigned long long word64;27-#endif28-29-template <class T> inline T rotlFixed(T x, unsigned int y)30-{31- assert(y < sizeof(T)*8);32- return T((x<<y) | (x>>(sizeof(T)*8-y)));33-}34-35-template <class T> inline T rotrFixed(T x, unsigned int y)36-{37- assert(y < sizeof(T)*8);38- return T((x>>y) | (x<<(sizeof(T)*8-y)));39-}40-41-// ************** endian reversal ***************42-43-#ifdef _MSC_VER44- #if _MSC_VER >= 140045- #define CRYPTOPP_FAST_ROTATE(x) 146- #elif _MSC_VER >= 130047- #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32 | (x) == 64)48- #else49- #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32)50- #endif51-#elif (defined(__MWERKS__) && TARGET_CPU_PPC) || \52- (defined(__GNUC__) && (defined(_ARCH_PWR2) || defined(_ARCH_PWR) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_ARCH_COM)))53- #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32)54-#elif defined(__GNUC__) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86) // depend on GCC's peephole optimization to generate rotate instructions55- #define CRYPTOPP_FAST_ROTATE(x) 156-#else57- #define CRYPTOPP_FAST_ROTATE(x) 058-#endif59-60-inline byte ByteReverse(byte value)61-{62- return value;63-}64-65-inline word16 ByteReverse(word16 value)66-{67-#ifdef CRYPTOPP_BYTESWAP_AVAILABLE68- return bswap_16(value);69-#elif defined(_MSC_VER) && _MSC_VER >= 130070- return _byteswap_ushort(value);71-#else72- return rotlFixed(value, 8U);73-#endif74-}75-76-inline word32 ByteReverse(word32 value)77-{78-#if defined(__GNUC__)79- __asm__ ("bswap %0" : "=r" (value) : "0" (value));80- return value;81-#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)82- return bswap_32(value);83-#elif defined(__MWERKS__) && TARGET_CPU_PPC84- return (word32)__lwbrx(&value,0);85-#elif _MSC_VER >= 1400 || (_MSC_VER >= 1300 && !defined(_DLL))86- return _byteswap_ulong(value);87-#elif CRYPTOPP_FAST_ROTATE(32)88- // 5 instructions with rotate instruction, 9 without89- return (rotrFixed(value, 8U) & 0xff00ff00) | (rotlFixed(value, 8U) & 0x00ff00ff);90-#else91- // 6 instructions with rotate instruction, 8 without92- value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);93- return rotlFixed(value, 16U);94-#endif95-}96-97-#ifdef WORD64_AVAILABLE98-inline word64 ByteReverse(word64 value)99-{100-#if defined(__GNUC__) && defined(__x86_64__)101- __asm__ ("bswap %0" : "=r" (value) : "0" (value));102- return value;103-#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)104- return bswap_64(value);105-#elif defined(_MSC_VER) && _MSC_VER >= 1300106- return _byteswap_uint64(value);107-#elif defined(CRYPTOPP_SLOW_WORD64)108- return (word64(ByteReverse(word32(value))) << 32) | ByteReverse(word32(value>>32));109-#else110- value = ((value & W64LIT(0xFF00FF00FF00FF00)) >> 8) | ((value & W64LIT(0x00FF00FF00FF00FF)) << 8);111- value = ((value & W64LIT(0xFFFF0000FFFF0000)) >> 16) | ((value & W64LIT(0x0000FFFF0000FFFF)) << 16);112- return rotlFixed(value, 32U);113-#endif114-}115-#endif116-117-118-//119-// SHA120-//121-122-// http://www.weidai.com/scan-mirror/md.html#SHA-1123-class SHA1124-{125-public:126- typedef word32 HashWordType;127- static void InitState(word32 *state);128- static void Transform(word32 *digest, const word32 *data);129- static const char * StaticAlgorithmName() {return "SHA-1";}130-};131-132-typedef SHA1 SHA; // for backwards compatibility133-134-// implements the SHA-256 standard135-class SHA256136-{137-public:138- typedef word32 HashWordType;139- static void InitState(word32 *state);140- static void Transform(word32 *digest, const word32 *data);141- static const char * StaticAlgorithmName() {return "SHA-256";}142-};143-144-// implements the SHA-224 standard145-class SHA224146-{147-public:148- typedef word32 HashWordType;149- static void InitState(word32 *state);150- static void Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);}151- static const char * StaticAlgorithmName() {return "SHA-224";}152-};153-154-#ifdef WORD64_AVAILABLE155-156-// implements the SHA-512 standard157-class SHA512158-{159-public:160- typedef word64 HashWordType;161- static void InitState(word64 *state);162- static void Transform(word64 *digest, const word64 *data);163- static const char * StaticAlgorithmName() {return "SHA-512";}164-};165-166-// implements the SHA-384 standard167-class SHA384168-{169-public:170- typedef word64 HashWordType;171- static void InitState(word64 *state);172- static void Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);}173- static const char * StaticAlgorithmName() {return "SHA-384";}174-};175-176-#endif177-178-}179-180-#endif181-
ui.cpp (modified)
1--- v0.3.3/ui.cpp2+++ v0.3.6/ui.cpp3@@ -14,6 +14,7 @@4 CMainFrame* pframeMain = NULL;5 CMyTaskBarIcon* ptaskbaricon = NULL;6 bool fClosedToTray = false;7+wxLocale g_locale;8 9 10 11@@ -263,7 +264,7 @@12 m_staticTextBalance->SetLabel(FormatMoney(GetBalance()) + " ");13 m_listCtrl->SetFocus();14 ptaskbaricon = new CMyTaskBarIcon();15-#ifdef __WXMAC__16+#ifdef __WXMAC_OSX__17 // Mac automatically moves wxID_EXIT, wxID_PREFERENCES and wxID_ABOUT18 // to their standard places, leaving these menus empty.19 GetMenuBar()->Remove(2); // remove Help menu20@@ -274,7 +275,7 @@21 int nDateWidth = DateTimeStr(1229413914).size() * 6 + 8;22 if (!strstr(DateTimeStr(1229413914).c_str(), "2008"))23 nDateWidth += 12;24-#ifdef __WXMAC__25+#ifdef __WXMAC_OSX__26 nDateWidth += 5;27 dResize -= 0.01;28 #endif29@@ -1437,6 +1438,154 @@30 31 32 33+34+//////////////////////////////////////////////////////////////////////////////35+//36+// Startup folder37+//38+39+#ifdef __WXMSW__40+string StartupShortcutPath()41+{42+ return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";43+}44+45+bool GetStartOnSystemStartup()46+{47+ return filesystem::exists(StartupShortcutPath().c_str());48+}49+50+void SetStartOnSystemStartup(bool fAutoStart)51+{52+ // If the shortcut exists already, remove it for updating53+ remove(StartupShortcutPath().c_str());54+55+ if (fAutoStart)56+ {57+ CoInitialize(NULL);58+59+ // Get a pointer to the IShellLink interface.60+ IShellLink* psl = NULL;61+ HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,62+ CLSCTX_INPROC_SERVER, IID_IShellLink,63+ reinterpret_cast<void**>(&psl));64+65+ if (SUCCEEDED(hres))66+ {67+ // Get the current executable path68+ TCHAR pszExePath[MAX_PATH];69+ GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));70+71+ // Set the path to the shortcut target72+ psl->SetPath(pszExePath);73+ PathRemoveFileSpec(pszExePath);74+ psl->SetWorkingDirectory(pszExePath);75+ psl->SetShowCmd(SW_SHOWMINNOACTIVE);76+77+ // Query IShellLink for the IPersistFile interface for78+ // saving the shortcut in persistent storage.79+ IPersistFile* ppf = NULL;80+ hres = psl->QueryInterface(IID_IPersistFile,81+ reinterpret_cast<void**>(&ppf));82+ if (SUCCEEDED(hres))83+ {84+ WCHAR pwsz[MAX_PATH];85+ // Ensure that the string is ANSI.86+ MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().c_str(), -1, pwsz, MAX_PATH);87+ // Save the link by calling IPersistFile::Save.88+ hres = ppf->Save(pwsz, TRUE);89+ ppf->Release();90+ }91+ psl->Release();92+ }93+ CoUninitialize();94+ }95+}96+97+#elif defined(__WXGTK__)98+99+// Follow the Desktop Application Autostart Spec:100+// http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html101+102+boost::filesystem::path GetAutostartDir()103+{104+ namespace fs = boost::filesystem;105+106+ char* pszConfigHome = getenv("XDG_CONFIG_HOME");107+ if (pszConfigHome) return fs::path(pszConfigHome) / fs::path("autostart");108+ char* pszHome = getenv("HOME");109+ if (pszHome) return fs::path(pszHome) / fs::path(".config/autostart");110+ return fs::path();111+}112+113+boost::filesystem::path GetAutostartFilePath()114+{115+ return GetAutostartDir() / boost::filesystem::path("bitcoin.desktop");116+}117+118+bool GetStartOnSystemStartup()119+{120+ boost::filesystem::ifstream optionFile(GetAutostartFilePath());121+ if (!optionFile.good())122+ return false;123+ // Scan through file for "Hidden=true":124+ string line;125+ while (!optionFile.eof())126+ {127+ getline(optionFile, line);128+ if (line.find("Hidden") != string::npos &&129+ line.find("true") != string::npos)130+ return false;131+ }132+ optionFile.close();133+134+ return true;135+}136+137+void SetStartOnSystemStartup(bool fAutoStart)138+{139+ if (!fAutoStart)140+ {141+ unlink(GetAutostartFilePath().native_file_string().c_str());142+ }143+ else144+ {145+ boost::filesystem::create_directories(GetAutostartDir());146+147+ boost::filesystem::ofstream optionFile(GetAutostartFilePath(), ios_base::out|ios_base::trunc);148+ if (!optionFile.good())149+ {150+ wxMessageBox(_("Cannot write autostart/bitcoin.desktop file"), "Bitcoin");151+ return;152+ }153+ // Write a bitcoin.desktop file to the autostart directory:154+ char pszExePath[MAX_PATH+1];155+ memset(pszExePath, 0, sizeof(pszExePath));156+ readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1);157+ optionFile << "[Desktop Entry]\n";158+ optionFile << "Type=Application\n";159+ optionFile << "Name=Bitcoin\n";160+ optionFile << "Exec=" << pszExePath << "\n";161+ optionFile << "Terminal=false\n";162+ optionFile << "Hidden=false\n";163+ optionFile.close();164+ }165+}166+#else167+168+// TODO: OSX startup stuff; see:169+// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html170+171+bool GetStartOnSystemStartup() { return false; }172+void SetStartOnSystemStartup(bool fAutoStart) { }173+174+#endif175+176+177+178+179+180+181 //////////////////////////////////////////////////////////////////////////////182 //183 // COptionsDialog184@@ -1606,6 +1755,7 @@185 186 187 188+189 //////////////////////////////////////////////////////////////////////////////190 //191 // CAboutDialog192@@ -1613,8 +1763,7 @@193 194 CAboutDialog::CAboutDialog(wxWindow* parent) : CAboutDialogBase(parent)195 {196- m_staticTextVersion->SetLabel(strprintf(_("version %d.%d.%d beta"), VERSION/10000, (VERSION/100)%100, VERSION%100));197- //m_staticTextVersion->SetLabel(strprintf(_("version %d.%d.%d%s beta"), VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer));198+ m_staticTextVersion->SetLabel(strprintf(_("version %d.%d.%d%s beta"), VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer));199 200 // Change (c) into UTF-8 or ANSI copyright symbol201 wxString str = m_staticTextMain->GetLabel();202@@ -2538,12 +2687,10 @@203 204 205 206-207-208-209-210-211-212+//////////////////////////////////////////////////////////////////////////////213+//214+// CMyApp215+//216 217 void CreateMainWindow()218 {219@@ -2562,3 +2709,189 @@220 CreateThread(ThreadDelayedRepaint, NULL);221 }222 223+224+// Define a new application225+class CMyApp : public wxApp226+{227+public:228+ CMyApp(){};229+ ~CMyApp(){};230+ bool OnInit();231+ bool OnInit2();232+ int OnExit();233+234+ // Hook Initialize so we can start without GUI235+ virtual bool Initialize(int& argc, wxChar** argv);236+237+ // 2nd-level exception handling: we get all the exceptions occurring in any238+ // event handler here239+ virtual bool OnExceptionInMainLoop();240+241+ // 3rd, and final, level exception handling: whenever an unhandled242+ // exception is caught, this function is called243+ virtual void OnUnhandledException();244+245+ // and now for something different: this function is called in case of a246+ // crash (e.g. dereferencing null pointer, division by 0, ...)247+ virtual void OnFatalException();248+};249+250+IMPLEMENT_APP(CMyApp)251+252+bool CMyApp::Initialize(int& argc, wxChar** argv)253+{254+ for (int i = 1; i < argc; i++)255+ if (!IsSwitchChar(argv[i][0]))256+ fCommandLine = true;257+258+ if (!fCommandLine)259+ {260+ // wxApp::Initialize will remove environment-specific parameters,261+ // so it's too early to call ParseParameters yet262+ for (int i = 1; i < argc; i++)263+ {264+ wxString str = argv[i];265+ #ifdef __WXMSW__266+ if (str.size() >= 1 && str[0] == '/')267+ str[0] = '-';268+ char pszLower[MAX_PATH];269+ strlcpy(pszLower, str.c_str(), sizeof(pszLower));270+ strlwr(pszLower);271+ str = pszLower;272+ #endif273+ if (str == "-daemon")274+ fDaemon = true;275+ }276+ }277+278+#ifdef __WXGTK__279+ if (fDaemon || fCommandLine)280+ {281+ // Call the original Initialize while suppressing error messages282+ // and ignoring failure. If unable to initialize GTK, it fails283+ // near the end so hopefully the last few things don't matter.284+ {285+ wxLogNull logNo;286+ wxApp::Initialize(argc, argv);287+ }288+289+ if (fDaemon)290+ {291+ // Daemonize292+ pid_t pid = fork();293+ if (pid < 0)294+ {295+ fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);296+ return false;297+ }298+ if (pid > 0)299+ pthread_exit((void*)0);300+ }301+302+ return true;303+ }304+#endif305+306+ return wxApp::Initialize(argc, argv);307+}308+309+bool CMyApp::OnInit()310+{311+#if defined(__WXMSW__) && defined(__WXDEBUG__) && defined(GUI)312+ // Disable malfunctioning wxWidgets debug assertion313+ extern int g_isPainting;314+ g_isPainting = 10000;315+#endif316+#ifdef GUI317+ wxImage::AddHandler(new wxPNGHandler);318+#endif319+#if defined(__WXMSW__ ) || defined(__WXMAC_OSX__)320+ SetAppName("Bitcoin");321+#else322+ SetAppName("bitcoin");323+#endif324+#ifdef __WXMSW__325+#if wxUSE_UNICODE326+ // Hack to set wxConvLibc codepage to UTF-8 on Windows,327+ // may break if wxMBConv_win32 implementation in strconv.cpp changes.328+ class wxMBConv_win32 : public wxMBConv329+ {330+ public:331+ long m_CodePage;332+ size_t m_minMBCharWidth;333+ };334+ if (((wxMBConv_win32*)&wxConvLibc)->m_CodePage == CP_ACP)335+ ((wxMBConv_win32*)&wxConvLibc)->m_CodePage = CP_UTF8;336+#endif337+#endif338+339+ // Load locale/<lang>/LC_MESSAGES/bitcoin.mo language file340+ g_locale.Init(wxLANGUAGE_DEFAULT, 0);341+ g_locale.AddCatalogLookupPathPrefix("locale");342+#ifndef __WXMSW__343+ g_locale.AddCatalogLookupPathPrefix("/usr/share/locale");344+ g_locale.AddCatalogLookupPathPrefix("/usr/local/share/locale");345+#endif346+ g_locale.AddCatalog("wxstd"); // wxWidgets standard translations, if any347+ g_locale.AddCatalog("bitcoin");348+349+ return AppInit(argc, argv);350+}351+352+int CMyApp::OnExit()353+{354+ Shutdown(NULL);355+ return wxApp::OnExit();356+}357+358+bool CMyApp::OnExceptionInMainLoop()359+{360+ try361+ {362+ throw;363+ }364+ catch (std::exception& e)365+ {366+ PrintException(&e, "CMyApp::OnExceptionInMainLoop()");367+ wxLogWarning("Exception %s %s", typeid(e).name(), e.what());368+ Sleep(1000);369+ throw;370+ }371+ catch (...)372+ {373+ PrintException(NULL, "CMyApp::OnExceptionInMainLoop()");374+ wxLogWarning("Unknown exception");375+ Sleep(1000);376+ throw;377+ }378+ return true;379+}380+381+void CMyApp::OnUnhandledException()382+{383+ // this shows how we may let some exception propagate uncaught384+ try385+ {386+ throw;387+ }388+ catch (std::exception& e)389+ {390+ PrintException(&e, "CMyApp::OnUnhandledException()");391+ wxLogWarning("Exception %s %s", typeid(e).name(), e.what());392+ Sleep(1000);393+ throw;394+ }395+ catch (...)396+ {397+ PrintException(NULL, "CMyApp::OnUnhandledException()");398+ wxLogWarning("Unknown exception");399+ Sleep(1000);400+ throw;401+ }402+}403+404+void CMyApp::OnFatalException()405+{406+ wxMessageBox(_("Program has crashed and will terminate. "), "Bitcoin", wxOK | wxICON_ERROR);407+}408+
ui.h (modified)
1--- v0.3.3/ui.h2+++ v0.3.6/ui.h3@@ -4,15 +4,28 @@4 5 DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)6 7-#if wxUSE_GUI8-static const bool fGUI=true;9-#else10-static const bool fGUI=false;11-#endif12+13+14+extern wxLocale g_locale;15+16+17+18+void HandleCtrlA(wxKeyEvent& event);19+string FormatTxStatus(const CWalletTx& wtx);20+void UIThreadCall(boost::function0<void>);21+int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);22+bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent);23+void CalledSetStatusBar(const string& strText, int nField);24+void MainFrameRepaint();25+void CreateMainWindow();26+void SetStartOnSystemStartup(bool fAutoStart);27+28+29+30 31 inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)32 {33-#if wxUSE_GUI34+#ifdef GUI35 if (!fDaemon)36 return wxMessageBox(message, caption, style, parent, x, y);37 #endif38@@ -22,49 +35,6 @@39 }40 #define wxMessageBox MyMessageBox41 42-43-44-45-void HandleCtrlA(wxKeyEvent& event);46-string FormatTxStatus(const CWalletTx& wtx);47-void UIThreadCall(boost::function0<void>);48-int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);49-bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent);50-void CalledSetStatusBar(const string& strText, int nField);51-void MainFrameRepaint();52-void CreateMainWindow();53-54-55-56-57-58-#if !wxUSE_GUI59-inline int ThreadSafeMessageBox(const string& message, const string& caption, int style, wxWindow* parent, int x, int y)60-{61- return MyMessageBox(message, caption, style, parent, x, y);62-}63-64-inline bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)65-{66- return true;67-}68-69-inline void CalledSetStatusBar(const string& strText, int nField)70-{71-}72-73-inline void UIThreadCall(boost::function0<void> fn)74-{75-}76-77-inline void MainFrameRepaint()78-{79-}80-81-inline void CreateMainWindow()82-{83-}84-#else // wxUSE_GUI85 86 87 88@@ -334,11 +304,10 @@89 m_textCtrl2->SetValue(strValue2);90 y += 46 + wxString(strMessage2).Freq('\n') * 14;91 }92- if (!fWindows)93- {94- x *= 1.14;95- y *= 1.14;96- }97+#ifndef __WXMSW__98+ x *= 1.14;99+ y *= 1.14;100+#endif101 SetSize(x, y);102 }103 104@@ -376,5 +345,3 @@105 DECLARE_EVENT_TABLE()106 };107 108-#endif // wxUSE_GUI109-
util.cpp (modified)
1--- v0.3.3/util.cpp2+++ v0.3.6/util.cpp3@@ -134,7 +134,7 @@4 inline int OutputDebugStringF(const char* pszFormat, ...)5 {6 int ret = 0;7- if (fPrintToConsole || wxTheApp == NULL)8+ if (fPrintToConsole)9 {10 // print to console11 va_list arg_ptr;12@@ -441,6 +441,7 @@13 14 const char* wxGetTranslation(const char* pszEnglish)15 {16+#ifdef GUI17 // Wrapper of wxGetTranslation returning the same const char* type as was passed in18 static CCriticalSection cs;19 CRITICAL_BLOCK(cs)20@@ -467,6 +468,9 @@21 return pszCached;22 }23 return NULL;24+#else25+ return pszEnglish;26+#endif27 }28 29 30@@ -485,8 +489,6 @@31 pszModule[0] = '\0';32 GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));33 #else34- // might not be thread safe, uses wxString35- //const char* pszModule = wxStandardPaths::Get().GetExecutablePath().mb_str();36 const char* pszModule = "bitcoin";37 #endif38 if (pex)39@@ -510,8 +512,10 @@40 FormatException(pszMessage, pex, pszThread);41 printf("\n\n************************\n%s\n", pszMessage);42 fprintf(stderr, "\n\n************************\n%s\n", pszMessage);43- if (wxTheApp && !fDaemon && fGUI)44+#ifdef GUI45+ if (wxTheApp && !fDaemon)46 MyMessageBox(pszMessage, "Error", wxOK | wxICON_ERROR);47+#endif48 throw;49 //DebugBreak();50 }51@@ -574,10 +578,10 @@52 string strHome = pszHome;53 if (strHome[strHome.size()-1] != '/')54 strHome += '/';55-#ifdef __WXOSX__56+#ifdef __WXMAC_OSX__57 // Mac58 strHome += "Library/Application Support/";59- _mkdir(strHome.c_str());60+ filesystem::create_directory(strHome.c_str());61 return strHome + "Bitcoin";62 #else63 // Unix64@@ -596,7 +600,7 @@65 if (!fMkdirDone)66 {67 fMkdirDone = true;68- _mkdir(pszDir);69+ filesystem::create_directory(pszDir);70 }71 }72 else73@@ -606,9 +610,8 @@74 static char pszCachedDir[MAX_PATH];75 if (pszCachedDir[0] == 0)76 {77- //strlcpy(pszCachedDir, wxStandardPaths::Get().GetUserDataDir().c_str(), sizeof(pszCachedDir));78 strlcpy(pszCachedDir, GetDefaultDataDir().c_str(), sizeof(pszCachedDir));79- _mkdir(pszCachedDir);80+ filesystem::create_directory(pszCachedDir);81 }82 strlcpy(pszDir, pszCachedDir, MAX_PATH);83 }
util.h (modified)
1--- v0.3.3/util.h2+++ v0.3.6/util.h3@@ -54,8 +54,21 @@4 return (T&)val;5 }6 7-#ifdef __WXMSW__8-static const bool fWindows = true;9+// Align by increasing pointer, must have extra space at end of buffer10+template <size_t nBytes, typename T>11+T* alignup(T* p)12+{13+ union14+ {15+ T* ptr;16+ size_t n;17+ } u;18+ u.ptr = p;19+ u.n = (u.n + (nBytes-1)) & ~(nBytes-1);20+ return u.ptr;21+}22+23+#ifdef __WXMSW__24 #define MSG_NOSIGNAL 025 #define MSG_DONTWAIT 026 #ifndef UINT64_MAX27@@ -70,7 +83,6 @@28 #define unlink _unlink29 typedef int socklen_t;30 #else31-static const bool fWindows = false;32 #define WSAGetLastError() errno33 #define WSAEWOULDBLOCK EWOULDBLOCK34 #define WSAEMSGSIZE EMSGSIZE35@@ -84,10 +96,12 @@36 #define _vsnprintf(a,b,c,d) vsnprintf(a,b,c,d)37 #define strlwr(psz) to_lower(psz)38 #define _strlwr(psz) to_lower(psz)39-#define _mkdir(psz) filesystem::create_directory(psz)40 #define MAX_PATH 102441-#define Sleep(n) wxMilliSleep(n)42 #define Beep(n1,n2) (0)43+inline void Sleep(int64 n)44+{45+ boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n));46+}47 #endif48 49 inline int myclosesocket(SOCKET& hSocket)50@@ -103,6 +117,13 @@51 return ret;52 }53 #define closesocket(s) myclosesocket(s)54+55+#ifndef GUI56+inline const char* _(const char* psz)57+{58+ return psz;59+}60+#endif61 62 63
