Browse Source

make bitcoin include files more modular

pull/1/head
Wladimir J. van der Laan 12 years ago committed by Witchspace
parent
commit
223b6f1ba4
  1. 45
      src/base58.h
  2. 12
      src/bignum.h
  3. 11
      src/db.cpp
  4. 96
      src/db.h
  5. 4
      src/headers.h
  6. 11
      src/init.cpp
  7. 4
      src/init.h
  8. 3
      src/irc.cpp
  9. 6
      src/irc.h
  10. 23
      src/key.h
  11. 118
      src/main.cpp
  12. 220
      src/main.h
  13. 57
      src/net.cpp
  14. 94
      src/net.h
  15. 13
      src/noui.h
  16. 46
      src/rpc.cpp
  17. 12
      src/script.cpp
  18. 53
      src/script.h
  19. 112
      src/serialize.h
  20. 4
      src/strlcpy.h
  21. 42
      src/ui.cpp
  22. 44
      src/ui.h
  23. 16
      src/uint256.h
  24. 9
      src/util.cpp
  25. 95
      src/util.h

45
src/base58.h

@ -11,12 +11,17 @@ @@ -11,12 +11,17 @@
// - E-mail usually won't line-break if there's no punctuation to break at.
// - Doubleclicking selects the whole number as one word if it's all alphanumeric.
//
#ifndef BITCOIN_BASE58_H
#define BITCOIN_BASE58_H
#include <string>
#include <vector>
#include "bignum.h"
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
inline string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
inline std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
{
CAutoBN_CTX pctx;
CBigNum bn58 = 58;
@ -24,15 +29,15 @@ inline string EncodeBase58(const unsigned char* pbegin, const unsigned char* pen @@ -24,15 +29,15 @@ inline string EncodeBase58(const unsigned char* pbegin, const unsigned char* pen
// Convert big endian data to little endian
// Extra zero at the end make sure bignum will interpret as a positive number
vector<unsigned char> vchTmp(pend-pbegin+1, 0);
std::vector<unsigned char> vchTmp(pend-pbegin+1, 0);
reverse_copy(pbegin, pend, vchTmp.begin());
// Convert little endian data to bignum
CBigNum bn;
bn.setvch(vchTmp);
// Convert bignum to string
string str;
// Convert bignum to std::string
std::string str;
str.reserve((pend - pbegin) * 138 / 100 + 1);
CBigNum dv;
CBigNum rem;
@ -49,17 +54,17 @@ inline string EncodeBase58(const unsigned char* pbegin, const unsigned char* pen @@ -49,17 +54,17 @@ inline string EncodeBase58(const unsigned char* pbegin, const unsigned char* pen
for (const unsigned char* p = pbegin; p < pend && *p == 0; p++)
str += pszBase58[0];
// Convert little endian string to big endian
// Convert little endian std::string to big endian
reverse(str.begin(), str.end());
return str;
}
inline string EncodeBase58(const vector<unsigned char>& vch)
inline std::string EncodeBase58(const std::vector<unsigned char>& vch)
{
return EncodeBase58(&vch[0], &vch[0] + vch.size());
}
inline bool DecodeBase58(const char* psz, vector<unsigned char>& vchRet)
inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
{
CAutoBN_CTX pctx;
vchRet.clear();
@ -88,7 +93,7 @@ inline bool DecodeBase58(const char* psz, vector<unsigned char>& vchRet) @@ -88,7 +93,7 @@ inline bool DecodeBase58(const char* psz, vector<unsigned char>& vchRet)
}
// Get bignum as little endian data
vector<unsigned char> vchTmp = bn.getvch();
std::vector<unsigned char> vchTmp = bn.getvch();
// Trim off sign byte if present
if (vchTmp.size() >= 2 && vchTmp.end()[-1] == 0 && vchTmp.end()[-2] >= 0x80)
@ -105,7 +110,7 @@ inline bool DecodeBase58(const char* psz, vector<unsigned char>& vchRet) @@ -105,7 +110,7 @@ inline bool DecodeBase58(const char* psz, vector<unsigned char>& vchRet)
return true;
}
inline bool DecodeBase58(const string& str, vector<unsigned char>& vchRet)
inline bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet)
{
return DecodeBase58(str.c_str(), vchRet);
}
@ -114,16 +119,16 @@ inline bool DecodeBase58(const string& str, vector<unsigned char>& vchRet) @@ -114,16 +119,16 @@ inline bool DecodeBase58(const string& str, vector<unsigned char>& vchRet)
inline string EncodeBase58Check(const vector<unsigned char>& vchIn)
inline std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn)
{
// add 4-byte hash check to the end
vector<unsigned char> vch(vchIn);
std::vector<unsigned char> vch(vchIn);
uint256 hash = Hash(vch.begin(), vch.end());
vch.insert(vch.end(), (unsigned char*)&hash, (unsigned char*)&hash + 4);
return EncodeBase58(vch);
}
inline bool DecodeBase58Check(const char* psz, vector<unsigned char>& vchRet)
inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet)
{
if (!DecodeBase58(psz, vchRet))
return false;
@ -142,7 +147,7 @@ inline bool DecodeBase58Check(const char* psz, vector<unsigned char>& vchRet) @@ -142,7 +147,7 @@ inline bool DecodeBase58Check(const char* psz, vector<unsigned char>& vchRet)
return true;
}
inline bool DecodeBase58Check(const string& str, vector<unsigned char>& vchRet)
inline bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet)
{
return DecodeBase58Check(str.c_str(), vchRet);
}
@ -154,17 +159,17 @@ inline bool DecodeBase58Check(const string& str, vector<unsigned char>& vchRet) @@ -154,17 +159,17 @@ inline bool DecodeBase58Check(const string& str, vector<unsigned char>& vchRet)
#define ADDRESSVERSION ((unsigned char)(fTestNet ? 111 : 0))
inline string Hash160ToAddress(uint160 hash160)
inline std::string Hash160ToAddress(uint160 hash160)
{
// add 1-byte version number to the front
vector<unsigned char> vch(1, ADDRESSVERSION);
std::vector<unsigned char> vch(1, ADDRESSVERSION);
vch.insert(vch.end(), UBEGIN(hash160), UEND(hash160));
return EncodeBase58Check(vch);
}
inline bool AddressToHash160(const char* psz, uint160& hash160Ret)
{
vector<unsigned char> vch;
std::vector<unsigned char> vch;
if (!DecodeBase58Check(psz, vch))
return false;
if (vch.empty())
@ -176,7 +181,7 @@ inline bool AddressToHash160(const char* psz, uint160& hash160Ret) @@ -176,7 +181,7 @@ inline bool AddressToHash160(const char* psz, uint160& hash160Ret)
return (nVersion <= ADDRESSVERSION);
}
inline bool AddressToHash160(const string& str, uint160& hash160Ret)
inline bool AddressToHash160(const std::string& str, uint160& hash160Ret)
{
return AddressToHash160(str.c_str(), hash160Ret);
}
@ -187,7 +192,7 @@ inline bool IsValidBitcoinAddress(const char* psz) @@ -187,7 +192,7 @@ inline bool IsValidBitcoinAddress(const char* psz)
return AddressToHash160(psz, hash160);
}
inline bool IsValidBitcoinAddress(const string& str)
inline bool IsValidBitcoinAddress(const std::string& str)
{
return IsValidBitcoinAddress(str.c_str());
}
@ -195,7 +200,9 @@ inline bool IsValidBitcoinAddress(const string& str) @@ -195,7 +200,9 @@ inline bool IsValidBitcoinAddress(const string& str)
inline string PubKeyToAddress(const vector<unsigned char>& vchPubKey)
inline std::string PubKeyToAddress(const std::vector<unsigned char>& vchPubKey)
{
return Hash160ToAddress(Hash160(vchPubKey));
}
#endif

