diff --git a/configure.ac b/configure.ac index f6d870f33..68dbfdc14 100644 --- a/configure.ac +++ b/configure.ac @@ -151,7 +151,7 @@ PKG_PROG_PKG_CONFIG ## compatibility with the legacy buildsystem. ## CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter" -CPPFLAGS="$CPPFLAGS -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO" +CPPFLAGS="$CPPFLAGS -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS" AC_LANG_PUSH([C++]) diff --git a/share/qt/extract_strings_qt.py b/share/qt/extract_strings_qt.py index c9a96b21f..e6afe3b48 100755 --- a/share/qt/extract_strings_qt.py +++ b/share/qt/extract_strings_qt.py @@ -57,7 +57,10 @@ child = Popen([XGETTEXT,'--output=-','-n','--keyword=_'] + files, stdout=PIPE) messages = parse_po(out) f = open(OUT_CPP, 'w') -f.write("""#include +f.write(""" + +#include + // Automatically generated by extract_strings.py #ifdef __GNUC__ #define UNUSED __attribute__((unused)) @@ -70,5 +73,5 @@ messages.sort(key=operator.itemgetter(0)) for (msgid, msgstr) in messages: if msgid != EMPTY: f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid))) -f.write('};') +f.write('};\n') f.close() diff --git a/src/Makefile.am b/src/Makefile.am index b09c65659..2571a6d75 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,7 @@ BITCOIN_CORE_H = addrman.h alert.h allocators.h base58.h bignum.h \ bitcoinrpc.h bloom.h chainparams.h checkpoints.h checkqueue.h \ clientversion.h compat.h core.h crypter.h db.h hash.h init.h \ key.h keystore.h leveldbwrapper.h limitedmap.h main.h miner.h mruset.h \ - netbase.h net.h protocol.h script.h serialize.h sync.h threadsafety.h \ + netbase.h net.h noui.h protocol.h script.h serialize.h sync.h threadsafety.h \ txdb.h txmempool.h ui_interface.h uint256.h util.h version.h walletdb.h wallet.h JSON_H = json/json_spirit.h json/json_spirit_error_position.h \ diff --git a/src/addrman.cpp b/src/addrman.cpp index 731ff2abe..815da07c9 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -3,7 +3,9 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "addrman.h" + #include "hash.h" +#include "serialize.h" using namespace std; @@ -12,12 +14,12 @@ int CAddrInfo::GetTriedBucket(const std::vector &nKey) const CDataStream ss1(SER_GETHASH, 0); std::vector vchKey = GetKey(); ss1 << nKey << vchKey; - uint64 hash1 = Hash(ss1.begin(), ss1.end()).Get64(); + uint64_t hash1 = Hash(ss1.begin(), ss1.end()).Get64(); CDataStream ss2(SER_GETHASH, 0); std::vector vchGroupKey = GetGroup(); ss2 << nKey << vchGroupKey << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP); - uint64 hash2 = Hash(ss2.begin(), ss2.end()).Get64(); + uint64_t hash2 = Hash(ss2.begin(), ss2.end()).Get64(); return hash2 % ADDRMAN_TRIED_BUCKET_COUNT; } @@ -27,15 +29,15 @@ int CAddrInfo::GetNewBucket(const std::vector &nKey, const CNetAd std::vector vchGroupKey = GetGroup(); std::vector vchSourceGroupKey = src.GetGroup(); ss1 << nKey << vchGroupKey << vchSourceGroupKey; - uint64 hash1 = Hash(ss1.begin(), ss1.end()).Get64(); + uint64_t hash1 = Hash(ss1.begin(), ss1.end()).Get64(); CDataStream ss2(SER_GETHASH, 0); ss2 << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP); - uint64 hash2 = Hash(ss2.begin(), ss2.end()).Get64(); + uint64_t hash2 = Hash(ss2.begin(), ss2.end()).Get64(); return hash2 % ADDRMAN_NEW_BUCKET_COUNT; } -bool CAddrInfo::IsTerrible(int64 nNow) const +bool CAddrInfo::IsTerrible(int64_t nNow) const { if (nLastTry && nLastTry >= nNow-60) // never remove things tried the last minute return false; @@ -55,12 +57,12 @@ bool CAddrInfo::IsTerrible(int64 nNow) const return false; } -double CAddrInfo::GetChance(int64 nNow) const +double CAddrInfo::GetChance(int64_t nNow) const { double fChance = 1.0; - int64 nSinceLastSeen = nNow - nTime; - int64 nSinceLastTry = nNow - nLastTry; + int64_t nSinceLastSeen = nNow - nTime; + int64_t nSinceLastTry = nNow - nLastTry; if (nSinceLastSeen < 0) nSinceLastSeen = 0; if (nSinceLastTry < 0) nSinceLastTry = 0; @@ -129,7 +131,7 @@ int CAddrMan::SelectTried(int nKBucket) // random shuffle the first few elements (using the entire list) // find the least recently tried among them - int64 nOldest = -1; + int64_t nOldest = -1; int nOldestPos = -1; for (unsigned int i = 0; i < ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT && i < vTried.size(); i++) { @@ -259,7 +261,7 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId, int nOrigin) return; } -void CAddrMan::Good_(const CService &addr, int64 nTime) +void CAddrMan::Good_(const CService &addr, int64_t nTime) { int nId; CAddrInfo *pinfo = Find(addr, &nId); @@ -308,7 +310,7 @@ void CAddrMan::Good_(const CService &addr, int64 nTime) MakeTried(info, nId, nUBucket); } -bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePenalty) +bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty) { if (!addr.IsRoutable()) return false; @@ -321,9 +323,9 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen { // periodically update nTime bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60); - int64 nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60); + int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60); if (addr.nTime && (!pinfo->nTime || pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty)) - pinfo->nTime = max((int64)0, addr.nTime - nTimePenalty); + pinfo->nTime = max((int64_t)0, addr.nTime - nTimePenalty); // add services pinfo->nServices |= addr.nServices; @@ -348,7 +350,7 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen return false; } else { pinfo = Create(addr, source, &nId); - pinfo->nTime = max((int64)0, (int64)pinfo->nTime - nTimePenalty); + pinfo->nTime = max((int64_t)0, (int64_t)pinfo->nTime - nTimePenalty); nNew++; fNew = true; } @@ -365,7 +367,7 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen return fNew; } -void CAddrMan::Attempt_(const CService &addr, int64 nTime) +void CAddrMan::Attempt_(const CService &addr, int64_t nTime) { CAddrInfo *pinfo = Find(addr); @@ -504,7 +506,7 @@ void CAddrMan::GetAddr_(std::vector &vAddr) } } -void CAddrMan::Connected_(const CService &addr, int64 nTime) +void CAddrMan::Connected_(const CService &addr, int64_t nTime) { CAddrInfo *pinfo = Find(addr); @@ -519,7 +521,7 @@ void CAddrMan::Connected_(const CService &addr, int64 nTime) return; // update info - int64 nUpdateInterval = 20 * 60; + int64_t nUpdateInterval = 20 * 60; if (nTime - info.nTime > nUpdateInterval) info.nTime = nTime; } diff --git a/src/addrman.h b/src/addrman.h index d703e1091..e2b0cb109 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -1,21 +1,22 @@ // Copyright (c) 2012 Pieter Wuille // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef _BITCOIN_ADDRMAN #define _BITCOIN_ADDRMAN 1 #include "netbase.h" #include "protocol.h" -#include "util.h" #include "sync.h" - +#include "util.h" #include +#include +#include #include #include - /** Extended statistics about a CAddress */ class CAddrInfo : public CAddress { @@ -24,10 +25,10 @@ private: CNetAddr source; // last successful connection by us - int64 nLastSuccess; + int64_t nLastSuccess; // last try whatsoever by us: - // int64 CAddress::nLastTry + // int64_t CAddress::nLastTry // connection attempts since last successful attempt int nAttempts; @@ -86,10 +87,10 @@ public: } // Determine whether the statistics about this entry are bad enough so that it can just be deleted - bool IsTerrible(int64 nNow = GetAdjustedTime()) const; + bool IsTerrible(int64_t nNow = GetAdjustedTime()) const; // Calculate the relative chance this entry should be given when selecting nodes to connect to - double GetChance(int64 nNow = GetAdjustedTime()) const; + double GetChance(int64_t nNow = GetAdjustedTime()) const; }; @@ -220,13 +221,13 @@ protected: void MakeTried(CAddrInfo& info, int nId, int nOrigin); // Mark an entry "good", possibly moving it from "new" to "tried". - void Good_(const CService &addr, int64 nTime); + void Good_(const CService &addr, int64_t nTime); // Add an entry to the "new" table. - bool Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePenalty); + bool Add_(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty); // Mark an entry as attempted to connect. - void Attempt_(const CService &addr, int64 nTime); + void Attempt_(const CService &addr, int64_t nTime); // Select an address to connect to. // nUnkBias determines how much to favor new addresses over tried ones (min=0, max=100) @@ -241,7 +242,7 @@ protected: void GetAddr_(std::vector &vAddr); // Mark an entry as currently-connected-to. - void Connected_(const CService &addr, int64 nTime); + void Connected_(const CService &addr, int64_t nTime); public: @@ -409,7 +410,7 @@ public: } // Add a single address. - bool Add(const CAddress &addr, const CNetAddr& source, int64 nTimePenalty = 0) + bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0) { bool fRet = false; { @@ -424,7 +425,7 @@ public: } // Add multiple addresses. - bool Add(const std::vector &vAddr, const CNetAddr& source, int64 nTimePenalty = 0) + bool Add(const std::vector &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0) { int nAdd = 0; { @@ -440,7 +441,7 @@ public: } // Mark an entry as accessible. - void Good(const CService &addr, int64 nTime = GetAdjustedTime()) + void Good(const CService &addr, int64_t nTime = GetAdjustedTime()) { { LOCK(cs); @@ -451,7 +452,7 @@ public: } // Mark an entry as connection attempted to. - void Attempt(const CService &addr, int64 nTime = GetAdjustedTime()) + void Attempt(const CService &addr, int64_t nTime = GetAdjustedTime()) { { LOCK(cs); @@ -489,7 +490,7 @@ public: } // Mark an entry as currently-connected-to. - void Connected(const CService &addr, int64 nTime = GetAdjustedTime()) + void Connected(const CService &addr, int64_t nTime = GetAdjustedTime()) { { LOCK(cs); diff --git a/src/alert.cpp b/src/alert.cpp index c9cde1795..b900fe41e 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -2,17 +2,20 @@ // Alert system // -#include -#include -#include -#include -#include - #include "alert.h" + #include "key.h" #include "net.h" -#include "sync.h" #include "ui_interface.h" +#include "util.h" + +#include +#include +#include + +#include +#include +#include using namespace std; @@ -48,8 +51,8 @@ std::string CUnsignedAlert::ToString() const return strprintf( "CAlert(\n" " nVersion = %d\n" - " nRelayUntil = %"PRI64d"\n" - " nExpiration = %"PRI64d"\n" + " nRelayUntil = %"PRId64"\n" + " nExpiration = %"PRId64"\n" " nID = %d\n" " nCancel = %d\n" " setCancel = %s\n" diff --git a/src/alert.h b/src/alert.h index e4841f9c3..da140be5e 100644 --- a/src/alert.h +++ b/src/alert.h @@ -6,13 +6,20 @@ #ifndef _BITCOINALERT_H_ #define _BITCOINALERT_H_ 1 +#include "serialize.h" +#include "sync.h" + +#include #include +#include #include -#include "uint256.h" -#include "util.h" - +class CAlert; class CNode; +class uint256; + +extern std::map mapAlerts; +extern CCriticalSection cs_mapAlerts; /** Alerts are for notifying old versions if they become too obsolete and * need to upgrade. The message is displayed in the status bar. @@ -24,8 +31,8 @@ class CUnsignedAlert { public: int nVersion; - int64 nRelayUntil; // when newer nodes stop relaying to newer nodes - int64 nExpiration; + int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes + int64_t nExpiration; int nID; int nCancel; std::set setCancel; diff --git a/src/allocators.h b/src/allocators.h index a806780ad..7012ef7e2 100644 --- a/src/allocators.h +++ b/src/allocators.h @@ -2,17 +2,18 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_ALLOCATORS_H #define BITCOIN_ALLOCATORS_H -#include +#include #include +#include + #include #include -#include #include // for OPENSSL_cleanse() - /** * Thread-safe class to keep track of locked (ie, non-swappable) memory pages. * diff --git a/src/base58.h b/src/base58.h index 44bf5281e..ebe537682 100644 --- a/src/base58.h +++ b/src/base58.h @@ -3,7 +3,6 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. - // // Why base-58 instead of standard base-64 encoding? // - Don't want 0OIl characters that look the same in some fonts and @@ -15,14 +14,18 @@ #ifndef BITCOIN_BASE58_H #define BITCOIN_BASE58_H -#include -#include - -#include "chainparams.h" #include "bignum.h" +#include "chainparams.h" +#include "hash.h" #include "key.h" #include "script.h" -#include "allocators.h" +#include "uint256.h" + +#include +#include + +#include +#include static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; diff --git a/src/bignum.h b/src/bignum.h index e9d9007d3..0259338b3 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -2,14 +2,19 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_BIGNUM_H #define BITCOIN_BIGNUM_H +#include "serialize.h" +#include "uint256.h" +#include "version.h" + #include +#include #include -#include -#include "util.h" // for uint64 +#include /** Errors thrown by the bignum class */ class bignum_error : public std::runtime_error @@ -79,17 +84,17 @@ public: } //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'. - CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(int64 n) { BN_init(this); setint64(n); } - CBigNum(unsigned char n) { BN_init(this); setulong(n); } - CBigNum(unsigned short n) { BN_init(this); setulong(n); } - CBigNum(unsigned int n) { BN_init(this); setulong(n); } - CBigNum(unsigned long n) { BN_init(this); setulong(n); } - CBigNum(uint64 n) { BN_init(this); setuint64(n); } - explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); } + CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(long long n) { BN_init(this); setint64(n); } + CBigNum(unsigned char n) { BN_init(this); setulong(n); } + CBigNum(unsigned short n) { BN_init(this); setulong(n); } + CBigNum(unsigned int n) { BN_init(this); setulong(n); } + CBigNum(unsigned long n) { BN_init(this); setulong(n); } + CBigNum(unsigned long long n) { BN_init(this); setuint64(n); } + explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); } explicit CBigNum(const std::vector& vch) { @@ -122,14 +127,14 @@ public: return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::min() : -(int)n); } - void setint64(int64 sn) + void setint64(int64_t sn) { unsigned char pch[sizeof(sn) + 6]; unsigned char* p = pch + 4; bool fNegative; - uint64 n; + uint64_t n; - if (sn < (int64)0) + if (sn < (int64_t)0) { // Since the minimum signed integer cannot be represented as positive so long as its type is signed, // and it's not well-defined what happens if you make it unsigned before negating it, @@ -167,7 +172,7 @@ public: BN_mpi2bn(pch, p - pch, this); } - void setuint64(uint64 n) + void setuint64(uint64_t n) { unsigned char pch[sizeof(n) + 6]; unsigned char* p = pch + 4; diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index bb30c748b..aa6ce27c5 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -8,6 +8,8 @@ #include "bitcoinrpc.h" #include "ui_interface.h" /* for _(...) */ +#include + ////////////////////////////////////////////////////////////////////////////// // // Start diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index e0cf1a706..c1b26812b 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -3,12 +3,17 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "ui_interface.h" + + +#include "bitcoinrpc.h" #include "init.h" -#include "util.h" #include "main.h" -#include "bitcoinrpc.h" +#include "noui.h" +#include "ui_interface.h" +#include "util.h" + #include +#include void DetectShutdownThread(boost::thread_group* threadGroup) { @@ -138,7 +143,6 @@ bool AppInit(int argc, char* argv[]) return fRet; } -extern void noui_connect(); int main(int argc, char* argv[]) { bool fRet = false; diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index f3ea0adb4..6ecb70309 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -3,30 +3,27 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "chainparams.h" -#include "main.h" -#include "wallet.h" +#include "bitcoinrpc.h" + +#include "base58.h" #include "init.h" +#include "main.h" #include "util.h" -#include "sync.h" -#include "ui_interface.h" -#include "base58.h" -#include "bitcoinrpc.h" -#include "db.h" +#include "wallet.h" + +#include #include #include -#include #include #include #include -#include #include #include #include #include #include -#include +#include "json/json_spirit_writer_template.h" using namespace std; using namespace boost; @@ -89,18 +86,18 @@ void RPCTypeCheck(const Object& o, } } -int64 AmountFromValue(const Value& value) +int64_t AmountFromValue(const Value& value) { double dAmount = value.get_real(); if (dAmount <= 0.0 || dAmount > 21000000.0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); - int64 nAmount = roundint64(dAmount * COIN); + int64_t nAmount = roundint64(dAmount * COIN); if (!MoneyRange(nAmount)) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); return nAmount; } -Value ValueFromAmount(int64 amount) +Value ValueFromAmount(int64_t amount) { return (double)amount / (double)COIN; } @@ -897,7 +894,7 @@ void RPCRunHandler(const boost::system::error_code& err, boost::function func, int64 nSeconds) +void RPCRunLater(const std::string& name, boost::function func, int64_t nSeconds) { assert(rpc_io_service != NULL); diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 0c1c722b5..46e3ba4f1 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -6,18 +6,19 @@ #ifndef _BITCOINRPC_H_ #define _BITCOINRPC_H_ 1 -#include +#include "uint256.h" + #include #include - -class CBlockIndex; -class CReserveKey; +#include +#include #include "json/json_spirit_reader_template.h" -#include "json/json_spirit_writer_template.h" #include "json/json_spirit_utils.h" +#include "json/json_spirit_writer_template.h" -#include "util.h" +class CBlockIndex; +class CReserveKey; // HTTP status codes enum HTTPStatusCode @@ -96,7 +97,7 @@ void RPCTypeCheck(const json_spirit::Object& o, Run func nSeconds from now. Uses boost deadline timers. Overrides previous timer (if any). */ -void RPCRunLater(const std::string& name, boost::function func, int64 nSeconds); +void RPCRunLater(const std::string& name, boost::function func, int64_t nSeconds); typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp); @@ -146,9 +147,9 @@ extern std::vector ParseHexO(const json_spirit::Object& o, std::s extern void InitRPCMining(); extern void ShutdownRPCMining(); -extern int64 nWalletUnlockTime; -extern int64 AmountFromValue(const json_spirit::Value& value); -extern json_spirit::Value ValueFromAmount(int64 amount); +extern int64_t nWalletUnlockTime; +extern int64_t AmountFromValue(const json_spirit::Value& value); +extern json_spirit::Value ValueFromAmount(int64_t amount); extern double GetDifficulty(const CBlockIndex* blockindex = NULL); extern std::string HexBits(unsigned int nBits); extern std::string HelpRequiringPassphrase(); diff --git a/src/bloom.cpp b/src/bloom.cpp index 8e8d8fa06..cbb8cf4a8 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -1,13 +1,15 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include #include "bloom.h" + #include "core.h" #include "script.h" +#include +#include + #define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455 #define LN2 0.6931471805599453094172321214581765680755001343602552 diff --git a/src/bloom.h b/src/bloom.h index f482bfcc1..75e3f38c5 100644 --- a/src/bloom.h +++ b/src/bloom.h @@ -1,16 +1,17 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_BLOOM_H #define BITCOIN_BLOOM_H -#include - -#include "uint256.h" #include "serialize.h" +#include + class COutPoint; class CTransaction; +class uint256; // 20,000 items with fp rate < 0.1% or 10,000 items and <0.0001% static const unsigned int MAX_BLOOM_FILTER_SIZE = 36000; // bytes diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 82f41bcc5..14da3860a 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -3,9 +3,9 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "assert.h" - #include "chainparams.h" + +#include "assert.h" #include "core.h" #include "protocol.h" #include "util.h" @@ -158,7 +158,7 @@ public: // it'll get a pile of addresses with newer timestamps. // Seed nodes are given a random 'last seen time' of between one and two // weeks ago. - const int64 nOneWeek = 7*24*60*60; + const int64_t nOneWeek = 7*24*60*60; struct in_addr ip; memcpy(&ip, &pnSeed[i], sizeof(ip)); CAddress addr(CService(ip, GetDefaultPort())); diff --git a/src/chainparams.h b/src/chainparams.h index 3f99b7eb0..542afeaf9 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -8,7 +8,6 @@ #include "bignum.h" #include "uint256.h" -#include "util.h" #include diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 76ae911a5..40dd30d1a 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -2,14 +2,16 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include // for 'map_list_of()' -#include - #include "checkpoints.h" #include "main.h" #include "uint256.h" +#include + +#include // for 'map_list_of()' +#include + namespace Checkpoints { typedef std::map MapCheckpoints; @@ -23,8 +25,8 @@ namespace Checkpoints struct CCheckpointData { const MapCheckpoints *mapCheckpoints; - int64 nTimeLastCheckpoint; - int64 nTransactionsLastCheckpoint; + int64_t nTimeLastCheckpoint; + int64_t nTransactionsLastCheckpoint; double fTransactionsPerDay; }; @@ -105,7 +107,7 @@ namespace Checkpoints if (pindex==NULL) return 0.0; - int64 nNow = time(NULL); + int64_t nNow = time(NULL); double fWorkBefore = 0.0; // Amount of work done before pindex double fWorkAfter = 0.0; // Amount of work left after pindex (estimated) diff --git a/src/checkpoints.h b/src/checkpoints.h index 4afd29326..3724c5753 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -1,13 +1,14 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_CHECKPOINT_H #define BITCOIN_CHECKPOINT_H #include -class uint256; class CBlockIndex; +class uint256; /** Block-chain checkpoints are compiled-in sanity checks. * They are updated every release or three. diff --git a/src/checkqueue.h b/src/checkqueue.h index 6e2f609fc..ef7b4ca42 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -1,16 +1,17 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef CHECKQUEUE_H #define CHECKQUEUE_H +#include +#include + #include -#include -#include #include - -#include -#include +#include +#include template class CCheckQueueControl; diff --git a/src/compat.h b/src/compat.h index c910f01cb..1deef493c 100644 --- a/src/compat.h +++ b/src/compat.h @@ -2,6 +2,7 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef _BITCOIN_COMPAT_H #define _BITCOIN_COMPAT_H @@ -18,17 +19,24 @@ #undef FD_SETSIZE // prevent redefinition compiler warning #endif #define FD_SETSIZE 1024 // max number of fds in fd_set -#include + +#include // Must be included before mswsock.h and windows.h + +#include +#include #include #else -#include -#include -#include #include -#include +#include +#include #include +#include #include -#include +#include +#include +#include +#include +#include #endif #ifdef WIN32 diff --git a/src/core.cpp b/src/core.cpp index 5512f81b6..26c2cfc5c 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -4,8 +4,11 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "core.h" + #include "util.h" +#include + std::string COutPoint::ToString() const { return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n); @@ -50,7 +53,7 @@ void CTxIn::print() const LogPrintf("%s\n", ToString().c_str()); } -CTxOut::CTxOut(int64 nValueIn, CScript scriptPubKeyIn) +CTxOut::CTxOut(int64_t nValueIn, CScript scriptPubKeyIn) { nValue = nValueIn; scriptPubKey = scriptPubKeyIn; @@ -63,7 +66,7 @@ uint256 CTxOut::GetHash() const std::string CTxOut::ToString() const { - return strprintf("CTxOut(nValue=%"PRI64d".%08"PRI64d", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30).c_str()); + return strprintf("CTxOut(nValue=%"PRId64".%08"PRId64", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30).c_str()); } void CTxOut::print() const @@ -135,7 +138,7 @@ void CTransaction::print() const // * if e==9, we only know the resulting number is not zero, so output 1 + 10*(n - 1) + 9 // (this is decodable, as d is in [1-9] and e is in [0-9]) -uint64 CTxOutCompressor::CompressAmount(uint64 n) +uint64_t CTxOutCompressor::CompressAmount(uint64_t n) { if (n == 0) return 0; @@ -154,7 +157,7 @@ uint64 CTxOutCompressor::CompressAmount(uint64 n) } } -uint64 CTxOutCompressor::DecompressAmount(uint64 x) +uint64_t CTxOutCompressor::DecompressAmount(uint64_t x) { // x = 0 OR x = 1+10*(9*n + d - 1) + e OR x = 1+10*(n - 1) + 9 if (x == 0) @@ -163,7 +166,7 @@ uint64 CTxOutCompressor::DecompressAmount(uint64 x) // x = 10*(9*n + d - 1) + e int e = x % 10; x /= 10; - uint64 n = 0; + uint64_t n = 0; if (e < 9) { // x = 9*n + d - 1 int d = (x % 9) + 1; diff --git a/src/core.h b/src/core.h index 70e62716f..c881a78f9 100644 --- a/src/core.h +++ b/src/core.h @@ -2,14 +2,17 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_CORE_H #define BITCOIN_CORE_H -#include "uint256.h" -#include "serialize.h" #include "script.h" +#include "serialize.h" +#include "uint256.h" + +#include -#include +#include class CTransaction; @@ -114,7 +117,7 @@ public: class CTxOut { public: - int64 nValue; + int64_t nValue; CScript scriptPubKey; CTxOut() @@ -122,7 +125,7 @@ public: SetNull(); } - CTxOut(int64 nValueIn, CScript scriptPubKeyIn); + CTxOut(int64_t nValueIn, CScript scriptPubKeyIn); IMPLEMENT_SERIALIZE ( @@ -143,7 +146,7 @@ public: uint256 GetHash() const; - bool IsDust(int64 nMinRelayTxFee) const + bool IsDust(int64_t nMinRelayTxFee) const { // "Dust" is defined in terms of CTransaction::nMinRelayTxFee, // which has units satoshis-per-kilobyte. @@ -178,8 +181,8 @@ public: class CTransaction { public: - static int64 nMinTxFee; - static int64 nMinRelayTxFee; + static int64_t nMinTxFee; + static int64_t nMinRelayTxFee; static const int CURRENT_VERSION=1; int nVersion; std::vector vin; @@ -246,17 +249,17 @@ private: CTxOut &txout; public: - static uint64 CompressAmount(uint64 nAmount); - static uint64 DecompressAmount(uint64 nAmount); + static uint64_t CompressAmount(uint64_t nAmount); + static uint64_t DecompressAmount(uint64_t nAmount); CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { } IMPLEMENT_SERIALIZE(({ if (!fRead) { - uint64 nVal = CompressAmount(txout.nValue); + uint64_t nVal = CompressAmount(txout.nValue); READWRITE(VARINT(nVal)); } else { - uint64 nVal = 0; + uint64_t nVal = 0; READWRITE(VARINT(nVal)); txout.nValue = DecompressAmount(nVal); } @@ -599,9 +602,9 @@ public: uint256 GetHash() const; - int64 GetBlockTime() const + int64_t GetBlockTime() const { - return (int64)nTime; + return (int64_t)nTime; } }; diff --git a/src/crypter.cpp b/src/crypter.cpp index f3b9396da..10a34ae24 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -2,12 +2,13 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include -#include +#include "crypter.h" + #include +#include -#include "crypter.h" +#include +#include bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod) { diff --git a/src/crypter.h b/src/crypter.h index 22187791e..861c4f944 100644 --- a/src/crypter.h +++ b/src/crypter.h @@ -1,13 +1,15 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef __CRYPTER_H__ #define __CRYPTER_H__ -#include "allocators.h" /* for SecureString */ -#include "key.h" +#include "allocators.h" #include "serialize.h" +class uint256; + const unsigned int WALLET_CRYPTO_KEY_SIZE = 32; const unsigned int WALLET_CRYPTO_SALT_SIZE = 8; diff --git a/src/db.cpp b/src/db.cpp index 7e58ff45f..a286d9f72 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -3,19 +3,24 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "chainparams.h" #include "db.h" -#include "util.h" -#include "hash.h" + #include "addrman.h" -#include -#include -#include +#include "hash.h" +#include "protocol.h" +#include "util.h" + +#include +#include #ifndef WIN32 -#include "sys/stat.h" +#include #endif +#include +#include +#include + using namespace std; using namespace boost; @@ -430,7 +435,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) void CDBEnv::Flush(bool fShutdown) { - int64 nStart = GetTimeMillis(); + int64_t nStart = GetTimeMillis(); // Flush log data to the actual data file // on all files that are not in use LogPrint("db", "Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started"); @@ -459,7 +464,7 @@ void CDBEnv::Flush(bool fShutdown) else mi++; } - LogPrint("db", "DBFlush(%s)%s ended %15"PRI64d"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); + LogPrint("db", "DBFlush(%s)%s ended %15"PRId64"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); if (fShutdown) { char** listp; diff --git a/src/db.h b/src/db.h index 695e74ef2..e041a5930 100644 --- a/src/db.h +++ b/src/db.h @@ -2,30 +2,29 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_DB_H #define BITCOIN_DB_H -#include "sync.h" #include "serialize.h" +#include "sync.h" +#include "version.h" #include #include #include -#include +#include #include class CAddrMan; struct CBlockLocator; class CDiskBlockIndex; -class CMasterKey; class COutPoint; -class CWallet; extern unsigned int nWalletDBUpdated; void ThreadFlushWalletDB(const std::string& strWalletFile); -bool BackupWallet(const CWallet& wallet, const std::string& strDest); class CDBEnv diff --git a/src/hash.h b/src/hash.h index ff7d57399..7dbf1b644 100644 --- a/src/hash.h +++ b/src/hash.h @@ -2,16 +2,19 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_HASH_H #define BITCOIN_HASH_H -#include "uint256.h" #include "serialize.h" +#include "uint256.h" +#include "version.h" -#include -#include #include +#include +#include + template inline uint256 Hash(const T1 pbegin, const T1 pend) { diff --git a/src/init.cpp b/src/init.cpp index 80ba65f80..6749064ed 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -8,29 +8,30 @@ #endif #include "init.h" -#include "main.h" -#include "core.h" -#include "chainparams.h" -#include "txdb.h" -#include "walletdb.h" + +#include "addrman.h" #include "bitcoinrpc.h" -#include "net.h" -#include "util.h" +#include "checkpoints.h" #include "miner.h" +#include "net.h" +#include "txdb.h" #include "ui_interface.h" -#include "checkpoints.h" +#include "util.h" +#include "wallet.h" +#include "walletdb.h" -#include -#include -#include -#include -#include -#include +#include +#include #ifndef WIN32 #include #endif +#include +#include +#include +#include + using namespace std; using namespace boost; @@ -520,7 +521,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer) // cost to you of processing a transaction. if (mapArgs.count("-mintxfee")) { - int64 n = 0; + int64_t n = 0; if (ParseMoney(mapArgs["-mintxfee"], n) && n > 0) CTransaction::nMinTxFee = n; else @@ -528,7 +529,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer) } if (mapArgs.count("-minrelaytxfee")) { - int64 n = 0; + int64_t n = 0; if (ParseMoney(mapArgs["-minrelaytxfee"], n) && n > 0) CTransaction::nMinRelayTxFee = n; else @@ -582,7 +583,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer) threadGroup.create_thread(&ThreadScriptCheck); } - int64 nStart; + int64_t nStart; // ********************************************************* Step 5: verify wallet database integrity @@ -592,7 +593,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer) { // try moving the database env out of the way boost::filesystem::path pathDatabase = GetDataDir() / "database"; - boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%"PRI64d".bak", GetTime()); + boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%"PRId64".bak", GetTime()); try { boost::filesystem::rename(pathDatabase, pathDatabaseBak); LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string().c_str(), pathDatabaseBak.string().c_str()); @@ -864,7 +865,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer) LogPrintf("Shutdown requested. Exiting.\n"); return false; } - LogPrintf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart); + LogPrintf(" block index %15"PRId64"ms\n", GetTimeMillis() - nStart); if (GetBoolArg("-printblockindex", false) || GetBoolArg("-printblocktree", false)) { @@ -957,7 +958,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer) } LogPrintf("%s", strErrors.str().c_str()); - LogPrintf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart); + LogPrintf(" wallet %15"PRId64"ms\n", GetTimeMillis() - nStart); RegisterWallet(pwalletMain); @@ -979,7 +980,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer) LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight); nStart = GetTimeMillis(); pwalletMain->ScanForWalletTransactions(pindexRescan, true); - LogPrintf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart); + LogPrintf(" rescan %15"PRId64"ms\n", GetTimeMillis() - nStart); pwalletMain->SetBestChain(chainActive.GetLocator()); nWalletDBUpdated++; } @@ -1011,7 +1012,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer) LogPrintf("Invalid or missing peers.dat; recreating\n"); } - LogPrintf("Loaded %i addresses from peers.dat %"PRI64d"ms\n", + LogPrintf("Loaded %i addresses from peers.dat %"PRId64"ms\n", addrman.size(), GetTimeMillis() - nStart); // ********************************************************* Step 11: start node diff --git a/src/init.h b/src/init.h index c33da9425..864f2f461 100644 --- a/src/init.h +++ b/src/init.h @@ -2,14 +2,18 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_INIT_H #define BITCOIN_INIT_H #include -#include class CWallet; +namespace boost { + class thread_group; +}; + extern std::string strWalletFile; extern CWallet* pwalletMain; diff --git a/src/key.cpp b/src/key.cpp index 996539dca..2fd68fa56 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -2,13 +2,12 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "key.h" + #include #include -#include #include - -#include "key.h" - +#include // anonymous namespace with local implementation code (OpenSSL interaction) namespace { diff --git a/src/key.h b/src/key.h index bbe64d668..bb3777e38 100644 --- a/src/key.h +++ b/src/key.h @@ -2,15 +2,17 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_KEY_H #define BITCOIN_KEY_H -#include - #include "allocators.h" +#include "hash.h" #include "serialize.h" #include "uint256.h" -#include "hash.h" + +#include +#include // secp256k1: // const unsigned int PRIVATE_KEY_SIZE = 279; diff --git a/src/keystore.cpp b/src/keystore.cpp index 301180737..05427291e 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -4,8 +4,13 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "keystore.h" + +#include "crypter.h" +#include "key.h" #include "script.h" +#include + bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const { CKey key; diff --git a/src/keystore.h b/src/keystore.h index 4f28fba91..8d936bcab 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -2,11 +2,13 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_KEYSTORE_H #define BITCOIN_KEYSTORE_H -#include "crypter.h" +#include "key.h" #include "sync.h" + #include class CScript; @@ -88,8 +90,10 @@ public: virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const; }; +typedef std::vector > CKeyingMaterial; typedef std::map > > CryptedKeyMap; + /** Keystore which keeps the private keys encrypted. * It derives from the basic key store, which is used if no encryption is active. */ diff --git a/src/leveldbwrapper.cpp b/src/leveldbwrapper.cpp index 399208e66..39ed63b46 100644 --- a/src/leveldbwrapper.cpp +++ b/src/leveldbwrapper.cpp @@ -3,15 +3,15 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "leveldbwrapper.h" + #include "util.h" -#include +#include #include +#include #include #include -#include - void HandleError(const leveldb::Status &status) throw(leveldb_error) { if (status.ok()) return; diff --git a/src/leveldbwrapper.h b/src/leveldbwrapper.h index b4cc53b50..53e9e439b 100644 --- a/src/leveldbwrapper.h +++ b/src/leveldbwrapper.h @@ -7,12 +7,12 @@ #include "serialize.h" #include "util.h" +#include "version.h" +#include #include #include -#include - class leveldb_error : public std::runtime_error { public: diff --git a/src/limitedmap.h b/src/limitedmap.h index 01d1b07df..1623a372b 100644 --- a/src/limitedmap.h +++ b/src/limitedmap.h @@ -1,12 +1,12 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_LIMITEDMAP_H #define BITCOIN_LIMITEDMAP_H #include // TODO: remove #include -#include /** STL-like map container that only keeps the N elements with the highest value. */ template class limitedmap diff --git a/src/main.cpp b/src/main.cpp index 145ff7857..2a133b3ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,20 +3,26 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include -#include +#include "main.h" +#include "addrman.h" #include "alert.h" #include "chainparams.h" #include "checkpoints.h" #include "checkqueue.h" -#include "db.h" #include "init.h" #include "net.h" #include "txdb.h" #include "txmempool.h" #include "ui_interface.h" +#include "util.h" + +#include +#include + +#include +#include +#include using namespace std; using namespace boost; @@ -25,16 +31,13 @@ using namespace boost; // Global state // -CCriticalSection cs_setpwalletRegistered; -set setpwalletRegistered; - CCriticalSection cs_main; CTxMemPool mempool; map mapBlockIndex; CChain chainActive; -int64 nTimeBestReceived = 0; +int64_t nTimeBestReceived = 0; int nScriptCheckThreads = 0; bool fImporting = false; bool fReindex = false; @@ -43,9 +46,9 @@ bool fTxIndex = false; unsigned int nCoinCacheSize = 5000; /** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */ -int64 CTransaction::nMinTxFee = 10000; // Override with -mintxfee +int64_t CTransaction::nMinTxFee = 10000; // Override with -mintxfee /** Fees smaller than this (in satoshi) are considered zero fee (for relaying) */ -int64 CTransaction::nMinRelayTxFee = 10000; +int64_t CTransaction::nMinRelayTxFee = 10000; static CMedianFilter cPeerBlockCounts(8, 0); // Amount of blocks that other nodes claim to have @@ -61,7 +64,7 @@ CScript COINBASE_FLAGS; const string strMessageMagic = "Bitcoin Signed Message:\n"; // Settings -int64 nTransactionFee = 0; +int64_t nTransactionFee = 0; // Internal stuff namespace { @@ -481,7 +484,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason) return true; } -bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64 nBlockTime) +bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) { // Time based nLockTime implemented in 0.1.6 if (tx.nLockTime == 0) @@ -490,7 +493,7 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64 nBlockTime) nBlockHeight = chainActive.Height(); if (nBlockTime == 0) nBlockTime = GetAdjustedTime(); - if ((int64)tx.nLockTime < ((int64)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64)nBlockHeight : nBlockTime)) + if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime)) return true; BOOST_FOREACH(const CTxIn& txin, tx.vin) if (!txin.IsFinal()) @@ -501,9 +504,9 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64 nBlockTime) /** Amount of bitcoins spent by the transaction. @return sum of all outputs (note: does not include fees) */ -int64 GetValueOut(const CTransaction& tx) +int64_t GetValueOut(const CTransaction& tx) { - int64 nValueOut = 0; + int64_t nValueOut = 0; BOOST_FOREACH(const CTxOut& txout, tx.vout) { nValueOut += txout.nValue; @@ -672,7 +675,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state) return state.DoS(100, error("CTransaction::CheckTransaction() : size limits failed")); // Check for negative or overflow output values - int64 nValueOut = 0; + int64_t nValueOut = 0; BOOST_FOREACH(const CTxOut& txout, tx.vout) { if (txout.nValue < 0) @@ -708,13 +711,13 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state) return true; } -int64 GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mode) +int64_t GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mode) { // Base fee is either nMinTxFee or nMinRelayTxFee - int64 nBaseFee = (mode == GMF_RELAY) ? tx.nMinRelayTxFee : tx.nMinTxFee; + int64_t nBaseFee = (mode == GMF_RELAY) ? tx.nMinRelayTxFee : tx.nMinTxFee; unsigned int nBytes = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); - int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee; + int64_t nMinFee = (1 + (int64_t)nBytes / 1000) * nBaseFee; if (fAllowFree) { @@ -842,13 +845,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // you should add code here to check that the transaction does a // reasonable number of ECDSA signature verifications. - int64 nFees = view.GetValueIn(tx)-GetValueOut(tx); + int64_t nFees = view.GetValueIn(tx)-GetValueOut(tx); unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); // Don't accept it if it can't get into a block - int64 txMinFee = GetMinFee(tx, true, GMF_RELAY); + int64_t txMinFee = GetMinFee(tx, true, GMF_RELAY); if (fLimitFree && nFees < txMinFee) - return error("AcceptToMemoryPool: : not enough fees %s, %"PRI64d" < %"PRI64d, + return error("AcceptToMemoryPool: : not enough fees %s, %"PRId64" < %"PRId64, hash.ToString().c_str(), nFees, txMinFee); @@ -859,8 +862,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { static CCriticalSection csFreeLimiter; static double dFreeCount; - static int64 nLastTime; - int64 nNow = GetTime(); + static int64_t nLastTime; + int64_t nNow = GetTime(); LOCK(csFreeLimiter); @@ -876,7 +879,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } if (fRejectInsaneFee && nFees > CTransaction::nMinRelayTxFee * 10000) - return error("AcceptToMemoryPool: : insane fees %s, %"PRI64d" > %"PRI64d, + return error("AcceptToMemoryPool: : insane fees %s, %"PRId64" > %"PRId64, hash.ToString().c_str(), nFees, CTransaction::nMinRelayTxFee * 10000); @@ -1090,9 +1093,9 @@ uint256 static GetOrphanRoot(const CBlockHeader* pblock) return pblock->GetHash(); } -int64 GetBlockValue(int nHeight, int64 nFees) +int64_t GetBlockValue(int nHeight, int64_t nFees) { - int64 nSubsidy = 50 * COIN; + int64_t nSubsidy = 50 * COIN; // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years. nSubsidy >>= (nHeight / Params().SubsidyHalvingInterval()); @@ -1100,15 +1103,15 @@ int64 GetBlockValue(int nHeight, int64 nFees) return nSubsidy + nFees; } -static const int64 nTargetTimespan = 14 * 24 * 60 * 60; // two weeks -static const int64 nTargetSpacing = 10 * 60; -static const int64 nInterval = nTargetTimespan / nTargetSpacing; +static const int64_t nTargetTimespan = 14 * 24 * 60 * 60; // two weeks +static const int64_t nTargetSpacing = 10 * 60; +static const int64_t nInterval = nTargetTimespan / nTargetSpacing; // // minimum amount of work that could possibly be required nTime after // minimum work required was nBase // -unsigned int ComputeMinWork(unsigned int nBase, int64 nTime) +unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime) { const CBigNum &bnLimit = Params().ProofOfWorkLimit(); // Testnet has min-difficulty blocks @@ -1167,8 +1170,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead assert(pindexFirst); // Limit adjustment step - int64 nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime(); - LogPrintf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan); + int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime(); + LogPrintf(" nActualTimespan = %"PRId64" before bounds\n", nActualTimespan); if (nActualTimespan < nTargetTimespan/4) nActualTimespan = nTargetTimespan/4; if (nActualTimespan > nTargetTimespan*4) @@ -1185,7 +1188,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead /// debug print LogPrintf("GetNextWorkRequired RETARGET\n"); - LogPrintf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan); + LogPrintf("nTargetTimespan = %"PRId64" nActualTimespan = %"PRId64"\n", nTargetTimespan, nActualTimespan); LogPrintf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str()); LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str()); @@ -1218,7 +1221,7 @@ bool IsInitialBlockDownload() { if (fImporting || fReindex || chainActive.Height() < Checkpoints::GetTotalBlocksEstimate()) return true; - static int64 nLastUpdate; + static int64_t nLastUpdate; static CBlockIndex* pindexLastBest; if (chainActive.Tip() != pindexLastBest) { @@ -1420,12 +1423,12 @@ const CTxOut &CCoinsViewCache::GetOutputFor(const CTxIn& input) return coins.vout[input.prevout.n]; } -int64 CCoinsViewCache::GetValueIn(const CTransaction& tx) +int64_t CCoinsViewCache::GetValueIn(const CTransaction& tx) { if (tx.IsCoinBase()) return 0; - int64 nResult = 0; + int64_t nResult = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) nResult += GetOutputFor(tx.vin[i]).nValue; @@ -1496,8 +1499,8 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCach // While checking, GetBestBlock() refers to the parent block. // This is also true for mempool checks. int nSpendHeight = inputs.GetBestBlock()->nHeight + 1; - int64 nValueIn = 0; - int64 nFees = 0; + int64_t nValueIn = 0; + int64_t nFees = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { const COutPoint &prevout = tx.vin[i].prevout; @@ -1520,7 +1523,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCach return state.DoS(100, error("CheckInputs() : %s value in < value out", tx.GetHash().ToString().c_str())); // Tally transaction fees - int64 nTxFee = nValueIn - GetValueOut(tx); + int64_t nTxFee = nValueIn - GetValueOut(tx); if (nTxFee < 0) return state.DoS(100, error("CheckInputs() : %s nTxFee < 0", tx.GetHash().ToString().c_str())); nFees += nTxFee; @@ -1725,7 +1728,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C } // BIP16 didn't become active until Apr 1 2012 - int64 nBIP16SwitchTime = 1333238400; + int64_t nBIP16SwitchTime = 1333238400; bool fStrictPayToScriptHash = (pindex->nTime >= nBIP16SwitchTime); unsigned int flags = SCRIPT_VERIFY_NOCACHE | @@ -1735,8 +1738,8 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C CCheckQueueControl control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL); - int64 nStart = GetTimeMicros(); - int64 nFees = 0; + int64_t nStart = GetTimeMicros(); + int64_t nFees = 0; int nInputs = 0; unsigned int nSigOps = 0; CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size())); @@ -1782,16 +1785,16 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C vPos.push_back(std::make_pair(block.GetTxHash(i), pos)); pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION); } - int64 nTime = GetTimeMicros() - nStart; + int64_t nTime = GetTimeMicros() - nStart; if (fBenchmark) LogPrintf("- Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin)\n", (unsigned)block.vtx.size(), 0.001 * nTime, 0.001 * nTime / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * nTime / (nInputs-1)); if (GetValueOut(block.vtx[0]) > GetBlockValue(pindex->nHeight, nFees)) - return state.DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%"PRI64d" vs limit=%"PRI64d")", GetValueOut(block.vtx[0]), GetBlockValue(pindex->nHeight, nFees))); + return state.DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%"PRId64" vs limit=%"PRId64")", GetValueOut(block.vtx[0]), GetBlockValue(pindex->nHeight, nFees))); if (!control.Wait()) return state.DoS(100, false); - int64 nTime2 = GetTimeMicros() - nStart; + int64_t nTime2 = GetTimeMicros() - nStart; if (fBenchmark) LogPrintf("- Verify %u txins: %.2fms (%.3fms/txin)\n", nInputs - 1, 0.001 * nTime2, nInputs <= 1 ? 0 : 0.001 * nTime2 / (nInputs-1)); @@ -1879,7 +1882,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) CBlock block; if (!ReadBlockFromDisk(block, pindex)) return state.Abort(_("Failed to read block")); - int64 nStart = GetTimeMicros(); + int64_t nStart = GetTimeMicros(); if (!DisconnectBlock(block, state, pindex, view)) return error("SetBestBlock() : DisconnectBlock %s failed", pindex->GetBlockHash().ToString().c_str()); if (fBenchmark) @@ -1899,7 +1902,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) CBlock block; if (!ReadBlockFromDisk(block, pindex)) return state.Abort(_("Failed to read block")); - int64 nStart = GetTimeMicros(); + int64_t nStart = GetTimeMicros(); if (!ConnectBlock(block, state, pindex, view)) { if (state.IsInvalid()) { InvalidChainFound(pindexNew); @@ -1916,10 +1919,10 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) } // Flush changes to global coin state - int64 nStart = GetTimeMicros(); + int64_t nStart = GetTimeMicros(); int nModified = view.GetCacheSize(); assert(view.Flush()); - int64 nTime = GetTimeMicros() - nStart; + int64_t nTime = GetTimeMicros() - nStart; if (fBenchmark) LogPrintf("- Flush %i transactions: %.2fms (%.4fms/tx)\n", nModified, 0.001 * nTime, 0.001 * nTime / nModified); @@ -2056,7 +2059,7 @@ bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos } -bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64 nTime, bool fKnown = false) +bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) { bool fUpdatedLast = false; @@ -2309,7 +2312,7 @@ bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, uns return (nFound >= nRequired); } -int64 CBlockIndex::GetMedianTime() const +int64_t CBlockIndex::GetMedianTime() const { const CBlockIndex* pindex = this; for (int i = 0; i < nMedianTimeSpan/2; i++) @@ -2349,7 +2352,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl if (pcheckpoint && pblock->hashPrevBlock != (chainActive.Tip() ? chainActive.Tip()->GetBlockHash() : uint256(0))) { // Extra checks to prevent "fill up memory by spamming with bogus blocks" - int64 deltaTime = pblock->GetBlockTime() - pcheckpoint->nTime; + int64_t deltaTime = pblock->GetBlockTime() - pcheckpoint->nTime; if (deltaTime < 0) { return state.DoS(100, error("ProcessBlock() : block with timestamp before last checkpoint")); @@ -2579,9 +2582,9 @@ bool AbortNode(const std::string &strMessage) { return false; } -bool CheckDiskSpace(uint64 nAdditionalBytes) +bool CheckDiskSpace(uint64_t nAdditionalBytes) { - uint64 nFreeBytesAvailable = filesystem::space(GetDataDir()).available; + uint64_t nFreeBytesAvailable = filesystem::space(GetDataDir()).available; // Check for nMinDiskSpace bytes (currently 50MB) if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) @@ -2888,12 +2891,12 @@ void PrintBlockTree() bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) { - int64 nStart = GetTimeMillis(); + int64_t nStart = GetTimeMillis(); int nLoaded = 0; try { CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8, SER_DISK, CLIENT_VERSION); - uint64 nStartByte = 0; + uint64_t nStartByte = 0; if (dbp) { // (try to) skip already indexed part CBlockFileInfo info; @@ -2902,7 +2905,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) blkdat.Seek(info.nSize); } } - uint64 nRewind = blkdat.GetPos(); + uint64_t nRewind = blkdat.GetPos(); while (blkdat.good() && !blkdat.eof()) { boost::this_thread::interruption_point(); @@ -2928,7 +2931,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) } try { // read block - uint64 nBlockPos = blkdat.GetPos(); + uint64_t nBlockPos = blkdat.GetPos(); blkdat.SetLimit(nBlockPos + nSize); CBlock block; blkdat >> block; @@ -2954,7 +2957,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) AbortNode(_("Error: system error: ") + e.what()); } if (nLoaded > 0) - LogPrintf("Loaded %i blocks from external file in %"PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart); + LogPrintf("Loaded %i blocks from external file in %"PRId64"ms\n", nLoaded, GetTimeMillis() - nStart); return nLoaded > 0; } @@ -2972,9 +2975,6 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) // CAlert // -extern map mapAlerts; -extern CCriticalSection cs_mapAlerts; - string GetWarnings(string strFor) { int nPriority = 0; @@ -3197,10 +3197,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) return false; } - int64 nTime; + int64_t nTime; CAddress addrMe; CAddress addrFrom; - uint64 nNonce = 1; + uint64_t nNonce = 1; vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe; if (pfrom->nVersion < MIN_PEER_PROTO_VERSION) { @@ -3321,8 +3321,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // Store the new addresses vector vAddrOk; - int64 nNow = GetAdjustedTime(); - int64 nSince = nNow - 10 * 60; + int64_t nNow = GetAdjustedTime(); + int64_t nSince = nNow - 10 * 60; BOOST_FOREACH(CAddress& addr, vAddr) { boost::this_thread::interruption_point(); @@ -3341,7 +3341,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) static uint256 hashSalt; if (hashSalt == 0) hashSalt = GetRandHash(); - uint64 hashAddr = addr.GetHash(); + uint64_t hashAddr = addr.GetHash(); uint256 hashRand = hashSalt ^ (hashAddr<<32) ^ ((GetTime()+hashAddr)/(24*60*60)); hashRand = Hash(BEGIN(hashRand), END(hashRand)); multimap mapMix; @@ -3655,7 +3655,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { if (pfrom->nVersion > BIP0031_VERSION) { - uint64 nonce = 0; + uint64_t nonce = 0; vRecv >> nonce; // Echo the message back with the nonce. This allows for two useful features: // @@ -3675,8 +3675,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "pong") { - int64 pingUsecEnd = GetTimeMicros(); - uint64 nonce = 0; + int64_t pingUsecEnd = GetTimeMicros(); + uint64_t nonce = 0; size_t nAvail = vRecv.in_avail(); bool bPingFinished = false; std::string sProblem; @@ -3689,7 +3689,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (nonce == pfrom->nPingNonceSent) { // Matching pong received, this ping is no longer outstanding bPingFinished = true; - int64 pingUsecTime = pingUsecEnd - pfrom->nPingUsecStart; + int64_t pingUsecTime = pingUsecEnd - pfrom->nPingUsecStart; if (pingUsecTime > 0) { // Successful ping time measurement, replace previous pfrom->nPingUsecTime = pingUsecTime; @@ -3716,7 +3716,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } if (!(sProblem.empty())) { - LogPrint("net", "pong %s %s: %s, %"PRI64x" expected, %"PRI64x" received, %"PRIszu" bytes\n", + LogPrint("net", "pong %s %s: %s, %"PRIx64" expected, %"PRIx64" received, %"PRIszu" bytes\n", pfrom->addr.ToString().c_str(), pfrom->strSubVer.c_str(), sProblem.c_str(), @@ -3965,7 +3965,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pingSend = true; } if (pingSend) { - uint64 nonce = 0; + uint64_t nonce = 0; while (nonce == 0) { RAND_bytes((unsigned char*)&nonce, sizeof(nonce)); } @@ -3983,7 +3983,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } // Address refresh broadcast - static int64 nLastRebroadcast; + static int64_t nLastRebroadcast; if (!IsInitialBlockDownload() && (GetTime() - nLastRebroadcast > 24 * 60 * 60)) { { @@ -4103,7 +4103,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Message: getdata // vector vGetData; - int64 nNow = GetTime() * 1000000; + int64_t nNow = GetTime() * 1000000; while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow) { const CInv& inv = (*pto->mapAskFor.begin()).second; diff --git a/src/main.h b/src/main.h index 80972330f..d71780261 100644 --- a/src/main.h +++ b/src/main.h @@ -2,6 +2,7 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_MAIN_H #define BITCOIN_MAIN_H @@ -9,22 +10,27 @@ #include "bitcoin-config.h" #endif -#include "core.h" #include "bignum.h" -#include "sync.h" -#include "txmempool.h" +#include "chainparams.h" +#include "core.h" #include "net.h" #include "script.h" +#include "sync.h" +#include "txmempool.h" +#include "uint256.h" -#include +#include +#include +#include +#include +#include +#include +#include +#include -class CBlock; class CBlockIndex; +class CBloomFilter; class CInv; -class CKeyItem; -class CNode; -class CReserveKey; -class CWallet; /** The maximum allowed size for a serialized block, in bytes (network rule) */ static const unsigned int MAX_BLOCK_SIZE = 1000000; @@ -45,8 +51,8 @@ static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB /** Fake height value used in CCoins to signify they are only in the memory pool (since 0.8) */ static const unsigned int MEMPOOL_HEIGHT = 0x7FFFFFFF; /** No amount larger than this (in satoshi) is valid */ -static const int64 MAX_MONEY = 21000000 * COIN; -inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } +static const int64_t MAX_MONEY = 21000000 * COIN; +inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */ static const int COINBASE_MATURITY = 100; /** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */ @@ -72,10 +78,10 @@ extern CScript COINBASE_FLAGS; extern CCriticalSection cs_main; extern CTxMemPool mempool; extern std::map mapBlockIndex; -extern uint64 nLastBlockTx; -extern uint64 nLastBlockSize; +extern uint64_t nLastBlockTx; +extern uint64_t nLastBlockSize; extern const std::string strMessageMagic; -extern int64 nTimeBestReceived; +extern int64_t nTimeBestReceived; extern bool fImporting; extern bool fReindex; extern bool fBenchmark; @@ -85,17 +91,15 @@ extern unsigned int nCoinCacheSize; extern bool fHaveGUI; // Settings -extern int64 nTransactionFee; +extern int64_t nTransactionFee; // Minimum disk space required - used in CheckDiskSpace() -static const uint64 nMinDiskSpace = 52428800; +static const uint64_t nMinDiskSpace = 52428800; -class CReserveKey; class CCoinsDB; class CBlockTreeDB; struct CDiskBlockPos; -class CCoins; class CTxUndo; class CCoinsView; class CCoinsViewCache; @@ -124,7 +128,7 @@ void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd); /** Process an incoming block */ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL); /** Check whether enough disk space is available for an incoming block */ -bool CheckDiskSpace(uint64 nAdditionalBytes = 0); +bool CheckDiskSpace(uint64_t nAdditionalBytes = 0); /** Open a block file (blk?????.dat) */ FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false); /** Open an undo file (rev?????.dat) */ @@ -150,7 +154,7 @@ void ThreadScriptCheck(); /** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */ bool CheckProofOfWork(uint256 hash, unsigned int nBits); /** Calculate the minimum amount of work a received block needs, without knowing its direct parent */ -unsigned int ComputeMinWork(unsigned int nBase, int64 nTime); +unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime); /** Get the number of active peers */ int GetNumBlocksOfPeers(); /** Check whether we are doing an initial block download (synchronizing from disk or network) */ @@ -163,7 +167,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, b bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew); /** Find the best known block, and make it the tip of the block chain */ bool ConnectBestBlock(CValidationState &state); -int64 GetBlockValue(int nHeight, int64 nFees); +int64_t GetBlockValue(int nHeight, int64_t nFees); unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock); void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev); @@ -247,7 +251,7 @@ enum GetMinFee_mode GMF_SEND, }; -int64 GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mode); +int64_t GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mode); // // Check transaction inputs, and make sure any @@ -307,12 +311,12 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state); */ bool IsStandardTx(const CTransaction& tx, std::string& reason); -bool IsFinalTx(const CTransaction &tx, int nBlockHeight = 0, int64 nBlockTime = 0); +bool IsFinalTx(const CTransaction &tx, int nBlockHeight = 0, int64_t nBlockTime = 0); /** Amount of bitcoins spent by the transaction. @return sum of all outputs (note: does not include fees) */ -int64 GetValueOut(const CTransaction& tx); +int64_t GetValueOut(const CTransaction& tx); /** Undo information for a CBlock */ class CBlockUndo @@ -600,8 +604,8 @@ public: unsigned int nUndoSize; // number of used bytes in the undo file unsigned int nHeightFirst; // lowest height of block in file unsigned int nHeightLast; // highest height of block in file - uint64 nTimeFirst; // earliest time of block in file - uint64 nTimeLast; // latest time of block in file + uint64_t nTimeFirst; // earliest time of block in file + uint64_t nTimeLast; // latest time of block in file IMPLEMENT_SERIALIZE( READWRITE(VARINT(nBlocks)); @@ -632,7 +636,7 @@ public: } // update statistics (does not update nSize) - void AddBlock(unsigned int nHeightIn, uint64 nTimeIn) { + void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) { if (nBlocks==0 || nHeightFirst > nHeightIn) nHeightFirst = nHeightIn; if (nBlocks==0 || nTimeFirst > nTimeIn) @@ -786,9 +790,9 @@ public: return *phashBlock; } - int64 GetBlockTime() const + int64_t GetBlockTime() const { - return (int64)nTime; + return (int64_t)nTime; } CBigNum GetBlockWork() const @@ -807,11 +811,11 @@ public: enum { nMedianTimeSpan=11 }; - int64 GetMedianTimePast() const + int64_t GetMedianTimePast() const { - int64 pmedian[nMedianTimeSpan]; - int64* pbegin = &pmedian[nMedianTimeSpan]; - int64* pend = &pmedian[nMedianTimeSpan]; + int64_t pmedian[nMedianTimeSpan]; + int64_t* pbegin = &pmedian[nMedianTimeSpan]; + int64_t* pend = &pmedian[nMedianTimeSpan]; const CBlockIndex* pindex = this; for (int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->pprev) @@ -821,7 +825,7 @@ public: return pbegin[(pend - pbegin)/2]; } - int64 GetMedianTime() const; + int64_t GetMedianTime() const; /** * Returns true if there are nRequired or more blocks of minVersion or above @@ -1035,11 +1039,11 @@ struct CCoinsStats { int nHeight; uint256 hashBlock; - uint64 nTransactions; - uint64 nTransactionOutputs; - uint64 nSerializedSize; + uint64_t nTransactions; + uint64_t nTransactionOutputs; + uint64_t nSerializedSize; uint256 hashSerialized; - int64 nTotalAmount; + int64_t nTotalAmount; CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {} }; @@ -1130,7 +1134,8 @@ public: @return Sum of value of all inputs (scriptSigs) @see CTransaction::FetchInputs */ - int64 GetValueIn(const CTransaction& tx); + int64_t GetValueIn(const CTransaction& tx); + // Check whether all prevouts of the transaction are present in the UTXO set represented by this view bool HaveInputs(const CTransaction& tx); diff --git a/src/miner.cpp b/src/miner.cpp index b03f915dc..397c95c62 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -4,10 +4,16 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "miner.h" + +#include "core.h" #include "main.h" +#include "net.h" +#include "wallet.h" + +#include double dHashesPerSec = 0.0; -int64 nHPSTimerStart = 0; +int64_t nHPSTimerStart = 0; ////////////////////////////////////////////////////////////////////////////// // @@ -110,8 +116,8 @@ public: }; -uint64 nLastBlockTx = 0; -uint64 nLastBlockSize = 0; +uint64_t nLastBlockTx = 0; +uint64_t nLastBlockSize = 0; // We want to sort transactions by priority and fee, so: typedef boost::tuple TxPriority; @@ -173,7 +179,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); // Collect memory pool transactions into the block - int64 nFees = 0; + int64_t nFees = 0; { LOCK2(cs_main, mempool.cs); CBlockIndex* pindexPrev = chainActive.Tip(); @@ -195,7 +201,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) COrphan* porphan = NULL; double dPriority = 0; - int64 nTotalIn = 0; + int64_t nTotalIn = 0; bool fMissingInputs = false; BOOST_FOREACH(const CTxIn& txin, tx.vin) { @@ -229,7 +235,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } const CCoins &coins = view.GetCoins(txin.prevout.hash); - int64 nValueIn = coins.vout[txin.prevout.n].nValue; + int64_t nValueIn = coins.vout[txin.prevout.n].nValue; nTotalIn += nValueIn; int nConf = pindexPrev->nHeight - coins.nHeight + 1; @@ -269,8 +275,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } // Collect transactions into block - uint64 nBlockSize = 1000; - uint64 nBlockTx = 0; + uint64_t nBlockSize = 1000; + uint64_t nBlockTx = 0; int nBlockSigOps = 100; bool fSortedByFee = (nBlockPrioritySize <= 0); @@ -314,7 +320,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (!view.HaveInputs(tx)) continue; - int64 nTxFees = view.GetValueIn(tx)-GetValueOut(tx); + int64_t nTxFees = view.GetValueIn(tx)-GetValueOut(tx); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) @@ -363,7 +369,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - LogPrintf("CreateNewBlock(): total size %"PRI64u"\n", nBlockSize); + LogPrintf("CreateNewBlock(): total size %"PRIu64"\n", nBlockSize); pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees); pblocktemplate->vTxFees[0] = -nFees; @@ -550,7 +556,7 @@ void static BitcoinMiner(CWallet *pwallet) // // Search // - int64 nStart = GetTime(); + int64_t nStart = GetTime(); uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); uint256 hashbuf[2]; uint256& hash = *alignup<16>(hashbuf); @@ -589,7 +595,7 @@ void static BitcoinMiner(CWallet *pwallet) } // Meter hashes/sec - static int64 nHashCounter; + static int64_t nHashCounter; if (nHPSTimerStart == 0) { nHPSTimerStart = GetTimeMillis(); @@ -607,7 +613,7 @@ void static BitcoinMiner(CWallet *pwallet) dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart); nHPSTimerStart = GetTimeMillis(); nHashCounter = 0; - static int64 nLogTime; + static int64_t nLogTime; if (GetTime() - nLogTime > 30 * 60) { nLogTime = GetTime(); diff --git a/src/miner.h b/src/miner.h index a2800341d..2d953a16a 100644 --- a/src/miner.h +++ b/src/miner.h @@ -2,11 +2,18 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_MINER_H #define BITCOIN_MINER_H -#include "core.h" -#include "wallet.h" +#include + +class CBlock; +class CBlockIndex; +class CBlockTemplate; +class CReserveKey; +class CScript; +class CWallet; /** Run the miner threads */ void GenerateBitcoins(bool fGenerate, CWallet* pwallet); @@ -23,6 +30,6 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey); void SHA256Transform(void* pstate, void* pinput, const void* pinit); extern double dHashesPerSec; -extern int64 nHPSTimerStart; +extern int64_t nHPSTimerStart; #endif // BITCOIN_MINER_H diff --git a/src/mruset.h b/src/mruset.h index a52735182..c36a0c8f3 100644 --- a/src/mruset.h +++ b/src/mruset.h @@ -1,11 +1,13 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_MRUSET_H #define BITCOIN_MRUSET_H -#include #include +#include +#include /** STL-like set container that only keeps the most recent N elements. */ template class mruset diff --git a/src/net.cpp b/src/net.cpp index 8c0ada8f9..954fe5947 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -7,32 +7,34 @@ #include "bitcoin-config.h" #endif -#include "chainparams.h" -#include "db.h" #include "net.h" -#include "core.h" + #include "addrman.h" +#include "chainparams.h" +#include "core.h" +#include "db.h" #include "ui_interface.h" -#include "script.h" + +#include +#include #ifdef WIN32 #include -#endif - -#ifndef WIN32 +#else #include #endif #ifdef USE_UPNP -#include #include +#include #include #include #endif // Dump addresses to peers.dat every 15 minutes (900s) #define DUMP_ADDRESSES_INTERVAL 900 -#if !defined(HAVE_MSG_NOSIGNAL) + +#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) #define MSG_NOSIGNAL 0 #endif @@ -53,14 +55,14 @@ struct LocalServiceInfo { // Global state variables // bool fDiscover = true; -uint64 nLocalServices = NODE_NETWORK; +uint64_t nLocalServices = NODE_NETWORK; static CCriticalSection cs_mapLocalHost; static map mapLocalHost; static bool vfReachable[NET_MAX] = {}; static bool vfLimited[NET_MAX] = {}; static CNode* pnodeLocalHost = NULL; static CNode* pnodeSync = NULL; -uint64 nLocalHostNonce = 0; +uint64_t nLocalHostNonce = 0; static std::vector vhListenSocket; CAddrMan addrman; int nMaxConnections = 125; @@ -68,9 +70,9 @@ int nMaxConnections = 125; vector vNodes; CCriticalSection cs_vNodes; map mapRelay; -deque > vRelayExpiration; +deque > vRelayExpiration; CCriticalSection cs_mapRelay; -limitedmap mapAlreadyAskedFor(MAX_INV_SZ); +limitedmap mapAlreadyAskedFor(MAX_INV_SZ); static deque vOneShots; CCriticalSection cs_vOneShots; @@ -426,8 +428,8 @@ void AddressCurrentlyConnected(const CService& addr) -uint64 CNode::nTotalBytesRecv = 0; -uint64 CNode::nTotalBytesSent = 0; +uint64_t CNode::nTotalBytesRecv = 0; +uint64_t CNode::nTotalBytesSent = 0; CCriticalSection CNode::cs_totalBytesRecv; CCriticalSection CNode::cs_totalBytesSent; @@ -545,7 +547,7 @@ void CNode::PushVersion() int nBestHeight = g_signals.GetHeight().get_value_or(0); /// when NTP implemented, change to just nTime = GetAdjustedTime() - int64 nTime = (fInbound ? GetAdjustedTime() : GetTime()); + int64_t nTime = (fInbound ? GetAdjustedTime() : GetTime()); CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0))); CAddress addrMe = GetLocalAddress(&addr); RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); @@ -558,7 +560,7 @@ void CNode::PushVersion() -std::map CNode::setBanned; +std::map CNode::setBanned; CCriticalSection CNode::cs_setBanned; void CNode::ClearBanned() @@ -571,10 +573,10 @@ bool CNode::IsBanned(CNetAddr ip) bool fResult = false; { LOCK(cs_setBanned); - std::map::iterator i = setBanned.find(ip); + std::map::iterator i = setBanned.find(ip); if (i != setBanned.end()) { - int64 t = (*i).second; + int64_t t = (*i).second; if (GetTime() < t) fResult = true; } @@ -593,7 +595,7 @@ bool CNode::Misbehaving(int howmuch) nMisbehavior += howmuch; if (nMisbehavior >= GetArg("-banscore", 100)) { - int64 banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban + int64_t banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban LogPrintf("Misbehaving: %s (%d -> %d) DISCONNECTING\n", addr.ToString().c_str(), nMisbehavior-howmuch, nMisbehavior); { LOCK(cs_setBanned); @@ -631,7 +633,7 @@ void CNode::copyStats(CNodeStats &stats) // since pingtime does not update until the ping is complete, which might take a while. // So, if a ping is taking an unusually long time in flight, // the caller can immediately detect that this is happening. - int64 nPingUsecWait = 0; + int64_t nPingUsecWait = 0; if ((0 != nPingNonceSent) && (0 != nPingUsecStart)) { nPingUsecWait = GetTimeMicros() - nPingUsecStart; } @@ -1252,12 +1254,12 @@ void ThreadDNSAddressSeed() void DumpAddresses() { - int64 nStart = GetTimeMillis(); + int64_t nStart = GetTimeMillis(); CAddrDB adb; adb.Write(addrman); - LogPrint("net", "Flushed %d addresses to peers.dat %"PRI64d"ms\n", + LogPrint("net", "Flushed %d addresses to peers.dat %"PRId64"ms\n", addrman.size(), GetTimeMillis() - nStart); } @@ -1284,7 +1286,7 @@ void ThreadOpenConnections() // Connect to specific addresses if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) { - for (int64 nLoop = 0;; nLoop++) + for (int64_t nLoop = 0;; nLoop++) { ProcessOneShot(); BOOST_FOREACH(string strAddr, mapMultiArgs["-connect"]) @@ -1301,7 +1303,7 @@ void ThreadOpenConnections() } // Initiate network connections - int64 nStart = GetTime(); + int64_t nStart = GetTime(); while (true) { ProcessOneShot(); @@ -1340,7 +1342,7 @@ void ThreadOpenConnections() } } - int64 nANow = GetAdjustedTime(); + int64_t nANow = GetAdjustedTime(); int nTries = 0; while (true) @@ -1885,25 +1887,25 @@ void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataSt } } -void CNode::RecordBytesRecv(uint64 bytes) +void CNode::RecordBytesRecv(uint64_t bytes) { LOCK(cs_totalBytesRecv); nTotalBytesRecv += bytes; } -void CNode::RecordBytesSent(uint64 bytes) +void CNode::RecordBytesSent(uint64_t bytes) { LOCK(cs_totalBytesSent); nTotalBytesSent += bytes; } -uint64 CNode::GetTotalBytesRecv() +uint64_t CNode::GetTotalBytesRecv() { LOCK(cs_totalBytesRecv); return nTotalBytesRecv; } -uint64 CNode::GetTotalBytesSent() +uint64_t CNode::GetTotalBytesSent() { LOCK(cs_totalBytesSent); return nTotalBytesSent; diff --git a/src/net.h b/src/net.h index 35ee7a06a..b07c10610 100644 --- a/src/net.h +++ b/src/net.h @@ -2,34 +2,45 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_NET_H #define BITCOIN_NET_H +#include "bloom.h" +#include "compat.h" +#include "hash.h" +#include "limitedmap.h" +#include "mruset.h" +#include "netbase.h" +#include "protocol.h" +#include "sync.h" +#include "uint256.h" +#include "util.h" + #include -#include -#include -#include -#include +#include +#include #ifndef WIN32 #include #endif -#include "mruset.h" -#include "limitedmap.h" -#include "netbase.h" -#include "protocol.h" -#include "addrman.h" -#include "hash.h" -#include "bloom.h" - -/** The maximum number of entries in an 'inv' protocol message */ -static const unsigned int MAX_INV_SZ = 50000; +//#include +#include +#include +#include -class CNode; +class CAddrMan; class CBlockIndex; +class CNetAddr; +class CNode; +namespace boost { + class thread_group; +} +/** The maximum number of entries in an 'inv' protocol message */ +static const unsigned int MAX_INV_SZ = 50000; inline unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); } inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); } @@ -85,17 +96,17 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL); extern bool fDiscover; -extern uint64 nLocalServices; -extern uint64 nLocalHostNonce; +extern uint64_t nLocalServices; +extern uint64_t nLocalHostNonce; extern CAddrMan addrman; extern int nMaxConnections; extern std::vector vNodes; extern CCriticalSection cs_vNodes; extern std::map mapRelay; -extern std::deque > vRelayExpiration; +extern std::deque > vRelayExpiration; extern CCriticalSection cs_mapRelay; -extern limitedmap mapAlreadyAskedFor; +extern limitedmap mapAlreadyAskedFor; extern std::vector vAddedNodes; extern CCriticalSection cs_vAddedNodes; @@ -106,18 +117,18 @@ extern CCriticalSection cs_vAddedNodes; class CNodeStats { public: - uint64 nServices; - int64 nLastSend; - int64 nLastRecv; - int64 nTimeConnected; + uint64_t nServices; + int64_t nLastSend; + int64_t nLastRecv; + int64_t nTimeConnected; std::string addrName; int nVersion; std::string strSubVer; bool fInbound; int nStartingHeight; int nMisbehavior; - uint64 nSendBytes; - uint64 nRecvBytes; + uint64_t nSendBytes; + uint64_t nRecvBytes; bool fSyncNode; double dPingTime; double dPingWait; @@ -171,25 +182,25 @@ class CNode { public: // socket - uint64 nServices; + uint64_t nServices; SOCKET hSocket; CDataStream ssSend; size_t nSendSize; // total size of all vSendMsg entries size_t nSendOffset; // offset inside the first vSendMsg already sent - uint64 nSendBytes; + uint64_t nSendBytes; std::deque vSendMsg; CCriticalSection cs_vSend; std::deque vRecvGetData; std::deque vRecvMsg; CCriticalSection cs_vRecvMsg; - uint64 nRecvBytes; + uint64_t nRecvBytes; int nRecvVersion; - int64 nLastSend; - int64 nLastRecv; - int64 nLastSendEmpty; - int64 nTimeConnected; + int64_t nLastSend; + int64_t nLastRecv; + int64_t nLastSendEmpty; + int64_t nTimeConnected; CAddress addr; std::string addrName; CService addrLocal; @@ -214,7 +225,7 @@ protected: // Denial-of-service detection/prevention // Key is IP address, value is banned-until-time - static std::map setBanned; + static std::map setBanned; static CCriticalSection cs_setBanned; int nMisbehavior; @@ -238,12 +249,12 @@ public: mruset setInventoryKnown; std::vector vInventoryToSend; CCriticalSection cs_inventory; - std::multimap mapAskFor; + std::multimap mapAskFor; // Ping time measurement - uint64 nPingNonceSent; - int64 nPingUsecStart; - int64 nPingUsecTime; + uint64_t nPingNonceSent; + int64_t nPingUsecStart; + int64_t nPingUsecTime; bool fPingQueued; CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : ssSend(SER_NETWORK, INIT_PROTO_VERSION) @@ -305,8 +316,8 @@ private: // Network usage totals static CCriticalSection cs_totalBytesRecv; static CCriticalSection cs_totalBytesSent; - static uint64 nTotalBytesRecv; - static uint64 nTotalBytesSent; + static uint64_t nTotalBytesRecv; + static uint64_t nTotalBytesSent; CNode(const CNode&); void operator=(const CNode&); @@ -389,17 +400,17 @@ public: { // We're using mapAskFor as a priority queue, // the key is the earliest time the request can be sent - int64 nRequestTime; - limitedmap::const_iterator it = mapAlreadyAskedFor.find(inv); + int64_t nRequestTime; + limitedmap::const_iterator it = mapAlreadyAskedFor.find(inv); if (it != mapAlreadyAskedFor.end()) nRequestTime = it->second; else nRequestTime = 0; - LogPrint("net", "askfor %s %"PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str()); + LogPrint("net", "askfor %s %"PRId64" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str()); // Make sure not to reuse time indexes to keep things in the same order - int64 nNow = (GetTime() - 1) * 1000000; - static int64 nLastTime; + int64_t nNow = (GetTime() - 1) * 1000000; + static int64_t nLastTime; ++nLastTime; nNow = std::max(nNow, nLastTime); nLastTime = nNow; @@ -664,11 +675,11 @@ public: void copyStats(CNodeStats &stats); // Network stats - static void RecordBytesRecv(uint64 bytes); - static void RecordBytesSent(uint64 bytes); + static void RecordBytesRecv(uint64_t bytes); + static void RecordBytesSent(uint64_t bytes); - static uint64 GetTotalBytesRecv(); - static uint64 GetTotalBytesSent(); + static uint64_t GetTotalBytesRecv(); + static uint64_t GetTotalBytesSent(); }; diff --git a/src/netbase.cpp b/src/netbase.cpp index 36b90e0d4..88c58f854 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -4,9 +4,13 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "netbase.h" -#include "util.h" -#include "sync.h" + #include "hash.h" +#include "sync.h" +#include "uint256.h" +#include "util.h" + +#include #ifndef WIN32 #include @@ -15,7 +19,7 @@ #include // for to_lower() #include // for startswith() and endswith() -#if !defined(HAVE_MSG_NOSIGNAL) +#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) #define MSG_NOSIGNAL 0 #endif @@ -883,10 +887,10 @@ std::vector CNetAddr::GetGroup() const return vchRet; } -uint64 CNetAddr::GetHash() const +uint64_t CNetAddr::GetHash() const { uint256 hash = Hash(&ip[0], &ip[16]); - uint64 nRet; + uint64_t nRet; memcpy(&nRet, &hash, sizeof(nRet)); return nRet; } diff --git a/src/netbase.h b/src/netbase.h index c14fa5075..af40aee94 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -1,6 +1,7 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_NETBASE_H #define BITCOIN_NETBASE_H @@ -8,12 +9,13 @@ #include "bitcoin-config.h" #endif +#include "compat.h" +#include "serialize.h" + +#include #include #include -#include "serialize.h" -#include "compat.h" - extern int nConnectTimeout; #ifdef WIN32 @@ -69,7 +71,7 @@ class CNetAddr std::string ToString() const; std::string ToStringIP() const; unsigned int GetByte(int n) const; - uint64 GetHash() const; + uint64_t GetHash() const; bool GetInAddr(struct in_addr* pipv4Addr) const; std::vector GetGroup() const; int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const; diff --git a/src/noui.cpp b/src/noui.cpp index 06c507d0e..fd285c571 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -3,10 +3,12 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "noui.h" + #include "ui_interface.h" -#include "init.h" -#include "bitcoinrpc.h" +#include "util.h" +#include #include static bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style) @@ -32,7 +34,7 @@ static bool noui_ThreadSafeMessageBox(const std::string& message, const std::str return false; } -static bool noui_ThreadSafeAskFee(int64 /*nFeeRequired*/) +static bool noui_ThreadSafeAskFee(int64_t /*nFeeRequired*/) { return true; } diff --git a/src/noui.h b/src/noui.h new file mode 100644 index 000000000..755d987fd --- /dev/null +++ b/src/noui.h @@ -0,0 +1,10 @@ +// Copyright (c) 2013 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_NOUI_H +#define BITCOIN_NOUI_H + +extern void noui_connect(); + +#endif diff --git a/src/protocol.cpp b/src/protocol.cpp index a841bbc14..798227581 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -4,8 +4,10 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "protocol.h" + #include "util.h" -#include "netbase.h" + +#include #ifndef WIN32 # include @@ -81,7 +83,7 @@ CAddress::CAddress() : CService() Init(); } -CAddress::CAddress(CService ipIn, uint64 nServicesIn) : CService(ipIn) +CAddress::CAddress(CService ipIn, uint64_t nServicesIn) : CService(ipIn) { Init(); nServices = nServicesIn; diff --git a/src/protocol.h b/src/protocol.h index 3d8eae55f..86e08ddcf 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -11,11 +11,13 @@ #define __INCLUDED_PROTOCOL_H__ #include "chainparams.h" -#include "serialize.h" #include "netbase.h" -#include +#include "serialize.h" #include "uint256.h" +#include +#include + /** Message header. * (4) message start. * (12) command. @@ -67,7 +69,7 @@ class CAddress : public CService { public: CAddress(); - explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK); + explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK); void Init(); @@ -90,13 +92,13 @@ class CAddress : public CService // TODO: make private (improves encapsulation) public: - uint64 nServices; + uint64_t nServices; // disk and network only unsigned int nTime; // memory only - int64 nLastTry; + int64_t nLastTry; }; /** inv message data */ diff --git a/src/qt/aboutdialog.cpp b/src/qt/aboutdialog.cpp index e3ef92cae..797ebf97e 100644 --- a/src/qt/aboutdialog.cpp +++ b/src/qt/aboutdialog.cpp @@ -6,6 +6,7 @@ #include "ui_aboutdialog.h" #include "clientmodel.h" + #include "clientversion.h" AboutDialog::AboutDialog(QWidget *parent) : diff --git a/src/qt/aboutdialog.h b/src/qt/aboutdialog.h index 72545f9b2..b02be7484 100644 --- a/src/qt/aboutdialog.h +++ b/src/qt/aboutdialog.h @@ -7,10 +7,11 @@ #include +class ClientModel; + namespace Ui { class AboutDialog; } -class ClientModel; /** "About" dialog box */ class AboutDialog : public QDialog diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index cef307b86..5e82d4d17 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -11,14 +11,14 @@ #include "addresstablemodel.h" #include "bitcoingui.h" -#include "editaddressdialog.h" #include "csvmodelwriter.h" +#include "editaddressdialog.h" #include "guiutil.h" -#include -#include -#include +#include #include +#include +#include AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : QDialog(parent), diff --git a/src/qt/addressbookpage.h b/src/qt/addressbookpage.h index 60b5d8c47..a9192efc8 100644 --- a/src/qt/addressbookpage.h +++ b/src/qt/addressbookpage.h @@ -7,17 +7,19 @@ #include +class AddressTableModel; +class OptionsModel; + namespace Ui { class AddressBookPage; } -class AddressTableModel; QT_BEGIN_NAMESPACE -class QTableView; class QItemSelection; -class QSortFilterProxyModel; class QMenu; class QModelIndex; +class QSortFilterProxyModel; +class QTableView; QT_END_NAMESPACE /** Widget that shows a list of sending or receiving addresses. diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index ab1900fbf..d686cd4fd 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -7,8 +7,8 @@ #include "guiutil.h" #include "walletmodel.h" -#include "wallet.h" #include "base58.h" +#include "wallet.h" #include #include diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h index 1ddee1aeb..71691f5a2 100644 --- a/src/qt/addresstablemodel.h +++ b/src/qt/addresstablemodel.h @@ -9,9 +9,10 @@ #include class AddressTablePriv; -class CWallet; class WalletModel; +class CWallet; + /** Qt model of the address book in the core. This allows views to access and modify the address book. */ diff --git a/src/qt/askpassphrasedialog.cpp b/src/qt/askpassphrasedialog.cpp index 521585644..2a6d6abc3 100644 --- a/src/qt/askpassphrasedialog.cpp +++ b/src/qt/askpassphrasedialog.cpp @@ -8,9 +8,11 @@ #include "guiconstants.h" #include "walletmodel.h" +#include "allocators.h" + +#include #include #include -#include AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) : QDialog(parent), diff --git a/src/qt/askpassphrasedialog.h b/src/qt/askpassphrasedialog.h index 838ad21be..4c92afcd5 100644 --- a/src/qt/askpassphrasedialog.h +++ b/src/qt/askpassphrasedialog.h @@ -7,10 +7,11 @@ #include +class WalletModel; + namespace Ui { class AskPassphraseDialog; } -class WalletModel; /** Multifunctional dialog to ask for passphrases. Used for encryption, unlocking, and changing the passphrase. */ diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 1e2f93f1e..2fa7979ea 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -3,28 +3,35 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "bitcoingui.h" + #include "clientmodel.h" -#include "walletmodel.h" -#include "optionsmodel.h" -#include "guiutil.h" #include "guiconstants.h" -#include "init.h" -#include "util.h" -#include "ui_interface.h" +#include "guiutil.h" +#include "intro.h" +#include "optionsmodel.h" #include "paymentserver.h" #include "splashscreen.h" -#include "intro.h" +#include "walletmodel.h" + +#include "init.h" +#include "main.h" +#include "ui_interface.h" +#include "util.h" +#include + +#include #include +#include +#include #include +#include +#include +#include + #if QT_VERSION < 0x050000 #include #endif -#include -#include -#include -#include -#include #if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED) #define _BITCOIN_QT_PLUGINS_INCLUDED @@ -68,7 +75,7 @@ static bool ThreadSafeMessageBox(const std::string& message, const std::string& } } -static bool ThreadSafeAskFee(int64 nFeeRequired) +static bool ThreadSafeAskFee(int64_t nFeeRequired) { if(!guiref) return false; diff --git a/src/qt/bitcoinamountfield.cpp b/src/qt/bitcoinamountfield.cpp index f722a454f..6b083331d 100644 --- a/src/qt/bitcoinamountfield.cpp +++ b/src/qt/bitcoinamountfield.cpp @@ -4,15 +4,14 @@ #include "bitcoinamountfield.h" -#include "qvaluecombobox.h" #include "bitcoinunits.h" #include "guiconstants.h" +#include "qvaluecombobox.h" #include +#include #include #include -#include - #include // for qPow() BitcoinAmountField::BitcoinAmountField(QWidget *parent): diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 0b6bd517e..a1bb0ee2f 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -4,49 +4,54 @@ #include "bitcoingui.h" -#include "optionsdialog.h" #include "aboutdialog.h" -#include "clientmodel.h" -#include "walletmodel.h" -#include "walletframe.h" -#include "optionsmodel.h" #include "bitcoinunits.h" +#include "clientmodel.h" #include "guiconstants.h" -#include "notificator.h" #include "guiutil.h" +#include "notificator.h" +#include "optionsdialog.h" +#include "optionsmodel.h" #include "rpcconsole.h" -#include "ui_interface.h" -#include "wallet.h" -#include "init.h" +#include "walletframe.h" +#include "walletmodel.h" #ifdef Q_OS_MAC #include "macdockiconhandler.h" #endif +#include "init.h" +#include "ui_interface.h" + +#include + #include -#include -#include +#include +#include +#include #include -#include -#include -#include #include +#include +#include +#include #include +#include +#include #include +#include #include -#include -#include +#include +#include #include -#include +#include +#include + #if QT_VERSION < 0x050000 #include #include +#else +#include #endif -#include -#include -#include - -#include const QString BitcoinGUI::DEFAULT_WALLET = "~Default"; diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 6a2058e0b..2e3b3e74b 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -6,32 +6,22 @@ #define BITCOINGUI_H #include -#include #include +#include -class WalletFrame; -class WalletView; class ClientModel; -class WalletModel; -class WalletStack; -class OverviewPage; -class SendCoinsDialog; -class SendCoinsRecipient; -class SignVerifyMessageDialog; class Notificator; class RPCConsole; +class SendCoinsRecipient; +class WalletFrame; +class WalletModel; class CWallet; QT_BEGIN_NAMESPACE +class QAction; class QLabel; -class QModelIndex; class QProgressBar; -class QStackedWidget; -class QUrl; -class QListWidget; -class QPushButton; -class QAction; QT_END_NAMESPACE /** diff --git a/src/qt/bitcoinstrings.cpp b/src/qt/bitcoinstrings.cpp index 457090b1f..45a9bf6a4 100644 --- a/src/qt/bitcoinstrings.cpp +++ b/src/qt/bitcoinstrings.cpp @@ -1,4 +1,7 @@ + + #include + // Automatically generated by extract_strings.py #ifdef __GNUC__ #define UNUSED __attribute__((unused)) @@ -221,4 +224,4 @@ QT_TRANSLATE_NOOP("bitcoin-core", "Warning"), QT_TRANSLATE_NOOP("bitcoin-core", "Warning: This version is obsolete, upgrade required!"), QT_TRANSLATE_NOOP("bitcoin-core", "You need to rebuild the database using -reindex to change -txindex"), QT_TRANSLATE_NOOP("bitcoin-core", "wallet.dat corrupt, salvage failed"), -}; \ No newline at end of file +}; diff --git a/src/qt/bitcoinunits.h b/src/qt/bitcoinunits.h index 3342eeec1..46517fc07 100644 --- a/src/qt/bitcoinunits.h +++ b/src/qt/bitcoinunits.h @@ -5,8 +5,8 @@ #ifndef BITCOINUNITS_H #define BITCOINUNITS_H -#include #include +#include /** Bitcoin unit definitions. Encapsulates parsing and formatting and serves as list model for drop-down selection boxes. diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 872d71403..c64e411bc 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -5,21 +5,21 @@ #include "clientmodel.h" #include "guiconstants.h" -#include "optionsmodel.h" -#include "addresstablemodel.h" -#include "transactiontablemodel.h" -#include "chainparams.h" #include "alert.h" -#include "main.h" +#include "chainparams.h" #include "checkpoints.h" +#include "main.h" +#include "net.h" #include "ui_interface.h" +#include + #include -#include #include +#include -static const int64 nClientStartupTime = GetTime(); +static const int64_t nClientStartupTime = GetTime(); ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) : QObject(parent), optionsModel(optionsModel), diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index 008320dcc..dcc528f4f 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -7,9 +7,10 @@ #include -class OptionsModel; class AddressTableModel; +class OptionsModel; class TransactionTableModel; + class CWallet; QT_BEGIN_NAMESPACE diff --git a/src/qt/csvmodelwriter.h b/src/qt/csvmodelwriter.h index 890deab09..29de251ef 100644 --- a/src/qt/csvmodelwriter.h +++ b/src/qt/csvmodelwriter.h @@ -5,8 +5,8 @@ #ifndef CSVMODELWRITER_H #define CSVMODELWRITER_H -#include #include +#include QT_BEGIN_NAMESPACE class QAbstractItemModel; diff --git a/src/qt/editaddressdialog.h b/src/qt/editaddressdialog.h index 874678616..a448c4b23 100644 --- a/src/qt/editaddressdialog.h +++ b/src/qt/editaddressdialog.h @@ -7,10 +7,11 @@ #include +class AddressTableModel; + namespace Ui { class EditAddressDialog; } -class AddressTableModel; QT_BEGIN_NAMESPACE class QDataWidgetMapper; diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index eb50aa8ed..e6a1138f1 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -5,33 +5,12 @@ #include "guiutil.h" #include "bitcoinaddressvalidator.h" -#include "walletmodel.h" #include "bitcoinunits.h" +#include "walletmodel.h" -#include "util.h" +#include "core.h" #include "init.h" - -#include -#include -#include -#include -#include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif -#include // for Qt::mightBeRichText -#include -#include -#include -#include -#include -#include -#include - -#include -#include +#include "util.h" #ifdef WIN32 #ifdef _WIN32_WINNT @@ -46,9 +25,31 @@ #ifndef NOMINMAX #define NOMINMAX #endif -#include "shlwapi.h" -#include "shlobj.h" #include "shellapi.h" +#include "shlobj.h" +#include "shlwapi.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // for Qt::mightBeRichText +#include + +#if QT_VERSION < 0x050000 +#include +#else +#include #endif namespace GUIUtil { diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 3c9f137de..8bd0eab9d 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -5,19 +5,19 @@ #ifndef GUIUTIL_H #define GUIUTIL_H -#include -#include #include +#include +#include class SendCoinsRecipient; QT_BEGIN_NAMESPACE +class QAbstractItemView; +class QDateTime; class QFont; class QLineEdit; -class QWidget; -class QDateTime; class QUrl; -class QAbstractItemView; +class QWidget; QT_END_NAMESPACE /** Utility functions used by the Bitcoin Qt UI. diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index e7e768225..3ecd96cc4 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -4,17 +4,17 @@ #include "intro.h" #include "ui_intro.h" + #include "util.h" +#include #include #include #include -#include - /* Minimum free space (in bytes) needed for data directory */ -static const uint64 GB_BYTES = 1000000000LL; -static const uint64 BLOCK_CHAIN_SIZE = 10LL * GB_BYTES; +static const uint64_t GB_BYTES = 1000000000LL; +static const uint64_t BLOCK_CHAIN_SIZE = 10LL * GB_BYTES; /* Check free space asynchronously to prevent hanging the UI thread. @@ -60,7 +60,7 @@ void FreespaceChecker::check() namespace fs = boost::filesystem; QString dataDirStr = intro->getPathToCheck(); fs::path dataDir = fs::path(dataDirStr.toStdString()); - uint64 freeBytesAvailable = 0; + uint64_t freeBytesAvailable = 0; int replyStatus = ST_OK; QString replyMessage = tr("A new data directory will be created."); diff --git a/src/qt/intro.h b/src/qt/intro.h index b25d3f115..72693d554 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -6,13 +6,14 @@ #define INTRO_H #include -#include #include +#include + +class FreespaceChecker; namespace Ui { class Intro; } -class FreespaceChecker; /** Introduction screen (pre-GUI startup). Allows the user to choose a data directory, diff --git a/src/qt/macdockiconhandler.h b/src/qt/macdockiconhandler.h index fba7305a6..b21a61cb0 100644 --- a/src/qt/macdockiconhandler.h +++ b/src/qt/macdockiconhandler.h @@ -5,12 +5,12 @@ #ifndef MACDOCKICONHANDLER_H #define MACDOCKICONHANDLER_H -#include #include +#include QT_BEGIN_NAMESPACE -class QMenu; class QIcon; +class QMenu; class QWidget; QT_END_NAMESPACE diff --git a/src/qt/macnotificationhandler.h b/src/qt/macnotificationhandler.h index 257adde22..bc335eded 100644 --- a/src/qt/macnotificationhandler.h +++ b/src/qt/macnotificationhandler.h @@ -4,6 +4,7 @@ #ifndef MACNOTIFICATIONHANDLER_H #define MACNOTIFICATIONHANDLER_H + #include /** Macintosh-specific notification handler (supports UserNotificationCenter and Growl). diff --git a/src/qt/monitoreddatamapper.cpp b/src/qt/monitoreddatamapper.cpp index 7abecbb12..5931c5387 100644 --- a/src/qt/monitoreddatamapper.cpp +++ b/src/qt/monitoreddatamapper.cpp @@ -4,9 +4,9 @@ #include "monitoreddatamapper.h" -#include #include #include +#include MonitoredDataMapper::MonitoredDataMapper(QObject *parent) : QDataWidgetMapper(parent) diff --git a/src/qt/notificator.cpp b/src/qt/notificator.cpp index fcde23f7e..c9f6834ec 100644 --- a/src/qt/notificator.cpp +++ b/src/qt/notificator.cpp @@ -4,27 +4,31 @@ #include "notificator.h" + #include -#include -#include +#include #include +#include +#include +#include #include -#include #include -#include #include -#include +#include + +#ifdef Q_OS_MAC +#include "macnotificationhandler.h" + +#include +#endif #ifdef USE_DBUS -#include #include -#endif -#ifdef Q_OS_MAC -#include -#include "macnotificationhandler.h" +#include #endif + // https://wiki.ubuntu.com/NotificationDevelopmentGuidelines recommends at least 128 const int FREEDESKTOP_NOTIFICATION_ICON_SIZE = 128; diff --git a/src/qt/notificator.h b/src/qt/notificator.h index e00d08b9c..d6298c3c0 100644 --- a/src/qt/notificator.h +++ b/src/qt/notificator.h @@ -9,11 +9,12 @@ #include "bitcoin-config.h" #endif -#include #include +#include QT_BEGIN_NAMESPACE class QSystemTrayIcon; + #ifdef USE_DBUS class QDBusInterface; #endif diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 85d49e6a2..1e91a877a 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -11,9 +11,10 @@ #include "bitcoinunits.h" #include "monitoreddatamapper.h" -#include "netbase.h" #include "optionsmodel.h" +#include "netbase.h" + #include #include #include diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index fea5c6d2f..05234f645 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -7,12 +7,13 @@ #include +class MonitoredDataMapper; +class OptionsModel; +class QValidatedLineEdit; + namespace Ui { class OptionsDialog; } -class OptionsModel; -class MonitoredDataMapper; -class QValidatedLineEdit; /** Preferences dialog. */ class OptionsDialog : public QDialog diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 48bf357ab..65c017f08 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -9,12 +9,12 @@ #include "optionsmodel.h" #include "bitcoinunits.h" +#include "guiutil.h" + #include "init.h" -#include "core.h" -#include "wallet.h" -#include "netbase.h" +#include "main.h" +#include "net.h" #include "walletdb.h" -#include "guiutil.h" #include @@ -200,7 +200,7 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const return QVariant(5); } case Fee: - return QVariant(nTransactionFee); + return QVariant((qint64) nTransactionFee); case DisplayUnit: return QVariant(nDisplayUnit); case DisplayAddresses: @@ -274,7 +274,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in break; case Fee: nTransactionFee = value.toLongLong(); - settings.setValue("nTransactionFee", nTransactionFee); + settings.setValue("nTransactionFee", (qint64) nTransactionFee); break; case DisplayUnit: nDisplayUnit = value.toInt(); @@ -299,7 +299,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in qint64 OptionsModel::getTransactionFee() { - return nTransactionFee; + return (qint64) nTransactionFee; } bool OptionsModel::getProxySettings(QString& proxyIP, quint16 &proxyPort) const diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index d60ff194c..016097c5a 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -5,14 +5,14 @@ #include "overviewpage.h" #include "ui_overviewpage.h" -#include "clientmodel.h" -#include "walletmodel.h" #include "bitcoinunits.h" +#include "clientmodel.h" +#include "guiconstants.h" +#include "guiutil.h" #include "optionsmodel.h" -#include "transactiontablemodel.h" #include "transactionfilterproxy.h" -#include "guiutil.h" -#include "guiconstants.h" +#include "transactiontablemodel.h" +#include "walletmodel.h" #include #include diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index f66224283..2507a3fb3 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -7,13 +7,14 @@ #include +class ClientModel; +class TransactionFilterProxy; +class TxViewDelegate; +class WalletModel; + namespace Ui { class OverviewPage; } -class ClientModel; -class WalletModel; -class TxViewDelegate; -class TransactionFilterProxy; QT_BEGIN_NAMESPACE class QModelIndex; diff --git a/src/qt/paymentrequestplus.cpp b/src/qt/paymentrequestplus.cpp index c1476a4d5..e369734a9 100644 --- a/src/qt/paymentrequestplus.cpp +++ b/src/qt/paymentrequestplus.cpp @@ -7,16 +7,16 @@ // with some extra methods // -#include -#include -#include +#include "paymentrequestplus.h" + +#include #include #include +#include +#include +#include -#include - -#include "paymentrequestplus.h" class SSLVerifyError : public std::runtime_error { diff --git a/src/qt/paymentrequestplus.h b/src/qt/paymentrequestplus.h index 04848ec4b..8c126b1fa 100644 --- a/src/qt/paymentrequestplus.h +++ b/src/qt/paymentrequestplus.h @@ -5,13 +5,14 @@ #ifndef PAYMENTREQUESTPLUS_H #define PAYMENTREQUESTPLUS_H +#include "paymentrequest.pb.h" + +#include "base58.h" + #include #include #include -#include "base58.h" -#include "paymentrequest.pb.h" - // // Wraps dumb protocol buffer paymentRequest // with extra methods diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 87db4bbf3..cb6291c35 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -2,6 +2,23 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "paymentserver.h" + +#include "bitcoinunits.h" +#include "guiconstants.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "paymentserver.h" +#include "walletmodel.h" + +#include "base58.h" +#include "ui_interface.h" +#include "wallet.h" + +#include + +#include +#include #include #include #include @@ -13,8 +30,6 @@ #include #include #include -#include -#include #include #include #include @@ -22,27 +37,16 @@ #include #include #include +#include +#include + #if QT_VERSION < 0x050000 #include #else #include #endif -#include - -#include -#include - -#include "base58.h" -#include "bitcoinunits.h" -#include "guiconstants.h" -#include "guiutil.h" -#include "optionsmodel.h" -#include "paymentserver.h" -#include "ui_interface.h" -#include "util.h" -#include "wallet.h" -#include "walletmodel.h" +using namespace boost; const int BITCOIN_IPC_CONNECT_TIMEOUT = 1000; // milliseconds const QString BITCOIN_IPC_PREFIX("bitcoin:"); @@ -357,10 +361,10 @@ void PaymentServer::handleURIOrFile(const QString& s) if (s.startsWith(BITCOIN_IPC_PREFIX, Qt::CaseInsensitive)) // bitcoin: { -#if QT_VERSION >= 0x050000 - QUrlQuery uri((QUrl(s))); -#else +#if QT_VERSION < 0x050000 QUrl uri(s); +#else + QUrlQuery uri((QUrl(s))); #endif if (uri.hasQueryItem("request")) { diff --git a/src/qt/paymentserver.h b/src/qt/paymentserver.h index 76cdb819d..65bf03435 100644 --- a/src/qt/paymentserver.h +++ b/src/qt/paymentserver.h @@ -4,8 +4,6 @@ #ifndef PAYMENTSERVER_H #define PAYMENTSERVER_H - -// // This class handles payment requests from clicking on // bitcoin: URIs // @@ -32,13 +30,13 @@ // and, if a server is running in another process, // sends them to the server. // -#include -#include #include "paymentrequestplus.h" #include "walletmodel.h" -class CWallet; +#include +#include + class OptionsModel; QT_BEGIN_NAMESPACE @@ -51,6 +49,8 @@ class QSslError; class QUrl; QT_END_NAMESPACE +class CWallet; + class PaymentServer : public QObject { Q_OBJECT diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 05bc460ab..64a3a68ba 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -6,18 +6,20 @@ #include "ui_rpcconsole.h" #include "clientmodel.h" -#include "bitcoinrpc.h" #include "guiutil.h" -#include -#include +#include "bitcoinrpc.h" + +#include "json/json_spirit_value.h" +#include #include +#include +#include +#include + #if QT_VERSION < 0x050000 #include #endif -#include - -#include // TODO: add a scrollback limit, as there is currently none // TODO: make it possible to filter out categories (esp debug messages when implemented) diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 076575fa3..1370d0b10 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -7,10 +7,11 @@ #include +class ClientModel; + namespace Ui { class RPCConsole; } -class ClientModel; /** Local Bitcoin RPC console. */ class RPCConsole: public QDialog diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 2490c6483..b9c5eb08d 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -6,16 +6,17 @@ #include "ui_sendcoinsdialog.h" #include "bitcoinunits.h" +#include "guiutil.h" #include "optionsmodel.h" #include "sendcoinsentry.h" -#include "guiutil.h" -#include "askpassphrasedialog.h" +#include "walletmodel.h" + #include "base58.h" #include "ui_interface.h" #include -#include #include +#include SendCoinsDialog::SendCoinsDialog(QWidget *parent) : QDialog(parent), @@ -324,7 +325,7 @@ bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient &rv) if (rv.paymentRequest.IsInitialized()) { // Expired payment request? const payments::PaymentDetails& details = rv.paymentRequest.getDetails(); - if (details.has_expires() && (int64)details.expires() < GetTime()) + if (details.has_expires() && (int64_t)details.expires() < GetTime()) { emit message(strSendCoins, tr("Payment request expired"), CClientUIInterface::MSG_WARNING); diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index dcb1f2972..9d5f34f0c 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -8,12 +8,8 @@ #include "walletmodel.h" #include -#include -#include -namespace Ui { - class SendCoinsDialog; -} +class OptionsModel; class SendCoinsEntry; class SendCoinsRecipient; @@ -21,6 +17,10 @@ QT_BEGIN_NAMESPACE class QUrl; QT_END_NAMESPACE +namespace Ui { + class SendCoinsDialog; +} + /** Dialog for sending bitcoins */ class SendCoinsDialog : public QDialog { diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 490b9caf5..2d240f1fe 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -5,12 +5,11 @@ #include "sendcoinsentry.h" #include "ui_sendcoinsentry.h" -#include "guiutil.h" -#include "bitcoinunits.h" #include "addressbookpage.h" -#include "walletmodel.h" -#include "optionsmodel.h" #include "addresstablemodel.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "walletmodel.h" #include #include diff --git a/src/qt/sendcoinsentry.h b/src/qt/sendcoinsentry.h index b658f6205..6fc36f978 100644 --- a/src/qt/sendcoinsentry.h +++ b/src/qt/sendcoinsentry.h @@ -5,14 +5,15 @@ #ifndef SENDCOINSENTRY_H #define SENDCOINSENTRY_H +#include "walletmodel.h" + #include -#include "walletmodel.h" +class WalletModel; namespace Ui { class SendCoinsEntry; } -class WalletModel; /** * A single entry in the dialog for sending bitcoins. diff --git a/src/qt/signverifymessagedialog.cpp b/src/qt/signverifymessagedialog.cpp index 567d46ad3..0fa51cb92 100644 --- a/src/qt/signverifymessagedialog.cpp +++ b/src/qt/signverifymessagedialog.cpp @@ -6,19 +6,18 @@ #include "ui_signverifymessagedialog.h" #include "addressbookpage.h" -#include "base58.h" #include "guiutil.h" -#include "init.h" -#include "main.h" -#include "optionsmodel.h" #include "walletmodel.h" -#include "wallet.h" -#include +#include "base58.h" +#include "init.h" +#include "wallet.h" #include #include +#include + SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SignVerifyMessageDialog), diff --git a/src/qt/signverifymessagedialog.h b/src/qt/signverifymessagedialog.h index a91a30308..c741450b8 100644 --- a/src/qt/signverifymessagedialog.h +++ b/src/qt/signverifymessagedialog.h @@ -7,10 +7,11 @@ #include +class WalletModel; + namespace Ui { class SignVerifyMessageDialog; } -class WalletModel; class SignVerifyMessageDialog : public QDialog { diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index 13d99a589..12280bb70 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -3,9 +3,10 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "splashscreen.h" + +#include "chainparams.h" #include "clientversion.h" #include "util.h" -#include "chainparams.h" #include #include diff --git a/src/qt/test/paymentservertests.cpp b/src/qt/test/paymentservertests.cpp index 34079e94f..f7d26fb91 100644 --- a/src/qt/test/paymentservertests.cpp +++ b/src/qt/test/paymentservertests.cpp @@ -1,17 +1,17 @@ -#include -#include -#include -#include -#include - -#include -#include +#include "paymentservertests.h" #include "optionsmodel.h" -#include "paymentservertests.h" #include "paymentrequestdata.h" + #include "util.h" +#include +#include +#include +#include +#include +#include +#include X509 *parse_b64der_cert(const char* cert_data) diff --git a/src/qt/test/paymentservertests.h b/src/qt/test/paymentservertests.h index 5aa24ebaf..0bff923ad 100644 --- a/src/qt/test/paymentservertests.h +++ b/src/qt/test/paymentservertests.h @@ -1,11 +1,11 @@ #ifndef PAYMENTSERVERTESTS_H #define PAYMENTSERVERTESTS_H -#include -#include - #include "../paymentserver.h" +#include +#include + class PaymentServerTests : public QObject { Q_OBJECT diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp index dae4e6041..5c941c638 100644 --- a/src/qt/test/test_main.cpp +++ b/src/qt/test/test_main.cpp @@ -1,8 +1,10 @@ -#include -#include -#include "uritests.h" + #include "paymentservertests.h" +#include "uritests.h" + +#include +#include // This is all you need to run all the tests int main(int argc, char *argv[]) diff --git a/src/qt/test/uritests.cpp b/src/qt/test/uritests.cpp index df4df3154..5c0f4406a 100644 --- a/src/qt/test/uritests.cpp +++ b/src/qt/test/uritests.cpp @@ -1,6 +1,7 @@ #include "uritests.h" -#include "../guiutil.h" -#include "../walletmodel.h" + +#include "guiutil.h" +#include "walletmodel.h" #include diff --git a/src/qt/test/uritests.h b/src/qt/test/uritests.h index 1237516e5..17d4280a9 100644 --- a/src/qt/test/uritests.h +++ b/src/qt/test/uritests.h @@ -1,8 +1,8 @@ #ifndef URITESTS_H #define URITESTS_H -#include #include +#include class URITests : public QObject { diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 3a9daf066..8bd2bf564 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -4,16 +4,18 @@ #include "transactiondesc.h" -#include "guiutil.h" #include "bitcoinunits.h" -#include "main.h" -#include "wallet.h" -#include "db.h" -#include "ui_interface.h" +#include "guiutil.h" + #include "base58.h" +#include "db.h" +#include "main.h" #include "paymentserver.h" #include "transactionrecord.h" +#include "ui_interface.h" +#include "wallet.h" +#include #include QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx) @@ -46,10 +48,10 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, int vout, int u strHTML.reserve(4000); strHTML += ""; - int64 nTime = wtx.GetTxTime(); - int64 nCredit = wtx.GetCredit(); - int64 nDebit = wtx.GetDebit(); - int64 nNet = nCredit - nDebit; + int64_t nTime = wtx.GetTxTime(); + int64_t nCredit = wtx.GetCredit(); + int64_t nDebit = wtx.GetDebit(); + int64_t nNet = nCredit - nDebit; strHTML += "" + tr("Status") + ": " + FormatTxStatus(wtx); int nRequests = wtx.GetRequestCount(); @@ -129,7 +131,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, int vout, int u // // Coinbase // - int64 nUnmatured = 0; + int64_t nUnmatured = 0; BOOST_FOREACH(const CTxOut& txout, wtx.vout) nUnmatured += wallet->GetCredit(txout); strHTML += "" + tr("Credit") + ": "; @@ -186,13 +188,13 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, int vout, int u if (fAllToMe) { // Payment to self - int64 nChange = wtx.GetChange(); - int64 nValue = nCredit - nChange; + int64_t nChange = wtx.GetChange(); + int64_t nValue = nCredit - nChange; strHTML += "" + tr("Debit") + ": " + BitcoinUnits::formatWithUnit(unit, -nValue) + "
"; strHTML += "" + tr("Credit") + ": " + BitcoinUnits::formatWithUnit(unit, nValue) + "
"; } - int64 nTxFee = nDebit - GetValueOut(wtx); + int64_t nTxFee = nDebit - GetValueOut(wtx); if (nTxFee > 0) strHTML += "" + tr("Transaction fee") + ": " + BitcoinUnits::formatWithUnit(unit, -nTxFee) + "
"; } diff --git a/src/qt/transactiondesc.h b/src/qt/transactiondesc.h index 62f89b728..92d093b3e 100644 --- a/src/qt/transactiondesc.h +++ b/src/qt/transactiondesc.h @@ -5,8 +5,8 @@ #ifndef TRANSACTIONDESC_H #define TRANSACTIONDESC_H -#include #include +#include class CWallet; class CWalletTx; diff --git a/src/qt/transactionfilterproxy.cpp b/src/qt/transactionfilterproxy.cpp index cccb6176a..a14e74a46 100644 --- a/src/qt/transactionfilterproxy.cpp +++ b/src/qt/transactionfilterproxy.cpp @@ -6,10 +6,10 @@ #include "transactiontablemodel.h" -#include - #include +#include + // Earliest date that can be represented (far in the past) const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0); // Last date that can be represented (far in the future) diff --git a/src/qt/transactionfilterproxy.h b/src/qt/transactionfilterproxy.h index 1a7612348..6d1644d48 100644 --- a/src/qt/transactionfilterproxy.h +++ b/src/qt/transactionfilterproxy.h @@ -5,8 +5,8 @@ #ifndef TRANSACTIONFILTERPROXY_H #define TRANSACTIONFILTERPROXY_H -#include #include +#include /** Filter the transaction list according to pre-specified rules. */ class TransactionFilterProxy : public QSortFilterProxyModel diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index c488e2d21..675daa9c9 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -4,8 +4,10 @@ #include "transactionrecord.h" -#include "wallet.h" #include "base58.h" +#include "wallet.h" + +#include /* Return positive answer if transaction should be shown in list. */ @@ -28,10 +30,10 @@ bool TransactionRecord::showTransaction(const CWalletTx &wtx) QList TransactionRecord::decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx) { QList parts; - int64 nTime = wtx.GetTxTime(); - int64 nCredit = wtx.GetCredit(true); - int64 nDebit = wtx.GetDebit(); - int64 nNet = nCredit - nDebit; + int64_t nTime = wtx.GetTxTime(); + int64_t nCredit = wtx.GetCredit(true); + int64_t nDebit = wtx.GetDebit(); + int64_t nNet = nCredit - nDebit; uint256 hash = wtx.GetHash(); std::map mapValue = wtx.mapValue; @@ -83,7 +85,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * if (fAllFromMe && fAllToMe) { // Payment to self - int64 nChange = wtx.GetChange(); + int64_t nChange = wtx.GetChange(); parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, "", -(nDebit - nChange), nCredit - nChange)); @@ -93,7 +95,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * // // Debit // - int64 nTxFee = nDebit - GetValueOut(wtx); + int64_t nTxFee = nDebit - GetValueOut(wtx); for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++) { @@ -122,7 +124,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * sub.address = mapValue["to"]; } - int64 nValue = txout.nValue; + int64_t nValue = txout.nValue; /* Add fee to first output */ if (nTxFee > 0) { @@ -198,7 +200,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx) // For generated transactions, determine maturity if(type == TransactionRecord::Generated) { - int64 nCredit = wtx.GetCredit(true); + int64_t nCredit = wtx.GetCredit(true); if (nCredit == 0) { status.maturity = TransactionStatus::Immature; diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 6f68f93fa..8a7c9044e 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -51,8 +51,8 @@ public: /** @name Reported status @{*/ Status status; - int64 depth; - int64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number + qint64 depth; + qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number of additional blocks that need to be mined before finalization */ /**@}*/ @@ -86,15 +86,15 @@ public: { } - TransactionRecord(uint256 hash, int64 time): + TransactionRecord(uint256 hash, qint64 time): hash(hash), time(time), type(Other), address(""), debit(0), credit(0), idx(0) { } - TransactionRecord(uint256 hash, int64 time, + TransactionRecord(uint256 hash, qint64 time, Type type, const std::string &address, - int64 debit, int64 credit): + qint64 debit, qint64 credit): hash(hash), time(time), type(type), address(address), debit(debit), credit(credit), idx(0) { @@ -108,11 +108,11 @@ public: /** @name Immutable transaction attributes @{*/ uint256 hash; - int64 time; + qint64 time; Type type; std::string address; - int64 debit; - int64 credit; + qint64 debit; + qint64 credit; /**@}*/ /** Subtransaction index, for sort key */ diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index a33f2b5a7..3777e82f3 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -4,24 +4,27 @@ #include "transactiontablemodel.h" -#include "guiutil.h" -#include "transactionrecord.h" +#include "addresstablemodel.h" +#include "bitcoinunits.h" #include "guiconstants.h" +#include "guiutil.h" +#include "optionsmodel.h" #include "transactiondesc.h" +#include "transactionrecord.h" #include "walletmodel.h" -#include "optionsmodel.h" -#include "addresstablemodel.h" -#include "bitcoinunits.h" +#include "main.h" +#include "sync.h" +#include "uint256.h" +#include "util.h" #include "wallet.h" -#include "ui_interface.h" -#include #include -#include -#include #include #include +#include +#include +#include // Amount column is right-aligned it contains numbers static int column_alignments[] = { diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index d1b4f706d..c23c606c3 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -8,11 +8,12 @@ #include #include -class CWallet; -class TransactionTablePriv; class TransactionRecord; +class TransactionTablePriv; class WalletModel; +class CWallet; + /** UI model for the transaction table of a wallet. */ class TransactionTableModel : public QAbstractTableModel diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 46245f00a..d3e2bdf40 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -4,31 +4,32 @@ #include "transactionview.h" -#include "transactionfilterproxy.h" -#include "transactionrecord.h" -#include "walletmodel.h" #include "addresstablemodel.h" -#include "transactiontablemodel.h" #include "bitcoinunits.h" #include "csvmodelwriter.h" -#include "transactiondescdialog.h" #include "editaddressdialog.h" -#include "optionsmodel.h" #include "guiutil.h" +#include "optionsmodel.h" +#include "transactiondescdialog.h" +#include "transactionfilterproxy.h" +#include "transactionrecord.h" +#include "transactiontablemodel.h" +#include "walletmodel.h" + #include "ui_interface.h" -#include #include +#include #include #include -#include -#include -#include #include -#include -#include #include -#include +#include +#include +#include +#include +#include +#include TransactionView::TransactionView(QWidget *parent) : QWidget(parent), model(0), transactionProxyModel(0), diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index 2690cbb8a..18f2b9bfc 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -7,17 +7,17 @@ #include -class WalletModel; class TransactionFilterProxy; +class WalletModel; QT_BEGIN_NAMESPACE -class QTableView; class QComboBox; +class QDateTimeEdit; +class QFrame; class QLineEdit; -class QModelIndex; class QMenu; -class QFrame; -class QDateTimeEdit; +class QModelIndex; +class QTableView; QT_END_NAMESPACE /** Widget showing the transaction list for a wallet, including a filter row. diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index bacc70070..04eea5916 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -3,12 +3,13 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "walletframe.h" -#include "walletview.h" + #include "bitcoingui.h" +#include "walletview.h" + +#include #include -#include -#include WalletFrame::WalletFrame(BitcoinGUI *_gui) : QFrame(_gui), diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 1c24ffb20..b1d770e1a 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -3,18 +3,25 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "walletmodel.h" -#include "guiconstants.h" -#include "optionsmodel.h" + #include "addresstablemodel.h" +#include "guiconstants.h" #include "transactiontablemodel.h" +#include "base58.h" +#include "db.h" +#include "keystore.h" +#include "main.h" +#include "sync.h" #include "ui_interface.h" +#include "wallet.h" #include "walletdb.h" // for BackupWallet -#include "base58.h" +#include + +#include #include #include -#include WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) : QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0), @@ -133,7 +140,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact { qint64 total = 0; QList recipients = transaction.getRecipients(); - std::vector > vecSend; + std::vector > vecSend; if(recipients.empty()) { @@ -148,7 +155,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact { if (rcp.paymentRequest.IsInitialized()) { // PaymentRequest... - int64 subtotal = 0; + int64_t subtotal = 0; const payments::PaymentDetails& details = rcp.paymentRequest.getDetails(); for (int i = 0; i < details.outputs_size(); i++) { @@ -157,7 +164,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact subtotal += out.amount(); const unsigned char* scriptStr = (const unsigned char*)out.script().data(); CScript scriptPubKey(scriptStr, scriptStr+out.script().size()); - vecSend.push_back(std::pair(scriptPubKey, out.amount())); + vecSend.push_back(std::pair(scriptPubKey, out.amount())); } if (subtotal <= 0) { @@ -180,7 +187,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact CScript scriptPubKey; scriptPubKey.SetDestination(CBitcoinAddress(rcp.address.toStdString()).Get()); - vecSend.push_back(std::pair(scriptPubKey, rcp.amount)); + vecSend.push_back(std::pair(scriptPubKey, rcp.amount)); total += rcp.amount; } @@ -205,7 +212,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact LOCK2(cs_main, wallet->cs_wallet); transaction.newPossibleKeyChange(wallet); - int64 nFeeRequired = 0; + int64_t nFeeRequired = 0; std::string strFailReason; CWalletTx *newTx = transaction.getTransaction(); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index efa6ccc66..f39e9dfca 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -5,19 +5,20 @@ #ifndef WALLETMODEL_H #define WALLETMODEL_H -#include +#include "paymentrequestplus.h" +#include "walletmodeltransaction.h" #include "allocators.h" /* for SecureString */ -#include "wallet.h" -#include "walletmodeltransaction.h" -#include "paymentrequestplus.h" -class OptionsModel; +#include + class AddressTableModel; +class OptionsModel; class TransactionTableModel; -class CWallet; class WalletModelTransaction; +class CWallet; + QT_BEGIN_NAMESPACE class QTimer; QT_END_NAMESPACE diff --git a/src/qt/walletmodeltransaction.cpp b/src/qt/walletmodeltransaction.cpp index 96c2794df..943f13e20 100644 --- a/src/qt/walletmodeltransaction.cpp +++ b/src/qt/walletmodeltransaction.cpp @@ -4,6 +4,8 @@ #include "walletmodeltransaction.h" +#include "wallet.h" + WalletModelTransaction::WalletModelTransaction(const QList &recipients) : recipients(recipients), walletTransaction(0), diff --git a/src/qt/walletmodeltransaction.h b/src/qt/walletmodeltransaction.h index efc481443..a948808a7 100644 --- a/src/qt/walletmodeltransaction.h +++ b/src/qt/walletmodeltransaction.h @@ -7,8 +7,14 @@ #include "walletmodel.h" +#include + class SendCoinsRecipient; +class CReserveKey; +class CWallet; +class CWalletTx; + /** Data model for a walletmodel transaction. */ class WalletModelTransaction { diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index b026ca544..248568853 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -3,25 +3,29 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "walletview.h" -#include "bitcoingui.h" -#include "transactiontablemodel.h" + #include "addressbookpage.h" -#include "sendcoinsdialog.h" -#include "receivecoinsdialog.h" -#include "signverifymessagedialog.h" +#include "askpassphrasedialog.h" +#include "bitcoingui.h" #include "clientmodel.h" -#include "walletmodel.h" +#include "guiutil.h" #include "optionsmodel.h" -#include "transactionview.h" #include "overviewpage.h" -#include "askpassphrasedialog.h" +#include "receivecoinsdialog.h" +#include "sendcoinsdialog.h" +#include "signverifymessagedialog.h" +#include "transactiontablemodel.h" +#include "transactionview.h" +#include "walletmodel.h" + #include "ui_interface.h" -#include "guiutil.h" -#include -#include #include +#include +#include +#include #include +#include WalletView::WalletView(QWidget *parent): QStackedWidget(parent), diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 19be8f4d8..d95169162 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -9,17 +9,14 @@ class BitcoinGUI; class ClientModel; -class WalletModel; -class TransactionView; class OverviewPage; -class SendCoinsDialog; class ReceiveCoinsDialog; +class SendCoinsDialog; class SendCoinsRecipient; -class SignVerifyMessageDialog; -class RPCConsole; +class TransactionView; +class WalletModel; QT_BEGIN_NAMESPACE -class QLabel; class QModelIndex; QT_END_NAMESPACE diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 6ea805a7f..18e213257 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -3,8 +3,15 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "main.h" + + #include "bitcoinrpc.h" +#include "main.h" +#include "sync.h" + +#include + +#include "json/json_spirit_value.h" using namespace json_spirit; using namespace std; @@ -112,7 +119,7 @@ Value settxfee(const Array& params, bool fHelp) " is a real and is rounded to the nearest 0.00000001 btc per kb"); // Amount - int64 nAmount = 0; + int64_t nAmount = 0; if (params[0].get_real() != 0.0) nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index f24e6b8a9..68d412490 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -2,30 +2,33 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include -#include "init.h" // for pwalletMain -#include "wallet.h" -#include "bitcoinrpc.h" -#include "ui_interface.h" + #include "base58.h" +#include "bitcoinrpc.h" +#include "init.h" +#include "main.h" +#include "sync.h" +#include "wallet.h" +#include +#include + +#include #include #include -#include -#include +#include "json/json_spirit_value.h" using namespace json_spirit; using namespace std; void EnsureWalletIsUnlocked(); -std::string static EncodeDumpTime(int64 nTime) { - return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime); +std::string static EncodeDumpTime(int64_t nTime) { + return DateTimeStrFormat("%Y-%m-%"PRId64"T%H:%M:%SZ", nTime); } -int64 static DecodeDumpTime(const std::string &str) { +int64_t static DecodeDumpTime(const std::string &str) { static boost::posix_time::time_input_facet facet("%Y-%m-%dT%H:%M:%SZ"); static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0); const std::locale loc(std::locale::classic(), &facet); @@ -125,7 +128,8 @@ Value importwallet(const Array& params, bool fHelp) if (!file.is_open()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); - int64 nTimeBegin = chainActive.Tip()->nTime; + int64_t nTimeBegin = chainActive.Tip()->nTime; + bool fGood = true; @@ -149,7 +153,7 @@ Value importwallet(const Array& params, bool fHelp) LogPrintf("Skipping import of %s (key already present)\n", CBitcoinAddress(keyid).ToString().c_str()); continue; } - int64 nTime = DecodeDumpTime(vstr[1]); + int64_t nTime = DecodeDumpTime(vstr[1]); std::string strLabel; bool fLabel = true; for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) { @@ -228,14 +232,14 @@ Value dumpwallet(const Array& params, bool fHelp) if (!file.is_open()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); - std::map mapKeyBirth; + std::map mapKeyBirth; std::set setKeyPool; pwalletMain->GetKeyBirthTimes(mapKeyBirth); pwalletMain->GetAllReserveKeys(setKeyPool); // sort time/key pairs - std::vector > vKeyBirth; - for (std::map::const_iterator it = mapKeyBirth.begin(); it != mapKeyBirth.end(); it++) { + std::vector > vKeyBirth; + for (std::map::const_iterator it = mapKeyBirth.begin(); it != mapKeyBirth.end(); it++) { vKeyBirth.push_back(std::make_pair(it->second, it->first)); } mapKeyBirth.clear(); @@ -247,7 +251,7 @@ Value dumpwallet(const Array& params, bool fHelp) file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString().c_str()); file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->nTime).c_str()); file << "\n"; - for (std::vector >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) { + for (std::vector >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) { const CKeyID &keyid = it->second; std::string strTime = EncodeDumpTime(it->first); std::string strAddr = CBitcoinAddress(keyid).ToString(); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index d91f26e20..5fe464da8 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -3,11 +3,21 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + + +#include "bitcoinrpc.h" #include "chainparams.h" #include "db.h" #include "init.h" +#include "net.h" +#include "main.h" #include "miner.h" -#include "bitcoinrpc.h" +#include "wallet.h" + +#include + +#include "json/json_spirit_utils.h" +#include "json/json_spirit_value.h" using namespace json_spirit; using namespace std; @@ -51,11 +61,11 @@ Value GetNetworkHashPS(int lookup, int height) { lookup = pb->nHeight; CBlockIndex *pb0 = pb; - int64 minTime = pb0->GetBlockTime(); - int64 maxTime = minTime; + int64_t minTime = pb0->GetBlockTime(); + int64_t maxTime = minTime; for (int i = 0; i < lookup; i++) { pb0 = pb0->pprev; - int64 time = pb0->GetBlockTime(); + int64_t time = pb0->GetBlockTime(); minTime = std::min(time, minTime); maxTime = std::max(time, maxTime); } @@ -65,7 +75,7 @@ Value GetNetworkHashPS(int lookup, int height) { return 0; uint256 workDiff = pb->nChainWork - pb0->nChainWork; - int64 timeDiff = maxTime - minTime; + int64_t timeDiff = maxTime - minTime; return (boost::int64_t)(workDiff.getdouble() / timeDiff); } @@ -187,7 +197,7 @@ Value getwork(const Array& params, bool fHelp) // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; - static int64 nStart; + static int64_t nStart; static CBlockTemplate* pblocktemplate; if (pindexPrev != chainActive.Tip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)) @@ -323,7 +333,7 @@ Value getblocktemplate(const Array& params, bool fHelp) // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; - static int64 nStart; + static int64_t nStart; static CBlockTemplate* pblocktemplate; if (pindexPrev != chainActive.Tip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5)) diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 5d87a2449..488575839 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -2,8 +2,19 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "net.h" + + #include "bitcoinrpc.h" +#include "net.h" +#include "netbase.h" +#include "protocol.h" +#include "sync.h" +#include "util.h" + +#include + +#include +#include "json/json_spirit_value.h" using namespace json_spirit; using namespace std; @@ -68,7 +79,7 @@ Value getpeerinfo(const Array& params, bool fHelp) obj.push_back(Pair("addr", stats.addrName)); if (!(stats.addrLocal.empty())) obj.push_back(Pair("addrlocal", stats.addrLocal)); - obj.push_back(Pair("services", strprintf("%08"PRI64x, stats.nServices))); + obj.push_back(Pair("services", strprintf("%08"PRIx64, stats.nServices))); obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend)); obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv)); obj.push_back(Pair("bytessent", (boost::int64_t)stats.nSendBytes)); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 4771094e1..4912f71f9 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -3,15 +3,21 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include + #include "base58.h" #include "bitcoinrpc.h" -#include "db.h" #include "init.h" #include "net.h" +#include "uint256.h" #include "wallet.h" +#include + +#include +#include "json/json_spirit_utils.h" +#include "json/json_spirit_value.h" + using namespace std; using namespace boost; using namespace boost::assign; @@ -188,7 +194,7 @@ Value listunspent(const Array& params, bool fHelp) continue; } - int64 nValue = out.tx->vout[out.i].nValue; + int64_t nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; Object entry; entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); @@ -269,7 +275,7 @@ Value createrawtransaction(const Array& params, bool fHelp) CScript scriptPubKey; scriptPubKey.SetDestination(address.Get()); - int64 nAmount = AmountFromValue(s.value_); + int64_t nAmount = AmountFromValue(s.value_); CTxOut out(nAmount, scriptPubKey); rawTx.vout.push_back(out); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index fe22dfe54..cb445ed11 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -3,20 +3,29 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include "wallet.h" -#include "walletdb.h" + +#include "base58.h" #include "bitcoinrpc.h" #include "init.h" -#include "base58.h" +#include "net.h" +#include "netbase.h" +#include "util.h" +#include "wallet.h" +#include "walletdb.h" + +#include + +#include +#include "json/json_spirit_utils.h" +#include "json/json_spirit_value.h" using namespace std; using namespace boost; using namespace boost::assign; using namespace json_spirit; -int64 nWalletUnlockTime; +int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; std::string HelpRequiringPassphrase() @@ -287,7 +296,7 @@ Value sendtoaddress(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); // Amount - int64 nAmount = AmountFromValue(params[1]); + int64_t nAmount = AmountFromValue(params[1]); // Wallet comments CWalletTx wtx; @@ -316,7 +325,7 @@ Value listaddressgroupings(const Array& params, bool fHelp) "in past transactions"); Array jsonGroupings; - map balances = pwalletMain->GetAddressBalances(); + map balances = pwalletMain->GetAddressBalances(); BOOST_FOREACH(set grouping, pwalletMain->GetAddressGroupings()) { Array jsonGrouping; @@ -431,7 +440,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) nMinDepth = params[1].get_int(); // Tally - int64 nAmount = 0; + int64_t nAmount = 0; for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; @@ -465,7 +474,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) set setAddress = pwalletMain->GetAccountAddresses(strAccount); // Tally - int64 nAmount = 0; + int64_t nAmount = 0; for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; @@ -485,9 +494,9 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) } -int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth) +int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth) { - int64 nBalance = 0; + int64_t nBalance = 0; // Tally wallet transactions for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) @@ -496,7 +505,7 @@ int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinD if (!IsFinalTx(wtx)) continue; - int64 nReceived, nSent, nFee; + int64_t nReceived, nSent, nFee; wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee); if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth) @@ -510,7 +519,7 @@ int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinD return nBalance; } -int64 GetAccountBalance(const string& strAccount, int nMinDepth) +int64_t GetAccountBalance(const string& strAccount, int nMinDepth) { CWalletDB walletdb(pwalletMain->strWalletFile); return GetAccountBalance(walletdb, strAccount, nMinDepth); @@ -536,24 +545,24 @@ Value getbalance(const Array& params, bool fHelp) // Calculate total balance a different way from GetBalance() // (GetBalance() sums up all unspent TxOuts) // getbalance and getbalance '*' 0 should return the same number - int64 nBalance = 0; + int64_t nBalance = 0; for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; if (!wtx.IsConfirmed()) continue; - int64 allFee; + int64_t allFee; string strSentAccount; - list > listReceived; - list > listSent; + list > listReceived; + list > listSent; wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount); if (wtx.GetDepthInMainChain() >= nMinDepth) { - BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listReceived) + BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived) nBalance += r.second; } - BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listSent) + BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listSent) nBalance -= r.second; nBalance -= allFee; } @@ -562,7 +571,7 @@ Value getbalance(const Array& params, bool fHelp) string strAccount = AccountFromValue(params[0]); - int64 nBalance = GetAccountBalance(strAccount, nMinDepth); + int64_t nBalance = GetAccountBalance(strAccount, nMinDepth); return ValueFromAmount(nBalance); } @@ -577,7 +586,7 @@ Value movecmd(const Array& params, bool fHelp) string strFrom = AccountFromValue(params[0]); string strTo = AccountFromValue(params[1]); - int64 nAmount = AmountFromValue(params[2]); + int64_t nAmount = AmountFromValue(params[2]); if (params.size() > 3) // unused parameter, used to be nMinDepth, keep type-checking it though (void)params[3].get_int(); @@ -589,7 +598,7 @@ Value movecmd(const Array& params, bool fHelp) if (!walletdb.TxnBegin()) throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); - int64 nNow = GetAdjustedTime(); + int64_t nNow = GetAdjustedTime(); // Debit CAccountingEntry debit; @@ -630,7 +639,7 @@ Value sendfrom(const Array& params, bool fHelp) CBitcoinAddress address(params[1].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); - int64 nAmount = AmountFromValue(params[2]); + int64_t nAmount = AmountFromValue(params[2]); int nMinDepth = 1; if (params.size() > 3) nMinDepth = params[3].get_int(); @@ -645,7 +654,7 @@ Value sendfrom(const Array& params, bool fHelp) EnsureWalletIsUnlocked(); // Check funds - int64 nBalance = GetAccountBalance(strAccount, nMinDepth); + int64_t nBalance = GetAccountBalance(strAccount, nMinDepth); if (nAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); @@ -678,9 +687,9 @@ Value sendmany(const Array& params, bool fHelp) wtx.mapValue["comment"] = params[3].get_str(); set setAddress; - vector > vecSend; + vector > vecSend; - int64 totalAmount = 0; + int64_t totalAmount = 0; BOOST_FOREACH(const Pair& s, sendTo) { CBitcoinAddress address(s.name_); @@ -693,7 +702,7 @@ Value sendmany(const Array& params, bool fHelp) CScript scriptPubKey; scriptPubKey.SetDestination(address.Get()); - int64 nAmount = AmountFromValue(s.value_); + int64_t nAmount = AmountFromValue(s.value_); totalAmount += nAmount; vecSend.push_back(make_pair(scriptPubKey, nAmount)); @@ -702,13 +711,13 @@ Value sendmany(const Array& params, bool fHelp) EnsureWalletIsUnlocked(); // Check funds - int64 nBalance = GetAccountBalance(strAccount, nMinDepth); + int64_t nBalance = GetAccountBalance(strAccount, nMinDepth); if (totalAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); // Send CReserveKey keyChange(pwalletMain); - int64 nFeeRequired = 0; + int64_t nFeeRequired = 0; string strFailReason; bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason); if (!fCreated) @@ -826,7 +835,7 @@ Value createmultisig(const Array& params, bool fHelp) struct tallyitem { - int64 nAmount; + int64_t nAmount; int nConf; vector txids; tallyitem() @@ -885,7 +894,7 @@ Value ListReceived(const Array& params, bool fByAccounts) if (it == mapTally.end() && !fIncludeEmpty) continue; - int64 nAmount = 0; + int64_t nAmount = 0; int nConf = std::numeric_limits::max(); if (it != mapTally.end()) { @@ -923,7 +932,7 @@ Value ListReceived(const Array& params, bool fByAccounts) { for (map::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it) { - int64 nAmount = (*it).second.nAmount; + int64_t nAmount = (*it).second.nAmount; int nConf = (*it).second.nConf; Object obj; obj.push_back(Pair("account", (*it).first)); @@ -977,10 +986,10 @@ static void MaybePushAddress(Object & entry, const CTxDestination &dest) void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret) { - int64 nFee; + int64_t nFee; string strSentAccount; - list > listReceived; - list > listSent; + list > listReceived; + list > listSent; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount); @@ -989,7 +998,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe // Sent if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) { - BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent) { Object entry; entry.push_back(Pair("account", strSentAccount)); @@ -1006,7 +1015,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe // Received if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { - BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived) { string account; if (pwalletMain->mapAddressBook.count(r.first)) @@ -1122,7 +1131,7 @@ Value listaccounts(const Array& params, bool fHelp) if (params.size() > 0) nMinDepth = params[0].get_int(); - map mapAccountBalances; + map mapAccountBalances; BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) { if (IsMine(*pwalletMain, entry.first)) // This address belongs to me mapAccountBalances[entry.second.name] = 0; @@ -1131,17 +1140,17 @@ Value listaccounts(const Array& params, bool fHelp) for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; - int64 nFee; + int64_t nFee; string strSentAccount; - list > listReceived; - list > listSent; + list > listReceived; + list > listSent; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount); mapAccountBalances[strSentAccount] -= nFee; - BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent) mapAccountBalances[strSentAccount] -= s.second; if (wtx.GetDepthInMainChain() >= nMinDepth) { - BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived) if (pwalletMain->mapAddressBook.count(r.first)) mapAccountBalances[pwalletMain->mapAddressBook[r.first].name] += r.second; else @@ -1155,7 +1164,7 @@ Value listaccounts(const Array& params, bool fHelp) mapAccountBalances[entry.strAccount] += entry.nCreditDebit; Object ret; - BOOST_FOREACH(const PAIRTYPE(string, int64)& accountBalance, mapAccountBalances) { + BOOST_FOREACH(const PAIRTYPE(string, int64_t)& accountBalance, mapAccountBalances) { ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second))); } return ret; @@ -1226,10 +1235,10 @@ Value gettransaction(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); const CWalletTx& wtx = pwalletMain->mapWallet[hash]; - int64 nCredit = wtx.GetCredit(); - int64 nDebit = wtx.GetDebit(); - int64 nNet = nCredit - nDebit; - int64 nFee = (wtx.IsFromMe() ? GetValueOut(wtx) - nDebit : 0); + int64_t nCredit = wtx.GetCredit(); + int64_t nDebit = wtx.GetDebit(); + int64_t nNet = nCredit - nDebit; + int64_t nFee = (wtx.IsFromMe() ? GetValueOut(wtx) - nDebit : 0); entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee))); if (wtx.IsFromMe()) @@ -1268,7 +1277,7 @@ Value keypoolrefill(const Array& params, bool fHelp) "Fills the keypool." + HelpRequiringPassphrase()); - unsigned int kpSize = max(GetArg("-keypool", 100), 0LL); + unsigned int kpSize = max(GetArg("-keypool", 100), (int64_t) 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); @@ -1325,7 +1334,7 @@ Value walletpassphrase(const Array& params, bool fHelp) pwalletMain->TopUpKeyPool(); - int64 nSleepTime = params[1].get_int64(); + int64_t nSleepTime = params[1].get_int64(); LOCK(cs_nWalletUnlockTime); nWalletUnlockTime = GetTime() + nSleepTime; RPCRunLater("lockwallet", boost::bind(LockWallet, pwalletMain), nSleepTime); diff --git a/src/script.cpp b/src/script.cpp index ec9e9d61d..dbf391b2a 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -2,24 +2,27 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #include "script.h" -#include "core.h" -#include "keystore.h" + #include "bignum.h" +#include "core.h" +#include "hash.h" #include "key.h" +#include "keystore.h" #include "sync.h" +#include "uint256.h" #include "util.h" +#include + #include #include +#include using namespace std; using namespace boost; -bool CheckSig(vector vchSig, const vector &vchPubKey, const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, int flags); - - - typedef vector valtype; static const valtype vchFalse(0); static const valtype vchZero(0); @@ -30,6 +33,7 @@ static const CBigNum bnFalse(0); static const CBigNum bnTrue(1); static const size_t nMaxNumSize = 4; +bool CheckSig(vector vchSig, const vector &vchPubKey, const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, int flags); CBigNum CastToBigNum(const valtype& vch) { @@ -1124,12 +1128,12 @@ public: // (~200 bytes per cache entry times 50,000 entries) // Since there are a maximum of 20,000 signature operations per block // 50,000 is a reasonable default. - int64 nMaxCacheSize = GetArg("-maxsigcachesize", 50000); + int64_t nMaxCacheSize = GetArg("-maxsigcachesize", 50000); if (nMaxCacheSize <= 0) return; boost::unique_lock lock(cs_sigcache); - while (static_cast(setValid.size()) > nMaxCacheSize) + while (static_cast(setValid.size()) > nMaxCacheSize) { // Evict a random entry. Random because that helps // foil would-be DoS attackers who might try to pre-generate diff --git a/src/script.h b/src/script.h index 931307007..bd120cc07 100644 --- a/src/script.h +++ b/src/script.h @@ -2,19 +2,24 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef H_BITCOIN_SCRIPT #define H_BITCOIN_SCRIPT +#include "bignum.h" +#include "key.h" +#include "util.h" + +#include +#include #include #include #include #include -#include "keystore.h" -#include "bignum.h" - class CCoins; +class CKeyStore; class CTransaction; static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes @@ -247,7 +252,7 @@ inline std::string StackString(const std::vector >& v class CScript : public std::vector { protected: - CScript& push_int64(int64 n) + CScript& push_int64(int64_t n) { if (n == -1 || (n >= 1 && n <= 16)) { @@ -261,7 +266,7 @@ protected: return *this; } - CScript& push_uint64(uint64 n) + CScript& push_uint64(uint64_t n) { if (n >= 1 && n <= 16) { @@ -298,16 +303,16 @@ public: //explicit CScript(char b) is not portable. Use 'signed char' or 'unsigned char'. - explicit CScript(signed char b) { operator<<(b); } - explicit CScript(short b) { operator<<(b); } - explicit CScript(int b) { operator<<(b); } - explicit CScript(long b) { operator<<(b); } - explicit CScript(int64 b) { operator<<(b); } - explicit CScript(unsigned char b) { operator<<(b); } - explicit CScript(unsigned int b) { operator<<(b); } - explicit CScript(unsigned short b) { operator<<(b); } - explicit CScript(unsigned long b) { operator<<(b); } - explicit CScript(uint64 b) { operator<<(b); } + explicit CScript(signed char b) { operator<<(b); } + explicit CScript(short b) { operator<<(b); } + explicit CScript(int b) { operator<<(b); } + explicit CScript(long b) { operator<<(b); } + explicit CScript(long long b) { operator<<(b); } + explicit CScript(unsigned char b) { operator<<(b); } + explicit CScript(unsigned int b) { operator<<(b); } + explicit CScript(unsigned short b) { operator<<(b); } + explicit CScript(unsigned long b) { operator<<(b); } + explicit CScript(unsigned long long b) { operator<<(b); } explicit CScript(opcodetype b) { operator<<(b); } explicit CScript(const uint256& b) { operator<<(b); } @@ -316,16 +321,16 @@ public: //CScript& operator<<(char b) is not portable. Use 'signed char' or 'unsigned char'. - CScript& operator<<(signed char b) { return push_int64(b); } - CScript& operator<<(short b) { return push_int64(b); } - CScript& operator<<(int b) { return push_int64(b); } - CScript& operator<<(long b) { return push_int64(b); } - CScript& operator<<(int64 b) { return push_int64(b); } - CScript& operator<<(unsigned char b) { return push_uint64(b); } - CScript& operator<<(unsigned int b) { return push_uint64(b); } - CScript& operator<<(unsigned short b) { return push_uint64(b); } - CScript& operator<<(unsigned long b) { return push_uint64(b); } - CScript& operator<<(uint64 b) { return push_uint64(b); } + CScript& operator<<(signed char b) { return push_int64(b); } + CScript& operator<<(short b) { return push_int64(b); } + CScript& operator<<(int b) { return push_int64(b); } + CScript& operator<<(long b) { return push_int64(b); } + CScript& operator<<(long long b) { return push_int64(b); } + CScript& operator<<(unsigned char b) { return push_uint64(b); } + CScript& operator<<(unsigned int b) { return push_uint64(b); } + CScript& operator<<(unsigned short b) { return push_uint64(b); } + CScript& operator<<(unsigned long b) { return push_uint64(b); } + CScript& operator<<(unsigned long long b) { return push_uint64(b); } CScript& operator<<(opcodetype opcode) { diff --git a/src/serialize.h b/src/serialize.h index 115ea1d44..4a9ff579f 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -2,32 +2,31 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_SERIALIZE_H #define BITCOIN_SERIALIZE_H -#include -#include +#include "allocators.h" + +#include +#include +#include +#include #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include #include -#include -#include - -#include "allocators.h" -#include "version.h" - -typedef long long int64; -typedef unsigned long long uint64; +#include -class CScript; -class CDataStream; class CAutoFile; +class CDataStream; +class CScript; + static const unsigned int MAX_SIZE = 0x02000000; // Used to bypass the rule against non-const reference to temporary @@ -103,47 +102,47 @@ enum #define WRITEDATA(s, obj) s.write((char*)&(obj), sizeof(obj)) #define READDATA(s, obj) s.read((char*)&(obj), sizeof(obj)) -inline unsigned int GetSerializeSize(char a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(signed char a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(unsigned char a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(signed short a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(unsigned short a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(signed int a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(unsigned int a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(signed long a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(unsigned long a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(int64 a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(uint64 a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(float a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(double a, int, int=0) { return sizeof(a); } - -template inline void Serialize(Stream& s, char a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, signed char a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, unsigned char a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, signed short a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, unsigned short a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, signed int a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, unsigned int a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, signed long a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, unsigned long a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, int64 a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, uint64 a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, float a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, double a, int, int=0) { WRITEDATA(s, a); } - -template inline void Unserialize(Stream& s, char& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, signed char& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, unsigned char& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, signed short& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, unsigned short& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, signed int& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, unsigned int& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, signed long& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, unsigned long& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, int64& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, uint64& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, float& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, double& a, int, int=0) { READDATA(s, a); } +inline unsigned int GetSerializeSize(char a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(signed char a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(unsigned char a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(signed short a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(unsigned short a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(signed int a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(unsigned int a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(signed long a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(unsigned long a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(signed long long a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(unsigned long long a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(float a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(double a, int, int=0) { return sizeof(a); } + +template inline void Serialize(Stream& s, char a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, signed char a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, unsigned char a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, signed short a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, unsigned short a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, signed int a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, unsigned int a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, signed long a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, unsigned long a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, signed long long a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, unsigned long long a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, float a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, double a, int, int=0) { WRITEDATA(s, a); } + +template inline void Unserialize(Stream& s, char& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, signed char& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, unsigned char& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, signed short& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, unsigned short& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, signed int& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, unsigned int& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, signed long& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, unsigned long& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, signed long long& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, unsigned long long& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, float& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, double& a, int, int=0) { READDATA(s, a); } inline unsigned int GetSerializeSize(bool a, int, int=0) { return sizeof(char); } template inline void Serialize(Stream& s, bool a, int, int=0) { char f=a; WRITEDATA(s, f); } @@ -161,16 +160,16 @@ template inline void Unserialize(Stream& s, bool& a, int, int=0 // size <= UINT_MAX -- 5 bytes (254 + 4 bytes) // size > UINT_MAX -- 9 bytes (255 + 8 bytes) // -inline unsigned int GetSizeOfCompactSize(uint64 nSize) +inline unsigned int GetSizeOfCompactSize(uint64_t nSize) { if (nSize < 253) return sizeof(unsigned char); else if (nSize <= std::numeric_limits::max()) return sizeof(unsigned char) + sizeof(unsigned short); else if (nSize <= std::numeric_limits::max()) return sizeof(unsigned char) + sizeof(unsigned int); - else return sizeof(unsigned char) + sizeof(uint64); + else return sizeof(unsigned char) + sizeof(uint64_t); } template -void WriteCompactSize(Stream& os, uint64 nSize) +void WriteCompactSize(Stream& os, uint64_t nSize) { if (nSize < 253) { @@ -194,7 +193,7 @@ void WriteCompactSize(Stream& os, uint64 nSize) else { unsigned char chSize = 255; - uint64 xSize = nSize; + uint64_t xSize = nSize; WRITEDATA(os, chSize); WRITEDATA(os, xSize); } @@ -202,11 +201,11 @@ void WriteCompactSize(Stream& os, uint64 nSize) } template -uint64 ReadCompactSize(Stream& is) +uint64_t ReadCompactSize(Stream& is) { unsigned char chSize; READDATA(is, chSize); - uint64 nSizeRet = 0; + uint64_t nSizeRet = 0; if (chSize < 253) { nSizeRet = chSize; @@ -229,13 +228,13 @@ uint64 ReadCompactSize(Stream& is) } else { - uint64 xSize; + uint64_t xSize; READDATA(is, xSize); nSizeRet = xSize; if (nSizeRet < 0x100000000LLu) throw std::ios_base::failure("non-canonical ReadCompactSize()"); } - if (nSizeRet > (uint64)MAX_SIZE) + if (nSizeRet > (uint64_t)MAX_SIZE) throw std::ios_base::failure("ReadCompactSize() : size too large"); return nSizeRet; } @@ -1227,10 +1226,10 @@ class CBufferedFile { private: FILE *src; // source file - uint64 nSrcPos; // how many bytes have been read from source - uint64 nReadPos; // how many bytes have been read from this - uint64 nReadLimit; // up to which position we're allowed to read - uint64 nRewind; // how many bytes we guarantee to rewind + uint64_t nSrcPos; // how many bytes have been read from source + uint64_t nReadPos; // how many bytes have been read from this + uint64_t nReadLimit; // up to which position we're allowed to read + uint64_t nRewind; // how many bytes we guarantee to rewind std::vector vchBuf; // the buffer short state; @@ -1266,8 +1265,8 @@ public: int nType; int nVersion; - CBufferedFile(FILE *fileIn, uint64 nBufSize, uint64 nRewindIn, int nTypeIn, int nVersionIn) : - src(fileIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0), + CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) : + src(fileIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0), state(0), exceptmask(std::ios_base::badbit | std::ios_base::failbit), nType(nTypeIn), nVersion(nVersionIn) { } @@ -1305,12 +1304,12 @@ public: } // return the current reading position - uint64 GetPos() { + uint64_t GetPos() { return nReadPos; } // rewind to a given reading position - bool SetPos(uint64 nPos) { + bool SetPos(uint64_t nPos) { nReadPos = nPos; if (nReadPos + nRewind < nSrcPos) { nReadPos = nSrcPos - nRewind; @@ -1323,9 +1322,9 @@ public: } } - bool Seek(uint64 nPos) { + bool Seek(uint64_t nPos) { long nLongPos = nPos; - if (nPos != (uint64)nLongPos) + if (nPos != (uint64_t)nLongPos) return false; if (fseek(src, nLongPos, SEEK_SET)) return false; @@ -1338,7 +1337,7 @@ public: // prevent reading beyond a certain position // no argument removes the limit - bool SetLimit(uint64 nPos = (uint64)(-1)) { + bool SetLimit(uint64_t nPos = (uint64_t)(-1)) { if (nPos < nReadPos) return false; nReadLimit = nPos; diff --git a/src/sync.cpp b/src/sync.cpp index d6444141d..33e121954 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "sync.h" + #include "util.h" #include diff --git a/src/sync.h b/src/sync.h index 10e0470a2..39f2cb515 100644 --- a/src/sync.h +++ b/src/sync.h @@ -2,14 +2,16 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_SYNC_H #define BITCOIN_SYNC_H +#include "threadsafety.h" + +#include +#include #include #include -#include -#include -#include "threadsafety.h" //////////////////////////////////////////////// diff --git a/src/test/Checkpoints_tests.cpp b/src/test/Checkpoints_tests.cpp index b14e9f705..78b0236b7 100644 --- a/src/test/Checkpoints_tests.cpp +++ b/src/test/Checkpoints_tests.cpp @@ -1,12 +1,12 @@ // // Unit tests for block-chain checkpoints // -#include // for 'map_list_of()' -#include -#include -#include "../checkpoints.h" -#include "../util.h" +#include "checkpoints.h" + +#include "uint256.h" + +#include using namespace std; diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp index c7f968da7..f0fb84bc5 100644 --- a/src/test/DoS_tests.cpp +++ b/src/test/DoS_tests.cpp @@ -1,21 +1,23 @@ // // Unit tests for denial-of-service detection/prevention code // -#include -#include // for 'map_list_of()' -#include -#include -#include -#include "chainparams.h" + +#include "bignum.h" +#include "keystore.h" #include "main.h" -#include "wallet.h" #include "net.h" -#include "util.h" +#include "script.h" +#include "serialize.h" #include +#include // for 'map_list_of()' +#include +#include +#include + // Tests this internal-to-main.cpp method: extern bool AddOrphanTx(const CTransaction& tx); extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans); @@ -67,7 +69,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore) BOOST_AUTO_TEST_CASE(DoS_bantime) { CNode::ClearBanned(); - int64 nStartTime = GetTime(); + int64_t nStartTime = GetTime(); SetMockTime(nStartTime); // Overrides future calls to GetTime() CAddress addr(ip(0xa0b0c001)); @@ -83,11 +85,11 @@ BOOST_AUTO_TEST_CASE(DoS_bantime) BOOST_CHECK(!CNode::IsBanned(addr)); } -static bool CheckNBits(unsigned int nbits1, int64 time1, unsigned int nbits2, int64 time2)\ +static bool CheckNBits(unsigned int nbits1, int64_t time1, unsigned int nbits2, int64_t time2)\ { if (time1 > time2) return CheckNBits(nbits2, time2, nbits1, time1); - int64 deltaTime = time2-time1; + int64_t deltaTime = time2-time1; CBigNum required; required.SetCompact(ComputeMinWork(nbits1, deltaTime)); @@ -102,7 +104,7 @@ BOOST_AUTO_TEST_CASE(DoS_checknbits) // Timestamps,nBits from the bitcoin block chain. // These are the block-chain checkpoint blocks - typedef std::map BlockData; + typedef std::map BlockData; BlockData chainData = map_list_of(1239852051,486604799)(1262749024,486594666) (1279305360,469854461)(1280200847,469830746)(1281678674,469809688) diff --git a/src/test/accounting_tests.cpp b/src/test/accounting_tests.cpp index 8ac657288..5f79436e4 100644 --- a/src/test/accounting_tests.cpp +++ b/src/test/accounting_tests.cpp @@ -1,15 +1,19 @@ -#include -#include -#include "init.h" #include "wallet.h" #include "walletdb.h" +#include + +#include +#include + +extern CWallet* pwalletMain; + BOOST_AUTO_TEST_SUITE(accounting_tests) static void -GetResults(CWalletDB& walletdb, std::map& results) +GetResults(CWalletDB& walletdb, std::map& results) { std::list aes; @@ -28,7 +32,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) std::vector vpwtx; CWalletTx wtx; CAccountingEntry ae; - std::map results; + std::map results; ae.strAccount = ""; ae.nCreditDebit = 1; diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp index cb941943f..adfbec9de 100644 --- a/src/test/alert_tests.cpp +++ b/src/test/alert_tests.cpp @@ -2,14 +2,18 @@ // Unit tests for alert system // -#include -#include -#include - #include "alert.h" +#include "data/alertTests.raw.h" + #include "serialize.h" #include "util.h" -#include "data/alertTests.raw.h" +#include "version.h" + +#include + +#include +#include +#include #if 0 // diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp index d5cb8e810..490dff87e 100644 --- a/src/test/allocator_tests.cpp +++ b/src/test/allocator_tests.cpp @@ -1,9 +1,9 @@ -#include -#include "init.h" -#include "main.h" + #include "util.h" +#include + BOOST_AUTO_TEST_SUITE(allocator_tests) // Dummy memory page locker for platform independent tests diff --git a/src/test/base32_tests.cpp b/src/test/base32_tests.cpp index fdf328591..580e87f65 100644 --- a/src/test/base32_tests.cpp +++ b/src/test/base32_tests.cpp @@ -1,7 +1,9 @@ -#include + #include "util.h" +#include + BOOST_AUTO_TEST_SUITE(base32_tests) BOOST_AUTO_TEST_CASE(base32_testvectors) diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index 05675685b..84db99d81 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -1,13 +1,20 @@ -#include -#include "json/json_spirit_reader_template.h" -#include "json/json_spirit_writer_template.h" -#include "json/json_spirit_utils.h" +#include "base58.h" + #include "data/base58_encode_decode.json.h" #include "data/base58_keys_invalid.json.h" #include "data/base58_keys_valid.json.h" -#include "base58.h" +#include "key.h" +#include "script.h" +#include "uint256.h" #include "util.h" + +#include +#include +#include "json/json_spirit_reader_template.h" +#include "json/json_spirit_utils.h" +#include "json/json_spirit_writer_template.h" + using namespace json_spirit; extern Array read_json(const std::string& jsondata); diff --git a/src/test/base64_tests.cpp b/src/test/base64_tests.cpp index c5a053e2e..c59c29066 100644 --- a/src/test/base64_tests.cpp +++ b/src/test/base64_tests.cpp @@ -1,9 +1,9 @@ -#include -#include "main.h" -#include "wallet.h" + #include "util.h" +#include + BOOST_AUTO_TEST_SUITE(base64_tests) BOOST_AUTO_TEST_CASE(base64_testvectors) diff --git a/src/test/bignum_tests.cpp b/src/test/bignum_tests.cpp index f16c26fd1..9d67324c7 100644 --- a/src/test/bignum_tests.cpp +++ b/src/test/bignum_tests.cpp @@ -1,8 +1,9 @@ -#include +#include "bignum.h" + #include +#include -#include "bignum.h" -#include "util.h" +#include BOOST_AUTO_TEST_SUITE(bignum_tests) @@ -46,7 +47,7 @@ BOOST_AUTO_TEST_SUITE(bignum_tests) // Let's force this code not to be inlined, in order to actually // test a generic version of the function. This increases the chance // that -ftrapv will detect overflows. -NOINLINE void mysetint64(CBigNum& num, int64 n) +NOINLINE void mysetint64(CBigNum& num, int64_t n) { num.setint64(n); } @@ -55,7 +56,7 @@ NOINLINE void mysetint64(CBigNum& num, int64 n) // value to 0, then the second one with a non-inlined function. BOOST_AUTO_TEST_CASE(bignum_setint64) { - int64 n; + int64_t n; { n = 0; @@ -103,7 +104,7 @@ BOOST_AUTO_TEST_CASE(bignum_setint64) BOOST_CHECK(num.ToString() == "-5"); } { - n = std::numeric_limits::min(); + n = std::numeric_limits::min(); CBigNum num(n); BOOST_CHECK(num.ToString() == "-9223372036854775808"); num.setulong(0); @@ -112,7 +113,7 @@ BOOST_AUTO_TEST_CASE(bignum_setint64) BOOST_CHECK(num.ToString() == "-9223372036854775808"); } { - n = std::numeric_limits::max(); + n = std::numeric_limits::max(); CBigNum num(n); BOOST_CHECK(num.ToString() == "9223372036854775807"); num.setulong(0); diff --git a/src/test/bip32_tests.cpp b/src/test/bip32_tests.cpp index 66d2330fb..2bcca2433 100644 --- a/src/test/bip32_tests.cpp +++ b/src/test/bip32_tests.cpp @@ -1,13 +1,13 @@ #include -#include -#include - -#include "key.h" #include "base58.h" +#include "key.h" #include "uint256.h" #include "util.h" +#include +#include + struct TestDerivation { std::string pub; std::string prv; diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp index 0d349a990..c4e4403b7 100644 --- a/src/test/bloom_tests.cpp +++ b/src/test/bloom_tests.cpp @@ -1,11 +1,15 @@ -#include -#include - #include "bloom.h" -#include "util.h" -#include "key.h" + #include "base58.h" +#include "key.h" #include "main.h" +#include "serialize.h" +#include "uint256.h" +#include "util.h" + +#include + +#include using namespace std; using namespace boost::tuples; diff --git a/src/test/canonical_tests.cpp b/src/test/canonical_tests.cpp index ec32ceb8a..c521f2cf9 100644 --- a/src/test/canonical_tests.cpp +++ b/src/test/canonical_tests.cpp @@ -1,16 +1,19 @@ // // Unit tests for canonical signatures +// + -#include "json/json_spirit_writer_template.h" -#include -#include -#include "key.h" #include "script.h" #include "util.h" #include "data/sig_noncanonical.json.h" #include "data/sig_canonical.json.h" +#include +#include +#include "json/json_spirit_writer_template.h" +#include + using namespace std; using namespace json_spirit; diff --git a/src/test/checkblock_tests.cpp b/src/test/checkblock_tests.cpp index e34680db9..d47a33fd4 100644 --- a/src/test/checkblock_tests.cpp +++ b/src/test/checkblock_tests.cpp @@ -1,17 +1,17 @@ // // Unit tests for block.CheckBlock() // -#include -#include // for 'map_list_of()' -#include -#include -#include + #include "main.h" -#include "wallet.h" -#include "net.h" -#include "util.h" + +#include + +#include +#include +#include + BOOST_AUTO_TEST_SUITE(CheckBlock_tests) diff --git a/src/test/compress_tests.cpp b/src/test/compress_tests.cpp index 71b86bcb4..4d1691477 100644 --- a/src/test/compress_tests.cpp +++ b/src/test/compress_tests.cpp @@ -1,9 +1,11 @@ -#include -#include -#include #include "main.h" +#include "util.h" + +#include + +#include // amounts 0.00000001 .. 0.00100000 #define NUM_MULTIPLES_UNIT 100000 @@ -17,19 +19,17 @@ // amounts 50 .. 21000000 #define NUM_MULTIPLES_50BTC 420000 -using namespace std; - BOOST_AUTO_TEST_SUITE(compress_tests) -bool static TestEncode(uint64 in) { +bool static TestEncode(uint64_t in) { return in == CTxOutCompressor::DecompressAmount(CTxOutCompressor::CompressAmount(in)); } -bool static TestDecode(uint64 in) { +bool static TestDecode(uint64_t in) { return in == CTxOutCompressor::CompressAmount(CTxOutCompressor::DecompressAmount(in)); } -bool static TestPair(uint64 dec, uint64 enc) { +bool static TestPair(uint64_t dec, uint64_t enc) { return CTxOutCompressor::CompressAmount(dec) == enc && CTxOutCompressor::DecompressAmount(enc) == dec; } @@ -43,19 +43,19 @@ BOOST_AUTO_TEST_CASE(compress_amounts) BOOST_CHECK(TestPair( 50*COIN, 0x32)); BOOST_CHECK(TestPair(21000000*COIN, 0x1406f40)); - for (uint64 i = 1; i <= NUM_MULTIPLES_UNIT; i++) + for (uint64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++) BOOST_CHECK(TestEncode(i)); - for (uint64 i = 1; i <= NUM_MULTIPLES_CENT; i++) + for (uint64_t i = 1; i <= NUM_MULTIPLES_CENT; i++) BOOST_CHECK(TestEncode(i * CENT)); - for (uint64 i = 1; i <= NUM_MULTIPLES_1BTC; i++) + for (uint64_t i = 1; i <= NUM_MULTIPLES_1BTC; i++) BOOST_CHECK(TestEncode(i * COIN)); - for (uint64 i = 1; i <= NUM_MULTIPLES_50BTC; i++) + for (uint64_t i = 1; i <= NUM_MULTIPLES_50BTC; i++) BOOST_CHECK(TestEncode(i * 50 * COIN)); - for (uint64 i = 0; i < 100000; i++) + for (uint64_t i = 0; i < 100000; i++) BOOST_CHECK(TestDecode(i)); } diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp index c89d218f8..d76124885 100644 --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -1,9 +1,14 @@ + + +#include "util.h" + +#include +#include + #include #include #include -#include "util.h" - BOOST_AUTO_TEST_SUITE(getarg_tests) static void ResetArgs(const std::string& strArg) diff --git a/src/test/hash_tests.cpp b/src/test/hash_tests.cpp index d69cfd706..28410f0fe 100644 --- a/src/test/hash_tests.cpp +++ b/src/test/hash_tests.cpp @@ -1,8 +1,11 @@ -#include -#include -#include "util.h" + #include "hash.h" +#include "util.h" + +#include + +#include using namespace std; diff --git a/src/test/hmac_tests.cpp b/src/test/hmac_tests.cpp index 92ca5e6af..68868866a 100644 --- a/src/test/hmac_tests.cpp +++ b/src/test/hmac_tests.cpp @@ -1,8 +1,10 @@ -#include + #include "hash.h" #include "util.h" +#include + using namespace std; BOOST_AUTO_TEST_SUITE(hmac_tests) diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp index c004521d1..421ffeac4 100644 --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -1,13 +1,15 @@ -#include - -#include -#include - #include "key.h" + #include "base58.h" +#include "script.h" #include "uint256.h" #include "util.h" +#include +#include + +#include + using namespace std; static const string strSecret1 ("5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj"); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 67165760b..dcb7f9abd 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -1,12 +1,14 @@ -#include -#include "init.h" + #include "main.h" +#include "miner.h" #include "uint256.h" #include "util.h" -#include "miner.h" #include "wallet.h" +#include + +extern CWallet* pwalletMain; extern void SHA256Transform(void* pstate, void* pinput, const void* pinit); BOOST_AUTO_TEST_SUITE(miner_tests) diff --git a/src/test/mruset_tests.cpp b/src/test/mruset_tests.cpp index 64a6678a7..638c88fab 100644 --- a/src/test/mruset_tests.cpp +++ b/src/test/mruset_tests.cpp @@ -1,13 +1,16 @@ -#include - -using namespace std; - #include "mruset.h" + #include "util.h" +#include + +#include + #define NUM_TESTS 16 #define MAX_SIZE 100 +using namespace std; + class mrutester { private: diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp index 05309f1a4..772217b88 100644 --- a/src/test/multisig_tests.cpp +++ b/src/test/multisig_tests.cpp @@ -1,18 +1,14 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "key.h" #include "keystore.h" #include "main.h" #include "script.h" -#include "wallet.h" +#include "uint256.h" + +#include +#include +#include using namespace std; using namespace boost::assign; diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp index e5a7562d9..412ba0491 100644 --- a/src/test/netbase_tests.cpp +++ b/src/test/netbase_tests.cpp @@ -1,9 +1,8 @@ -#include +#include "netbase.h" #include -#include -#include "netbase.h" +#include using namespace std; diff --git a/src/test/pmt_tests.cpp b/src/test/pmt_tests.cpp index cf0942161..dea5e1b82 100644 --- a/src/test/pmt_tests.cpp +++ b/src/test/pmt_tests.cpp @@ -1,7 +1,12 @@ -#include -#include "uint256.h" + #include "main.h" +#include "serialize.h" +#include "uint256.h" + +#include + +#include using namespace std; diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index 25849054e..4fb2aeb6a 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -1,10 +1,9 @@ -#include -#include -#include +#include "bitcoinrpc.h" #include "base58.h" -#include "util.h" -#include "bitcoinrpc.h" + +#include +#include using namespace std; using namespace json_spirit; diff --git a/src/test/script_P2SH_tests.cpp b/src/test/script_P2SH_tests.cpp index 3c666d284..e57dc9bbb 100644 --- a/src/test/script_P2SH_tests.cpp +++ b/src/test/script_P2SH_tests.cpp @@ -1,13 +1,13 @@ -#include -#include -#include -#include -#include -#include +#include "script.h" + +#include "key.h" +#include "keystore.h" +#include "main.h" +#include "script.h" -#include "../main.h" -#include "../script.h" -#include "../wallet.h" +#include + +#include using namespace std; diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 32be91441..dee0f110a 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -1,21 +1,28 @@ -#include +#include "script.h" + +#include "data/script_invalid.json.h" +#include "data/script_valid.json.h" + +#include "key.h" +#include "keystore.h" +#include "main.h" + #include +#include +#include #include + #include #include #include #include +#include +#include #include -#include #include #include "json/json_spirit_reader_template.h" -#include "json/json_spirit_writer_template.h" #include "json/json_spirit_utils.h" - -#include "main.h" -#include "wallet.h" -#include "data/script_invalid.json.h" -#include "data/script_valid.json.h" +#include "json/json_spirit_writer_template.h" using namespace std; using namespace json_spirit; @@ -60,7 +67,7 @@ ParseScript(string s) (starts_with(w, "-") && all(string(w.begin()+1, w.end()), is_digit()))) { // Number - int64 n = atoi64(w); + int64_t n = atoi64(w); result << n; } else if (starts_with(w, "0x") && IsHex(string(w.begin()+2, w.end()))) diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp index 7e193c88c..afcdd118b 100644 --- a/src/test/serialize_tests.cpp +++ b/src/test/serialize_tests.cpp @@ -1,9 +1,8 @@ -#include +#include "serialize.h" -#include -#include +#include -#include "serialize.h" +#include using namespace std; @@ -21,7 +20,7 @@ BOOST_AUTO_TEST_CASE(varints) BOOST_CHECK(size == ss.size()); } - for (uint64 i = 0; i < 100000000000ULL; i += 999999937) { + for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) { ss << VARINT(i); size += ::GetSerializeSize(VARINT(i), 0, 0); BOOST_CHECK(size == ss.size()); @@ -34,8 +33,8 @@ BOOST_AUTO_TEST_CASE(varints) BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i); } - for (uint64 i = 0; i < 100000000000ULL; i += 999999937) { - uint64 j = -1; + for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) { + uint64_t j = -1; ss >> VARINT(j); BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i); } diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp index 5a87f1760..96f663cce 100644 --- a/src/test/sigopcount_tests.cpp +++ b/src/test/sigopcount_tests.cpp @@ -1,9 +1,13 @@ -#include -#include -#include -#include "script.h" + #include "key.h" +#include "script.h" +#include "uint256.h" + +#include + +#include +#include using namespace std; diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 1bf9a28ac..f94716759 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -1,12 +1,17 @@ #define BOOST_TEST_MODULE Bitcoin Test Suite -#include -#include + + #include "db.h" -#include "txdb.h" #include "main.h" -#include "wallet.h" +#include "txdb.h" +#include "ui_interface.h" #include "util.h" +#include "wallet.h" + +#include +#include + CWallet* pwalletMain; CClientUIInterface uiInterface; diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index bd999caa1..ad33184bc 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -1,13 +1,19 @@ + + +#include "data/tx_invalid.json.h" +#include "data/tx_valid.json.h" + +#include "key.h" +#include "keystore.h" +#include "main.h" +#include "script.h" + #include #include + #include #include "json/json_spirit_writer_template.h" -#include "main.h" -#include "wallet.h" -#include "data/tx_invalid.json.h" -#include "data/tx_valid.json.h" - using namespace std; using namespace json_spirit; diff --git a/src/test/uint160_tests.cpp b/src/test/uint160_tests.cpp index 35cb35b25..87418fabe 100644 --- a/src/test/uint160_tests.cpp +++ b/src/test/uint160_tests.cpp @@ -1,7 +1,9 @@ -#include - #include "uint256.h" +#include + +#include + BOOST_AUTO_TEST_SUITE(uint160_tests) BOOST_AUTO_TEST_CASE(uint160_equality) @@ -10,7 +12,7 @@ BOOST_AUTO_TEST_CASE(uint160_equality) uint160 num2 = 11; BOOST_CHECK(num1+1 == num2); - uint64 num3 = 10; + uint64_t num3 = 10; BOOST_CHECK(num1 == num3); BOOST_CHECK(num1+num2 == num3+num2); } diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp index e34efcc47..188635dcb 100644 --- a/src/test/uint256_tests.cpp +++ b/src/test/uint256_tests.cpp @@ -1,8 +1,10 @@ -#include - #include "uint256.h" #include +#include + +#include + BOOST_AUTO_TEST_SUITE(uint256_tests) BOOST_AUTO_TEST_CASE(uint256_equality) @@ -11,7 +13,7 @@ BOOST_AUTO_TEST_CASE(uint256_equality) uint256 num2 = 11; BOOST_CHECK(num1+1 == num2); - uint64 num3 = 10; + uint64_t num3 = 10; BOOST_CHECK(num1 == num3); BOOST_CHECK(num1+num2 == num3+num2); } diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index abfd88265..6a9a787fa 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1,10 +1,11 @@ +#include "util.h" + +#include "sync.h" + +#include #include -#include -#include -#include "main.h" -#include "wallet.h" -#include "util.h" +#include using namespace std; @@ -200,7 +201,7 @@ BOOST_AUTO_TEST_CASE(util_FormatMoney) BOOST_AUTO_TEST_CASE(util_ParseMoney) { - int64 ret = 0; + int64_t ret = 0; BOOST_CHECK(ParseMoney("0.0", ret)); BOOST_CHECK_EQUAL(ret, 0); diff --git a/src/test/wallet_tests.cpp b/src/test/wallet_tests.cpp index 51f3b27c8..0acd94ef3 100644 --- a/src/test/wallet_tests.cpp +++ b/src/test/wallet_tests.cpp @@ -1,8 +1,13 @@ -#include - -#include "main.h" #include "wallet.h" +#include +#include +#include +#include + +#include +#include + // how many times to run all the tests to have a chance to catch errors that only show up with particular random shuffles #define RUN_TESTS 100 @@ -19,7 +24,7 @@ BOOST_AUTO_TEST_SUITE(wallet_tests) static CWallet wallet; static vector vCoins; -static void add_coin(int64 nValue, int nAge = 6*24, bool fIsFromMe = false, int nInput=0) +static void add_coin(int64_t nValue, int nAge = 6*24, bool fIsFromMe = false, int nInput=0) { static int nextLockTime = 0; CTransaction tx; @@ -55,7 +60,7 @@ static bool equal_sets(CoinSet a, CoinSet b) BOOST_AUTO_TEST_CASE(coin_selection_tests) { CoinSet setCoinsRet, setCoinsRet2; - int64 nValueRet; + int64_t nValueRet; // test multiple times to allow for differences in the shuffle order for (int i = 0; i < RUN_TESTS; i++) diff --git a/src/threadsafety.h b/src/threadsafety.h index 3d3d526fd..176060ac6 100644 --- a/src/threadsafety.h +++ b/src/threadsafety.h @@ -2,6 +2,7 @@ // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_THREADSAFETY_H #define BITCOIN_THREADSAFETY_H diff --git a/src/txdb.cpp b/src/txdb.cpp index f459f0c71..3c8b0b7fe 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -4,9 +4,11 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "txdb.h" -#include "main.h" -#include "hash.h" -#include "chainparams.h" + +#include "core.h" +#include "uint256.h" + +#include using namespace std; @@ -115,7 +117,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) { CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); stats.hashBlock = GetBestBlock()->GetBlockHash(); ss << stats.hashBlock; - int64 nTotalAmount = 0; + int64_t nTotalAmount = 0; while (pcursor->Valid()) { boost::this_thread::interruption_point(); try { diff --git a/src/txdb.h b/src/txdb.h index 4bc2902a0..8043a595a 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -2,11 +2,21 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_TXDB_LEVELDB_H #define BITCOIN_TXDB_LEVELDB_H -#include "main.h" #include "leveldbwrapper.h" +#include "main.h" + +#include +#include +#include +#include + +class CBigNum; +class CCoins; +class uint256; /** CCoinsView backed by the LevelDB coin database (chainstate/) */ class CCoinsViewDB : public CCoinsView diff --git a/src/txmempool.h b/src/txmempool.h index 1b555d99f..d5a7832ff 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -6,6 +6,7 @@ #define BITCOIN_TXMEMPOOL_H #include "core.h" +#include "sync.h" /* * CTxMemPool stores valid-according-to-the-current-best-chain diff --git a/src/ui_interface.h b/src/ui_interface.h index 5b0555c10..2378d5dfb 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -2,13 +2,15 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_UI_INTERFACE_H #define BITCOIN_UI_INTERFACE_H +#include #include -#include "util.h" // for int64 -#include + #include +#include class CBasicKeyStore; class CWallet; @@ -71,7 +73,7 @@ public: boost::signals2::signal > ThreadSafeMessageBox; /** Ask the user whether they want to pay a fee or not. */ - boost::signals2::signal > ThreadSafeAskFee; + boost::signals2::signal > ThreadSafeAskFee; /** Handle a URL passed at the command line. */ boost::signals2::signal ThreadSafeHandleURI; diff --git a/src/uint256.h b/src/uint256.h index b5a4950ea..7dbb3f83b 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -2,18 +2,16 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_UINT256_H #define BITCOIN_UINT256_H -#include +#include #include -#include -#include #include +#include #include -typedef long long int64; -typedef unsigned long long uint64; extern const signed char p_util_hexdigit[256]; // defined in util.cpp inline signed char HexDigit(char c) @@ -24,7 +22,6 @@ inline signed char HexDigit(char c) inline int Testuint256AdHoc(std::vector vArg); - /** Base class without constructors for uint256 and uint160. * This makes the compiler let you use it in a union. */ @@ -72,7 +69,7 @@ public: return ret; } - base_uint& operator=(uint64 b) + base_uint& operator=(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); @@ -102,14 +99,14 @@ public: return *this; } - base_uint& operator^=(uint64 b) + base_uint& operator^=(uint64_t b) { pn[0] ^= (unsigned int)b; pn[1] ^= (unsigned int)(b >> 32); return *this; } - base_uint& operator|=(uint64 b) + base_uint& operator|=(uint64_t b) { pn[0] |= (unsigned int)b; pn[1] |= (unsigned int)(b >> 32); @@ -152,10 +149,10 @@ public: base_uint& operator+=(const base_uint& b) { - uint64 carry = 0; + uint64_t carry = 0; for (int i = 0; i < WIDTH; i++) { - uint64 n = carry + pn[i] + b.pn[i]; + uint64_t n = carry + pn[i] + b.pn[i]; pn[i] = n & 0xffffffff; carry = n >> 32; } @@ -168,7 +165,7 @@ public: return *this; } - base_uint& operator+=(uint64 b64) + base_uint& operator+=(uint64_t b64) { base_uint b; b = b64; @@ -176,7 +173,7 @@ public: return *this; } - base_uint& operator-=(uint64 b64) + base_uint& operator-=(uint64_t b64) { base_uint b; b = b64; @@ -276,7 +273,7 @@ public: return true; } - friend inline bool operator==(const base_uint& a, uint64 b) + friend inline bool operator==(const base_uint& a, uint64_t b) { if (a.pn[0] != (unsigned int)b) return false; @@ -293,7 +290,7 @@ public: return (!(a == b)); } - friend inline bool operator!=(const base_uint& a, uint64 b) + friend inline bool operator!=(const base_uint& a, uint64_t b) { return (!(a == b)); } @@ -373,9 +370,9 @@ public: return sizeof(pn); } - uint64 Get64(int n=0) const + uint64_t Get64(int n=0) const { - return pn[2*n] | (uint64)pn[2*n+1] << 32; + return pn[2*n] | (uint64_t)pn[2*n+1] << 32; } // unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const @@ -446,7 +443,7 @@ public: return *this; } - uint160(uint64 b) + uint160(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); @@ -454,7 +451,7 @@ public: pn[i] = 0; } - uint160& operator=(uint64 b) + uint160& operator=(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); @@ -477,8 +474,8 @@ public: } }; -inline bool operator==(const uint160& a, uint64 b) { return (base_uint160)a == b; } -inline bool operator!=(const uint160& a, uint64 b) { return (base_uint160)a != b; } +inline bool operator==(const uint160& a, uint64_t b) { return (base_uint160)a == b; } +inline bool operator!=(const uint160& a, uint64_t b) { return (base_uint160)a != b; } inline const uint160 operator<<(const base_uint160& a, unsigned int shift) { return uint160(a) <<= shift; } inline const uint160 operator>>(const base_uint160& a, unsigned int shift) { return uint160(a) >>= shift; } inline const uint160 operator<<(const uint160& a, unsigned int shift) { return uint160(a) <<= shift; } @@ -490,41 +487,41 @@ inline const uint160 operator|(const base_uint160& a, const base_uint160& b) { r inline const uint160 operator+(const base_uint160& a, const base_uint160& b) { return uint160(a) += b; } inline const uint160 operator-(const base_uint160& a, const base_uint160& b) { return uint160(a) -= b; } -inline bool operator<(const base_uint160& a, const uint160& b) { return (base_uint160)a < (base_uint160)b; } -inline bool operator<=(const base_uint160& a, const uint160& b) { return (base_uint160)a <= (base_uint160)b; } -inline bool operator>(const base_uint160& a, const uint160& b) { return (base_uint160)a > (base_uint160)b; } -inline bool operator>=(const base_uint160& a, const uint160& b) { return (base_uint160)a >= (base_uint160)b; } -inline bool operator==(const base_uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const base_uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const base_uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const base_uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const base_uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } -inline const uint160 operator+(const base_uint160& a, const uint160& b) { return (base_uint160)a + (base_uint160)b; } -inline const uint160 operator-(const base_uint160& a, const uint160& b) { return (base_uint160)a - (base_uint160)b; } - -inline bool operator<(const uint160& a, const base_uint160& b) { return (base_uint160)a < (base_uint160)b; } -inline bool operator<=(const uint160& a, const base_uint160& b) { return (base_uint160)a <= (base_uint160)b; } -inline bool operator>(const uint160& a, const base_uint160& b) { return (base_uint160)a > (base_uint160)b; } -inline bool operator>=(const uint160& a, const base_uint160& b) { return (base_uint160)a >= (base_uint160)b; } -inline bool operator==(const uint160& a, const base_uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const uint160& a, const base_uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const uint160& a, const base_uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const uint160& a, const base_uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const uint160& a, const base_uint160& b) { return (base_uint160)a | (base_uint160)b; } -inline const uint160 operator+(const uint160& a, const base_uint160& b) { return (base_uint160)a + (base_uint160)b; } -inline const uint160 operator-(const uint160& a, const base_uint160& b) { return (base_uint160)a - (base_uint160)b; } - -inline bool operator<(const uint160& a, const uint160& b) { return (base_uint160)a < (base_uint160)b; } -inline bool operator<=(const uint160& a, const uint160& b) { return (base_uint160)a <= (base_uint160)b; } -inline bool operator>(const uint160& a, const uint160& b) { return (base_uint160)a > (base_uint160)b; } -inline bool operator>=(const uint160& a, const uint160& b) { return (base_uint160)a >= (base_uint160)b; } -inline bool operator==(const uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } -inline const uint160 operator+(const uint160& a, const uint160& b) { return (base_uint160)a + (base_uint160)b; } -inline const uint160 operator-(const uint160& a, const uint160& b) { return (base_uint160)a - (base_uint160)b; } +inline bool operator<(const base_uint160& a, const uint160& b) { return (base_uint160)a < (base_uint160)b; } +inline bool operator<=(const base_uint160& a, const uint160& b) { return (base_uint160)a <= (base_uint160)b; } +inline bool operator>(const base_uint160& a, const uint160& b) { return (base_uint160)a > (base_uint160)b; } +inline bool operator>=(const base_uint160& a, const uint160& b) { return (base_uint160)a >= (base_uint160)b; } +inline bool operator==(const base_uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } +inline bool operator!=(const base_uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } +inline const uint160 operator^(const base_uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } +inline const uint160 operator&(const base_uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } +inline const uint160 operator|(const base_uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } +inline const uint160 operator+(const base_uint160& a, const uint160& b) { return (base_uint160)a + (base_uint160)b; } +inline const uint160 operator-(const base_uint160& a, const uint160& b) { return (base_uint160)a - (base_uint160)b; } + +inline bool operator<(const uint160& a, const base_uint160& b) { return (base_uint160)a < (base_uint160)b; } +inline bool operator<=(const uint160& a, const base_uint160& b) { return (base_uint160)a <= (base_uint160)b; } +inline bool operator>(const uint160& a, const base_uint160& b) { return (base_uint160)a > (base_uint160)b; } +inline bool operator>=(const uint160& a, const base_uint160& b) { return (base_uint160)a >= (base_uint160)b; } +inline bool operator==(const uint160& a, const base_uint160& b) { return (base_uint160)a == (base_uint160)b; } +inline bool operator!=(const uint160& a, const base_uint160& b) { return (base_uint160)a != (base_uint160)b; } +inline const uint160 operator^(const uint160& a, const base_uint160& b) { return (base_uint160)a ^ (base_uint160)b; } +inline const uint160 operator&(const uint160& a, const base_uint160& b) { return (base_uint160)a & (base_uint160)b; } +inline const uint160 operator|(const uint160& a, const base_uint160& b) { return (base_uint160)a | (base_uint160)b; } +inline const uint160 operator+(const uint160& a, const base_uint160& b) { return (base_uint160)a + (base_uint160)b; } +inline const uint160 operator-(const uint160& a, const base_uint160& b) { return (base_uint160)a - (base_uint160)b; } + +inline bool operator<(const uint160& a, const uint160& b) { return (base_uint160)a < (base_uint160)b; } +inline bool operator<=(const uint160& a, const uint160& b) { return (base_uint160)a <= (base_uint160)b; } +inline bool operator>(const uint160& a, const uint160& b) { return (base_uint160)a > (base_uint160)b; } +inline bool operator>=(const uint160& a, const uint160& b) { return (base_uint160)a >= (base_uint160)b; } +inline bool operator==(const uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } +inline bool operator!=(const uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } +inline const uint160 operator^(const uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } +inline const uint160 operator&(const uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } +inline const uint160 operator|(const uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } +inline const uint160 operator+(const uint160& a, const uint160& b) { return (base_uint160)a + (base_uint160)b; } +inline const uint160 operator-(const uint160& a, const uint160& b) { return (base_uint160)a - (base_uint160)b; } @@ -561,7 +558,7 @@ public: return *this; } - uint256(uint64 b) + uint256(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); @@ -569,7 +566,7 @@ public: pn[i] = 0; } - uint256& operator=(uint64 b) + uint256& operator=(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); @@ -592,8 +589,8 @@ public: } }; -inline bool operator==(const uint256& a, uint64 b) { return (base_uint256)a == b; } -inline bool operator!=(const uint256& a, uint64 b) { return (base_uint256)a != b; } +inline bool operator==(const uint256& a, uint64_t b) { return (base_uint256)a == b; } +inline bool operator!=(const uint256& a, uint64_t b) { return (base_uint256)a != b; } inline const uint256 operator<<(const base_uint256& a, unsigned int shift) { return uint256(a) <<= shift; } inline const uint256 operator>>(const base_uint256& a, unsigned int shift) { return uint256(a) >>= shift; } inline const uint256 operator<<(const uint256& a, unsigned int shift) { return uint256(a) <<= shift; } diff --git a/src/util.cpp b/src/util.cpp index 539e759dd..9562cf310 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -3,71 +3,87 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "util.h" + +#include "chainparams.h" +#include "netbase.h" +#include "sync.h" +#include "ui_interface.h" +#include "uint256.h" +#include "version.h" + +#include +#include +#include + #ifndef WIN32 // for posix_fallocate -#ifdef __linux__ +#ifdef __linux_ + +#ifdef _POSIX_C_SOURCE +#undef _POSIX_C_SOURCE +#endif + #define _POSIX_C_SOURCE 200112L +#include + #endif + #include #include -#include #include -#endif - -#include "chainparams.h" -#include "util.h" -#include "sync.h" -#include "version.h" -#include "ui_interface.h" -#include -#include // for to_lower() -#include // for startswith() and endswith() - -// Work around clang compilation problem in Boost 1.46: -// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup -// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options -// http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION -namespace boost { - namespace program_options { - std::string to_internal(const std::string&); - } -} +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#else -#ifdef WIN32 #ifdef _MSC_VER #pragma warning(disable:4786) #pragma warning(disable:4804) #pragma warning(disable:4805) #pragma warning(disable:4717) #endif + #ifdef _WIN32_WINNT #undef _WIN32_WINNT #endif #define _WIN32_WINNT 0x0501 + #ifdef _WIN32_IE #undef _WIN32_IE #endif #define _WIN32_IE 0x0501 + #define WIN32_LEAN_AND_MEAN 1 #ifndef NOMINMAX #define NOMINMAX #endif + #include /* for _commit */ -#include "shlobj.h" -#elif defined(__linux__) -# include +#include #endif +#include // for to_lower() +#include +#include // for startswith() and endswith() +#include +#include +#include +#include +#include +#include +#include + +// Work around clang compilation problem in Boost 1.46: +// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup +// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options +// http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION +namespace boost { + namespace program_options { + std::string to_internal(const std::string&); + } +} + + using namespace std; map mapArgs; @@ -134,7 +150,7 @@ instance_of_cinit; void RandAddSeed() { // Seed with CPU performance counter - int64 nCounter = GetPerformanceCounter(); + int64_t nCounter = GetPerformanceCounter(); RAND_add(&nCounter, sizeof(nCounter), 1.5); memset(&nCounter, 0, sizeof(nCounter)); } @@ -144,7 +160,7 @@ void RandAddSeedPerfmon() RandAddSeed(); // This can take up to 2 seconds, so only do it every 10 minutes - static int64 nLastPerfmon; + static int64_t nLastPerfmon; if (GetTime() < nLastPerfmon + 10 * 60) return; nLastPerfmon = GetTime(); @@ -166,15 +182,15 @@ void RandAddSeedPerfmon() #endif } -uint64 GetRand(uint64 nMax) +uint64_t GetRand(uint64_t nMax) { if (nMax == 0) return 0; // The range of the random source must be a multiple of the modulus // to give every possible output value an equal possibility - uint64 nRange = (std::numeric_limits::max() / nMax) * nMax; - uint64 nRand = 0; + uint64_t nRange = (std::numeric_limits::max() / nMax) * nMax; + uint64_t nRand = 0; do RAND_bytes((unsigned char*)&nRand, sizeof(nRand)); while (nRand >= nRange); @@ -390,14 +406,14 @@ void ParseString(const string& str, char c, vector& v) } -string FormatMoney(int64 n, bool fPlus) +string FormatMoney(int64_t n, bool fPlus) { // Note: not using straight sprintf here because we do NOT want // localized number formatting. - int64 n_abs = (n > 0 ? n : -n); - int64 quotient = n_abs/COIN; - int64 remainder = n_abs%COIN; - string str = strprintf("%"PRI64d".%08"PRI64d, quotient, remainder); + int64_t n_abs = (n > 0 ? n : -n); + int64_t quotient = n_abs/COIN; + int64_t remainder = n_abs%COIN; + string str = strprintf("%"PRId64".%08"PRId64, quotient, remainder); // Right-trim excess zeros before the decimal point: int nTrim = 0; @@ -414,15 +430,15 @@ string FormatMoney(int64 n, bool fPlus) } -bool ParseMoney(const string& str, int64& nRet) +bool ParseMoney(const string& str, int64_t& nRet) { return ParseMoney(str.c_str(), nRet); } -bool ParseMoney(const char* pszIn, int64& nRet) +bool ParseMoney(const char* pszIn, int64_t& nRet) { string strWhole; - int64 nUnits = 0; + int64_t nUnits = 0; const char* p = pszIn; while (isspace(*p)) p++; @@ -431,7 +447,7 @@ bool ParseMoney(const char* pszIn, int64& nRet) if (*p == '.') { p++; - int64 nMult = CENT*10; + int64_t nMult = CENT*10; while (isdigit(*p) && (nMult > 0)) { nUnits += nMult * (*p++ - '0'); @@ -452,8 +468,8 @@ bool ParseMoney(const char* pszIn, int64& nRet) return false; if (nUnits < 0 || nUnits > COIN) return false; - int64 nWhole = atoi64(strWhole); - int64 nValue = nWhole*COIN + nUnits; + int64_t nWhole = atoi64(strWhole); + int64_t nValue = nWhole*COIN + nUnits; nRet = nValue; return true; @@ -581,7 +597,7 @@ std::string GetArg(const std::string& strArg, const std::string& strDefault) return strDefault; } -int64 GetArg(const std::string& strArg, int64 nDefault) +int64_t GetArg(const std::string& strArg, int64_t nDefault) { if (mapArgs.count(strArg)) return atoi64(mapArgs[strArg]); @@ -1215,7 +1231,7 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { // Windows-specific version HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); LARGE_INTEGER nFileSize; - int64 nEndPos = (int64)offset + length; + int64_t nEndPos = (int64_t)offset + length; nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF; nFileSize.u.HighPart = nEndPos >> 32; SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN); @@ -1290,37 +1306,37 @@ void ShrinkDebugFile() // - Median of other nodes clocks // - The user (asking the user to fix the system clock if the first two disagree) // -static int64 nMockTime = 0; // For unit testing +static int64_t nMockTime = 0; // For unit testing -int64 GetTime() +int64_t GetTime() { if (nMockTime) return nMockTime; return time(NULL); } -void SetMockTime(int64 nMockTimeIn) +void SetMockTime(int64_t nMockTimeIn) { nMockTime = nMockTimeIn; } static CCriticalSection cs_nTimeOffset; -static int64 nTimeOffset = 0; +static int64_t nTimeOffset = 0; -int64 GetTimeOffset() +int64_t GetTimeOffset() { LOCK(cs_nTimeOffset); return nTimeOffset; } -int64 GetAdjustedTime() +int64_t GetAdjustedTime() { return GetTime() + GetTimeOffset(); } -void AddTimeData(const CNetAddr& ip, int64 nTime) +void AddTimeData(const CNetAddr& ip, int64_t nTime) { - int64 nOffsetSample = nTime - GetTime(); + int64_t nOffsetSample = nTime - GetTime(); LOCK(cs_nTimeOffset); // Ignore duplicates @@ -1329,13 +1345,13 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) return; // Add data - static CMedianFilter vTimeOffsets(200,0); + static CMedianFilter vTimeOffsets(200,0); vTimeOffsets.input(nOffsetSample); - LogPrintf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); + LogPrintf("Added time data, samples %d, offset %+"PRId64" (%+"PRId64" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { - int64 nMedian = vTimeOffsets.median(); - std::vector vSorted = vTimeOffsets.sorted(); + int64_t nMedian = vTimeOffsets.median(); + std::vector vSorted = vTimeOffsets.sorted(); // Only let other nodes change our time by so much if (abs64(nMedian) < 70 * 60) { @@ -1350,7 +1366,7 @@ void AddTimeData(const CNetAddr& 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, vSorted) + BOOST_FOREACH(int64_t nOffset, vSorted) if (nOffset != 0 && abs64(nOffset) < 5 * 60) fMatch = true; @@ -1365,11 +1381,11 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) } } if (fDebug) { - BOOST_FOREACH(int64 n, vSorted) - LogPrintf("%+"PRI64d" ", n); + BOOST_FOREACH(int64_t n, vSorted) + LogPrintf("%+"PRId64" ", n); LogPrintf("| "); } - LogPrintf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); + LogPrintf("nTimeOffset = %+"PRId64" (%+"PRId64" minutes)\n", nTimeOffset, nTimeOffset/60); } } diff --git a/src/util.h b/src/util.h index 257369404..e52e6986b 100644 --- a/src/util.h +++ b/src/util.h @@ -2,38 +2,43 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_UTIL_H #define BITCOIN_UTIL_H -#include "uint256.h" +#if defined(HAVE_CONFIG_H) +#include "bitcoin-config.h" +#endif + +#include "compat.h" +#include "serialize.h" +#include +#include +#include +#include #include +#include +#include +#include +#include #ifndef WIN32 -#include -#include #include +#include +#include +#else +typedef int pid_t; /* define for Windows compatibility */ #endif -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include - -#include "netbase.h" // for AddTimeData +#include -typedef long long int64; -typedef unsigned long long uint64; +class CNetAddr; +class uint256; -static const int64 COIN = 100000000; -static const int64 CENT = 1000000; +static const int64_t COIN = 100000000; +static const int64_t CENT = 1000000; #define BEGIN(a) ((char*)&(a)) #define END(a) ((char*)&((&(a))[1])) @@ -41,18 +46,6 @@ static const int64 CENT = 1000000; #define UEND(a) ((unsigned char*)&((&(a))[1])) #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0])) -#ifndef PRI64d -#if defined(_MSC_VER) || defined(__MSVCRT__) -#define PRI64d "I64d" -#define PRI64u "I64u" -#define PRI64x "I64x" -#else -#define PRI64d "lld" -#define PRI64u "llu" -#define PRI64x "llx" -#endif -#endif - /* Format characters for (s)size_t and ptrdiff_t */ #if defined(_MSC_VER) || defined(__MSVCRT__) /* (s)size_t and ptrdiff_t have the same size specifier in MSVC: @@ -73,6 +66,7 @@ static const int64 CENT = 1000000; #define PRIpdd "td" #endif + // This is needed because the foreach macro can't get over the comma in pair #define PAIRTYPE(t1, t2) std::pair @@ -101,11 +95,11 @@ T* alignup(T* p) #define MAX_PATH 1024 #endif // As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0 -#ifndef MSG_NOSIGNAL +#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) #define MSG_NOSIGNAL 0 #endif -inline void MilliSleep(int64 n) +inline void MilliSleep(int64_t n) { // Boost's sleep_for was uninterruptable when backed by nanosleep from 1.50 // until fixed in 1.52. Use the deprecated sleep method for the broken case. @@ -178,9 +172,9 @@ void LogException(std::exception* pex, const char* pszThread); void PrintException(std::exception* pex, const char* pszThread); void PrintExceptionContinue(std::exception* pex, const char* pszThread); void ParseString(const std::string& str, char c, std::vector& v); -std::string FormatMoney(int64 n, bool fPlus=false); -bool ParseMoney(const std::string& str, int64& nRet); -bool ParseMoney(const char* pszIn, int64& nRet); +std::string FormatMoney(int64_t n, bool fPlus=false); +bool ParseMoney(const std::string& str, int64_t& nRet); +bool ParseMoney(const char* pszIn, int64_t& nRet); std::vector ParseHex(const char* psz); std::vector ParseHex(const std::string& str); bool IsHex(const std::string& str); @@ -215,15 +209,15 @@ boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true); boost::filesystem::path GetTempPath(); void ShrinkDebugFile(); int GetRandInt(int nMax); -uint64 GetRand(uint64 nMax); +uint64_t GetRand(uint64_t nMax); uint256 GetRandHash(); -int64 GetTime(); -void SetMockTime(int64 nMockTimeIn); -int64 GetAdjustedTime(); -int64 GetTimeOffset(); +int64_t GetTime(); +void SetMockTime(int64_t nMockTimeIn); +int64_t GetAdjustedTime(); +int64_t GetTimeOffset(); std::string FormatFullVersion(); std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector& comments); -void AddTimeData(const CNetAddr& ip, int64 nTime); +void AddTimeData(const CNetAddr& ip, int64_t nTime); void runCommand(std::string strCommand); @@ -234,9 +228,9 @@ void runCommand(std::string strCommand); -inline std::string i64tostr(int64 n) +inline std::string i64tostr(int64_t n) { - return strprintf("%"PRI64d, n); + return strprintf("%"PRId64, n); } inline std::string itostr(int n) @@ -244,7 +238,7 @@ inline std::string itostr(int n) return strprintf("%d", n); } -inline int64 atoi64(const char* psz) +inline int64_t atoi64(const char* psz) { #ifdef _MSC_VER return _atoi64(psz); @@ -253,7 +247,7 @@ inline int64 atoi64(const char* psz) #endif } -inline int64 atoi64(const std::string& str) +inline int64_t atoi64(const std::string& str) { #ifdef _MSC_VER return _atoi64(str.c_str()); @@ -272,12 +266,12 @@ inline int roundint(double d) return (int)(d > 0 ? d + 0.5 : d - 0.5); } -inline int64 roundint64(double d) +inline int64_t roundint64(double d) { - return (int64)(d > 0 ? d + 0.5 : d - 0.5); + return (int64_t)(d > 0 ? d + 0.5 : d - 0.5); } -inline int64 abs64(int64 n) +inline int64_t abs64(int64_t n) { return (n >= 0 ? n : -n); } @@ -318,32 +312,32 @@ inline void PrintHex(const std::vector& vch, const char* pszForma LogPrintf(pszFormat, HexStr(vch, fSpaces).c_str()); } -inline int64 GetPerformanceCounter() +inline int64_t GetPerformanceCounter() { - int64 nCounter = 0; + int64_t nCounter = 0; #ifdef WIN32 QueryPerformanceCounter((LARGE_INTEGER*)&nCounter); #else timeval t; gettimeofday(&t, NULL); - nCounter = (int64) t.tv_sec * 1000000 + t.tv_usec; + nCounter = (int64_t) t.tv_sec * 1000000 + t.tv_usec; #endif return nCounter; } -inline int64 GetTimeMillis() +inline int64_t GetTimeMillis() { return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds(); } -inline int64 GetTimeMicros() +inline int64_t GetTimeMicros() { return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds(); } -inline std::string DateTimeStrFormat(const char* pszFormat, int64 nTime) +inline std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime) { time_t n = nTime; struct tm* ptmTime = gmtime(&n); @@ -384,7 +378,7 @@ std::string GetArg(const std::string& strArg, const std::string& strDefault); * @param default (e.g. 1) * @return command-line argument (0 if invalid number) or default value */ -int64 GetArg(const std::string& strArg, int64 nDefault); +int64_t GetArg(const std::string& strArg, int64_t nDefault); /** * Return boolean argument or default value @@ -549,7 +543,7 @@ inline uint32_t ByteReverse(uint32_t value) // or maybe: // boost::function f = boost::bind(&FunctionWithArg, argument); // threadGroup.create_thread(boost::bind(&LoopForever >, "nothing", f, milliseconds)); -template void LoopForever(const char* name, Callable func, int64 msecs) +template void LoopForever(const char* name, Callable func, int64_t msecs) { std::string s = strprintf("bitcoin-%s", name); RenameThread(s.c_str()); diff --git a/src/version.cpp b/src/version.cpp index d9d6724a0..904451ac5 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -1,10 +1,11 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include #include "version.h" +#include + // Name of client reported in the 'version' message. Report the same name // for both bitcoind and bitcoin-qt, to make it harder for attackers to // target servers or GUI users specifically. diff --git a/src/version.h b/src/version.h index f5fa9f213..9ae929c0a 100644 --- a/src/version.h +++ b/src/version.h @@ -5,6 +5,7 @@ #define BITCOIN_VERSION_H #include "clientversion.h" + #include // diff --git a/src/wallet.cpp b/src/wallet.cpp index ea1e01e6e..6e49ef7b8 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -4,11 +4,15 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "wallet.h" -#include "walletdb.h" -#include "crypter.h" -#include "ui_interface.h" + #include "base58.h" +#include "net.h" + +#include +#include + #include +#include using namespace std; @@ -20,8 +24,8 @@ using namespace std; struct CompareValueOnly { - bool operator()(const pair >& t1, - const pair >& t2) const + bool operator()(const pair >& t1, + const pair >& t2) const { return t1.first < t2.first; } @@ -42,7 +46,7 @@ CPubKey CWallet::GenerateNewKey() CPubKey pubkey = secret.GetPubKey(); // Create new metadata - int64 nCreationTime = GetTime(); + int64_t nCreationTime = GetTime(); mapKeyMetadata[pubkey.GetID()] = CKeyMetadata(nCreationTime); if (!nTimeFirstKey || nCreationTime < nTimeFirstKey) nTimeFirstKey = nCreationTime; @@ -148,7 +152,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, return false; if (CCryptoKeyStore::Unlock(vMasterKey)) { - int64 nStartTime = GetTimeMillis(); + int64_t nStartTime = GetTimeMillis(); crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime))); @@ -256,7 +260,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) RAND_bytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE); CCrypter crypter; - int64 nStartTime = GetTimeMillis(); + int64_t nStartTime = GetTimeMillis(); crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod); kMasterKey.nDeriveIterations = 2500000 / ((double)(GetTimeMillis() - nStartTime)); @@ -319,9 +323,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) return true; } -int64 CWallet::IncOrderPosNext(CWalletDB *pwalletdb) +int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb) { - int64 nRet = nOrderPosNext++; + int64_t nRet = nOrderPosNext++; if (pwalletdb) { pwalletdb->WriteOrderPosNext(nOrderPosNext); } else { @@ -414,7 +418,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) unsigned int latestEntry = 0; { // Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future - int64 latestTolerated = latestNow + 300; + int64_t latestTolerated = latestNow + 300; std::list acentries; TxItems txOrdered = OrderedTxItems(acentries); for (TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) @@ -423,7 +427,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) if (pwtx == &wtx) continue; CAccountingEntry *const pacentry = (*it).second.second; - int64 nSmartTime; + int64_t nSmartTime; if (pwtx) { nSmartTime = pwtx->nTimeSmart; @@ -558,7 +562,7 @@ bool CWallet::IsMine(const CTxIn &txin) const return false; } -int64 CWallet::GetDebit(const CTxIn &txin) const +int64_t CWallet::GetDebit(const CTxIn &txin) const { { LOCK(cs_wallet); @@ -594,9 +598,9 @@ bool CWallet::IsChange(const CTxOut& txout) const return false; } -int64 CWalletTx::GetTxTime() const +int64_t CWalletTx::GetTxTime() const { - int64 n = nTimeSmart; + int64_t n = nTimeSmart; return n ? n : nTimeReceived; } @@ -639,8 +643,8 @@ int CWalletTx::GetRequestCount() const return nRequests; } -void CWalletTx::GetAmounts(list >& listReceived, - list >& listSent, int64& nFee, string& strSentAccount) const +void CWalletTx::GetAmounts(list >& listReceived, + list >& listSent, int64_t& nFee, string& strSentAccount) const { nFee = 0; listReceived.clear(); @@ -648,10 +652,10 @@ void CWalletTx::GetAmounts(list >& listReceived, strSentAccount = strFromAccount; // Compute fee: - int64 nDebit = GetDebit(); + int64_t nDebit = GetDebit(); if (nDebit > 0) // debit>0 means we signed/sent this transaction { - int64 nValueOut = GetValueOut(*this); + int64_t nValueOut = GetValueOut(*this); nFee = nDebit - nValueOut; } @@ -692,26 +696,26 @@ void CWalletTx::GetAmounts(list >& listReceived, } -void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nReceived, - int64& nSent, int64& nFee) const +void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived, + int64_t& nSent, int64_t& nFee) const { nReceived = nSent = nFee = 0; - int64 allFee; + int64_t allFee; string strSentAccount; - list > listReceived; - list > listSent; + list > listReceived; + list > listSent; GetAmounts(listReceived, listSent, allFee, strSentAccount); if (strAccount == strSentAccount) { - BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& s, listSent) + BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& s, listSent) nSent += s.second; nFee = allFee; } { LOCK(pwallet->cs_wallet); - BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listReceived) + BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived) { if (pwallet->mapAddressBook.count(r.first)) { @@ -932,7 +936,7 @@ void CWallet::ResendWalletTransactions() CWalletTx& wtx = item.second; // Don't rebroadcast until it's had plenty of time that // it should have gotten in already by now. - if (nTimeBestReceived - (int64)wtx.nTimeReceived > 5 * 60) + if (nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60) mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx)); } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) @@ -954,9 +958,9 @@ void CWallet::ResendWalletTransactions() // -int64 CWallet::GetBalance() const +int64_t CWallet::GetBalance() const { - int64 nTotal = 0; + int64_t nTotal = 0; { LOCK(cs_wallet); for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) @@ -970,9 +974,9 @@ int64 CWallet::GetBalance() const return nTotal; } -int64 CWallet::GetUnconfirmedBalance() const +int64_t CWallet::GetUnconfirmedBalance() const { - int64 nTotal = 0; + int64_t nTotal = 0; { LOCK(cs_wallet); for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) @@ -985,9 +989,9 @@ int64 CWallet::GetUnconfirmedBalance() const return nTotal; } -int64 CWallet::GetImmatureBalance() const +int64_t CWallet::GetImmatureBalance() const { - int64 nTotal = 0; + int64_t nTotal = 0; { LOCK(cs_wallet); for (map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) @@ -1028,8 +1032,8 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed) const } } -static void ApproximateBestSubset(vector > >vValue, int64 nTotalLower, int64 nTargetValue, - vector& vfBest, int64& nBest, int iterations = 1000) +static void ApproximateBestSubset(vector > >vValue, int64_t nTotalLower, int64_t nTargetValue, + vector& vfBest, int64_t& nBest, int iterations = 1000) { vector vfIncluded; @@ -1041,7 +1045,7 @@ static void ApproximateBestSubset(vector vCoins, - set >& setCoinsRet, int64& nValueRet) const +bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, vector vCoins, + set >& setCoinsRet, int64_t& nValueRet) const { setCoinsRet.clear(); nValueRet = 0; // List of values less than target - pair > coinLowestLarger; - coinLowestLarger.first = std::numeric_limits::max(); + pair > coinLowestLarger; + coinLowestLarger.first = std::numeric_limits::max(); coinLowestLarger.second.first = NULL; - vector > > vValue; - int64 nTotalLower = 0; + vector > > vValue; + int64_t nTotalLower = 0; random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt); @@ -1097,9 +1101,9 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe continue; int i = output.i; - int64 n = pcoin->vout[i].nValue; + int64_t n = pcoin->vout[i].nValue; - pair > coin = make_pair(n,make_pair(pcoin, i)); + pair > coin = make_pair(n,make_pair(pcoin, i)); if (n == nTargetValue) { @@ -1140,7 +1144,7 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe // Solve subset sum by stochastic approximation sort(vValue.rbegin(), vValue.rend(), CompareValueOnly()); vector vfBest; - int64 nBest; + int64_t nBest; ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, 1000); if (nBest != nTargetValue && nTotalLower >= nTargetValue + CENT) @@ -1172,7 +1176,7 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe return true; } -bool CWallet::SelectCoins(int64 nTargetValue, set >& setCoinsRet, int64& nValueRet) const +bool CWallet::SelectCoins(int64_t nTargetValue, set >& setCoinsRet, int64_t& nValueRet) const { vector vCoins; AvailableCoins(vCoins); @@ -1185,11 +1189,11 @@ bool CWallet::SelectCoins(int64 nTargetValue, set >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason) +bool CWallet::CreateTransaction(const vector >& vecSend, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason) { - int64 nValue = 0; - BOOST_FOREACH (const PAIRTYPE(CScript, int64)& s, vecSend) + int64_t nValue = 0; + BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) { if (nValue < 0) { @@ -1216,10 +1220,10 @@ bool CWallet::CreateTransaction(const vector >& vecSend, wtxNew.vout.clear(); wtxNew.fFromMe = true; - int64 nTotalValue = nValue + nFeeRet; + int64_t nTotalValue = nValue + nFeeRet; double dPriority = 0; // vouts to the payees - BOOST_FOREACH (const PAIRTYPE(CScript, int64)& s, vecSend) + BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) { CTxOut txout(s.second, s.first); if (txout.IsDust(CTransaction::nMinRelayTxFee)) @@ -1232,7 +1236,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, // Choose coins to use set > setCoins; - int64 nValueIn = 0; + int64_t nValueIn = 0; if (!SelectCoins(nTotalValue, setCoins, nValueIn)) { strFailReason = _("Insufficient funds"); @@ -1240,21 +1244,21 @@ bool CWallet::CreateTransaction(const vector >& vecSend, } BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { - int64 nCredit = pcoin.first->vout[pcoin.second].nValue; + int64_t nCredit = pcoin.first->vout[pcoin.second].nValue; //The priority after the next block (depth+1) is used instead of the current, //reflecting an assumption the user would accept a bit more delay for //a chance at a free transaction. dPriority += (double)nCredit * (pcoin.first->GetDepthInMainChain()+1); } - int64 nChange = nValueIn - nValue - nFeeRet; + int64_t nChange = nValueIn - nValue - nFeeRet; // The following if statement should be removed once enough miners // have upgraded to the 0.9 GetMinFee() rules. Until then, this avoids // creating free transactions that have change outputs less than // CENT bitcoins. if (nFeeRet < CTransaction::nMinTxFee && nChange > 0 && nChange < CENT) { - int64 nMoveToFee = min(nChange, CTransaction::nMinTxFee - nFeeRet); + int64_t nMoveToFee = min(nChange, CTransaction::nMinTxFee - nFeeRet); nChange -= nMoveToFee; nFeeRet += nMoveToFee; } @@ -1328,9 +1332,9 @@ bool CWallet::CreateTransaction(const vector >& vecSend, dPriority /= nTxSizeMod; // Check that enough fee is included - int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000); + int64_t nPayFee = nTransactionFee * (1 + (int64_t)nBytes / 1000); bool fAllowFree = AllowFree(dPriority); - int64 nMinFee = GetMinFee(wtxNew, fAllowFree, GMF_SEND); + int64_t nMinFee = GetMinFee(wtxNew, fAllowFree, GMF_SEND); if (nFeeRet < max(nPayFee, nMinFee)) { nFeeRet = max(nPayFee, nMinFee); @@ -1348,10 +1352,10 @@ bool CWallet::CreateTransaction(const vector >& vecSend, return true; } -bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason) +bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason) { - vector< pair > vecSend; + vector< pair > vecSend; vecSend.push_back(make_pair(scriptPubKey, nValue)); return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, strFailReason); } @@ -1408,10 +1412,10 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) -string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee) +string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee) { CReserveKey reservekey(this); - int64 nFeeRequired; + int64_t nFeeRequired; if (IsLocked()) { @@ -1439,7 +1443,7 @@ string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, -string CWallet::SendMoneyToDestination(const CTxDestination& address, int64 nValue, CWalletTx& wtxNew, bool fAskFee) +string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee) { // Check amount if (nValue <= 0) @@ -1528,21 +1532,21 @@ bool CWallet::NewKeyPool() { LOCK(cs_wallet); CWalletDB walletdb(strWalletFile); - BOOST_FOREACH(int64 nIndex, setKeyPool) + BOOST_FOREACH(int64_t nIndex, setKeyPool) walletdb.ErasePool(nIndex); setKeyPool.clear(); if (IsLocked()) return false; - int64 nKeys = max(GetArg("-keypool", 100), (int64)0); + int64_t nKeys = max(GetArg("-keypool", 100), (int64_t)0); for (int i = 0; i < nKeys; i++) { - int64 nIndex = i+1; + int64_t nIndex = i+1; walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey())); setKeyPool.insert(nIndex); } - LogPrintf("CWallet::NewKeyPool wrote %"PRI64d" new keys\n", nKeys); + LogPrintf("CWallet::NewKeyPool wrote %"PRId64" new keys\n", nKeys); } return true; } @@ -1562,23 +1566,23 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize) if (kpSize > 0) nTargetSize = kpSize; else - nTargetSize = max(GetArg("-keypool", 100), 0LL); + nTargetSize = max(GetArg("-keypool", 100), (int64_t) 0); while (setKeyPool.size() < (nTargetSize + 1)) { - int64 nEnd = 1; + int64_t nEnd = 1; if (!setKeyPool.empty()) nEnd = *(--setKeyPool.end()) + 1; if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) throw runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); - LogPrintf("keypool added key %"PRI64d", size=%"PRIszu"\n", nEnd, setKeyPool.size()); + LogPrintf("keypool added key %"PRId64", size=%"PRIszu"\n", nEnd, setKeyPool.size()); } } return true; } -void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) +void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) { nIndex = -1; keypool.vchPubKey = CPubKey(); @@ -1601,17 +1605,17 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) if (!HaveKey(keypool.vchPubKey.GetID())) throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); - LogPrintf("keypool reserve %"PRI64d"\n", nIndex); + LogPrintf("keypool reserve %"PRId64"\n", nIndex); } } -int64 CWallet::AddReserveKey(const CKeyPool& keypool) +int64_t CWallet::AddReserveKey(const CKeyPool& keypool) { { LOCK2(cs_main, cs_wallet); CWalletDB walletdb(strWalletFile); - int64 nIndex = 1 + *(--setKeyPool.end()); + int64_t nIndex = 1 + *(--setKeyPool.end()); if (!walletdb.WritePool(nIndex, keypool)) throw runtime_error("AddReserveKey() : writing added key failed"); setKeyPool.insert(nIndex); @@ -1620,7 +1624,7 @@ int64 CWallet::AddReserveKey(const CKeyPool& keypool) return -1; } -void CWallet::KeepKey(int64 nIndex) +void CWallet::KeepKey(int64_t nIndex) { // Remove from key pool if (fFileBacked) @@ -1628,22 +1632,22 @@ void CWallet::KeepKey(int64 nIndex) CWalletDB walletdb(strWalletFile); walletdb.ErasePool(nIndex); } - LogPrintf("keypool keep %"PRI64d"\n", nIndex); + LogPrintf("keypool keep %"PRId64"\n", nIndex); } -void CWallet::ReturnKey(int64 nIndex) +void CWallet::ReturnKey(int64_t nIndex) { // Return to key pool { LOCK(cs_wallet); setKeyPool.insert(nIndex); } - LogPrintf("keypool return %"PRI64d"\n", nIndex); + LogPrintf("keypool return %"PRId64"\n", nIndex); } bool CWallet::GetKeyFromPool(CPubKey& result) { - int64 nIndex = 0; + int64_t nIndex = 0; CKeyPool keypool; { LOCK(cs_wallet); @@ -1660,9 +1664,9 @@ bool CWallet::GetKeyFromPool(CPubKey& result) return true; } -int64 CWallet::GetOldestKeyPoolTime() +int64_t CWallet::GetOldestKeyPoolTime() { - int64 nIndex = 0; + int64_t nIndex = 0; CKeyPool keypool; ReserveKeyFromKeyPool(nIndex, keypool); if (nIndex == -1) @@ -1671,9 +1675,9 @@ int64 CWallet::GetOldestKeyPoolTime() return keypool.nTime; } -std::map CWallet::GetAddressBalances() +std::map CWallet::GetAddressBalances() { - map balances; + map balances; { LOCK(cs_wallet); @@ -1699,7 +1703,7 @@ std::map CWallet::GetAddressBalances() if(!ExtractDestination(pcoin->vout[i].scriptPubKey, addr)) continue; - int64 n = pcoin->IsSpent(i) ? 0 : pcoin->vout[i].nValue; + int64_t n = pcoin->IsSpent(i) ? 0 : pcoin->vout[i].nValue; if (!balances.count(addr)) balances[addr] = 0; @@ -1860,7 +1864,7 @@ void CWallet::GetAllReserveKeys(set& setAddress) const CWalletDB walletdb(strWalletFile); LOCK2(cs_main, cs_wallet); - BOOST_FOREACH(const int64& id, setKeyPool) + BOOST_FOREACH(const int64_t& id, setKeyPool) { CKeyPool keypool; if (!walletdb.ReadPool(id, keypool)) @@ -1915,7 +1919,7 @@ void CWallet::ListLockedCoins(std::vector& vOutpts) } } -void CWallet::GetKeyBirthTimes(std::map &mapKeyBirth) const { +void CWallet::GetKeyBirthTimes(std::map &mapKeyBirth) const { mapKeyBirth.clear(); // get birth times for keys with metadata diff --git a/src/wallet.h b/src/wallet.h index 21510f8c3..5c38d7a1a 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -5,25 +5,29 @@ #ifndef BITCOIN_WALLET_H #define BITCOIN_WALLET_H -#include "walletdb.h" - -#include -#include - -#include - -#include "main.h" +#include "core.h" +#include "crypter.h" #include "key.h" #include "keystore.h" -#include "script.h" +#include "main.h" #include "ui_interface.h" #include "util.h" +#include "walletdb.h" + +#include +#include +#include +#include +#include +#include +#include +#include class CAccountingEntry; -class CWalletTx; -class CReserveKey; class COutput; -class CWalletDB; +class CReserveKey; +class CScript; +class CWalletTx; /** (client) version numbers for particular wallet features */ enum WalletFeature @@ -41,7 +45,7 @@ enum WalletFeature class CKeyPool { public: - int64 nTime; + int64_t nTime; CPubKey vchPubKey; CKeyPool() @@ -83,7 +87,7 @@ public: class CWallet : public CCryptoKeyStore, public CWalletInterface { private: - bool SelectCoins(int64 nTargetValue, std::set >& setCoinsRet, int64& nValueRet) const; + bool SelectCoins(int64_t nTargetValue, std::set >& setCoinsRet, int64_t& nValueRet) const; CWalletDB *pwalletdbEncryption; @@ -93,8 +97,8 @@ private: // the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded int nWalletMaxVersion; - int64 nNextResend; - int64 nLastResend; + int64_t nNextResend; + int64_t nLastResend; public: mutable CCriticalSection cs_wallet; @@ -102,7 +106,7 @@ public: bool fFileBacked; std::string strWalletFile; - std::set setKeyPool; + std::set setKeyPool; std::map mapKeyMetadata; typedef std::map MasterKeyMap; @@ -134,7 +138,7 @@ public: } std::map mapWallet; - int64 nOrderPosNext; + int64_t nOrderPosNext; std::map mapRequestCount; std::map mapAddressBook; @@ -143,13 +147,13 @@ public: std::set setLockedCoins; - int64 nTimeFirstKey; + int64_t nTimeFirstKey; // check whether we are allowed to upgrade (or already support) to the named feature bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; } void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true) const; - bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64& nValueRet) const; + bool SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const; bool IsLockedCoin(uint256 hash, unsigned int n) const; void LockCoin(COutPoint& output); void UnlockCoin(COutPoint& output); @@ -179,15 +183,15 @@ public: bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); bool EncryptWallet(const SecureString& strWalletPassphrase); - void GetKeyBirthTimes(std::map &mapKeyBirth) const; + void GetKeyBirthTimes(std::map &mapKeyBirth) const; /** Increment the next transaction order id @return next transaction order id */ - int64 IncOrderPosNext(CWalletDB *pwalletdb = NULL); + int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL); typedef std::pair TxPair; - typedef std::multimap TxItems; + typedef std::multimap TxItems; /** Get the wallet's activity log @return multimap of ordered transactions and accounting entries @@ -204,46 +208,46 @@ public: int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); void ReacceptWalletTransactions(); void ResendWalletTransactions(); - int64 GetBalance() const; - int64 GetUnconfirmedBalance() const; - int64 GetImmatureBalance() const; - bool CreateTransaction(const std::vector >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason); - bool CreateTransaction(CScript scriptPubKey, int64 nValue, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason); + int64_t GetBalance() const; + int64_t GetUnconfirmedBalance() const; + int64_t GetImmatureBalance() const; + bool CreateTransaction(const std::vector >& vecSend, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason); + bool CreateTransaction(CScript scriptPubKey, int64_t nValue, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); - std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); - std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); + std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee=false); + std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee=false); bool NewKeyPool(); bool TopUpKeyPool(unsigned int kpSize = 0); - int64 AddReserveKey(const CKeyPool& keypool); - void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool); - void KeepKey(int64 nIndex); - void ReturnKey(int64 nIndex); + int64_t AddReserveKey(const CKeyPool& keypool); + void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool); + void KeepKey(int64_t nIndex); + void ReturnKey(int64_t nIndex); bool GetKeyFromPool(CPubKey &key); - int64 GetOldestKeyPoolTime(); + int64_t GetOldestKeyPoolTime(); void GetAllReserveKeys(std::set& setAddress) const; std::set< std::set > GetAddressGroupings(); - std::map GetAddressBalances(); + std::map GetAddressBalances(); std::set GetAccountAddresses(std::string strAccount) const; bool IsMine(const CTxIn& txin) const; - int64 GetDebit(const CTxIn& txin) const; + int64_t GetDebit(const CTxIn& txin) const; bool IsMine(const CTxOut& txout) const { return ::IsMine(*this, txout.scriptPubKey); } - int64 GetCredit(const CTxOut& txout) const + int64_t GetCredit(const CTxOut& txout) const { if (!MoneyRange(txout.nValue)) throw std::runtime_error("CWallet::GetCredit() : value out of range"); return (IsMine(txout) ? txout.nValue : 0); } bool IsChange(const CTxOut& txout) const; - int64 GetChange(const CTxOut& txout) const + int64_t GetChange(const CTxOut& txout) const { if (!MoneyRange(txout.nValue)) throw std::runtime_error("CWallet::GetChange() : value out of range"); @@ -260,9 +264,9 @@ public: { return (GetDebit(tx) > 0); } - int64 GetDebit(const CTransaction& tx) const + int64_t GetDebit(const CTransaction& tx) const { - int64 nDebit = 0; + int64_t nDebit = 0; BOOST_FOREACH(const CTxIn& txin, tx.vin) { nDebit += GetDebit(txin); @@ -271,9 +275,9 @@ public: } return nDebit; } - int64 GetCredit(const CTransaction& tx) const + int64_t GetCredit(const CTransaction& tx) const { - int64 nCredit = 0; + int64_t nCredit = 0; BOOST_FOREACH(const CTxOut& txout, tx.vout) { nCredit += GetCredit(txout); @@ -282,9 +286,9 @@ public: } return nCredit; } - int64 GetChange(const CTransaction& tx) const + int64_t GetChange(const CTransaction& tx) const { - int64 nChange = 0; + int64_t nChange = 0; BOOST_FOREACH(const CTxOut& txout, tx.vout) { nChange += GetChange(txout); @@ -349,7 +353,7 @@ class CReserveKey { protected: CWallet* pwallet; - int64 nIndex; + int64_t nIndex; CPubKey vchPubKey; public: CReserveKey(CWallet* pwalletIn) @@ -372,7 +376,7 @@ public: typedef std::map mapValue_t; -static void ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue) +static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue) { if (!mapValue.count("n")) { @@ -383,7 +387,7 @@ static void ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue) } -static void WriteOrderPos(const int64& nOrderPos, mapValue_t& mapValue) +static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) { if (nOrderPos == -1) return; @@ -409,7 +413,7 @@ public: char fFromMe; std::string strFromAccount; std::vector vfSpent; // which outputs are already spent - int64 nOrderPos; // position in ordered transaction list + int64_t nOrderPos; // position in ordered transaction list // memory only mutable bool fDebitCached; @@ -417,11 +421,11 @@ public: mutable bool fImmatureCreditCached; mutable bool fAvailableCreditCached; mutable bool fChangeCached; - mutable int64 nDebitCached; - mutable int64 nCreditCached; - mutable int64 nImmatureCreditCached; - mutable int64 nAvailableCreditCached; - mutable int64 nChangeCached; + mutable int64_t nDebitCached; + mutable int64_t nCreditCached; + mutable int64_t nImmatureCreditCached; + mutable int64_t nAvailableCreditCached; + mutable int64_t nChangeCached; CWalletTx() { @@ -581,7 +585,7 @@ public: return (!!vfSpent[nOut]); } - int64 GetDebit() const + int64_t GetDebit() const { if (vin.empty()) return 0; @@ -592,7 +596,7 @@ public: return nDebitCached; } - int64 GetCredit(bool fUseCache=true) const + int64_t GetCredit(bool fUseCache=true) const { // Must wait until coinbase is safely deep enough in the chain before valuing it if (IsCoinBase() && GetBlocksToMaturity() > 0) @@ -606,7 +610,7 @@ public: return nCreditCached; } - int64 GetImmatureCredit(bool fUseCache=true) const + int64_t GetImmatureCredit(bool fUseCache=true) const { if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { @@ -620,7 +624,7 @@ public: return 0; } - int64 GetAvailableCredit(bool fUseCache=true) const + int64_t GetAvailableCredit(bool fUseCache=true) const { // Must wait until coinbase is safely deep enough in the chain before valuing it if (IsCoinBase() && GetBlocksToMaturity() > 0) @@ -629,7 +633,7 @@ public: if (fUseCache && fAvailableCreditCached) return nAvailableCreditCached; - int64 nCredit = 0; + int64_t nCredit = 0; for (unsigned int i = 0; i < vout.size(); i++) { if (!IsSpent(i)) @@ -647,7 +651,7 @@ public: } - int64 GetChange() const + int64_t GetChange() const { if (fChangeCached) return nChangeCached; @@ -656,11 +660,11 @@ public: return nChangeCached; } - void GetAmounts(std::list >& listReceived, - std::list >& listSent, int64& nFee, std::string& strSentAccount) const; + void GetAmounts(std::list >& listReceived, + std::list >& listSent, int64_t& nFee, std::string& strSentAccount) const; - void GetAccountAmounts(const std::string& strAccount, int64& nReceived, - int64& nSent, int64& nFee) const; + void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived, + int64_t& nSent, int64_t& nFee) const; bool IsFromMe() const { @@ -712,7 +716,7 @@ public: bool WriteToDisk(); - int64 GetTxTime() const; + int64_t GetTxTime() const; int GetRequestCount() const; void AddSupportingTransactions(); @@ -754,13 +758,13 @@ class CWalletKey { public: CPrivKey vchPrivKey; - int64 nTimeCreated; - int64 nTimeExpires; + int64_t nTimeCreated; + int64_t nTimeExpires; std::string strComment; //// todo: add something to note what created it (user, getnewaddress, change) //// maybe should have a map property map - CWalletKey(int64 nExpires=0) + CWalletKey(int64_t nExpires=0) { nTimeCreated = (nExpires ? GetTime() : 0); nTimeExpires = nExpires; @@ -817,13 +821,13 @@ class CAccountingEntry { public: std::string strAccount; - int64 nCreditDebit; - int64 nTime; + int64_t nCreditDebit; + int64_t nTime; std::string strOtherAccount; std::string strComment; mapValue_t mapValue; - int64 nOrderPos; // position in ordered transaction list - uint64 nEntryNo; + int64_t nOrderPos; // position in ordered transaction list + uint64_t nEntryNo; CAccountingEntry() { diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 831ef8b00..8317862f7 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -4,15 +4,24 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "walletdb.h" + +#include "base58.h" +#include "protocol.h" +#include "serialize.h" +#include "sync.h" #include "wallet.h" -#include + +#include +#include + #include +#include using namespace std; using namespace boost; -static uint64 nAccountingEntryNumber = 0; +static uint64_t nAccountingEntryNumber = 0; // // CWalletDB @@ -44,6 +53,119 @@ bool CWalletDB::ErasePurpose(const string& strPurpose) return Erase(make_pair(string("purpose"), strPurpose)); } +bool CWalletDB::WriteTx(uint256 hash, const CWalletTx& wtx) +{ + nWalletDBUpdated++; + return Write(std::make_pair(std::string("tx"), hash), wtx); +} + +bool CWalletDB::EraseTx(uint256 hash) +{ + nWalletDBUpdated++; + return Erase(std::make_pair(std::string("tx"), hash)); +} + +bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta) +{ + nWalletDBUpdated++; + + if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), + keyMeta, false)) + return false; + + // hash pubkey/privkey to accelerate wallet load + std::vector vchKey; + vchKey.reserve(vchPubKey.size() + vchPrivKey.size()); + vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end()); + vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end()); + + return Write(std::make_pair(std::string("key"), vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false); +} + +bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey, + const std::vector& vchCryptedSecret, + const CKeyMetadata &keyMeta) +{ + const bool fEraseUnencryptedKey = true; + nWalletDBUpdated++; + + if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), + keyMeta)) + return false; + + if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false)) + return false; + if (fEraseUnencryptedKey) + { + Erase(std::make_pair(std::string("key"), vchPubKey)); + Erase(std::make_pair(std::string("wkey"), vchPubKey)); + } + return true; +} + +bool CWalletDB::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey) +{ + nWalletDBUpdated++; + return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true); +} + +bool CWalletDB::WriteCScript(const uint160& hash, const CScript& redeemScript) +{ + nWalletDBUpdated++; + return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false); +} + +bool CWalletDB::WriteBestBlock(const CBlockLocator& locator) +{ + nWalletDBUpdated++; + return Write(std::string("bestblock"), locator); +} + +bool CWalletDB::ReadBestBlock(CBlockLocator& locator) +{ + return Read(std::string("bestblock"), locator); +} + +bool CWalletDB::WriteOrderPosNext(int64_t nOrderPosNext) +{ + nWalletDBUpdated++; + return Write(std::string("orderposnext"), nOrderPosNext); +} + +bool CWalletDB::WriteDefaultKey(const CPubKey& vchPubKey) +{ + nWalletDBUpdated++; + return Write(std::string("defaultkey"), vchPubKey); +} + +bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool) +{ + return Read(std::make_pair(std::string("pool"), nPool), keypool); +} + +bool CWalletDB::WritePool(int64_t nPool, const CKeyPool& keypool) +{ + nWalletDBUpdated++; + return Write(std::make_pair(std::string("pool"), nPool), keypool); +} + +bool CWalletDB::ErasePool(int64_t nPool) +{ + nWalletDBUpdated++; + return Erase(std::make_pair(std::string("pool"), nPool)); +} + +bool CWalletDB::EraseSetting(const std::string& strKey) +{ + nWalletDBUpdated++; + return Erase(std::make_pair(std::string("setting"), strKey)); +} + +bool CWalletDB::WriteMinVersion(int nVersion) +{ + return Write(std::string("minversion"), nVersion); +} + bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account) { account.SetNull(); @@ -55,7 +177,7 @@ bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account) return Write(make_pair(string("acc"), strAccount), account); } -bool CWalletDB::WriteAccountingEntry(const uint64 nAccEntryNum, const CAccountingEntry& acentry) +bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry) { return Write(boost::make_tuple(string("acentry"), acentry.strAccount, nAccEntryNum), acentry); } @@ -65,12 +187,12 @@ bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry) return WriteAccountingEntry(++nAccountingEntryNumber, acentry); } -int64 CWalletDB::GetAccountCreditDebit(const string& strAccount) +int64_t CWalletDB::GetAccountCreditDebit(const string& strAccount) { list entries; ListAccountCreditDebit(strAccount, entries); - int64 nCreditDebit = 0; + int64_t nCreditDebit = 0; BOOST_FOREACH (const CAccountingEntry& entry, entries) nCreditDebit += entry.nCreditDebit; @@ -90,7 +212,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list TxPair; - typedef multimap TxItems; + typedef multimap TxItems; TxItems txByTime; for (map::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) @@ -145,14 +267,14 @@ CWalletDB::ReorderTransactions(CWallet* pwallet) txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry))); } - int64& nOrderPosNext = pwallet->nOrderPosNext; + int64_t& nOrderPosNext = pwallet->nOrderPosNext; nOrderPosNext = 0; - std::vector nOrderPosOffsets; + std::vector nOrderPosOffsets; for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it) { CWalletTx *const pwtx = (*it).second.first; CAccountingEntry *const pacentry = (*it).second.second; - int64& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos; + int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos; if (nOrderPos == -1) { @@ -166,8 +288,8 @@ CWalletDB::ReorderTransactions(CWallet* pwallet) } else { - int64 nOrderPosOff = 0; - BOOST_FOREACH(const int64& nOffsetStart, nOrderPosOffsets) + int64_t nOrderPosOff = 0; + BOOST_FOREACH(const int64_t& nOffsetStart, nOrderPosOffsets) { if (nOrderPos >= nOffsetStart) ++nOrderPosOff; @@ -272,7 +394,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, //// debug print //LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString().c_str()); - //LogPrintf(" %12"PRI64d" %s %s %s\n", + //LogPrintf(" %12"PRId64" %s %s %s\n", // wtx.vout[0].nValue, // DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()).c_str(), // wtx.hashBlock.ToString().c_str(), @@ -282,7 +404,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, { string strAccount; ssKey >> strAccount; - uint64 nNumber; + uint64_t nNumber; ssKey >> nNumber; if (nNumber > nAccountingEntryNumber) nAccountingEntryNumber = nNumber; @@ -410,7 +532,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, } else if (strType == "pool") { - int64 nIndex; + int64_t nIndex; ssKey >> nIndex; CKeyPool keypool; ssValue >> keypool; @@ -573,7 +695,7 @@ void ThreadFlushWalletDB(const string& strFile) unsigned int nLastSeen = nWalletDBUpdated; unsigned int nLastFlushed = nWalletDBUpdated; - int64 nLastWalletUpdate = GetTime(); + int64_t nLastWalletUpdate = GetTime(); while (true) { MilliSleep(500); @@ -606,14 +728,14 @@ void ThreadFlushWalletDB(const string& strFile) { LogPrint("db", "Flushing wallet.dat\n"); nLastFlushed = nWalletDBUpdated; - int64 nStart = GetTimeMillis(); + int64_t nStart = GetTimeMillis(); // Flush wallet.dat so it's self contained bitdb.CloseDb(strFile); bitdb.CheckpointLSN(strFile); bitdb.mapFileUseCount.erase(mi++); - LogPrint("db", "Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart); + LogPrint("db", "Flushed wallet.dat %"PRId64"ms\n", GetTimeMillis() - nStart); } } } @@ -673,8 +795,8 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys) // Rewrite salvaged data to wallet.dat // Set -rescan so any missing transactions will be // found. - int64 now = GetTime(); - std::string newFilename = strprintf("wallet.%"PRI64d".bak", now); + int64_t now = GetTime(); + std::string newFilename = strprintf("wallet.%"PRId64".bak", now); int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL, newFilename.c_str(), DB_AUTO_COMMIT); diff --git a/src/walletdb.h b/src/walletdb.h index b6d0d4544..c3b87bb2a 100644 --- a/src/walletdb.h +++ b/src/walletdb.h @@ -6,13 +6,24 @@ #define BITCOIN_WALLETDB_H #include "db.h" -#include "base58.h" +#include "key.h" + +#include +#include +#include +#include +#include -class CKeyPool; class CAccount; class CAccountingEntry; +class CBlockLocator; +class CKeyPool; +class CMasterKey; +class CScript; class CWallet; class CWalletTx; +class uint160; +class uint256; /** Error statuses for the wallet database */ enum DBErrors @@ -30,13 +41,13 @@ class CKeyMetadata public: static const int CURRENT_VERSION=1; int nVersion; - int64 nCreateTime; // 0 means unknown + int64_t nCreateTime; // 0 means unknown CKeyMetadata() { SetNull(); } - CKeyMetadata(int64 nCreateTime_) + CKeyMetadata(int64_t nCreateTime_) { nVersion = CKeyMetadata::CURRENT_VERSION; nCreateTime = nCreateTime_; @@ -73,108 +84,25 @@ public: bool WritePurpose(const std::string& strAddress, const std::string& purpose); bool ErasePurpose(const std::string& strAddress); - bool WriteTx(uint256 hash, const CWalletTx& wtx) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("tx"), hash), wtx); - } + bool WriteTx(uint256 hash, const CWalletTx& wtx); + bool EraseTx(uint256 hash); - bool EraseTx(uint256 hash) - { - nWalletDBUpdated++; - return Erase(std::make_pair(std::string("tx"), hash)); - } + bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta); + bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector& vchCryptedSecret, const CKeyMetadata &keyMeta); + bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey); - bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, - const CKeyMetadata &keyMeta) - { - nWalletDBUpdated++; + bool WriteCScript(const uint160& hash, const CScript& redeemScript); - if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), - keyMeta)) - return false; - - // hash pubkey/privkey to accelerate wallet load - std::vector vchKey; - vchKey.reserve(vchPubKey.size() + vchPrivKey.size()); - vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end()); - vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end()); - - return Write(std::make_pair(std::string("key"), vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false); - } + bool WriteBestBlock(const CBlockLocator& locator); + bool ReadBestBlock(CBlockLocator& locator); - bool WriteCryptedKey(const CPubKey& vchPubKey, - const std::vector& vchCryptedSecret, - const CKeyMetadata &keyMeta) - { - const bool fEraseUnencryptedKey = true; - nWalletDBUpdated++; + bool WriteOrderPosNext(int64_t nOrderPosNext); - if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), - keyMeta)) - return false; - - if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false)) - return false; - if (fEraseUnencryptedKey) - { - Erase(std::make_pair(std::string("key"), vchPubKey)); - Erase(std::make_pair(std::string("wkey"), vchPubKey)); - } - return true; - } + bool WriteDefaultKey(const CPubKey& vchPubKey); - bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true); - } - - bool WriteCScript(const uint160& hash, const CScript& redeemScript) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false); - } - - bool WriteBestBlock(const CBlockLocator& locator) - { - nWalletDBUpdated++; - return Write(std::string("bestblock"), locator); - } - - bool ReadBestBlock(CBlockLocator& locator) - { - return Read(std::string("bestblock"), locator); - } - - bool WriteOrderPosNext(int64 nOrderPosNext) - { - nWalletDBUpdated++; - return Write(std::string("orderposnext"), nOrderPosNext); - } - - bool WriteDefaultKey(const CPubKey& vchPubKey) - { - nWalletDBUpdated++; - return Write(std::string("defaultkey"), vchPubKey); - } - - bool ReadPool(int64 nPool, CKeyPool& keypool) - { - return Read(std::make_pair(std::string("pool"), nPool), keypool); - } - - bool WritePool(int64 nPool, const CKeyPool& keypool) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("pool"), nPool), keypool); - } - - bool ErasePool(int64 nPool) - { - nWalletDBUpdated++; - return Erase(std::make_pair(std::string("pool"), nPool)); - } + bool ReadPool(int64_t nPool, CKeyPool& keypool); + bool WritePool(int64_t nPool, const CKeyPool& keypool); + bool ErasePool(int64_t nPool); // Settings are no longer stored in wallet.dat; these are // used only for backwards compatibility: @@ -189,24 +117,18 @@ public: nWalletDBUpdated++; return Write(std::make_pair(std::string("setting"), strKey), value); } - bool EraseSetting(const std::string& strKey) - { - nWalletDBUpdated++; - return Erase(std::make_pair(std::string("setting"), strKey)); - } + + bool EraseSetting(const std::string& strKey); - bool WriteMinVersion(int nVersion) - { - return Write(std::string("minversion"), nVersion); - } + bool WriteMinVersion(int nVersion); bool ReadAccount(const std::string& strAccount, CAccount& account); bool WriteAccount(const std::string& strAccount, const CAccount& account); private: - bool WriteAccountingEntry(const uint64 nAccEntryNum, const CAccountingEntry& acentry); + bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry); public: bool WriteAccountingEntry(const CAccountingEntry& acentry); - int64 GetAccountCreditDebit(const std::string& strAccount); + int64_t GetAccountCreditDebit(const std::string& strAccount); void ListAccountCreditDebit(const std::string& strAccount, std::list& acentries); DBErrors ReorderTransactions(CWallet*);