Browse Source

Cleanup code using forward declarations.

Use misc methods of avoiding unnecesary header includes.
Replace int typedefs with int##_t from stdint.h.
Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h.
Normalize QT_VERSION ifs where possible.
Resolve some indirect dependencies as direct ones.
Remove extern declarations from .cpp files.
pull/145/head
Brandon Dahler 11 years ago
parent
commit
51ed9ec971
  1. 2
      configure.ac
  2. 7
      share/qt/extract_strings_qt.py
  3. 2
      src/Makefile.am
  4. 36
      src/addrman.cpp
  5. 33
      src/addrman.h
  6. 21
      src/alert.cpp
  7. 17
      src/alert.h
  8. 7
      src/allocators.h
  9. 15
      src/base58.h
  10. 39
      src/bignum.h
  11. 2
      src/bitcoin-cli.cpp
  12. 12
      src/bitcoind.cpp
  13. 27
      src/bitcoinrpc.cpp
  14. 21
      src/bitcoinrpc.h
  15. 6
      src/bloom.cpp
  16. 7
      src/bloom.h
  17. 6
      src/chainparams.cpp
  18. 1
      src/chainparams.h
  19. 14
      src/checkpoints.cpp
  20. 3
      src/checkpoints.h
  21. 11
      src/checkqueue.h
  22. 20
      src/compat.h
  23. 13
      src/core.cpp
  24. 31
      src/core.h
  25. 9
      src/crypter.cpp
  26. 6
      src/crypter.h
  27. 23
      src/db.cpp
  28. 9
      src/db.h
  29. 9
      src/hash.h
  30. 45
      src/init.cpp
  31. 6
      src/init.h
  32. 7
      src/key.cpp
  33. 8
      src/key.h
  34. 5
      src/keystore.cpp
  35. 6
      src/keystore.h
  36. 6
      src/leveldbwrapper.cpp
  37. 4
      src/leveldbwrapper.h
  38. 2
      src/limitedmap.h
  39. 152
      src/main.cpp
  40. 83
      src/main.h
  41. 32
      src/miner.cpp
  42. 13
      src/miner.h
  43. 4
      src/mruset.h
  44. 62
      src/net.cpp
  45. 107
      src/net.h
  46. 14
      src/netbase.cpp
  47. 10
      src/netbase.h
  48. 8
      src/noui.cpp
  49. 10
      src/noui.h
  50. 6
      src/protocol.cpp
  51. 12
      src/protocol.h
  52. 1
      src/qt/aboutdialog.cpp
  53. 3
      src/qt/aboutdialog.h
  54. 8
      src/qt/addressbookpage.cpp
  55. 8
      src/qt/addressbookpage.h
  56. 2
      src/qt/addresstablemodel.cpp
  57. 3
      src/qt/addresstablemodel.h
  58. 4
      src/qt/askpassphrasedialog.cpp
  59. 3
      src/qt/askpassphrasedialog.h
  60. 33
      src/qt/bitcoin.cpp
  61. 5
      src/qt/bitcoinamountfield.cpp
  62. 49
      src/qt/bitcoingui.cpp
  63. 20
      src/qt/bitcoingui.h
  64. 5
      src/qt/bitcoinstrings.cpp
  65. 2
      src/qt/bitcoinunits.h
  66. 14
      src/qt/clientmodel.cpp
  67. 3
      src/qt/clientmodel.h
  68. 2
      src/qt/csvmodelwriter.h
  69. 3
      src/qt/editaddressdialog.h
  70. 53
      src/qt/guiutil.cpp
  71. 10
      src/qt/guiutil.h
  72. 10
      src/qt/intro.cpp
  73. 5
      src/qt/intro.h
  74. 4
      src/qt/macdockiconhandler.h
  75. 1
      src/qt/macnotificationhandler.h
  76. 2
      src/qt/monitoreddatamapper.cpp
  77. 24
      src/qt/notificator.cpp
  78. 3
      src/qt/notificator.h
  79. 3
      src/qt/optionsdialog.cpp
  80. 7
      src/qt/optionsdialog.h
  81. 14
      src/qt/optionsmodel.cpp
  82. 10
      src/qt/overviewpage.cpp
  83. 9
      src/qt/overviewpage.h
  84. 12
      src/qt/paymentrequestplus.cpp
  85. 7
      src/qt/paymentrequestplus.h
  86. 44
      src/qt/paymentserver.cpp
  87. 10
      src/qt/paymentserver.h
  88. 14
      src/qt/rpcconsole.cpp
  89. 3
      src/qt/rpcconsole.h
  90. 9
      src/qt/sendcoinsdialog.cpp
  91. 10
      src/qt/sendcoinsdialog.h
  92. 7
      src/qt/sendcoinsentry.cpp
  93. 5
      src/qt/sendcoinsentry.h
  94. 11
      src/qt/signverifymessagedialog.cpp
  95. 3
      src/qt/signverifymessagedialog.h
  96. 3
      src/qt/splashscreen.cpp
  97. 18
      src/qt/test/paymentservertests.cpp
  98. 6
      src/qt/test/paymentservertests.h
  99. 8
      src/qt/test/test_main.cpp
  100. 5
      src/qt/test/uritests.cpp
  101. 2
      src/qt/test/uritests.h
  102. 28
      src/qt/transactiondesc.cpp
  103. 2
      src/qt/transactiondesc.h
  104. 4
      src/qt/transactionfilterproxy.cpp
  105. 2
      src/qt/transactionfilterproxy.h
  106. 20
      src/qt/transactionrecord.cpp
  107. 16
      src/qt/transactionrecord.h
  108. 21
      src/qt/transactiontablemodel.cpp
  109. 5
      src/qt/transactiontablemodel.h
  110. 27
      src/qt/transactionview.cpp
  111. 10
      src/qt/transactionview.h
  112. 7
      src/qt/walletframe.cpp
  113. 25
      src/qt/walletmodel.cpp
  114. 13
      src/qt/walletmodel.h
  115. 2
      src/qt/walletmodeltransaction.cpp
  116. 6
      src/qt/walletmodeltransaction.h
  117. 26
      src/qt/walletview.cpp
  118. 9
      src/qt/walletview.h
  119. 11
      src/rpcblockchain.cpp
  120. 38
      src/rpcdump.cpp
  121. 24
      src/rpcmining.cpp
  122. 15
      src/rpcnet.cpp
  123. 14
      src/rpcrawtransaction.cpp
  124. 109
      src/rpcwallet.cpp
  125. 20
      src/script.cpp
  126. 55
      src/script.h
  127. 153
      src/serialize.h
  128. 1
      src/sync.cpp
  129. 8
      src/sync.h
  130. 10
      src/test/Checkpoints_tests.cpp
  131. 26
      src/test/DoS_tests.cpp
  132. 14
      src/test/accounting_tests.cpp
  133. 14
      src/test/alert_tests.cpp
  134. 6
      src/test/allocator_tests.cpp
  135. 4
      src/test/base32_tests.cpp
  136. 17
      src/test/base58_tests.cpp
  137. 6
      src/test/base64_tests.cpp
  138. 15
      src/test/bignum_tests.cpp
  139. 8
      src/test/bip32_tests.cpp
  140. 14
      src/test/bloom_tests.cpp
  141. 11
      src/test/canonical_tests.cpp
  142. 16
      src/test/checkblock_tests.cpp
  143. 26
      src/test/compress_tests.cpp
  144. 9
      src/test/getarg_tests.cpp
  145. 9
      src/test/hash_tests.cpp
  146. 4
      src/test/hmac_tests.cpp
  147. 12
      src/test/key_tests.cpp
  148. 8
      src/test/miner_tests.cpp
  149. 11
      src/test/mruset_tests.cpp
  150. 16
      src/test/multisig_tests.cpp
  151. 5
      src/test/netbase_tests.cpp
  152. 9
      src/test/pmt_tests.cpp
  153. 9
      src/test/rpc_tests.cpp
  154. 18
      src/test/script_P2SH_tests.cpp
  155. 25
      src/test/script_tests.cpp
  156. 13
      src/test/serialize_tests.cpp
  157. 12
      src/test/sigopcount_tests.cpp
  158. 13
      src/test/test_bitcoin.cpp
  159. 16
      src/test/transaction_tests.cpp
  160. 8
      src/test/uint160_tests.cpp
  161. 8
      src/test/uint256_tests.cpp
  162. 13
      src/test/util_tests.cpp
  163. 15
      src/test/wallet_tests.cpp
  164. 1
      src/threadsafety.h
  165. 10
      src/txdb.cpp
  166. 12
      src/txdb.h
  167. 1
      src/txmempool.h
  168. 8
      src/ui_interface.h
  169. 117
      src/uint256.h
  170. 154
      src/util.cpp
  171. 108
      src/util.h
  172. 3
      src/version.cpp
  173. 1
      src/version.h
  174. 178
      src/wallet.cpp
  175. 152
      src/wallet.h
  176. 162
      src/walletdb.cpp
  177. 144
      src/walletdb.h