12
src/bignum.h

@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_BIGNUM_H
#define BITCOIN_BIGNUM_H
#include <stdexcept>
#include <vector>
#include <openssl/bn.h>
#include "util.h"
class bignum_error : public std::runtime_error
{
@ -308,7 +308,7 @@ public: @@ -308,7 +308,7 @@ public:
CAutoBN_CTX pctx;
CBigNum bnBase = nBase;
CBigNum bn0 = 0;
string str;
std::string str;
CBigNum bn = *this;
BN_set_negative(&bn, false);
CBigNum dv;
@ -348,7 +348,7 @@ public: @@ -348,7 +348,7 @@ public:
template<typename Stream>
void Unserialize(Stream& s, int nType=0, int nVersion=VERSION)
{
vector<unsigned char> vch;
std::vector<unsigned char> vch;
::Unserialize(s, vch, nType, nVersion);
setvch(vch);
}
@ -530,3 +530,5 @@ inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, @@ -530,3 +530,5 @@ inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a,
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); }
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); }
#endif

11
src/db.cpp

@ -4,6 +4,9 @@ @@ -4,6 +4,9 @@
#include "headers.h"
using namespace std;
using namespace boost;
void ThreadFlushWalletDB(void* parg);
@ -434,13 +437,13 @@ bool CTxDB::LoadBlockIndex() @@ -434,13 +437,13 @@ bool CTxDB::LoadBlockIndex()
// Calculate bnChainWork
vector<pair<int, CBlockIndex*> > vSortedByHeight;
vSortedByHeight.reserve(mapBlockIndex.size());
foreach(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
{
CBlockIndex* pindex = item.second;
vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
}
sort(vSortedByHeight.begin(), vSortedByHeight.end());
foreach(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
{
CBlockIndex* pindex = item.second;
pindex->bnChainWork = (pindex->pprev ? pindex->pprev->bnChainWork : 0) + pindex->GetBlockWork();
@ -603,7 +606,7 @@ int64 CWalletDB::GetAccountCreditDebit(const string& strAccount) @@ -603,7 +606,7 @@ int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)
ListAccountCreditDebit(strAccount, entries);
int64 nCreditDebit = 0;
foreach (const CAccountingEntry& entry, entries)
BOOST_FOREACH (const CAccountingEntry& entry, entries)
nCreditDebit += entry.nCreditDebit;
return nCreditDebit;
@ -796,7 +799,7 @@ bool CWalletDB::LoadWallet() @@ -796,7 +799,7 @@ bool CWalletDB::LoadWallet()
pcursor->close();
}
foreach(uint256 hash, vWalletUpgrade)
BOOST_FOREACH(uint256 hash, vWalletUpgrade)
WriteTx(hash, mapWallet[hash]);
printf("nFileVersion = %d\n", nFileVersion);

96
src/db.h

@ -1,6 +1,16 @@ @@ -1,6 +1,16 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_DB_H
#define BITCOIN_DB_H
#include "key.h"
#include <map>
#include <string>
#include <vector>
#include <db_cxx.h>
class CTransaction;
class CTxIndex;
@ -15,9 +25,9 @@ class CAccount; @@ -15,9 +25,9 @@ class CAccount;
class CAccountingEntry;
class CBlockLocator;
extern map<string, string> mapAddressBook;
extern std::map<std::string, std::string> mapAddressBook;
extern CCriticalSection cs_mapAddressBook;
extern vector<unsigned char> vchDefaultKey;
extern std::vector<unsigned char> vchDefaultKey;
extern bool fClient;
extern int nBestHeight;
@ -27,7 +37,7 @@ extern DbEnv dbenv; @@ -27,7 +37,7 @@ extern DbEnv dbenv;
extern void DBFlush(bool fShutdown);
extern vector<unsigned char> GetKeyFromKeyPool();
extern std::vector<unsigned char> GetKeyFromKeyPool();
extern int64 GetOldestKeyPoolTime();
@ -37,8 +47,8 @@ class CDB @@ -37,8 +47,8 @@ class CDB
{
protected:
Db* pdb;
string strFile;
vector<DbTxn*> vTxn;
std::string strFile;
std::vector<DbTxn*> vTxn;
bool fReadOnly;
explicit CDB(const char* pszFile, const char* pszMode="r+");
@ -247,12 +257,12 @@ public: @@ -247,12 +257,12 @@ public:
bool ReadVersion(int& nVersion)
{
nVersion = 0;
return Read(string("version"), nVersion);
return Read(std::string("version"), nVersion);
}
bool WriteVersion(int nVersion)
{
return Write(string("version"), nVersion);
return Write(std::string("version"), nVersion);
}
};
@ -276,7 +286,7 @@ public: @@ -276,7 +286,7 @@ public:
bool AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight);
bool EraseTxIndex(const CTransaction& tx);
bool ContainsTx(uint256 hash);
bool ReadOwnerTxes(uint160 hash160, int nHeight, vector<CTransaction>& vtx);
bool ReadOwnerTxes(uint160 hash160, int nHeight, std::vector<CTransaction>& vtx);
bool ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex);
bool ReadDiskTx(uint256 hash, CTransaction& tx);
bool ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex);
@ -318,14 +328,14 @@ class CKeyPool @@ -318,14 +328,14 @@ class CKeyPool
{
public:
int64 nTime;
vector<unsigned char> vchPubKey;
std::vector<unsigned char> vchPubKey;
CKeyPool()
{
nTime = GetTime();
}
CKeyPool(const vector<unsigned char>& vchPubKeyIn)
CKeyPool(const std::vector<unsigned char>& vchPubKeyIn)
{
nTime = GetTime();
vchPubKey = vchPubKeyIn;
@ -353,101 +363,101 @@ private: @@ -353,101 +363,101 @@ private:
CWalletDB(const CWalletDB&);
void operator=(const CWalletDB&);
public:
bool ReadName(const string& strAddress, string& strName)
bool ReadName(const std::string& strAddress, std::string& strName)
{
strName = "";
return Read(make_pair(string("name"), strAddress), strName);
return Read(std::make_pair(std::string("name"), strAddress), strName);
}
bool WriteName(const string& strAddress, const string& strName)
bool WriteName(const std::string& strAddress, const std::string& strName)
{
CRITICAL_BLOCK(cs_mapAddressBook)
mapAddressBook[strAddress] = strName;
nWalletDBUpdated++;
return Write(make_pair(string("name"), strAddress), strName);
return Write(std::make_pair(std::string("name"), strAddress), strName);
}
bool EraseName(const string& strAddress)
bool EraseName(const std::string& strAddress)
{
// This should only be used for sending addresses, never for receiving addresses,
// receiving addresses must always have an address book entry if they're not change return.
CRITICAL_BLOCK(cs_mapAddressBook)
mapAddressBook.erase(strAddress);
nWalletDBUpdated++;
return Erase(make_pair(string("name"), strAddress));
return Erase(std::make_pair(std::string("name"), strAddress));
}
bool ReadTx(uint256 hash, CWalletTx& wtx)
{
return Read(make_pair(string("tx"), hash), wtx);
return Read(std::make_pair(std::string("tx"), hash), wtx);
}
bool WriteTx(uint256 hash, const CWalletTx& wtx)
{
nWalletDBUpdated++;
return Write(make_pair(string("tx"), hash), wtx);
return Write(std::make_pair(std::string("tx"), hash), wtx);
}
bool EraseTx(uint256 hash)
{
nWalletDBUpdated++;
return Erase(make_pair(string("tx"), hash));
return Erase(std::make_pair(std::string("tx"), hash));
}
bool ReadKey(const vector<unsigned char>& vchPubKey, CPrivKey& vchPrivKey)
bool ReadKey(const std::vector<unsigned char>& vchPubKey, CPrivKey& vchPrivKey)
{
vchPrivKey.clear();
return Read(make_pair(string("key"), vchPubKey), vchPrivKey);
return Read(std::make_pair(std::string("key"), vchPubKey), vchPrivKey);
}
bool WriteKey(const vector<unsigned char>& vchPubKey, const CPrivKey& vchPrivKey)
bool WriteKey(const std::vector<unsigned char>& vchPubKey, const CPrivKey& vchPrivKey)
{
nWalletDBUpdated++;
return Write(make_pair(string("key"), vchPubKey), vchPrivKey, false);
return Write(std::make_pair(std::string("key"), vchPubKey), vchPrivKey, false);
}
bool WriteBestBlock(const CBlockLocator& locator)
{
nWalletDBUpdated++;
return Write(string("bestblock"), locator);
return Write(std::string("bestblock"), locator);
}
bool ReadBestBlock(CBlockLocator& locator)
{
return Read(string("bestblock"), locator);
return Read(std::string("bestblock"), locator);
}
bool ReadDefaultKey(vector<unsigned char>& vchPubKey)
bool ReadDefaultKey(std::vector<unsigned char>& vchPubKey)
{
vchPubKey.clear();
return Read(string("defaultkey"), vchPubKey);
return Read(std::string("defaultkey"), vchPubKey);
}
bool WriteDefaultKey(const vector<unsigned char>& vchPubKey)
bool WriteDefaultKey(const std::vector<unsigned char>& vchPubKey)
{
vchDefaultKey = vchPubKey;
nWalletDBUpdated++;
return Write(string("defaultkey"), vchPubKey);
return Write(std::string("defaultkey"), vchPubKey);
}
template<typename T>
bool ReadSetting(const string& strKey, T& value)
bool ReadSetting(const std::string& strKey, T& value)
{
return Read(make_pair(string("setting"), strKey), value);
return Read(std::make_pair(std::string("setting"), strKey), value);
}
template<typename T>
bool WriteSetting(const string& strKey, const T& value)
bool WriteSetting(const std::string& strKey, const T& value)
{
nWalletDBUpdated++;
return Write(make_pair(string("setting"), strKey), value);
return Write(std::make_pair(std::string("setting"), strKey), value);
}
bool ReadAccount(const string& strAccount, CAccount& account);
bool WriteAccount(const string& strAccount, const CAccount& account);
bool ReadAccount(const std::string& strAccount, CAccount& account);
bool WriteAccount(const std::string& strAccount, const CAccount& account);
bool WriteAccountingEntry(const CAccountingEntry& acentry);
int64 GetAccountCreditDebit(const string& strAccount);
void ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& acentries);
int64 GetAccountCreditDebit(const std::string& strAccount);
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
bool LoadWallet();
protected:
@ -455,14 +465,14 @@ protected: @@ -455,14 +465,14 @@ protected:
void KeepKey(int64 nIndex);
static void ReturnKey(int64 nIndex);
friend class CReserveKey;
friend vector<unsigned char> GetKeyFromKeyPool();
friend std::vector<unsigned char> GetKeyFromKeyPool();
friend int64 GetOldestKeyPoolTime();
};
bool LoadWallet(bool& fFirstRunRet);
void BackupWallet(const string& strDest);
void BackupWallet(const std::string& strDest);
inline bool SetAddressBookName(const string& strAddress, const string& strName)
inline bool SetAddressBookName(const std::string& strAddress, const std::string& strName)
{
return CWalletDB().WriteName(strAddress, strName);
}
@ -471,7 +481,7 @@ class CReserveKey @@ -471,7 +481,7 @@ class CReserveKey
{
protected:
int64 nIndex;
vector<unsigned char> vchPubKey;
std::vector<unsigned char> vchPubKey;
public:
CReserveKey()
{
@ -484,7 +494,7 @@ public: @@ -484,7 +494,7 @@ public:
ReturnKey();
}
vector<unsigned char> GetReservedKey()
std::vector<unsigned char> GetReservedKey()
{
if (nIndex == -1)
{
@ -512,3 +522,5 @@ public: @@ -512,3 +522,5 @@ public:
vchPubKey.clear();
}
};
#endif

4
src/headers.h

@ -109,8 +109,6 @@ @@ -109,8 +109,6 @@
#pragma hdrstop
using namespace std;
using namespace boost;
#include "strlcpy.h"
#include "serialize.h"
@ -133,6 +131,7 @@ using namespace boost; @@ -133,6 +131,7 @@ using namespace boost;
#endif
#include "init.h"
#ifdef GUI
#include "xpm/addressbook16.xpm"
#include "xpm/addressbook20.xpm"
#include "xpm/bitcoin16.xpm"
@ -145,3 +144,4 @@ using namespace boost; @@ -145,3 +144,4 @@ using namespace boost;
#include "xpm/send16noshadow.xpm"
#include "xpm/send20.xpm"
#include "xpm/about.xpm"
#endif

11
src/init.cpp

@ -1,14 +1,10 @@ @@ -1,14 +1,10 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#include "headers.h"
using namespace std;
using namespace boost;
//////////////////////////////////////////////////////////////////////////////
//
@ -71,7 +67,6 @@ void HandleSIGTERM(int) @@ -71,7 +67,6 @@ void HandleSIGTERM(int)
//
// Start
//
#ifndef GUI
int main(int argc, char* argv[])
{
@ -458,7 +453,7 @@ bool AppInit2(int argc, char* argv[]) @@ -458,7 +453,7 @@ bool AppInit2(int argc, char* argv[])
if (mapArgs.count("-addnode"))
{
foreach(string strAddr, mapMultiArgs["-addnode"])
BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"])
{
CAddress addr(strAddr, fAllowDNS);
addr.nTime = 0; // so it won't relay unless successfully connected

4
src/init.h

@ -1,7 +1,11 @@ @@ -1,7 +1,11 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_INIT_H
#define BITCOIN_INIT_H
void Shutdown(void* parg);
bool AppInit(int argc, char* argv[]);
bool AppInit2(int argc, char* argv[]);
#endif

3
src/irc.cpp

@ -4,6 +4,9 @@ @@ -4,6 +4,9 @@
#include "headers.h"
using namespace std;
using namespace boost;
int nGotIRCAddresses = 0;
bool fGotExternalIP = false;

6
src/irc.h

@ -1,9 +1,13 @@ @@ -1,9 +1,13 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_IRC_H
#define BITCOIN_IRC_H
bool RecvLine(SOCKET hSocket, string& strLine);
bool RecvLine(SOCKET hSocket, std::string& strLine);
void ThreadIRCSeed(void* parg);
extern int nGotIRCAddresses;
extern bool fGotExternalIP;
#endif

23
src/key.h

@ -1,7 +1,12 @@ @@ -1,7 +1,12 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_KEY_H
#define BITCOIN_KEY_H
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
// secp160k1
// const unsigned int PRIVATE_KEY_SIZE = 192;
@ -36,7 +41,7 @@ public: @@ -36,7 +41,7 @@ public:
// secure_allocator is defined in serialize.h
typedef vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
@ -109,7 +114,7 @@ public: @@ -109,7 +114,7 @@ public:
return vchPrivKey;
}
bool SetPubKey(const vector<unsigned char>& vchPubKey)
bool SetPubKey(const std::vector<unsigned char>& vchPubKey)
{
const unsigned char* pbegin = &vchPubKey[0];
if (!o2i_ECPublicKey(&pkey, &pbegin, vchPubKey.size()))
@ -118,19 +123,19 @@ public: @@ -118,19 +123,19 @@ public:
return true;
}
vector<unsigned char> GetPubKey() const
std::vector<unsigned char> GetPubKey() const
{
unsigned int nSize = i2o_ECPublicKey(pkey, NULL);
if (!nSize)
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey failed");
vector<unsigned char> vchPubKey(nSize, 0);
std::vector<unsigned char> vchPubKey(nSize, 0);
unsigned char* pbegin = &vchPubKey[0];
if (i2o_ECPublicKey(pkey, &pbegin) != nSize)
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey returned unexpected size");
return vchPubKey;
}
bool Sign(uint256 hash, vector<unsigned char>& vchSig)
bool Sign(uint256 hash, std::vector<unsigned char>& vchSig)
{
vchSig.clear();
unsigned char pchSig[10000];
@ -142,7 +147,7 @@ public: @@ -142,7 +147,7 @@ public:
return true;
}
bool Verify(uint256 hash, const vector<unsigned char>& vchSig)
bool Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
{
// -1 = error, 0 = bad sig, 1 = good
if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1)
@ -150,7 +155,7 @@ public: @@ -150,7 +155,7 @@ public:
return true;
}
static bool Sign(const CPrivKey& vchPrivKey, uint256 hash, vector<unsigned char>& vchSig)
static bool Sign(const CPrivKey& vchPrivKey, uint256 hash, std::vector<unsigned char>& vchSig)
{
CKey key;
if (!key.SetPrivKey(vchPrivKey))
@ -158,7 +163,7 @@ public: @@ -158,7 +163,7 @@ public:
return key.Sign(hash, vchSig);
}
static bool Verify(const vector<unsigned char>& vchPubKey, uint256 hash, const vector<unsigned char>& vchSig)
static bool Verify(const std::vector<unsigned char>& vchPubKey, uint256 hash, const std::vector<unsigned char>& vchSig)
{
CKey key;
if (!key.SetPubKey(vchPubKey))
@ -166,3 +171,5 @@ public: @@ -166,3 +171,5 @@ public:
return key.Verify(hash, vchSig);
}
};
#endif

118
src/main.cpp

@ -1,13 +1,11 @@ @@ -1,13 +1,11 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#include "headers.h"
#include "cryptopp/sha.h"
using namespace std;
using namespace boost;
//
// Global state
@ -156,7 +154,7 @@ bool AddToWallet(const CWalletTx& wtxIn) @@ -156,7 +154,7 @@ bool AddToWallet(const CWalletTx& wtxIn)
// If default receiving address gets used, replace it with a new one
CScript scriptDefaultKey;
scriptDefaultKey.SetBitcoinAddress(vchDefaultKey);
foreach(const CTxOut& txout, wtx.vout)
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{
if (txout.scriptPubKey == scriptDefaultKey)
{
@ -244,7 +242,7 @@ void AddOrphanTx(const CDataStream& vMsg) @@ -244,7 +242,7 @@ void AddOrphanTx(const CDataStream& vMsg)
if (mapOrphanTransactions.count(hash))
return;
CDataStream* pvMsg = mapOrphanTransactions[hash] = new CDataStream(vMsg);
foreach(const CTxIn& txin, tx.vin)
BOOST_FOREACH(const CTxIn& txin, tx.vin)
mapOrphanTransactionsByPrev.insert(make_pair(txin.prevout.hash, pvMsg));
}
@ -255,7 +253,7 @@ void EraseOrphanTx(uint256 hash) @@ -255,7 +253,7 @@ void EraseOrphanTx(uint256 hash)
const CDataStream* pvMsg = mapOrphanTransactions[hash];
CTransaction tx;
CDataStream(*pvMsg) >> tx;
foreach(const CTxIn& txin, tx.vin)
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
for (multimap<uint256, CDataStream*>::iterator mi = mapOrphanTransactionsByPrev.lower_bound(txin.prevout.hash);
mi != mapOrphanTransactionsByPrev.upper_bound(txin.prevout.hash);)
@ -426,7 +424,7 @@ void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, l @@ -426,7 +424,7 @@ void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, l
// Sent/received. Standard client will never generate a send-to-multiple-recipients,
// but non-standard clients might (so return a list of address/amount pairs)
foreach(const CTxOut& txout, vout)
BOOST_FOREACH(const CTxOut& txout, vout)
{
string address;
uint160 hash160;
@ -471,13 +469,13 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, i @@ -471,13 +469,13 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, i
nGenerated = allGeneratedMature;
if (strAccount == strSentAccount)
{
foreach(const PAIRTYPE(string,int64)& s, listSent)
BOOST_FOREACH(const PAIRTYPE(string,int64)& s, listSent)
nSent += s.second;
nFee = allFee;
}
CRITICAL_BLOCK(cs_mapAddressBook)
{
foreach(const PAIRTYPE(string,int64)& r, listReceived)
BOOST_FOREACH(const PAIRTYPE(string,int64)& r, listReceived)
{
if (mapAddressBook.count(r.first))
{
@ -557,7 +555,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) @@ -557,7 +555,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
if (SetMerkleBranch() < COPY_DEPTH)
{
vector<uint256> vWorkQueue;
foreach(const CTxIn& txin, vin)
BOOST_FOREACH(const CTxIn& txin, vin)
vWorkQueue.push_back(txin.prevout.hash);
// This critsect is OK because txdb is already open
@ -576,7 +574,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) @@ -576,7 +574,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
if (mapWallet.count(hash))
{
tx = mapWallet[hash];
foreach(const CMerkleTx& txWalletPrev, mapWallet[hash].vtxPrev)
BOOST_FOREACH(const CMerkleTx& txWalletPrev, mapWallet[hash].vtxPrev)
mapWalletPrev[txWalletPrev.GetHash()] = &txWalletPrev;
}
else if (mapWalletPrev.count(hash))
@ -597,7 +595,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) @@ -597,7 +595,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
vtxPrev.push_back(tx);
if (nDepth < COPY_DEPTH)
foreach(const CTxIn& txin, tx.vin)
BOOST_FOREACH(const CTxIn& txin, tx.vin)
vWorkQueue.push_back(txin.prevout.hash);
}
}
@ -628,7 +626,7 @@ bool CTransaction::CheckTransaction() const @@ -628,7 +626,7 @@ bool CTransaction::CheckTransaction() const
// Check for negative or overflow output values
int64 nValueOut = 0;
foreach(const CTxOut& txout, vout)
BOOST_FOREACH(const CTxOut& txout, vout)
{
if (txout.nValue < 0)
return error("CTransaction::CheckTransaction() : txout.nValue negative");
@ -646,7 +644,7 @@ bool CTransaction::CheckTransaction() const @@ -646,7 +644,7 @@ bool CTransaction::CheckTransaction() const
}
else
{
foreach(const CTxIn& txin, vin)
BOOST_FOREACH(const CTxIn& txin, vin)
if (txin.prevout.IsNull())
return error("CTransaction::CheckTransaction() : prevout is null");
}
@ -804,7 +802,7 @@ bool CTransaction::RemoveFromMemoryPool() @@ -804,7 +802,7 @@ bool CTransaction::RemoveFromMemoryPool()
// Remove transaction from memory pool
CRITICAL_BLOCK(cs_mapTransactions)
{
foreach(const CTxIn& txin, vin)
BOOST_FOREACH(const CTxIn& txin, vin)
mapNextTx.erase(txin.prevout);
mapTransactions.erase(GetHash());
nTransactionsUpdated++;
@ -872,7 +870,7 @@ bool CWalletTx::AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs) @@ -872,7 +870,7 @@ bool CWalletTx::AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs)
CRITICAL_BLOCK(cs_mapTransactions)
{
// Add previous supporting transactions first
foreach(CMerkleTx& tx, vtxPrev)
BOOST_FOREACH(CMerkleTx& tx, vtxPrev)
{
if (!tx.IsCoinBase())
{
@ -897,7 +895,7 @@ int ScanForWalletTransactions(CBlockIndex* pindexStart) @@ -897,7 +895,7 @@ int ScanForWalletTransactions(CBlockIndex* pindexStart)
{
CBlock block;
block.ReadFromDisk(pindex, true);
foreach(CTransaction& tx, block.vtx)
BOOST_FOREACH(CTransaction& tx, block.vtx)
{
if (AddToWalletIfInvolvingMe(tx, &block))
ret++;
@ -916,7 +914,7 @@ void ReacceptWalletTransactions() @@ -916,7 +914,7 @@ void ReacceptWalletTransactions()
{
fRepeat = false;
vector<CDiskTxPos> vMissingTx;
foreach(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
{
CWalletTx& wtx = item.second;
if (wtx.IsCoinBase() && wtx.IsSpent(0))
@ -969,7 +967,7 @@ void ReacceptWalletTransactions() @@ -969,7 +967,7 @@ void ReacceptWalletTransactions()
void CWalletTx::RelayWalletTransaction(CTxDB& txdb)
{
foreach(const CMerkleTx& tx, vtxPrev)
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
{
if (!tx.IsCoinBase())
{
@ -1014,7 +1012,7 @@ void ResendWalletTransactions() @@ -1014,7 +1012,7 @@ void ResendWalletTransactions()
{
// Sort them in chronological order
multimap<unsigned int, CWalletTx*> mapSorted;
foreach(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
{
CWalletTx& wtx = item.second;
// Don't rebroadcast until it's had plenty of time that
@ -1022,7 +1020,7 @@ void ResendWalletTransactions() @@ -1022,7 +1020,7 @@ void ResendWalletTransactions()
if (nTimeBestReceived - (int64)wtx.nTimeReceived > 5 * 60)
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
}
foreach(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
{
CWalletTx& wtx = *item.second;
wtx.RelayWalletTransaction(txdb);
@ -1198,7 +1196,7 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb) @@ -1198,7 +1196,7 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
// Relinquish previous transactions' spent pointers
if (!IsCoinBase())
{
foreach(const CTxIn& txin, vin)
BOOST_FOREACH(const CTxIn& txin, vin)
{
COutPoint prevout = txin.prevout;
@ -1421,7 +1419,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex) @@ -1421,7 +1419,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
map<uint256, CTxIndex> mapUnused;
int64 nFees = 0;
foreach(CTransaction& tx, vtx)
BOOST_FOREACH(CTransaction& tx, vtx)
{
CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos);
nTxPos += ::GetSerializeSize(tx, SER_DISK);
@ -1444,7 +1442,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex) @@ -1444,7 +1442,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
}
// Watch for transactions paying to me
foreach(CTransaction& tx, vtx)
BOOST_FOREACH(CTransaction& tx, vtx)
AddToWalletIfInvolvingMe(tx, this, true);
return true;
@ -1481,7 +1479,7 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) @@ -1481,7 +1479,7 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew)
// Disconnect shorter branch
vector<CTransaction> vResurrect;
foreach(CBlockIndex* pindex, vDisconnect)
BOOST_FOREACH(CBlockIndex* pindex, vDisconnect)
{
CBlock block;
if (!block.ReadFromDisk(pindex))
@ -1490,7 +1488,7 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) @@ -1490,7 +1488,7 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew)
return error("Reorganize() : DisconnectBlock failed");
// Queue memory transactions to resurrect
foreach(const CTransaction& tx, block.vtx)
BOOST_FOREACH(const CTransaction& tx, block.vtx)
if (!tx.IsCoinBase())
vResurrect.push_back(tx);
}
@ -1511,7 +1509,7 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) @@ -1511,7 +1509,7 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew)
}
// Queue memory transactions to delete
foreach(const CTransaction& tx, block.vtx)
BOOST_FOREACH(const CTransaction& tx, block.vtx)
vDelete.push_back(tx);
}
if (!txdb.WriteHashBestChain(pindexNew->GetBlockHash()))
@ -1522,21 +1520,21 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) @@ -1522,21 +1520,21 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew)
return error("Reorganize() : TxnCommit failed");
// Disconnect shorter branch
foreach(CBlockIndex* pindex, vDisconnect)
BOOST_FOREACH(CBlockIndex* pindex, vDisconnect)
if (pindex->pprev)
pindex->pprev->pnext = NULL;
// Connect longer branch
foreach(CBlockIndex* pindex, vConnect)
BOOST_FOREACH(CBlockIndex* pindex, vConnect)
if (pindex->pprev)
pindex->pprev->pnext = pindex;
// Resurrect memory transactions that were in the disconnected branch
foreach(CTransaction& tx, vResurrect)
BOOST_FOREACH(CTransaction& tx, vResurrect)
tx.AcceptToMemoryPool(txdb, false);
// Delete redundant memory transactions that are in the connected branch
foreach(CTransaction& tx, vDelete)
BOOST_FOREACH(CTransaction& tx, vDelete)
tx.RemoveFromMemoryPool();
return true;
@ -1571,7 +1569,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) @@ -1571,7 +1569,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
pindexNew->pprev->pnext = pindexNew;
// Delete redundant memory transactions
foreach(CTransaction& tx, vtx)
BOOST_FOREACH(CTransaction& tx, vtx)
tx.RemoveFromMemoryPool();
}
else
@ -1682,7 +1680,7 @@ bool CBlock::CheckBlock() const @@ -1682,7 +1680,7 @@ bool CBlock::CheckBlock() const
return error("CheckBlock() : more than one coinbase");
// Check transactions
foreach(const CTransaction& tx, vtx)
BOOST_FOREACH(const CTransaction& tx, vtx)
if (!tx.CheckTransaction())
return error("CheckBlock() : CheckTransaction failed");
@ -1720,7 +1718,7 @@ bool CBlock::AcceptBlock() @@ -1720,7 +1718,7 @@ bool CBlock::AcceptBlock()
return error("AcceptBlock() : block's timestamp is too early");
// Check that all transactions are finalized
foreach(const CTransaction& tx, vtx)
BOOST_FOREACH(const CTransaction& tx, vtx)
if (!tx.IsFinal(nHeight, GetBlockTime()))
return error("AcceptBlock() : contains a non-final transaction");
@ -1748,7 +1746,7 @@ bool CBlock::AcceptBlock() @@ -1748,7 +1746,7 @@ bool CBlock::AcceptBlock()
// Relay inventory, but don't relay old inventory during initial block download
if (hashBestChain == hash)
CRITICAL_BLOCK(cs_vNodes)
foreach(CNode* pnode, vNodes)
BOOST_FOREACH(CNode* pnode, vNodes)
if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 118000))
pnode->PushInventory(CInv(MSG_BLOCK, hash));
@ -2120,7 +2118,7 @@ string GetWarnings(string strFor) @@ -2120,7 +2118,7 @@ string GetWarnings(string strFor)
// Alerts
CRITICAL_BLOCK(cs_mapAlerts)
{
foreach(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
{
const CAlert& alert = item.second;
if (alert.AppliesToMe() && alert.nPriority > nPriority)
@ -2167,7 +2165,7 @@ bool CAlert::ProcessAlert() @@ -2167,7 +2165,7 @@ bool CAlert::ProcessAlert()
}
// Check if this alert has been cancelled
foreach(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
{
const CAlert& alert = item.second;
if (alert.Cancels(*this))
@ -2431,7 +2429,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -2431,7 +2429,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// Relay alerts
CRITICAL_BLOCK(cs_mapAlerts)
foreach(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
item.second.RelayTo(pfrom);
pfrom->fSuccessfullyConnected = true;
@ -2469,7 +2467,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -2469,7 +2467,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// Store the new addresses
int64 nNow = GetAdjustedTime();
int64 nSince = nNow - 10 * 60;
foreach(CAddress& addr, vAddr)
BOOST_FOREACH(CAddress& addr, vAddr)
{
if (fShutdown)
return true;
@ -2493,7 +2491,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -2493,7 +2491,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
uint256 hashRand = hashSalt ^ (((int64)addr.ip)<<32) ^ ((GetTime()+addr.ip)/(24*60*60));
hashRand = Hash(BEGIN(hashRand), END(hashRand));
multimap<uint256, CNode*> mapMix;
foreach(CNode* pnode, vNodes)
BOOST_FOREACH(CNode* pnode, vNodes)
{
if (pnode->nVersion < 31402)
continue;
@ -2522,7 +2520,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -2522,7 +2520,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return error("message inv size() = %d", vInv.size());
CTxDB txdb("r");
foreach(const CInv& inv, vInv)
BOOST_FOREACH(const CInv& inv, vInv)
{
if (fShutdown)
return true;
@ -2554,7 +2552,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -2554,7 +2552,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (vInv.size() > 50000)
return error("message getdata size() = %d", vInv.size());
foreach(const CInv& inv, vInv)
BOOST_FOREACH(const CInv& inv, vInv)
{
if (fShutdown)
return true;
@ -2717,7 +2715,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -2717,7 +2715,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
}
foreach(uint256 hash, vWorkQueue)
BOOST_FOREACH(uint256 hash, vWorkQueue)
EraseOrphanTx(hash);
}
else if (fMissingInputs)
@ -2752,13 +2750,13 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -2752,13 +2750,13 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CRITICAL_BLOCK(cs_mapAddresses)
{
unsigned int nCount = 0;
foreach(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)
BOOST_FOREACH(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)
{
const CAddress& addr = item.second;
if (addr.nTime > nSince)
nCount++;
}
foreach(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)
BOOST_FOREACH(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)
{
const CAddress& addr = item.second;
if (addr.nTime > nSince && GetRand(nCount) < 2500)
@ -2861,7 +2859,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -2861,7 +2859,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// Relay
pfrom->setKnown.insert(alert.GetHash());
CRITICAL_BLOCK(cs_vNodes)
foreach(CNode* pnode, vNodes)
BOOST_FOREACH(CNode* pnode, vNodes)
alert.RelayTo(pnode);
}
}
@ -2912,7 +2910,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) @@ -2912,7 +2910,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
nLastRebroadcast = GetTime();
CRITICAL_BLOCK(cs_vNodes)
{
foreach(CNode* pnode, vNodes)
BOOST_FOREACH(CNode* pnode, vNodes)
{
// Periodically clear setAddrKnown to allow refresh broadcasts
pnode->setAddrKnown.clear();
@ -2964,7 +2962,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) @@ -2964,7 +2962,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
{
vector<CAddress> vAddr;
vAddr.reserve(pto->vAddrToSend.size());
foreach(const CAddress& addr, pto->vAddrToSend)
BOOST_FOREACH(const CAddress& addr, pto->vAddrToSend)
{
// returns true if wasn't already contained in the set
if (pto->setAddrKnown.insert(addr).second)
@ -2993,7 +2991,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) @@ -2993,7 +2991,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
{
vInv.reserve(pto->vInventoryToSend.size());
vInvWait.reserve(pto->vInventoryToSend.size());
foreach(const CInv& inv, pto->vInventoryToSend)
BOOST_FOREACH(const CInv& inv, pto->vInventoryToSend)
{
if (pto->setInventoryKnown.count(inv))
continue;
@ -3220,7 +3218,7 @@ public: @@ -3220,7 +3218,7 @@ public:
void print() const
{
printf("COrphan(hash=%s, dPriority=%.1f)\n", ptx->GetHash().ToString().substr(0,10).c_str(), dPriority);
foreach(uint256 hash, setDependsOn)
BOOST_FOREACH(uint256 hash, setDependsOn)
printf(" setDependsOn %s\n", hash.ToString().substr(0,10).c_str());
}
};
@ -3264,7 +3262,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) @@ -3264,7 +3262,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
COrphan* porphan = NULL;
double dPriority = 0;
foreach(const CTxIn& txin, tx.vin)
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
// Read prev transaction
CTransaction txPrev;
@ -3349,7 +3347,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) @@ -3349,7 +3347,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
uint256 hash = tx.GetHash();
if (mapDependers.count(hash))
{
foreach(COrphan* porphan, mapDependers[hash])
BOOST_FOREACH(COrphan* porphan, mapDependers[hash])
{
if (!porphan->setDependsOn.empty())
{
@ -3679,7 +3677,7 @@ bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set< @@ -3679,7 +3677,7 @@ bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set<
vCoins.push_back(&(*it).second);
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
foreach(CWalletTx* pcoin, vCoins)
BOOST_FOREACH(CWalletTx* pcoin, vCoins)
{
if (!pcoin->IsFinal() || !pcoin->IsConfirmed())
continue;
@ -3817,7 +3815,7 @@ bool SelectCoins(int64 nTargetValue, set<pair<CWalletTx*,unsigned int> >& setCoi @@ -3817,7 +3815,7 @@ bool SelectCoins(int64 nTargetValue, set<pair<CWalletTx*,unsigned int> >& setCoi
bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet)
{
int64 nValue = 0;
foreach (const PAIRTYPE(CScript, int64)& s, vecSend)
BOOST_FOREACH (const PAIRTYPE(CScript, int64)& s, vecSend)
{
if (nValue < 0)
return false;
@ -3842,7 +3840,7 @@ bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx& @@ -3842,7 +3840,7 @@ bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx&
int64 nTotalValue = nValue + nFeeRet;
double dPriority = 0;
// vouts to the payees
foreach (const PAIRTYPE(CScript, int64)& s, vecSend)
BOOST_FOREACH (const PAIRTYPE(CScript, int64)& s, vecSend)
wtxNew.vout.push_back(CTxOut(s.second, s.first));
// Choose coins to use
@ -3850,7 +3848,7 @@ bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx& @@ -3850,7 +3848,7 @@ bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx&
int64 nValueIn = 0;
if (!SelectCoins(nTotalValue, setCoins, nValueIn))
return false;
foreach(PAIRTYPE(CWalletTx*, unsigned int) pcoin, setCoins)
BOOST_FOREACH(PAIRTYPE(CWalletTx*, unsigned int) pcoin, setCoins)
{
int64 nCredit = pcoin.first->vout[pcoin.second].nValue;
dPriority += (double)nCredit * pcoin.first->GetDepthInMainChain();
@ -3886,12 +3884,12 @@ bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx& @@ -3886,12 +3884,12 @@ bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx&
reservekey.ReturnKey();
// Fill vin
foreach(const PAIRTYPE(CWalletTx*,unsigned int)& coin, setCoins)
BOOST_FOREACH(const PAIRTYPE(CWalletTx*,unsigned int)& coin, setCoins)
wtxNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second));
// Sign
int nIn = 0;
foreach(const PAIRTYPE(CWalletTx*,unsigned int)& coin, setCoins)
BOOST_FOREACH(const PAIRTYPE(CWalletTx*,unsigned int)& coin, setCoins)
if (!SignSignature(*coin.first, wtxNew, nIn++))
return false;