diff options
-rw-r--r-- | bitcoin-qt.pro | 6 | ||||
-rw-r--r-- | src/bignum.h | 4 | ||||
-rw-r--r-- | src/bitcoinrpc.cpp | 16 | ||||
-rw-r--r-- | src/headers.h | 4 | ||||
-rw-r--r-- | src/init.cpp | 158 | ||||
-rw-r--r-- | src/init.h | 3 | ||||
-rw-r--r-- | src/key.h | 13 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/main.h | 12 | ||||
-rw-r--r-- | src/makefile.linux-mingw | 2 | ||||
-rw-r--r-- | src/net.cpp | 6 | ||||
-rw-r--r-- | src/protocol.cpp | 2 | ||||
-rw-r--r-- | src/qt/bitcoin.cpp | 2 | ||||
-rw-r--r-- | src/qt/optionsmodel.cpp | 7 | ||||
-rw-r--r-- | src/qt/transactionrecord.cpp | 2 | ||||
-rw-r--r-- | src/serialize.h | 18 | ||||
-rw-r--r-- | src/uint256.h | 8 | ||||
-rw-r--r-- | src/util.cpp | 26 | ||||
-rw-r--r-- | src/util.h | 38 | ||||
-rw-r--r-- | src/wallet.cpp | 2 |
20 files changed, 238 insertions, 95 deletions
diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 853f2faf93..0bd2113c67 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -253,10 +253,14 @@ isEmpty(BOOST_INCLUDE_PATH) { macx:BOOST_INCLUDE_PATH = /opt/local/include } -windows:LIBS += -lws2_32 +windows:LIBS += -lws2_32 -lshlwapi windows:DEFINES += WIN32 windows:RC_FILE = src/qt/res/bitcoin-qt.rc +!windows:!mac { + DEFINES += LINUX +} + macx:HEADERS += src/qt/macdockiconhandler.h macx:OBJECTIVE_SOURCES += src/qt/macdockiconhandler.mm macx:LIBS += -framework Foundation -framework ApplicationServices -framework AppKit diff --git a/src/bignum.h b/src/bignum.h index f5d545f07e..135eade679 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -115,9 +115,9 @@ public: { unsigned long n = BN_get_word(this); if (!BN_is_negative(this)) - return (n > INT_MAX ? INT_MAX : n); + return (n > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n); else - return (n > INT_MAX ? INT_MIN : -(int)n); + return (n > std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n); } void setint64(int64 n) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 1a1c99157f..bed90d4f6c 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -91,7 +91,13 @@ Value ValueFromAmount(int64 amount) void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { - entry.push_back(Pair("confirmations", wtx.GetDepthInMainChain())); + int confirms = wtx.GetDepthInMainChain(); + entry.push_back(Pair("confirmations", confirms)); + if (confirms) + { + entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); + entry.push_back(Pair("blockindex", wtx.nIndex)); + } entry.push_back(Pair("txid", wtx.GetHash().GetHex())); entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) @@ -1006,7 +1012,7 @@ struct tallyitem tallyitem() { nAmount = 0; - nConf = INT_MAX; + nConf = std::numeric_limits<int>::max(); } }; @@ -1058,7 +1064,7 @@ Value ListReceived(const Array& params, bool fByAccounts) continue; int64 nAmount = 0; - int nConf = INT_MAX; + int nConf = std::numeric_limits<int>::max(); if (it != mapTally.end()) { nAmount = (*it).second.nAmount; @@ -1077,7 +1083,7 @@ Value ListReceived(const Array& params, bool fByAccounts) obj.push_back(Pair("address", address.ToString())); obj.push_back(Pair("account", strAccount)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); - obj.push_back(Pair("confirmations", (nConf == INT_MAX ? 0 : nConf))); + obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf))); ret.push_back(obj); } } @@ -1091,7 +1097,7 @@ Value ListReceived(const Array& params, bool fByAccounts) Object obj; obj.push_back(Pair("account", (*it).first)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); - obj.push_back(Pair("confirmations", (nConf == INT_MAX ? 0 : nConf))); + obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf))); ret.push_back(obj); } } diff --git a/src/headers.h b/src/headers.h index fd086faee8..b6903fe93e 100644 --- a/src/headers.h +++ b/src/headers.h @@ -21,9 +21,6 @@ // Include boost/foreach here as it defines __STDC_LIMIT_MACROS on some systems. #include <boost/foreach.hpp> -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS // to enable UINT64_MAX from stdint.h -#endif #if (defined(__unix__) || defined(unix)) && !defined(USG) #include <sys/param.h> // to get BSD define @@ -44,7 +41,6 @@ #include <stdlib.h> #include <time.h> #include <math.h> -#include <limits.h> #include <float.h> #include <assert.h> #include <iostream> diff --git a/src/init.cpp b/src/init.cpp index 76317557bc..1e389b226b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -10,6 +10,7 @@ #include "strlcpy.h" #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> +#include <boost/filesystem/convenience.hpp> #include <boost/interprocess/sync/file_lock.hpp> #if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED) @@ -148,7 +149,10 @@ bool AppInit2(int argc, char* argv[]) // // Parameters // + // If Qt is used, parameters are parsed in qt/bitcoin.cpp's main() +#if !defined(QT_GUI) ParseParameters(argc, argv); +#endif if (mapArgs.count("-datadir")) { @@ -523,6 +527,11 @@ bool AppInit2(int argc, char* argv[]) if (fServer) CreateThread(ThreadRPCServer, NULL); +#ifdef QT_GUI + if(GetStartOnSystemStartup()) + SetStartOnSystemStartup(true); // Remove startup links to bitcoin-wx +#endif + #if !defined(QT_GUI) while (1) Sleep(5000); @@ -530,3 +539,152 @@ bool AppInit2(int argc, char* argv[]) return true; } + +#ifdef WIN32 +string StartupShortcutPath() +{ + return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk"; +} + +bool GetStartOnSystemStartup() +{ + return filesystem::exists(StartupShortcutPath().c_str()); +} + +bool SetStartOnSystemStartup(bool fAutoStart) +{ + // If the shortcut exists already, remove it for updating + remove(StartupShortcutPath().c_str()); + + if (fAutoStart) + { + CoInitialize(NULL); + + // Get a pointer to the IShellLink interface. + IShellLink* psl = NULL; + HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, + CLSCTX_INPROC_SERVER, IID_IShellLink, + reinterpret_cast<void**>(&psl)); + + if (SUCCEEDED(hres)) + { + // Get the current executable path + TCHAR pszExePath[MAX_PATH]; + GetModuleFileName(NULL, pszExePath, sizeof(pszExePath)); + + TCHAR pszArgs[5] = TEXT("-min"); + + // Set the path to the shortcut target + psl->SetPath(pszExePath); + PathRemoveFileSpec(pszExePath); + psl->SetWorkingDirectory(pszExePath); + psl->SetShowCmd(SW_SHOWMINNOACTIVE); + psl->SetArguments(pszArgs); + + // Query IShellLink for the IPersistFile interface for + // saving the shortcut in persistent storage. + IPersistFile* ppf = NULL; + hres = psl->QueryInterface(IID_IPersistFile, + reinterpret_cast<void**>(&ppf)); + if (SUCCEEDED(hres)) + { + WCHAR pwsz[MAX_PATH]; + // Ensure that the string is ANSI. + MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().c_str(), -1, pwsz, MAX_PATH); + // Save the link by calling IPersistFile::Save. + hres = ppf->Save(pwsz, TRUE); + ppf->Release(); + psl->Release(); + CoUninitialize(); + return true; + } + psl->Release(); + } + CoUninitialize(); + return false; + } + return true; +} + +#elif defined(LINUX) + +// Follow the Desktop Application Autostart Spec: +// http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html + +boost::filesystem::path GetAutostartDir() +{ + namespace fs = boost::filesystem; + + char* pszConfigHome = getenv("XDG_CONFIG_HOME"); + if (pszConfigHome) return fs::path(pszConfigHome) / fs::path("autostart"); + char* pszHome = getenv("HOME"); + if (pszHome) return fs::path(pszHome) / fs::path(".config/autostart"); + return fs::path(); +} + +boost::filesystem::path GetAutostartFilePath() +{ + return GetAutostartDir() / boost::filesystem::path("bitcoin.desktop"); +} + +bool GetStartOnSystemStartup() +{ + boost::filesystem::ifstream optionFile(GetAutostartFilePath()); + if (!optionFile.good()) + return false; + // Scan through file for "Hidden=true": + string line; + while (!optionFile.eof()) + { + getline(optionFile, line); + if (line.find("Hidden") != string::npos && + line.find("true") != string::npos) + return false; + } + optionFile.close(); + + return true; +} + +bool SetStartOnSystemStartup(bool fAutoStart) +{ + if (!fAutoStart) + { +#if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION >= 3 + unlink(GetAutostartFilePath().string().c_str()); +#else + unlink(GetAutostartFilePath().native_file_string().c_str()); +#endif + } + else + { + char pszExePath[MAX_PATH+1]; + memset(pszExePath, 0, sizeof(pszExePath)); + if (readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1) == -1) + return false; + + boost::filesystem::create_directories(GetAutostartDir()); + + boost::filesystem::ofstream optionFile(GetAutostartFilePath(), ios_base::out|ios_base::trunc); + if (!optionFile.good()) + return false; + // Write a bitcoin.desktop file to the autostart directory: + optionFile << "[Desktop Entry]\n"; + optionFile << "Type=Application\n"; + optionFile << "Name=Bitcoin\n"; + optionFile << "Exec=" << pszExePath << " -min\n"; + optionFile << "Terminal=false\n"; + optionFile << "Hidden=false\n"; + optionFile.close(); + } + return true; +} +#else + +// TODO: OSX startup stuff; see: +// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html + +bool GetStartOnSystemStartup() { return false; } +bool SetStartOnSystemStartup(bool fAutoStart) { return false; } + +#endif diff --git a/src/init.h b/src/init.h index 4017f25707..6721b2899b 100644 --- a/src/init.h +++ b/src/init.h @@ -11,4 +11,7 @@ void Shutdown(void* parg); bool AppInit(int argc, char* argv[]); bool AppInit2(int argc, char* argv[]); +bool GetStartOnSystemStartup(); +bool SetStartOnSystemStartup(bool fAutoStart); + #endif @@ -178,13 +178,14 @@ public: bool Sign(uint256 hash, std::vector<unsigned char>& vchSig) { - vchSig.clear(); - unsigned char pchSig[10000]; - unsigned int nSize = 0; - if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), pchSig, &nSize, pkey)) + unsigned int nSize = ECDSA_size(pkey); + vchSig.resize(nSize); // Make sure it is big enough + if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], &nSize, pkey)) + { + vchSig.clear(); return false; - vchSig.resize(nSize); - memcpy(&vchSig[0], pchSig, nSize); + } + vchSig.resize(nSize); // Shrink to fit actual size return true; } diff --git a/src/main.cpp b/src/main.cpp index 5db708a8cf..cfd6ac2c46 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -427,7 +427,7 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi return DoS(100, error("AcceptToMemoryPool() : coinbase as individual tx")); // To help v0.1.5 clients who would see it as a negative number - if ((int64)nLockTime > INT_MAX) + if ((int64)nLockTime > std::numeric_limits<int>::max()) return error("AcceptToMemoryPool() : not accepting nLockTime beyond 2038 yet"); // Rather not work on nonstandard transactions (unless -testnet) @@ -2004,7 +2004,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } // Ask the first connected node for block updates - static int nAskedForBlocks; + static int nAskedForBlocks = 0; if (!pfrom->fClient && (pfrom->nVersion < 32000 || pfrom->nVersion >= 32400) && (nAskedForBlocks < 1 || vNodes.size() <= 1)) diff --git a/src/main.h b/src/main.h index 26d14b0d3f..4543065d72 100644 --- a/src/main.h +++ b/src/main.h @@ -258,17 +258,17 @@ public: CTxIn() { - nSequence = UINT_MAX; + nSequence = std::numeric_limits<unsigned int>::max(); } - explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=UINT_MAX) + explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max()) { prevout = prevoutIn; scriptSig = scriptSigIn; nSequence = nSequenceIn; } - CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=UINT_MAX) + CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max()) { prevout = COutPoint(hashPrevTx, nOut); scriptSig = scriptSigIn; @@ -284,7 +284,7 @@ public: bool IsFinal() const { - return (nSequence == UINT_MAX); + return (nSequence == std::numeric_limits<unsigned int>::max()); } friend bool operator==(const CTxIn& a, const CTxIn& b) @@ -308,7 +308,7 @@ public: str += strprintf(", coinbase %s", HexStr(scriptSig).c_str()); else str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24).c_str()); - if (nSequence != UINT_MAX) + if (nSequence != std::numeric_limits<unsigned int>::max()) str += strprintf(", nSequence=%u", nSequence); str += ")"; return str; @@ -468,7 +468,7 @@ public: return false; bool fNewer = false; - unsigned int nLowest = UINT_MAX; + unsigned int nLowest = std::numeric_limits<unsigned int>::max(); for (int i = 0; i < vin.size(); i++) { if (vin[i].nSequence != old.vin[i].nSequence) diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index 61f8d4881f..c96a12182d 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -64,6 +64,7 @@ LIBS += -l mingwthrd -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l w OBJS= \ obj/checkpoints.o \ obj/crypter.o \ + obj/key.o \ obj/db.o \ obj/init.o \ obj/irc.o \ @@ -72,6 +73,7 @@ OBJS= \ obj/net.o \ obj/protocol.o \ obj/bitcoinrpc.o \ + obj/rpcdump.o \ obj/script.o \ obj/util.o \ obj/wallet.o diff --git a/src/net.cpp b/src/net.cpp index 7d2f18b2d0..9b8dbe11e8 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -249,8 +249,8 @@ bool Lookup(const char *pszName, vector<CAddress>& vaddr, int nServices, int nMa else pszColon[0] = 0; port = portParsed; - if (port < 0 || port > USHRT_MAX) - port = USHRT_MAX; + if (port < 0 || port > std::numeric_limits<unsigned short>::max()) + port = std::numeric_limits<unsigned short>::max(); } } @@ -1488,7 +1488,7 @@ void ThreadOpenConnections2(void* parg) // Choose an address to connect to based on most recently seen // CAddress addrConnect; - int64 nBest = INT64_MIN; + int64 nBest = std::numeric_limits<int64>::min(); // Only connect to one address per a.b.?.? range. // Do this here so we don't have to critsect vNodes inside mapAddresses critsect. diff --git a/src/protocol.cpp b/src/protocol.cpp index f46570e21c..27efb8f293 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -223,7 +223,7 @@ bool CAddress::IsValid() const if (memcmp(pchReserved, pchIPv4+3, sizeof(pchIPv4)-3) == 0) return false; - return (ip != 0 && ip != INADDR_NONE && port != htons(USHRT_MAX)); + return (ip != 0 && ip != INADDR_NONE && port != htons(std::numeric_limits<unsigned short>::max())); } unsigned char CAddress::GetByte(int n) const diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index dd326a690f..cba4e851b4 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -120,6 +120,8 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(bitcoin); QApplication app(argc, argv); + ParseParameters(argc, argv); + // Load language files for system locale: // - First load the translator for the base language, without territory // - Then load the more specific locale translator diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index efc216dab8..a68c84c957 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -2,6 +2,7 @@ #include "bitcoinunits.h" #include "headers.h" +#include "init.h" OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) : QAbstractListModel(parent), @@ -27,7 +28,7 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const switch(index.row()) { case StartAtStartup: - return QVariant(); + return QVariant(GetStartOnSystemStartup()); case MinimizeToTray: return QVariant(fMinimizeToTray); case MapPortUPnP: @@ -62,7 +63,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in switch(index.row()) { case StartAtStartup: - successful = false; /*TODO*/ + successful = SetStartOnSystemStartup(value.toBool()); break; case MinimizeToTray: fMinimizeToTray = value.toBool(); @@ -101,7 +102,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in case ProxyPort: { int nPort = atoi(value.toString().toAscii().data()); - if (nPort > 0 && nPort < USHRT_MAX) + if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max()) { addrProxy.port = htons(nPort); walletdb.WriteSetting("addrProxy", addrProxy); diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 77c5a01260..53cd35b2da 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -187,7 +187,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx) // Sort order, unrecorded transactions sort to the top status.sortKey = strprintf("%010d-%01d-%010u-%03d", - (pindex ? pindex->nHeight : INT_MAX), + (pindex ? pindex->nHeight : std::numeric_limits<int>::max()), (wtx.IsCoinBase() ? 1 : 0), wtx.nTimeReceived, idx); diff --git a/src/serialize.h b/src/serialize.h index d3f6b7d703..54555907d8 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -10,7 +10,7 @@ #include <map> #include <set> #include <cassert> -#include <climits> +#include <limits> #include <cstring> #include <cstdio> @@ -19,16 +19,8 @@ #include <boost/tuple/tuple_comparison.hpp> #include <boost/tuple/tuple_io.hpp> -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else typedef long long int64; typedef unsigned long long uint64; -#endif -#if defined(_MSC_VER) && _MSC_VER < 1300 -#define for if (false) ; else for -#endif #ifdef WIN32 #include <windows.h> @@ -197,8 +189,8 @@ template<typename Stream> inline void Unserialize(Stream& s, bool& a, int, int=0 inline unsigned int GetSizeOfCompactSize(uint64 nSize) { if (nSize < 253) return sizeof(unsigned char); - else if (nSize <= USHRT_MAX) return sizeof(unsigned char) + sizeof(unsigned short); - else if (nSize <= UINT_MAX) return sizeof(unsigned char) + sizeof(unsigned int); + else if (nSize <= std::numeric_limits<unsigned short>::max()) return sizeof(unsigned char) + sizeof(unsigned short); + else if (nSize <= std::numeric_limits<unsigned int>::max()) return sizeof(unsigned char) + sizeof(unsigned int); else return sizeof(unsigned char) + sizeof(uint64); } @@ -210,14 +202,14 @@ void WriteCompactSize(Stream& os, uint64 nSize) unsigned char chSize = nSize; WRITEDATA(os, chSize); } - else if (nSize <= USHRT_MAX) + else if (nSize <= std::numeric_limits<unsigned short>::max()) { unsigned char chSize = 253; unsigned short xSize = nSize; WRITEDATA(os, chSize); WRITEDATA(os, xSize); } - else if (nSize <= UINT_MAX) + else if (nSize <= std::numeric_limits<unsigned int>::max()) { unsigned char chSize = 254; unsigned int xSize = nSize; diff --git a/src/uint256.h b/src/uint256.h index b6132822c5..d3da1f26d2 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -11,16 +11,8 @@ #include <string> #include <vector> -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else typedef long long int64; typedef unsigned long long uint64; -#endif -#if defined(_MSC_VER) && _MSC_VER < 1300 -#define for if (false) ; else for -#endif inline int Testuint256AdHoc(std::vector<std::string> vArg); diff --git a/src/util.cpp b/src/util.cpp index ef276e5103..a45ce33a1c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -31,7 +31,7 @@ string strMiscWarning; bool fTestNet = false; bool fNoListen = false; bool fLogTimestamps = false; - +CMedianFilter<int64> vTimeOffsets(200,0); @@ -133,7 +133,7 @@ uint64 GetRand(uint64 nMax) // The range of the random source must be a multiple of the modulus // to give every possible output value an equal possibility - uint64 nRange = (UINT64_MAX / nMax) * nMax; + uint64 nRange = (std::numeric_limits<uint64>::max() / nMax) * nMax; uint64 nRand = 0; do RAND_bytes((unsigned char*)&nRand, sizeof(nRand)); @@ -941,15 +941,12 @@ void AddTimeData(unsigned int ip, int64 nTime) return; // Add data - static vector<int64> vTimeOffsets; - if (vTimeOffsets.empty()) - vTimeOffsets.push_back(0); - vTimeOffsets.push_back(nOffsetSample); - printf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), vTimeOffsets.back(), vTimeOffsets.back()/60); + vTimeOffsets.input(nOffsetSample); + printf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { - sort(vTimeOffsets.begin(), vTimeOffsets.end()); - int64 nMedian = vTimeOffsets[vTimeOffsets.size()/2]; + int64 nMedian = vTimeOffsets.median(); + std::vector<int64> vSorted = vTimeOffsets.sorted(); // Only let other nodes change our time by so much if (abs64(nMedian) < 70 * 60) { @@ -964,7 +961,7 @@ void AddTimeData(unsigned int ip, int64 nTime) { // If nobody has a time different than ours but within 5 minutes of ours, give a warning bool fMatch = false; - BOOST_FOREACH(int64 nOffset, vTimeOffsets) + BOOST_FOREACH(int64 nOffset, vSorted) if (nOffset != 0 && abs64(nOffset) < 5 * 60) fMatch = true; @@ -978,9 +975,12 @@ void AddTimeData(unsigned int ip, int64 nTime) } } } - BOOST_FOREACH(int64 n, vTimeOffsets) - printf("%+"PRI64d" ", n); - printf("| nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); + if (fDebug) { + BOOST_FOREACH(int64 n, vSorted) + printf("%+"PRI64d" ", n); + printf("| "); + } + printf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); } } diff --git a/src/util.h b/src/util.h index d9a0841a61..bb90869962 100644 --- a/src/util.h +++ b/src/util.h @@ -25,19 +25,8 @@ #include <openssl/ripemd.h> -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else typedef long long int64; typedef unsigned long long uint64; -#endif -#if defined(_MSC_VER) && _MSC_VER < 1300 -#define for if (false) ; else for -#endif -#ifndef _MSC_VER -#define __forceinline inline -#endif #define loop for (;;) #define BEGIN(a) ((char*)&(a)) @@ -53,7 +42,7 @@ typedef unsigned long long uint64; #define snprintf my_snprintf #ifndef PRI64d -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MSVCRT__) +#if defined(_MSC_VER) || defined(__MSVCRT__) #define PRI64d "I64d" #define PRI64u "I64u" #define PRI64x "I64x" @@ -84,11 +73,7 @@ T* alignup(T* p) #ifdef WIN32 #define MSG_NOSIGNAL 0 #define MSG_DONTWAIT 0 -#ifndef UINT64_MAX -#define UINT64_MAX _UI64_MAX -#define INT64_MAX _I64_MAX -#define INT64_MIN _I64_MIN -#endif + #ifndef S_IRUSR #define S_IRUSR 0400 #define S_IWUSR 0200 @@ -474,15 +459,6 @@ inline bool GetBoolArg(const std::string& strArg) -inline void heapchk() -{ -#ifdef WIN32 - /// for debugging - //if (_heapchk() != _HEAPOK) - // DebugBreak(); -#endif -} - // Randomize the stack to help protect against buffer overrun exploits #define IMPLEMENT_RANDOMIZE_STACK(ThreadFn) \ { \ @@ -622,6 +598,16 @@ public: return (vSorted[size/2-1] + vSorted[size/2]) / 2; } } + + int size() const + { + return vValues.size(); + } + + std::vector<T> sorted () const + { + return vSorted; + } }; diff --git a/src/wallet.cpp b/src/wallet.cpp index 3dc804c851..539452841f 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -808,7 +808,7 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe // List of values less than target pair<int64, pair<const CWalletTx*,unsigned int> > coinLowestLarger; - coinLowestLarger.first = INT64_MAX; + coinLowestLarger.first = std::numeric_limits<int64>::max(); coinLowestLarger.second.first = NULL; vector<pair<int64, pair<const CWalletTx*,unsigned int> > > vValue; int64 nTotalLower = 0; |