2
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++])

7
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 <QtGlobal>
f.write("""
#include <QtGlobal>
// 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()

2
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 \

36
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<unsigned char> &nKey) const
CDataStream ss1(SER_GETHASH, 0);
std::vector<unsigned char> 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<unsigned char> 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<unsigned char> &nKey, const CNetAd
std::vector<unsigned char> vchGroupKey = GetGroup();
std::vector<unsigned char> 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<CAddress> &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;
}

33
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 <map>
#include <set>
#include <stdint.h>
#include <vector>
#include <openssl/rand.h>
/** 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<CAddress> &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<CAddress> &vAddr, const CNetAddr& source, int64 nTimePenalty = 0)
bool Add(const std::vector<CAddress> &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);

21
src/alert.cpp

@ -2,17 +2,20 @@
// Alert system
//
#include <algorithm>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/foreach.hpp>
#include <map>
#include "alert.h"
#include "key.h"
#include "net.h"
#include "sync.h"
#include "ui_interface.h"
#include "util.h"
#include <algorithm>
#include <inttypes.h>
#include <map>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/foreach.hpp>
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"

17
src/alert.h

@ -6,13 +6,20 @@
#ifndef _BITCOINALERT_H_
#define _BITCOINALERT_H_ 1
#include "serialize.h"
#include "sync.h"
#include <map>
#include <set>
#include <stdint.h>
#include <string>
#include "uint256.h"
#include "util.h"
class CAlert;
class CNode;
class uint256;
extern std::map<uint256, CAlert> 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<int> setCancel;

7
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 <string.h>
#include <map>
#include <string>
#include <string.h>
#include <boost/thread/mutex.hpp>
#include <boost/thread/once.hpp>
#include <map>
#include <openssl/crypto.h> // for OPENSSL_cleanse()
/**
* Thread-safe class to keep track of locked (ie, non-swappable) memory pages.
*

15
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 <string>
#include <vector>
#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 <string>
#include <vector>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

39
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 <stdexcept>
#include <stdint.h>
#include <vector>
#include <openssl/bn.h>
#include "util.h" // for uint64
#include <openssl/bn.h>
/** 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<unsigned char>& vch)
{
@ -122,14 +127,14 @@ public:
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::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;

2
src/bitcoin-cli.cpp

@ -8,6 +8,8 @@
#include "bitcoinrpc.h"
#include "ui_interface.h" /* for _(...) */
#include <boost/filesystem/operations.hpp>
//////////////////////////////////////////////////////////////////////////////
//
// Start

12
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 <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
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;

27
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 <stdint.h>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ip/v6_only.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>
#include <list>
#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<void(vo
func();
}
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64 nSeconds)
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds)
{
assert(rpc_io_service != NULL);

21
src/bitcoinrpc.h

@ -6,18 +6,19 @@
#ifndef _BITCOINRPC_H_
#define _BITCOINRPC_H_ 1
#include <string>
#include "uint256.h"
#include <list>
#include <map>
class CBlockIndex;
class CReserveKey;
#include <stdint.h>
#include <string>
#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 <name> (if any).
*/
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64 nSeconds);
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
@ -146,9 +147,9 @@ extern std::vector<unsigned char> 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();

6
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 <math.h>
#include <stdlib.h>
#include "bloom.h"
#include "core.h"
#include "script.h"
#include <math.h>
#include <stdlib.h>
#define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
#define LN2 0.6931471805599453094172321214581765680755001343602552

7
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 <vector>
#include "uint256.h"
#include "serialize.h"
#include <vector>
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

6
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()));

1
src/chainparams.h

@ -8,7 +8,6 @@
#include "bignum.h"
#include "uint256.h"
#include "util.h"
#include <vector>

14
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 <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/foreach.hpp>
#include "checkpoints.h"
#include "main.h"
#include "uint256.h"
#include <stdint.h>
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/foreach.hpp>
namespace Checkpoints
{
typedef std::map<int, uint256> 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)

3
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 <map>
class uint256;
class CBlockIndex;
class uint256;
/** Block-chain checkpoints are compiled-in sanity checks.
* They are updated every release or three.

11
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 <algorithm>
#include <vector>
#include <boost/foreach.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/condition_variable.hpp>
#include <vector>
#include <algorithm>
#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
template<typename T> class CCheckQueueControl;

20
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 <winsock2.h>
#include <winsock2.h> // Must be included before mswsock.h and windows.h
#include <mswsock.h>
#include <windows.h>
#include <ws2tcpip.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/fcntl.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <limits.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <ifaddrs.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#endif
#ifdef WIN32

13
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 <stdint.h>
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;

31
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 <stdint.h>
#include <stdio.h>
#include <boost/foreach.hpp>
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<CTxIn> 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;
}
};

9
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 <openssl/aes.h>
#include <openssl/evp.h>
#include <vector>
#include "crypter.h"
#include <string>
#include <vector>
#include "crypter.h"
#include <openssl/aes.h>
#include <openssl/evp.h>
bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
{

6
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;

23
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 <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <openssl/rand.h>
#include "hash.h"
#include "protocol.h"
#include "util.h"
#include <inttypes.h>
#include <stdint.h>
#ifndef WIN32
#include "sys/stat.h"
#include <sys/stat.h>
#endif
#include <boost/filesystem.hpp>
#include <boost/version.hpp>
#include <openssl/rand.h>
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;

9
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 <map>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <db_cxx.h>
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

9
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 <openssl/sha.h>
#include <openssl/ripemd.h>
#include <vector>
#include <openssl/ripemd.h>
#include <openssl/sha.h>
template<typename T1>
inline uint256 Hash(const T1 pbegin, const T1 pend)
{

45
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 <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <openssl/crypto.h>
#include <inttypes.h>
#include <stdint.h>
#ifndef WIN32
#include <signal.h>
#endif
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/interprocess/sync/file_lock.hpp>
#include <openssl/crypto.h>
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

6
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 <string>
#include <boost/thread.hpp>
class CWallet;
namespace boost {
class thread_group;
};
extern std::string strWalletFile;
extern CWallet* pwalletMain;

7
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 <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/rand.h>
#include <openssl/obj_mac.h>
#include "key.h"
#include <openssl/rand.h>
// anonymous namespace with local implementation code (OpenSSL interaction)
namespace {

8
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 <vector>
#include "allocators.h"
#include "hash.h"
#include "serialize.h"
#include "uint256.h"
#include "hash.h"
#include <stdexcept>
#include <vector>
// secp256k1:
// const unsigned int PRIVATE_KEY_SIZE = 279;

5
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 <boost/foreach.hpp>
bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
{
CKey key;

6
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 <boost/signals2/signal.hpp>
class CScript;
@ -88,8 +90,10 @@ public:
virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const;
};
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> > > CryptedKeyMap;
/** Keystore which keeps the private keys encrypted.
* It derives from the basic key store, which is used if no encryption is active.
*/

6
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 <leveldb/env.h>
#include <boost/filesystem.hpp>
#include <leveldb/cache.h>
#include <leveldb/env.h>
#include <leveldb/filter_policy.h>
#include <memenv/memenv.h>
#include <boost/filesystem.hpp>
void HandleError(const leveldb::Status &status) throw(leveldb_error) {
if (status.ok())
return;

4
src/leveldbwrapper.h

@ -7,12 +7,12 @@
#include "serialize.h"
#include "util.h"
#include "version.h"
#include <boost/filesystem/path.hpp>
#include <leveldb/db.h>
#include <leveldb/write_batch.h>
#include <boost/filesystem/path.hpp>
class leveldb_error : public std::runtime_error
{
public:

2
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 <assert.h> // TODO: remove
#include <map>
#include <deque>
/** STL-like map container that only keeps the N elements with the highest value. */
template <typename K, typename V> class limitedmap

152
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 <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#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 <inttypes.h>
#include <stdint.h>
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
using namespace std;
using namespace boost;
@ -25,16 +31,13 @@ using namespace boost;
// Global state
//
CCriticalSection cs_setpwalletRegistered;
set<CWallet*> setpwalletRegistered;
CCriticalSection cs_main;
CTxMemPool mempool;
map<uint256, CBlockIndex*> 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<int> 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<CScriptCheck> 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<uint256, CAlert> 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<CAddress> 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<uint256, CNode*> 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<CInv> 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;

83
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 <list>
#include <algorithm>
#include <exception>
#include <map>
#include <set>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
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<uint256, CBlockIndex*> 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);

32
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 <stdint.h>
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<double, double, CTransaction*> 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();

13
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 <stdint.h>
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

4
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 <set>
#include <deque>
#include <set>
#include <utility>
/** STL-like set container that only keeps the most recent N elements. */
template <typename T> class mruset

62
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 <inttypes.h>
#include <stdint.h>
#ifdef WIN32
#include <string.h>
#endif
#ifndef WIN32
#else
#include <fcntl.h>
#endif
#ifdef USE_UPNP
#include <miniupnpc/miniwget.h>
#include <miniupnpc/miniupnpc.h>
#include <miniupnpc/miniwget.h>
#include <miniupnpc/upnpcommands.h>
#include <miniupnpc/upnperrors.h>
#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<CNetAddr, LocalServiceInfo> 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<SOCKET> vhListenSocket;
CAddrMan addrman;
int nMaxConnections = 125;
@ -68,9 +70,9 @@ int nMaxConnections = 125;
vector<CNode*> vNodes;
CCriticalSection cs_vNodes;
map<CInv, CDataStream> mapRelay;
deque<pair<int64, CInv> > vRelayExpiration;
deque<pair<int64_t, CInv> > vRelayExpiration;
CCriticalSection cs_mapRelay;
limitedmap<CInv, int64> mapAlreadyAskedFor(MAX_INV_SZ);
limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
static deque<string> 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<CNetAddr, int64> CNode::setBanned;
std::map<CNetAddr, int64_t> 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<CNetAddr, int64>::iterator i = setBanned.find(ip);
std::map<CNetAddr, int64_t>::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;

107
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 <deque>
#include <boost/array.hpp>
#include <boost/foreach.hpp>
#include <boost/signals2/signal.hpp>
#include <openssl/rand.h>
#include <inttypes.h>
#include <stdint.h>
#ifndef WIN32
#include <arpa/inet.h>
#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 <boost/array.hpp>
#include <boost/foreach.hpp>
#include <boost/signals2/signal.hpp>
#include <openssl/rand.h>
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<CNode*> vNodes;
extern CCriticalSection cs_vNodes;
extern std::map<CInv, CDataStream> mapRelay;
extern std::deque<std::pair<int64, CInv> > vRelayExpiration;
extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
extern CCriticalSection cs_mapRelay;
extern limitedmap<CInv, int64> mapAlreadyAskedFor;
extern limitedmap<CInv, int64_t> mapAlreadyAskedFor;
extern std::vector<std::string> 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<CSerializeData> vSendMsg;
CCriticalSection cs_vSend;
std::deque<CInv> vRecvGetData;
std::deque<CNetMessage> 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<CNetAddr, int64> setBanned;
static std::map<CNetAddr, int64_t> setBanned;
static CCriticalSection cs_setBanned;
int nMisbehavior;
@ -238,12 +249,12 @@ public:
mruset<CInv> setInventoryKnown;
std::vector<CInv> vInventoryToSend;
CCriticalSection cs_inventory;
std::multimap<int64, CInv> mapAskFor;
std::multimap<int64_t, CInv> 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<CInv, int64>::const_iterator it = mapAlreadyAskedFor.find(inv);
int64_t nRequestTime;
limitedmap<CInv, int64_t>::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();
};

14
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 <stdint.h>
#ifndef WIN32
#include <fcntl.h>
@ -15,7 +19,7 @@
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string/predicate.hpp> // 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<unsigned char> 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;
}

10
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 <stdint.h>
#include <string>
#include <vector>
#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<unsigned char> GetGroup() const;
int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const;

8
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 <stdint.h>
#include <string>
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;
}

10
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

6
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 <stdint.h>
#ifndef WIN32
# include <arpa/inet.h>
@ -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;

12
src/protocol.h

@ -11,11 +11,13 @@
#define __INCLUDED_PROTOCOL_H__
#include "chainparams.h"
#include "serialize.h"
#include "netbase.h"
#include <string>
#include "serialize.h"
#include "uint256.h"
#include <stdint.h>
#include <string>
/** 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 */

1
src/qt/aboutdialog.cpp

@ -6,6 +6,7 @@
#include "ui_aboutdialog.h"
#include "clientmodel.h"
#include "clientversion.h"
AboutDialog::AboutDialog(QWidget *parent) :

3
src/qt/aboutdialog.h

@ -7,10 +7,11 @@
#include <QDialog>
class ClientModel;
namespace Ui {
class AboutDialog;
}
class ClientModel;
/** "About" dialog box */
class AboutDialog : public QDialog

8
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 <QSortFilterProxyModel>
#include <QClipboard>
#include <QMessageBox>
#include <QIcon>
#include <QMenu>
#include <QMessageBox>
#include <QSortFilterProxyModel>
AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
QDialog(parent),

8
src/qt/addressbookpage.h

@ -7,17 +7,19 @@
#include <QDialog>
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.

2
src/qt/addresstablemodel.cpp

@ -7,8 +7,8 @@
#include "guiutil.h"
#include "walletmodel.h"
#include "wallet.h"
#include "base58.h"
#include "wallet.h"
#include <QFont>
#include <QDebug>

3
src/qt/addresstablemodel.h

@ -9,9 +9,10 @@
#include <QStringList>
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.
*/

4
src/qt/askpassphrasedialog.cpp

@ -8,9 +8,11 @@
#include "guiconstants.h"
#include "walletmodel.h"
#include "allocators.h"
#include <QKeyEvent>
#include <QMessageBox>
#include <QPushButton>
#include <QKeyEvent>
AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
QDialog(parent),

3
src/qt/askpassphrasedialog.h

@ -7,10 +7,11 @@
#include <QDialog>
class WalletModel;
namespace Ui {
class AskPassphraseDialog;
}
class WalletModel;
/** Multifunctional dialog to ask for passphrases. Used for encryption, unlocking, and changing the passphrase.
*/

33
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 <stdint.h>
#include <boost/filesystem/operations.hpp>
#include <QApplication>
#include <QLibraryInfo>
#include <QLocale>
#include <QMessageBox>
#include <QSettings>
#include <QTimer>
#include <QTranslator>
#if QT_VERSION < 0x050000
#include <QTextCodec>
#endif
#include <QLocale>
#include <QTimer>
#include <QTranslator>
#include <QLibraryInfo>
#include <QSettings>
#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;

5
src/qt/bitcoinamountfield.cpp

@ -4,15 +4,14 @@
#include "bitcoinamountfield.h"
#include "qvaluecombobox.h"
#include "bitcoinunits.h"
#include "guiconstants.h"
#include "qvaluecombobox.h"
#include <QApplication>
#include <QDoubleSpinBox>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QDoubleSpinBox>
#include <qmath.h> // for qPow()
BitcoinAmountField::BitcoinAmountField(QWidget *parent):

49
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 <iostream>
#include <QApplication>
#include <QMenuBar>
#include <QMenu>
#include <QDateTime>
#include <QDesktopWidget>
#include <QDragEnterEvent>
#include <QIcon>
#include <QVBoxLayout>
#include <QToolBar>
#include <QStatusBar>
#include <QLabel>
#include <QListWidget>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include <QMimeData>
#include <QMovie>
#include <QProgressBar>
#include <QSettings>
#include <QStackedWidget>
#include <QDateTime>
#include <QMovie>
#include <QStatusBar>
#include <QStyle>
#include <QTimer>
#include <QDragEnterEvent>
#include <QToolBar>
#include <QVBoxLayout>
#if QT_VERSION < 0x050000
#include <QUrl>
#include <QTextDocument>
#else
#include <QUrlQuery>
#endif
#include <QMimeData>
#include <QStyle>
#include <QListWidget>
#include <iostream>
const QString BitcoinGUI::DEFAULT_WALLET = "~Default";

20
src/qt/bitcoingui.h

@ -6,32 +6,22 @@
#define BITCOINGUI_H
#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QMap>
#include <QSystemTrayIcon>
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
/**

5
src/qt/bitcoinstrings.cpp

@ -1,4 +1,7 @@
#include <QtGlobal>
// 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"),
};
};

2
src/qt/bitcoinunits.h

@ -5,8 +5,8 @@
#ifndef BITCOINUNITS_H
#define BITCOINUNITS_H
#include <QString>
#include <QAbstractListModel>
#include <QString>
/** Bitcoin unit definitions. Encapsulates parsing and formatting
and serves as list model for drop-down selection boxes.

14
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 <stdint.h>
#include <QDateTime>
#include <QTimer>
#include <QDebug>
#include <QTimer>
static const int64 nClientStartupTime = GetTime();
static const int64_t nClientStartupTime = GetTime();
ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
QObject(parent), optionsModel(optionsModel),

3
src/qt/clientmodel.h

@ -7,9 +7,10 @@
#include <QObject>
class OptionsModel;
class AddressTableModel;
class OptionsModel;
class TransactionTableModel;
class CWallet;
QT_BEGIN_NAMESPACE

2
src/qt/csvmodelwriter.h

@ -5,8 +5,8 @@
#ifndef CSVMODELWRITER_H
#define CSVMODELWRITER_H
#include <QObject>
#include <QList>
#include <QObject>
QT_BEGIN_NAMESPACE
class QAbstractItemModel;

3
src/qt/editaddressdialog.h

@ -7,10 +7,11 @@
#include <QDialog>
class AddressTableModel;
namespace Ui {
class EditAddressDialog;
}
class AddressTableModel;
QT_BEGIN_NAMESPACE
class QDataWidgetMapper;

53
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 <QApplication>
#include <QDateTime>
#include <QDoubleValidator>
#include <QFont>
#include <QLineEdit>
#if QT_VERSION >= 0x050000
#include <QUrlQuery>
#else
#include <QUrl>
#endif
#include <QTextDocument> // for Qt::mightBeRichText
#include <QAbstractItemView>
#include <QClipboard>
#include <QFileDialog>
#include <QDesktopServices>
#include <QThread>
#include <QSettings>
#include <QDesktopWidget>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#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 <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <QAbstractItemView>
#include <QApplication>
#include <QClipboard>
#include <QDateTime>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QDoubleValidator>
#include <QFileDialog>
#include <QFont>
#include <QLineEdit>
#include <QSettings>
#include <QTextDocument> // for Qt::mightBeRichText
#include <QThread>
#if QT_VERSION < 0x050000
#include <QUrl>
#else
#include <QUrlQuery>
#endif
namespace GUIUtil {

10
src/qt/guiutil.h

@ -5,19 +5,19 @@
#ifndef GUIUTIL_H
#define GUIUTIL_H
#include <QString>
#include <QObject>
#include <QMessageBox>
#include <QObject>
#include <QString>
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.

10
src/qt/intro.cpp

@ -4,17 +4,17 @@
#include "intro.h"
#include "ui_intro.h"
#include "util.h"
#include <boost/filesystem.hpp>
#include <QFileDialog>
#include <QSettings>
#include <QMessageBox>
#include <boost/filesystem.hpp>
/* 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.");

5
src/qt/intro.h

@ -6,13 +6,14 @@
#define INTRO_H
#include <QDialog>
#include <QThread>
#include <QMutex>
#include <QThread>
class FreespaceChecker;
namespace Ui {
class Intro;
}
class FreespaceChecker;
/** Introduction screen (pre-GUI startup).
Allows the user to choose a data directory,

4
src/qt/macdockiconhandler.h

@ -5,12 +5,12 @@
#ifndef MACDOCKICONHANDLER_H
#define MACDOCKICONHANDLER_H
#include <QObject>
#include <QMainWindow>
#include <QObject>
QT_BEGIN_NAMESPACE
class QMenu;
class QIcon;
class QMenu;
class QWidget;
QT_END_NAMESPACE

1
src/qt/macnotificationhandler.h

@ -4,6 +4,7 @@
#ifndef MACNOTIFICATIONHANDLER_H
#define MACNOTIFICATIONHANDLER_H
#include <QObject>
/** Macintosh-specific notification handler (supports UserNotificationCenter and Growl).

2
src/qt/monitoreddatamapper.cpp

@ -4,9 +4,9 @@
#include "monitoreddatamapper.h"
#include <QWidget>
#include <QMetaObject>
#include <QMetaProperty>
#include <QWidget>
MonitoredDataMapper::MonitoredDataMapper(QObject *parent) :
QDataWidgetMapper(parent)

24
src/qt/notificator.cpp

@ -4,27 +4,31 @@
#include "notificator.h"
#include <QApplication>
#include <QMetaType>
#include <QVariant>
#include <QByteArray>
#include <QIcon>
#include <QImageWriter>
#include <QMessageBox>
#include <QMetaType>
#include <QStyle>
#include <QByteArray>
#include <QSystemTrayIcon>
#include <QMessageBox>
#include <QTemporaryFile>
#include <QImageWriter>
#include <QVariant>
#ifdef Q_OS_MAC
#include "macnotificationhandler.h"
#include <ApplicationServices/ApplicationServices.h>
#endif
#ifdef USE_DBUS
#include <QtDBus>
#include <stdint.h>
#endif
#ifdef Q_OS_MAC
#include <ApplicationServices/ApplicationServices.h>
#include "macnotificationhandler.h"
#include <QtDBus>
#endif
// https://wiki.ubuntu.com/NotificationDevelopmentGuidelines recommends at least 128
const int FREEDESKTOP_NOTIFICATION_ICON_SIZE = 128;

3
src/qt/notificator.h

@ -9,11 +9,12 @@
#include "bitcoin-config.h"
#endif
#include <QObject>
#include <QIcon>
#include <QObject>
QT_BEGIN_NAMESPACE
class QSystemTrayIcon;
#ifdef USE_DBUS
class QDBusInterface;
#endif

3
src/qt/optionsdialog.cpp

@ -11,9 +11,10 @@
#include "bitcoinunits.h"
#include "monitoreddatamapper.h"
#include "netbase.h"
#include "optionsmodel.h"
#include "netbase.h"
#include <QDir>
#include <QIntValidator>
#include <QLocale>

7
src/qt/optionsdialog.h

@ -7,12 +7,13 @@
#include <QDialog>
class MonitoredDataMapper;
class OptionsModel;
class QValidatedLineEdit;
namespace Ui {
class OptionsDialog;
}
class OptionsModel;
class MonitoredDataMapper;
class QValidatedLineEdit;
/** Preferences dialog. */
class OptionsDialog : public QDialog

14
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 <QSettings>
@ -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

10
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 <QAbstractItemDelegate>
#include <QPainter>

9
src/qt/overviewpage.h

@ -7,13 +7,14 @@
#include <QWidget>
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;

12
src/qt/paymentrequestplus.cpp

@ -7,16 +7,16 @@
// with some extra methods
//
#include <QDateTime>
#include <QDebug>
#include <QSslCertificate>
#include "paymentrequestplus.h"
#include <stdexcept>
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#include <QDateTime>
#include <QDebug>
#include <QSslCertificate>
#include <stdexcept>
#include "paymentrequestplus.h"
class SSLVerifyError : public std::runtime_error
{

7
src/qt/paymentrequestplus.h

@ -5,13 +5,14 @@
#ifndef PAYMENTREQUESTPLUS_H
#define PAYMENTREQUESTPLUS_H
#include "paymentrequest.pb.h"
#include "base58.h"
#include <QByteArray>
#include <QList>
#include <QString>
#include "base58.h"
#include "paymentrequest.pb.h"
//
// Wraps dumb protocol buffer paymentRequest
// with extra methods

44
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 <cstdlib>
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#include <QApplication>
#include <QByteArray>
#include <QDataStream>
@ -13,8 +30,6 @@
#include <QList>
#include <QLocalServer>
#include <QLocalSocket>
#include <QStringList>
#include <QTextDocument>
#include <QNetworkAccessManager>
#include <QNetworkProxy>
#include <QNetworkReply>
@ -22,27 +37,16 @@
#include <QSslCertificate>
#include <QSslError>
#include <QSslSocket>
#include <QStringList>
#include <QTextDocument>
#if QT_VERSION < 0x050000
#include <QUrl>
#else
#include <QUrlQuery>
#endif
#include <cstdlib>
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#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"))
{

10
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 <QObject>
#include <QString>
#include "paymentrequestplus.h"
#include "walletmodel.h"
class CWallet;
#include <QObject>
#include <QString>
class OptionsModel;
QT_BEGIN_NAMESPACE
@ -51,6 +49,8 @@ class QSslError;
class QUrl;
QT_END_NAMESPACE
class CWallet;
class PaymentServer : public QObject
{
Q_OBJECT

14
src/qt/rpcconsole.cpp

@ -6,18 +6,20 @@
#include "ui_rpcconsole.h"
#include "clientmodel.h"
#include "bitcoinrpc.h"
#include "guiutil.h"
#include <QTime>
#include <QThread>
#include "bitcoinrpc.h"
#include "json/json_spirit_value.h"
#include <openssl/crypto.h>
#include <QKeyEvent>
#include <QScrollBar>
#include <QThread>
#include <QTime>
#if QT_VERSION < 0x050000
#include <QUrl>
#endif
#include <QScrollBar>
#include <openssl/crypto.h>
// TODO: add a scrollback limit, as there is currently none
// TODO: make it possible to filter out categories (esp debug messages when implemented)

3
src/qt/rpcconsole.h

@ -7,10 +7,11 @@
#include <QDialog>
class ClientModel;
namespace Ui {
class RPCConsole;
}
class ClientModel;
/** Local Bitcoin RPC console. */
class RPCConsole: public QDialog

9
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 <QMessageBox>
#include <QTextDocument>
#include <QScrollBar>
#include <QTextDocument>
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);

10
src/qt/sendcoinsdialog.h

@ -8,12 +8,8 @@
#include "walletmodel.h"
#include <QDialog>
#include <QVariant>
#include <QPair>
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
{

7
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 <QApplication>
#include <QClipboard>

5
src/qt/sendcoinsentry.h

@ -5,14 +5,15 @@
#ifndef SENDCOINSENTRY_H
#define SENDCOINSENTRY_H
#include "walletmodel.h"
#include <QStackedWidget>
#include "walletmodel.h"
class WalletModel;
namespace Ui {
class SendCoinsEntry;
}
class WalletModel;
/**
* A single entry in the dialog for sending bitcoins.

11
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 <QClipboard>
#include "base58.h"
#include "init.h"
#include "wallet.h"
#include <string>
#include <vector>
#include <QClipboard>
SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SignVerifyMessageDialog),

3
src/qt/signverifymessagedialog.h

@ -7,10 +7,11 @@
#include <QDialog>
class WalletModel;
namespace Ui {
class SignVerifyMessageDialog;
}
class WalletModel;
class SignVerifyMessageDialog : public QDialog
{

3
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 <QApplication>
#include <QPainter>

18
src/qt/test/paymentservertests.cpp

@ -1,17 +1,17 @@
#include <QCoreApplication>
#include <QDebug>
#include <QTemporaryFile>
#include <QVariant>
#include <QFileOpenEvent>
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#include "paymentservertests.h"
#include "optionsmodel.h"
#include "paymentservertests.h"
#include "paymentrequestdata.h"
#include "util.h"
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#include <QCoreApplication>
#include <QDebug>
#include <QFileOpenEvent>
#include <QTemporaryFile>
#include <QVariant>
X509 *parse_b64der_cert(const char* cert_data)

6
src/qt/test/paymentservertests.h

@ -1,11 +1,11 @@
#ifndef PAYMENTSERVERTESTS_H
#define PAYMENTSERVERTESTS_H
#include <QTest>
#include <QObject>
#include "../paymentserver.h"
#include <QObject>
#include <QTest>
class PaymentServerTests : public QObject
{
Q_OBJECT

8
src/qt/test/test_main.cpp

@ -1,8 +1,10 @@
#include <QTest>
#include <QObject>
#include "uritests.h"
#include "paymentservertests.h"
#include "uritests.h"
#include <QObject>
#include <QTest>
// This is all you need to run all the tests
int main(int argc, char *argv[])

5
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 <QUrl>

2
src/qt/test/uritests.h

@ -1,8 +1,8 @@
#ifndef URITESTS_H
#define URITESTS_H
#include <QTest>
#include <QObject>
#include <QTest>
class URITests : public QObject
{

28
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 <stdint.h>
#include <string>
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 += "<html><font face='verdana, arial, helvetica, sans-serif'>";
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 += "<b>" + tr("Status") + ":</b> " + 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 += "<b>" + tr("Credit") + ":</b> ";
@ -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 += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -nValue) + "<br>";
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, nValue) + "<br>";
}
int64 nTxFee = nDebit - GetValueOut(wtx);
int64_t nTxFee = nDebit - GetValueOut(wtx);
if (nTxFee > 0)
strHTML += "<b>" + tr("Transaction fee") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -nTxFee) + "<br>";
}

2
src/qt/transactiondesc.h

@ -5,8 +5,8 @@
#ifndef TRANSACTIONDESC_H
#define TRANSACTIONDESC_H
#include <QString>
#include <QObject>
#include <QString>
class CWallet;
class CWalletTx;

4
src/qt/transactionfilterproxy.cpp

@ -6,10 +6,10 @@
#include "transactiontablemodel.h"
#include <QDateTime>
#include <cstdlib>
#include <QDateTime>
// 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)

2
src/qt/transactionfilterproxy.h

@ -5,8 +5,8 @@
#ifndef TRANSACTIONFILTERPROXY_H
#define TRANSACTIONFILTERPROXY_H
#include <QSortFilterProxyModel>
#include <QDateTime>
#include <QSortFilterProxyModel>
/** Filter the transaction list according to pre-specified rules. */
class TransactionFilterProxy : public QSortFilterProxyModel

20
src/qt/transactionrecord.cpp

@ -4,8 +4,10 @@
#include "transactionrecord.h"
#include "wallet.h"
#include "base58.h"
#include "wallet.h"
#include <stdint.h>
/* Return positive answer if transaction should be shown in list.
*/
@ -28,10 +30,10 @@ bool TransactionRecord::showTransaction(const CWalletTx &wtx)
QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx)
{
QList<TransactionRecord> 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<std::string, std::string> mapValue = wtx.mapValue;
@ -83,7 +85,7 @@ QList<TransactionRecord> 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> 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> 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;

16
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 */

21
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 <QList>
#include <QColor>
#include <QTimer>
#include <QIcon>
#include <QDateTime>
#include <QDebug>
#include <QIcon>
#include <QList>
#include <QTimer>
// Amount column is right-aligned it contains numbers
static int column_alignments[] = {

5
src/qt/transactiontablemodel.h

@ -8,11 +8,12 @@
#include <QAbstractTableModel>
#include <QStringList>
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

27
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 <QScrollBar>
#include <QComboBox>
#include <QDateTimeEdit>
#include <QDoubleValidator>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QTableView>
#include <QHeaderView>
#include <QPoint>
#include <QMenu>
#include <QLabel>
#include <QDateTimeEdit>
#include <QLineEdit>
#include <QMenu>
#include <QPoint>
#include <QScrollBar>
#include <QTableView>
#include <QVBoxLayout>
TransactionView::TransactionView(QWidget *parent) :
QWidget(parent), model(0), transactionProxyModel(0),

10
src/qt/transactionview.h

@ -7,17 +7,17 @@
#include <QWidget>
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.

7
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 <cstdio>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QStackedWidget>
WalletFrame::WalletFrame(BitcoinGUI *_gui) :
QFrame(_gui),

25
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 <stdint.h>
#include <QDebug>
#include <QSet>
#include <QTimer>
#include <QDebug>
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<SendCoinsRecipient> recipients = transaction.getRecipients();
std::vector<std::pair<CScript, int64> > vecSend;
std::vector<std::pair<CScript, int64_t> > 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<CScript, int64>(scriptPubKey, out.amount()));
vecSend.push_back(std::pair<CScript, int64_t>(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<CScript, int64>(scriptPubKey, rcp.amount));
vecSend.push_back(std::pair<CScript, int64_t>(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();

13
src/qt/walletmodel.h

@ -5,19 +5,20 @@
#ifndef WALLETMODEL_H
#define WALLETMODEL_H
#include <QObject>
#include "paymentrequestplus.h"
#include "walletmodeltransaction.h"
#include "allocators.h" /* for SecureString */
#include "wallet.h"
#include "walletmodeltransaction.h"
#include "paymentrequestplus.h"
class OptionsModel;
#include <QObject>
class AddressTableModel;
class OptionsModel;
class TransactionTableModel;
class CWallet;
class WalletModelTransaction;
class CWallet;
QT_BEGIN_NAMESPACE
class QTimer;
QT_END_NAMESPACE

2
src/qt/walletmodeltransaction.cpp

@ -4,6 +4,8 @@
#include "walletmodeltransaction.h"
#include "wallet.h"
WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &recipients) :
recipients(recipients),
walletTransaction(0),

6
src/qt/walletmodeltransaction.h

@ -7,8 +7,14 @@
#include "walletmodel.h"
#include <QObject>
class SendCoinsRecipient;
class CReserveKey;
class CWallet;
class CWalletTx;
/** Data model for a walletmodel transaction. */
class WalletModelTransaction
{

26
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 <QHBoxLayout>
#include <QVBoxLayout>
#include <QAction>
#include <QActionGroup>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QPushButton>
#include <QVBoxLayout>
WalletView::WalletView(QWidget *parent):
QStackedWidget(parent),

9
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

11
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 <stdint.h>
#include "json/json_spirit_value.h"
using namespace json_spirit;
using namespace std;
@ -112,7 +119,7 @@ Value settxfee(const Array& params, bool fHelp)
"<amount> 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

38
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 <iostream>
#include <fstream>
#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 <fstream>
#include <stdint.h>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/variant/get.hpp>
#include <boost/algorithm/string.hpp>
#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<CKeyID, int64> mapKeyBirth;
std::map<CKeyID, int64_t> mapKeyBirth;
std::set<CKeyID> setKeyPool;
pwalletMain->GetKeyBirthTimes(mapKeyBirth);
pwalletMain->GetAllReserveKeys(setKeyPool);
// sort time/key pairs
std::vector<std::pair<int64, CKeyID> > vKeyBirth;
for (std::map<CKeyID, int64>::const_iterator it = mapKeyBirth.begin(); it != mapKeyBirth.end(); it++) {
std::vector<std::pair<int64_t, CKeyID> > vKeyBirth;
for (std::map<CKeyID, int64_t>::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<std::pair<int64, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
for (std::vector<std::pair<int64_t, CKeyID> >::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();

24
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 <stdint.h>
#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))

15
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 <inttypes.h>
#include <boost/foreach.hpp>
#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));

14
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 <boost/assign/list_of.hpp>
#include "base58.h"
#include "bitcoinrpc.h"
#include "db.h"
#include "init.h"
#include "net.h"
#include "uint256.h"
#include "wallet.h"
#include <stdint.h>
#include <boost/assign/list_of.hpp>
#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);

109
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 <boost/assign/list_of.hpp>
#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 <stdint.h>
#include <boost/assign/list_of.hpp>
#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<CTxDestination, int64> balances = pwalletMain->GetAddressBalances();
map<CTxDestination, int64_t> balances = pwalletMain->GetAddressBalances();
BOOST_FOREACH(set<CTxDestination> 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<uint256, CWalletTx>::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<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
// Tally
int64 nAmount = 0;
int64_t nAmount = 0;
for (map<uint256, CWalletTx>::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<uint256, CWalletTx>::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<uint256, CWalletTx>::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<pair<CTxDestination, int64> > listReceived;
list<pair<CTxDestination, int64> > listSent;
list<pair<CTxDestination, int64_t> > listReceived;
list<pair<CTxDestination, int64_t> > 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<CBitcoinAddress> setAddress;
vector<pair<CScript, int64> > vecSend;
vector<pair<CScript, int64_t> > 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<uint256> 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<int>::max();
if (it != mapTally.end())
{
@ -923,7 +932,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
{
for (map<string, tallyitem>::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<pair<CTxDestination, int64> > listReceived;
list<pair<CTxDestination, int64> > listSent;
list<pair<CTxDestination, int64_t> > listReceived;
list<pair<CTxDestination, int64_t> > 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<string, int64> mapAccountBalances;
map<string, int64_t> 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<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
int64 nFee;
int64_t nFee;
string strSentAccount;
list<pair<CTxDestination, int64> > listReceived;
list<pair<CTxDestination, int64> > listSent;
list<pair<CTxDestination, int64_t> > listReceived;
list<pair<CTxDestination, int64_t> > 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);

20
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 <stdint.h>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
using namespace std;
using namespace boost;
bool CheckSig(vector<unsigned char> vchSig, const vector<unsigned char> &vchPubKey, const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, int flags);
typedef vector<unsigned char> 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<unsigned char> vchSig, const vector<unsigned char> &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<boost::shared_mutex> lock(cs_sigcache);
while (static_cast<int64>(setValid.size()) > nMaxCacheSize)
while (static_cast<int64_t>(setValid.size()) > nMaxCacheSize)
{
// Evict a random entry. Random because that helps
// foil would-be DoS attackers who might try to pre-generate

55
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 <stdexcept>
#include <stdint.h>
#include <string>
#include <vector>
#include <boost/foreach.hpp>
#include <boost/variant.hpp>
#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<std::vector<unsigned char> >& v
class CScript : public std::vector<unsigned char>
{
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)
{

153
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 <string>
#include <vector>
#include "allocators.h"
#include <algorithm>
#include <assert.h>
#include <limits>
#include <ios>
#include <map>
#include <set>
#include <cassert>
#include <limits>
#include <cstring>
#include <cstdio>
#include <stdint.h>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <boost/type_traits/is_fundamental.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <boost/tuple/tuple_io.hpp>
#include "allocators.h"
#include "version.h"
typedef long long int64;
typedef unsigned long long uint64;
#include <boost/type_traits/is_fundamental.hpp>
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<typename Stream> inline void Serialize(Stream& s, char a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed char a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned char a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed short a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned short a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed int a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned int a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed long a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned long a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, int64 a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, uint64 a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, float a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, double a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, char& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed char& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned char& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed short& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned short& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed int& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned int& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed long& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned long& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, int64& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, uint64& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, float& a, int, int=0) { READDATA(s, a); }
template<typename Stream> 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<typename Stream> inline void Serialize(Stream& s, char a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed char a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned char a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed short a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned short a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed int a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned int a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed long a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned long a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, signed long long a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, unsigned long long a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, float a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Serialize(Stream& s, double a, int, int=0) { WRITEDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, char& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed char& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned char& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed short& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned short& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed int& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned int& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed long& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned long& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, signed long long& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, unsigned long long& a, int, int=0) { READDATA(s, a); }
template<typename Stream> inline void Unserialize(Stream& s, float& a, int, int=0) { READDATA(s, a); }
template<typename Stream> 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<typename Stream> inline void Serialize(Stream& s, bool a, int, int=0) { char f=a; WRITEDATA(s, f); }
@ -161,16 +160,16 @@ template<typename Stream> 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<unsigned short>::max()) return sizeof(unsigned char) + sizeof(unsigned short);
else if (nSize <= std::numeric_limits<unsigned int>::max()) return sizeof(unsigned char) + sizeof(unsigned int);
else return sizeof(unsigned char) + sizeof(uint64);
else return sizeof(unsigned char) + sizeof(uint64_t);
}
template<typename Stream>
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<typename Stream>
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<char> 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;

1
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 <boost/foreach.hpp>

8
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 <boost/thread/condition_variable.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/condition_variable.hpp>
#include "threadsafety.h"
////////////////////////////////////////////////

10
src/test/Checkpoints_tests.cpp

@ -1,12 +1,12 @@
//
// Unit tests for block-chain checkpoints
//
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include "../checkpoints.h"
#include "../util.h"
#include "checkpoints.h"
#include "uint256.h"
#include <boost/test/unit_test.hpp>
using namespace std;

26
src/test/DoS_tests.cpp

@ -1,21 +1,23 @@
//
// Unit tests for denial-of-service detection/prevention code
//
#include <algorithm>
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#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 <stdint.h>
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
// 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<int64, unsigned int> BlockData;
typedef std::map<int64_t, unsigned int> BlockData;
BlockData chainData =
map_list_of(1239852051,486604799)(1262749024,486594666)
(1279305360,469854461)(1280200847,469830746)(1281678674,469809688)

14
src/test/accounting_tests.cpp

@ -1,15 +1,19 @@
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include "init.h"
#include "wallet.h"
#include "walletdb.h"
#include <stdint.h>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
extern CWallet* pwalletMain;
BOOST_AUTO_TEST_SUITE(accounting_tests)
static void
GetResults(CWalletDB& walletdb, std::map<int64, CAccountingEntry>& results)
GetResults(CWalletDB& walletdb, std::map<int64_t, CAccountingEntry>& results)
{
std::list<CAccountingEntry> aes;
@ -28,7 +32,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
std::vector<CWalletTx*> vpwtx;
CWalletTx wtx;
CAccountingEntry ae;
std::map<int64, CAccountingEntry> results;
std::map<int64_t, CAccountingEntry> results;
ae.strAccount = "";
ae.nCreditDebit = 1;

14
src/test/alert_tests.cpp

@ -2,14 +2,18 @@
// Unit tests for alert system
//
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
#include <fstream>
#include "alert.h"
#include "data/alertTests.raw.h"
#include "serialize.h"
#include "util.h"
#include "data/alertTests.raw.h"
#include "version.h"
#include <fstream>
#include <boost/filesystem/operations.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
#if 0
//

6
src/test/allocator_tests.cpp

@ -1,9 +1,9 @@
#include <boost/test/unit_test.hpp>
#include "init.h"
#include "main.h"
#include "util.h"
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(allocator_tests)
// Dummy memory page locker for platform independent tests

4
src/test/base32_tests.cpp

@ -1,7 +1,9 @@
#include <boost/test/unit_test.hpp>
#include "util.h"
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(base32_tests)
BOOST_AUTO_TEST_CASE(base32_testvectors)

17
src/test/base58_tests.cpp

@ -1,13 +1,20 @@
#include <boost/test/unit_test.hpp>
#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 <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
#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);

6
src/test/base64_tests.cpp

@ -1,9 +1,9 @@
#include <boost/test/unit_test.hpp>
#include "main.h"
#include "wallet.h"
#include "util.h"
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(base64_tests)
BOOST_AUTO_TEST_CASE(base64_testvectors)

15
src/test/bignum_tests.cpp

@ -1,8 +1,9 @@
#include <boost/test/unit_test.hpp>
#include "bignum.h"
#include <limits>
#include <stdint.h>
#include "bignum.h"
#include "util.h"
#include <boost/test/unit_test.hpp>
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<int64>::min();
n = std::numeric_limits<int64_t>::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<int64>::max();
n = std::numeric_limits<int64_t>::max();
CBigNum num(n);
BOOST_CHECK(num.ToString() == "9223372036854775807");
num.setulong(0);

8
src/test/bip32_tests.cpp

@ -1,13 +1,13 @@
#include <boost/test/unit_test.hpp>
#include <string>
#include <vector>
#include "key.h"
#include "base58.h"
#include "key.h"
#include "uint256.h"
#include "util.h"
#include <string>
#include <vector>
struct TestDerivation {
std::string pub;
std::string prv;

14
src/test/bloom_tests.cpp

@ -1,11 +1,15 @@
#include <boost/test/unit_test.hpp>
#include <vector>
#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 <vector>
#include <boost/test/unit_test.hpp>
using namespace std;
using namespace boost::tuples;

11
src/test/canonical_tests.cpp

@ -1,16 +1,19 @@
//
// Unit tests for canonical signatures
//
#include "json/json_spirit_writer_template.h"
#include <boost/test/unit_test.hpp>
#include <openssl/ecdsa.h>
#include "key.h"
#include "script.h"
#include "util.h"
#include "data/sig_noncanonical.json.h"
#include "data/sig_canonical.json.h"
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
#include "json/json_spirit_writer_template.h"
#include <openssl/ecdsa.h>
using namespace std;
using namespace json_spirit;

16
src/test/checkblock_tests.cpp

@ -1,17 +1,17 @@
//
// Unit tests for block.CheckBlock()
//
#include <algorithm>
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include "main.h"
#include "wallet.h"
#include "net.h"
#include "util.h"
#include <cstdio>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(CheckBlock_tests)

26
src/test/compress_tests.cpp

@ -1,9 +1,11 @@
#include <boost/test/unit_test.hpp>
#include <string>
#include <vector>
#include "main.h"
#include "util.h"
#include <stdint.h>
#include <boost/test/unit_test.hpp>
// 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));
}

9
src/test/getarg_tests.cpp

@ -1,9 +1,14 @@
#include "util.h"
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
#include "util.h"
BOOST_AUTO_TEST_SUITE(getarg_tests)
static void ResetArgs(const std::string& strArg)

9
src/test/hash_tests.cpp

@ -1,8 +1,11 @@
#include <boost/test/unit_test.hpp>
#include <vector>
#include "util.h"
#include "hash.h"
#include "util.h"
#include <vector>
#include <boost/test/unit_test.hpp>
using namespace std;

4
src/test/hmac_tests.cpp

@ -1,8 +1,10 @@
#include <boost/test/unit_test.hpp>
#include "hash.h"
#include "util.h"
#include <boost/test/unit_test.hpp>
using namespace std;
BOOST_AUTO_TEST_SUITE(hmac_tests)

12
src/test/key_tests.cpp

@ -1,13 +1,15 @@
#include <boost/test/unit_test.hpp>
#include <string>
#include <vector>
#include "key.h"
#include "base58.h"
#include "script.h"
#include "uint256.h"
#include "util.h"
#include <string>
#include <vector>
#include <boost/test/unit_test.hpp>
using namespace std;
static const string strSecret1 ("5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj");

8
src/test/miner_tests.cpp

@ -1,12 +1,14 @@
#include <boost/test/unit_test.hpp>
#include "init.h"
#include "main.h"
#include "miner.h"
#include "uint256.h"
#include "util.h"
#include "miner.h"
#include "wallet.h"
#include <boost/test/unit_test.hpp>
extern CWallet* pwalletMain;
extern void SHA256Transform(void* pstate, void* pinput, const void* pinit);
BOOST_AUTO_TEST_SUITE(miner_tests)

11
src/test/mruset_tests.cpp

@ -1,13 +1,16 @@
#include <boost/test/unit_test.hpp>
using namespace std;
#include "mruset.h"
#include "util.h"
#include <set>
#include <boost/test/unit_test.hpp>
#define NUM_TESTS 16
#define MAX_SIZE 100
using namespace std;
class mrutester
{
private:

16
src/test/multisig_tests.cpp

@ -1,18 +1,14 @@
#include <boost/assert.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/assign/list_inserter.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <openssl/ec.h>
#include <openssl/err.h>
#include "key.h"
#include "keystore.h"
#include "main.h"
#include "script.h"
#include "wallet.h"
#include "uint256.h"
#include <boost/assign/std/vector.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
using namespace std;
using namespace boost::assign;

5
src/test/netbase_tests.cpp

@ -1,9 +1,8 @@
#include <boost/test/unit_test.hpp>
#include "netbase.h"
#include <string>
#include <vector>
#include "netbase.h"
#include <boost/test/unit_test.hpp>
using namespace std;

9
src/test/pmt_tests.cpp

@ -1,7 +1,12 @@
#include <boost/test/unit_test.hpp>
#include "uint256.h"
#include "main.h"
#include "serialize.h"
#include "uint256.h"
#include <vector>
#include <boost/test/unit_test.hpp>
using namespace std;

9
src/test/rpc_tests.cpp

@ -1,10 +1,9 @@
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
#include "bitcoinrpc.h"
#include "base58.h"
#include "util.h"
#include "bitcoinrpc.h"
#include <boost/algorithm/string.hpp>
#include <boost/test/unit_test.hpp>
using namespace std;
using namespace json_spirit;

18
src/test/script_P2SH_tests.cpp

@ -1,13 +1,13 @@
#include <boost/assert.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/assign/list_inserter.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#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 <vector>
#include <boost/test/unit_test.hpp>
using namespace std;

25
src/test/script_tests.cpp

@ -1,21 +1,28 @@
#include <iostream>
#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 <fstream>
#include <stdint.h>
#include <string>
#include <vector>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/foreach.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/test/unit_test.hpp>
#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())))

13
src/test/serialize_tests.cpp

@ -1,9 +1,8 @@
#include <boost/test/unit_test.hpp>
#include "serialize.h"
#include <string>
#include <vector>
#include <stdint.h>
#include "serialize.h"
#include <boost/test/unit_test.hpp>
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);
}

12
src/test/sigopcount_tests.cpp

@ -1,9 +1,13 @@
#include <vector>
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include "script.h"
#include "key.h"
#include "script.h"
#include "uint256.h"
#include <vector>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
using namespace std;

13
src/test/test_bitcoin.cpp

@ -1,12 +1,17 @@
#define BOOST_TEST_MODULE Bitcoin Test Suite
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#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 <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
CWallet* pwalletMain;
CClientUIInterface uiInterface;

16
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 <map>
#include <string>
#include <boost/test/unit_test.hpp>
#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;

8
src/test/uint160_tests.cpp

@ -1,7 +1,9 @@
#include <boost/test/unit_test.hpp>
#include "uint256.h"
#include <stdint.h>
#include <boost/test/unit_test.hpp>
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);
}

8
src/test/uint256_tests.cpp

@ -1,8 +1,10 @@
#include <boost/test/unit_test.hpp>
#include "uint256.h"
#include <string>
#include <stdint.h>
#include <boost/test/unit_test.hpp>
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);
}

13
src/test/util_tests.cpp

@ -1,10 +1,11 @@
#include "util.h"
#include "sync.h"
#include <stdint.h>
#include <vector>
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include "main.h"
#include "wallet.h"
#include "util.h"
#include <boost/test/unit_test.hpp>
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);

15
src/test/wallet_tests.cpp

@ -1,8 +1,13 @@
#include <boost/test/unit_test.hpp>
#include "main.h"
#include "wallet.h"
#include <set>
#include <stdint.h>
#include <utility>
#include <vector>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
// 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<COutput> 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++)

1
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

10
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 <stdint.h>
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 {

12
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 <map>
#include <string>
#include <utility>
#include <vector>
class CBigNum;
class CCoins;
class uint256;
/** CCoinsView backed by the LevelDB coin database (chainstate/) */
class CCoinsViewDB : public CCoinsView

1
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

8
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 <stdint.h>
#include <string>
#include "util.h" // for int64
#include <boost/signals2/signal.hpp>
#include <boost/signals2/last_value.hpp>
#include <boost/signals2/signal.hpp>
class CBasicKeyStore;
class CWallet;
@ -71,7 +73,7 @@ public:
boost::signals2::signal<bool (const std::string& message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeMessageBox;
/** Ask the user whether they want to pay a fee or not. */
boost::signals2::signal<bool (int64 nFeeRequired), boost::signals2::last_value<bool> > ThreadSafeAskFee;
boost::signals2::signal<bool (int64_t nFeeRequired), boost::signals2::last_value<bool> > ThreadSafeAskFee;
/** Handle a URL passed at the command line. */
boost::signals2::signal<void (const std::string& strURI)> ThreadSafeHandleURI;

117
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 <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <string>
#include <string.h>
#include <vector>
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<std::string> 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; }

154
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 <inttypes.h>
#include <stdarg.h>
#include <stdint.h>
#ifndef WIN32
// for posix_fallocate
#ifdef __linux__
#ifdef __linux_
#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif
#define _POSIX_C_SOURCE 200112L
#include <sys/prctl.h>
#endif
#include <algorithm>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/resource.h>
#endif
#include "chainparams.h"
#include "util.h"
#include "sync.h"
#include "version.h"
#include "ui_interface.h"
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string/predicate.hpp> // 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 <sys/stat.h>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <stdarg.h>
#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 <io.h> /* for _commit */
#include "shlobj.h"
#elif defined(__linux__)
# include <sys/prctl.h>
#include <shlobj.h>
#endif
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
// 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<string, string> 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<uint64>::max() / nMax) * nMax;
uint64 nRand = 0;
uint64_t nRange = (std::numeric_limits<uint64_t>::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<string>& 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<int64> vTimeOffsets(200,0);
static CMedianFilter<int64_t> 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<int64> vSorted = vTimeOffsets.sorted();
int64_t nMedian = vTimeOffsets.median();
std::vector<int64_t> 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);
}
}

108
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 <cstdio>
#include <exception>
#include <inttypes.h>
#include <map>
#include <stdarg.h>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
#ifndef WIN32
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#else
typedef int pid_t; /* define for Windows compatibility */
#endif
#include <map>
#include <list>
#include <utility>
#include <vector>
#include <string>
#include <boost/version.hpp>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/date_time/gregorian/gregorian_types.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "netbase.h" // for AddTimeData
#include <boost/thread.hpp>
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<t1, t2>
#define PAIRTYPE(t1, t2) std::pair<t1, t2>
@ -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<std::string>& 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<unsigned char> ParseHex(const char* psz);
std::vector<unsigned char> 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<std::string>& 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<unsigned char>& 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<void()> f = boost::bind(&FunctionWithArg, argument);
// threadGroup.create_thread(boost::bind(&LoopForever<boost::function<void()> >, "nothing", f, milliseconds));
template <typename Callable> void LoopForever(const char* name, Callable func, int64 msecs)
template <typename Callable> void LoopForever(const char* name, Callable func, int64_t msecs)
{
std::string s = strprintf("bitcoin-%s", name);
RenameThread(s.c_str());

3
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 <string>
#include "version.h"
#include <string>
// 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.

1
src/version.h

@ -5,6 +5,7 @@
#define BITCOIN_VERSION_H
#include "clientversion.h"
#include <string>
//

178
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 <inttypes.h>
#include <stdint.h>
#include <boost/algorithm/string/replace.hpp>
#include <openssl/rand.h>
using namespace std;
@ -20,8 +24,8 @@ using namespace std;
struct CompareValueOnly
{
bool operator()(const pair<int64, pair<const CWalletTx*, unsigned int> >& t1,
const pair<int64, pair<const CWalletTx*, unsigned int> >& t2) const
bool operator()(const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t1,
const pair<int64_t, pair<const CWalletTx*, unsigned int> >& 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<CAccountingEntry> 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<pair<CTxDestination, int64> >& listReceived,
list<pair<CTxDestination, int64> >& listSent, int64& nFee, string& strSentAccount) const
void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
list<pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, string& strSentAccount) const
{
nFee = 0;
listReceived.clear();
@ -648,10 +652,10 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64> >& 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<pair<CTxDestination, int64> >& 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<pair<CTxDestination, int64> > listReceived;
list<pair<CTxDestination, int64> > listSent;
list<pair<CTxDestination, int64_t> > listReceived;
list<pair<CTxDestination, int64_t> > 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<uint256, CWalletTx>::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<uint256, CWalletTx>::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<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
@ -1028,8 +1032,8 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed) const
}
}
static void ApproximateBestSubset(vector<pair<int64, pair<const CWalletTx*,unsigned int> > >vValue, int64 nTotalLower, int64 nTargetValue,
vector<char>& vfBest, int64& nBest, int iterations = 1000)
static void ApproximateBestSubset(vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > >vValue, int64_t nTotalLower, int64_t nTargetValue,
vector<char>& vfBest, int64_t& nBest, int iterations = 1000)
{
vector<char> vfIncluded;
@ -1041,7 +1045,7 @@ static void ApproximateBestSubset(vector<pair<int64, pair<const CWalletTx*,unsig
for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
{
vfIncluded.assign(vValue.size(), false);
int64 nTotal = 0;
int64_t nTotal = 0;
bool fReachedTarget = false;
for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
{
@ -1074,18 +1078,18 @@ static void ApproximateBestSubset(vector<pair<int64, pair<const CWalletTx*,unsig
}
}
bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const
bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
{
setCoinsRet.clear();
nValueRet = 0;
// List of values less than target
pair<int64, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
coinLowestLarger.first = std::numeric_limits<int64>::max();
pair<int64_t, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
coinLowestLarger.first = std::numeric_limits<int64_t>::max();
coinLowestLarger.second.first = NULL;
vector<pair<int64, pair<const CWalletTx*,unsigned int> > > vValue;
int64 nTotalLower = 0;
vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > > 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<int64,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
pair<int64_t,pair<const CWalletTx*,unsigned int> > 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<char> 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<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const
bool CWallet::SelectCoins(int64_t nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
{
vector<COutput> vCoins;
AvailableCoins(vCoins);
@ -1185,11 +1189,11 @@ bool CWallet::SelectCoins(int64 nTargetValue, set<pair<const CWalletTx*,unsigned
bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason)
bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& 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<pair<CScript, int64> >& 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<pair<CScript, int64> >& vecSend,
// Choose coins to use
set<pair<const CWalletTx*,unsigned int> > 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<pair<CScript, int64> >& 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<pair<CScript, int64> >& 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<pair<CScript, int64> >& 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<CScript, int64> > vecSend;
vector< pair<CScript, int64_t> > 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<CTxDestination, int64> CWallet::GetAddressBalances()
std::map<CTxDestination, int64_t> CWallet::GetAddressBalances()
{
map<CTxDestination, int64> balances;
map<CTxDestination, int64_t> balances;
{
LOCK(cs_wallet);
@ -1699,7 +1703,7 @@ std::map<CTxDestination, int64> 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<CKeyID>& 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<COutPoint>& vOutpts)
}
}
void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64> &mapKeyBirth) const {
void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
mapKeyBirth.clear();
// get birth times for keys with metadata

152
src/wallet.h

@ -5,25 +5,29 @@
#ifndef BITCOIN_WALLET_H
#define BITCOIN_WALLET_H
#include "walletdb.h"
#include <string>
#include <vector>
#include <stdlib.h>
#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 <algorithm>
#include <map>
#include <set>
#include <stdexcept>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
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<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const;
bool SelectCoins(int64_t nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& 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<int64> setKeyPool;
std::set<int64_t> setKeyPool;
std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
@ -134,7 +138,7 @@ public:
}
std::map<uint256, CWalletTx> mapWallet;
int64 nOrderPosNext;
int64_t nOrderPosNext;
std::map<uint256, int> mapRequestCount;
std::map<CTxDestination, CAddressBookData> mapAddressBook;
@ -143,13 +147,13 @@ public:
std::set<COutPoint> 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<COutput>& vCoins, bool fOnlyConfirmed=true) const;
bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const;
bool SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& 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<CKeyID, int64> &mapKeyBirth) const;
void GetKeyBirthTimes(std::map<CKeyID, int64_t> &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<CWalletTx*, CAccountingEntry*> TxPair;
typedef std::multimap<int64, TxPair > TxItems;
typedef std::multimap<int64_t, TxPair > 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<std::pair<CScript, int64> >& 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<std::pair<CScript, int64_t> >& 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<CKeyID>& setAddress) const;
std::set< std::set<CTxDestination> > GetAddressGroupings();
std::map<CTxDestination, int64> GetAddressBalances();
std::map<CTxDestination, int64_t> GetAddressBalances();
std::set<CTxDestination> 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<std::string, std::string> 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<char> 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<std::pair<CTxDestination, int64> >& listReceived,
std::list<std::pair<CTxDestination, int64> >& listSent, int64& nFee, std::string& strSentAccount) const;
void GetAmounts(std::list<std::pair<CTxDestination, int64_t> >& listReceived,
std::list<std::pair<CTxDestination, int64_t> >& 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<string, string> 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()
{

162
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 <boost/version.hpp>
#include <inttypes.h>
#include <stdint.h>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
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<unsigned char> 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<unsigned char>& 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<CAccountingEntry> 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<CAccountin
// Read next record
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
if (fFlags == DB_SET_RANGE)
ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64_t(0));
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
fFlags = DB_NEXT;
@ -130,7 +252,7 @@ CWalletDB::ReorderTransactions(CWallet* pwallet)
// First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
typedef multimap<int64, TxPair > TxItems;
typedef multimap<int64_t, TxPair > TxItems;
TxItems txByTime;
for (map<uint256, CWalletTx>::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<int64> nOrderPosOffsets;
std::vector<int64_t> 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);

144
src/walletdb.h

@ -6,13 +6,24 @@
#define BITCOIN_WALLETDB_H
#include "db.h"
#include "base58.h"
#include "key.h"
#include <list>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
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<unsigned char>& 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<unsigned char> 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<unsigned char>& 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<CAccountingEntry>& acentries);
DBErrors ReorderTransactions(CWallet*);

Loading…
Cancel
Save