aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core.cpp23
-rw-r--r--src/key.cpp33
-rw-r--r--src/serialize.h115
-rw-r--r--src/test/util_tests.cpp12
-rw-r--r--src/utilstrencodings.cpp8
-rw-r--r--src/version.cpp10
-rw-r--r--src/walletdb.cpp8
7 files changed, 74 insertions, 135 deletions
diff --git a/src/core.cpp b/src/core.cpp
index 380b1c38e0..6a7a9ff378 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -7,8 +7,6 @@
#include "tinyformat.h"
-#include <boost/foreach.hpp>
-
std::string COutPoint::ToString() const
{
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
@@ -113,10 +111,10 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
CAmount CTransaction::GetValueOut() const
{
CAmount nValueOut = 0;
- BOOST_FOREACH(const CTxOut& txout, vout)
+ for (std::vector<CTxOut>::const_iterator it(vout.begin()); it != vout.end(); ++it)
{
- nValueOut += txout.nValue;
- if (!MoneyRange(txout.nValue) || !MoneyRange(nValueOut))
+ nValueOut += it->nValue;
+ if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut))
throw std::runtime_error("CTransaction::GetValueOut() : value out of range");
}
return nValueOut;
@@ -139,10 +137,9 @@ unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const
// risk encouraging people to create junk outputs to redeem later.
if (nTxSize == 0)
nTxSize = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
-
- BOOST_FOREACH(const CTxIn& txin, vin)
+ for (std::vector<CTxIn>::const_iterator it(vin.begin()); it != vin.end(); ++it)
{
- unsigned int offset = 41U + std::min(110U, (unsigned int)txin.scriptSig.size());
+ unsigned int offset = 41U + std::min(110U, (unsigned int)it->scriptSig.size());
if (nTxSize > offset)
nTxSize -= offset;
}
@@ -263,8 +260,8 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
*/
vMerkleTree.clear();
vMerkleTree.reserve(vtx.size() * 2 + 16); // Safe upper bound for the number of total nodes.
- BOOST_FOREACH(const CTransaction& tx, vtx)
- vMerkleTree.push_back(tx.GetHash());
+ for (std::vector<CTransaction>::const_iterator it(vtx.begin()); it != vtx.end(); ++it)
+ vMerkleTree.push_back(it->GetHash());
int j = 0;
bool mutated = false;
for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
@@ -307,12 +304,12 @@ uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMer
{
if (nIndex == -1)
return 0;
- BOOST_FOREACH(const uint256& otherside, vMerkleBranch)
+ for (std::vector<uint256>::const_iterator it(vMerkleBranch.begin()); it != vMerkleBranch.end(); ++it)
{
if (nIndex & 1)
- hash = Hash(BEGIN(otherside), END(otherside), BEGIN(hash), END(hash));
+ hash = Hash(BEGIN(*it), END(*it), BEGIN(hash), END(hash));
else
- hash = Hash(BEGIN(hash), END(hash), BEGIN(otherside), END(otherside));
+ hash = Hash(BEGIN(hash), END(hash), BEGIN(*it), END(*it));
nIndex >>= 1;
}
return hash;
diff --git a/src/key.cpp b/src/key.cpp
index c2251b4f2a..079e2c6540 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -179,19 +179,17 @@ public:
BN_clear_free(&bn);
}
- void GetPrivKey(CPrivKey &privkey, bool fCompressed) {
+ int GetPrivKeySize(bool fCompressed) {
EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
- int nSize = i2d_ECPrivateKey(pkey, NULL);
- assert(nSize);
- privkey.resize(nSize);
- unsigned char* pbegin = &privkey[0];
- int nSize2 = i2d_ECPrivateKey(pkey, &pbegin);
- assert(nSize == nSize2);
+ return i2d_ECPrivateKey(pkey, NULL);
+ }
+ int GetPrivKey(unsigned char* privkey, bool fCompressed) {
+ EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
+ return i2d_ECPrivateKey(pkey, &privkey);
}
- bool SetPrivKey(const CPrivKey &privkey, bool fSkipCheck=false) {
- const unsigned char* pbegin = &privkey[0];
- if (d2i_ECPrivateKey(&pkey, &pbegin, privkey.size())) {
+ bool SetPrivKey(const unsigned char* privkey, size_t size, bool fSkipCheck=false) {
+ if (d2i_ECPrivateKey(&pkey, &privkey, size)) {
if(fSkipCheck)
return true;
@@ -424,7 +422,7 @@ bool CKey::SetPrivKey(const CPrivKey &privkey, bool fCompressedIn) {
return false;
#else
CECKey key;
- if (!key.SetPrivKey(privkey))
+ if (!key.SetPrivKey(&privkey[0], privkey.size()))
return false;
key.GetSecretBytes(vch);
#endif
@@ -436,16 +434,21 @@ bool CKey::SetPrivKey(const CPrivKey &privkey, bool fCompressedIn) {
CPrivKey CKey::GetPrivKey() const {
assert(fValid);
CPrivKey privkey;
+ int privkeylen, ret;
#ifdef USE_SECP256K1
privkey.resize(279);
- int privkeylen = 279;
- int ret = secp256k1_ecdsa_privkey_export(begin(), (unsigned char*)&privkey[0], &privkeylen, fCompressed);
+ privkeylen = 279;
+ ret = secp256k1_ecdsa_privkey_export(begin(), (unsigned char*)&privkey[0], &privkeylen, fCompressed);
assert(ret);
privkey.resize(privkeylen);
#else
CECKey key;
key.SetSecretBytes(vch);
- key.GetPrivKey(privkey, fCompressed);
+ privkeylen = key.GetPrivKeySize(fCompressed);
+ assert(privkeylen);
+ privkey.resize(privkeylen);
+ ret = key.GetPrivKey(&privkey[0], fCompressed);
+ assert(ret == (int)privkey.size());
#endif
return privkey;
}
@@ -517,7 +520,7 @@ bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) {
return false;
#else
CECKey key;
- if (!key.SetPrivKey(privkey, fSkipCheck))
+ if (!key.SetPrivKey(&privkey[0], privkey.size(), fSkipCheck))
return false;
key.GetSecretBytes(vch);
#endif
diff --git a/src/serialize.h b/src/serialize.h
index ff11edc06c..55b6891394 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -20,9 +20,6 @@
#include <utility>
#include <vector>
-#include <boost/tuple/tuple.hpp>
-#include <boost/type_traits/is_fundamental.hpp>
-
class CAutoFile;
class CDataStream;
class CScript;
@@ -432,14 +429,15 @@ template<typename Stream, typename C> void Serialize(Stream& os, const std::basi
template<typename Stream, typename C> void Unserialize(Stream& is, std::basic_string<C>& str, int, int=0);
// vector
-template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&);
-template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&);
+// vectors of unsigned char are a special case and are intended to be serialized as a single opaque blob.
+template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const unsigned char&);
+template<typename T, typename A, typename V> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const V&);
template<typename T, typename A> inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion);
-template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&);
-template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&);
+template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const unsigned char&);
+template<typename Stream, typename T, typename A, typename V> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const V&);
template<typename Stream, typename T, typename A> inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion);
-template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&);
-template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&);
+template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const unsigned char&);
+template<typename Stream, typename T, typename A, typename V> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const V&);
template<typename Stream, typename T, typename A> inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion);
// others derived from vector
@@ -452,16 +450,6 @@ template<typename K, typename T> unsigned int GetSerializeSize(const std::pair<K
template<typename Stream, typename K, typename T> void Serialize(Stream& os, const std::pair<K, T>& item, int nType, int nVersion);
template<typename Stream, typename K, typename T> void Unserialize(Stream& is, std::pair<K, T>& item, int nType, int nVersion);
-// 3 tuple
-template<typename T0, typename T1, typename T2> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2>& item, int nType, int nVersion);
-template<typename Stream, typename T0, typename T1, typename T2> void Serialize(Stream& os, const boost::tuple<T0, T1, T2>& item, int nType, int nVersion);
-template<typename Stream, typename T0, typename T1, typename T2> void Unserialize(Stream& is, boost::tuple<T0, T1, T2>& item, int nType, int nVersion);
-
-// 4 tuple
-template<typename T0, typename T1, typename T2, typename T3> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion);
-template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Serialize(Stream& os, const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion);
-template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Unserialize(Stream& is, boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion);
-
// map
template<typename K, typename T, typename Pred, typename A> unsigned int GetSerializeSize(const std::map<K, T, Pred, A>& m, int nType, int nVersion);
template<typename Stream, typename K, typename T, typename Pred, typename A> void Serialize(Stream& os, const std::map<K, T, Pred, A>& m, int nType, int nVersion);
@@ -536,13 +524,13 @@ void Unserialize(Stream& is, std::basic_string<C>& str, int, int)
// vector
//
template<typename T, typename A>
-unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&)
+unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const unsigned char&)
{
return (GetSizeOfCompactSize(v.size()) + v.size() * sizeof(T));
}
-template<typename T, typename A>
-unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&)
+template<typename T, typename A, typename V>
+unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const V&)
{
unsigned int nSize = GetSizeOfCompactSize(v.size());
for (typename std::vector<T, A>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
@@ -553,20 +541,20 @@ unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nV
template<typename T, typename A>
inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion)
{
- return GetSerializeSize_impl(v, nType, nVersion, boost::is_fundamental<T>());
+ return GetSerializeSize_impl(v, nType, nVersion, T());
}
template<typename Stream, typename T, typename A>
-void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&)
+void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const unsigned char&)
{
WriteCompactSize(os, v.size());
if (!v.empty())
os.write((char*)&v[0], v.size() * sizeof(T));
}
-template<typename Stream, typename T, typename A>
-void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&)
+template<typename Stream, typename T, typename A, typename V>
+void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const V&)
{
WriteCompactSize(os, v.size());
for (typename std::vector<T, A>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
@@ -576,12 +564,12 @@ void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVers
template<typename Stream, typename T, typename A>
inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion)
{
- Serialize_impl(os, v, nType, nVersion, boost::is_fundamental<T>());
+ Serialize_impl(os, v, nType, nVersion, T());
}
template<typename Stream, typename T, typename A>
-void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&)
+void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const unsigned char&)
{
// Limit size per read so bogus size value won't cause out of memory
v.clear();
@@ -596,8 +584,8 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion,
}
}
-template<typename Stream, typename T, typename A>
-void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&)
+template<typename Stream, typename T, typename A, typename V>
+void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const V&)
{
v.clear();
unsigned int nSize = ReadCompactSize(is);
@@ -617,7 +605,7 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion,
template<typename Stream, typename T, typename A>
inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion)
{
- Unserialize_impl(is, v, nType, nVersion, boost::is_fundamental<T>());
+ Unserialize_impl(is, v, nType, nVersion, T());
}
@@ -670,71 +658,6 @@ void Unserialize(Stream& is, std::pair<K, T>& item, int nType, int nVersion)
//
-// 3 tuple
-//
-template<typename T0, typename T1, typename T2>
-unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2>& item, int nType, int nVersion)
-{
- unsigned int nSize = 0;
- nSize += GetSerializeSize(boost::get<0>(item), nType, nVersion);
- nSize += GetSerializeSize(boost::get<1>(item), nType, nVersion);
- nSize += GetSerializeSize(boost::get<2>(item), nType, nVersion);
- return nSize;
-}
-
-template<typename Stream, typename T0, typename T1, typename T2>
-void Serialize(Stream& os, const boost::tuple<T0, T1, T2>& item, int nType, int nVersion)
-{
- Serialize(os, boost::get<0>(item), nType, nVersion);
- Serialize(os, boost::get<1>(item), nType, nVersion);
- Serialize(os, boost::get<2>(item), nType, nVersion);
-}
-
-template<typename Stream, typename T0, typename T1, typename T2>
-void Unserialize(Stream& is, boost::tuple<T0, T1, T2>& item, int nType, int nVersion)
-{
- Unserialize(is, boost::get<0>(item), nType, nVersion);
- Unserialize(is, boost::get<1>(item), nType, nVersion);
- Unserialize(is, boost::get<2>(item), nType, nVersion);
-}
-
-
-
-//
-// 4 tuple
-//
-template<typename T0, typename T1, typename T2, typename T3>
-unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)
-{
- unsigned int nSize = 0;
- nSize += GetSerializeSize(boost::get<0>(item), nType, nVersion);
- nSize += GetSerializeSize(boost::get<1>(item), nType, nVersion);
- nSize += GetSerializeSize(boost::get<2>(item), nType, nVersion);
- nSize += GetSerializeSize(boost::get<3>(item), nType, nVersion);
- return nSize;
-}
-
-template<typename Stream, typename T0, typename T1, typename T2, typename T3>
-void Serialize(Stream& os, const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)
-{
- Serialize(os, boost::get<0>(item), nType, nVersion);
- Serialize(os, boost::get<1>(item), nType, nVersion);
- Serialize(os, boost::get<2>(item), nType, nVersion);
- Serialize(os, boost::get<3>(item), nType, nVersion);
-}
-
-template<typename Stream, typename T0, typename T1, typename T2, typename T3>
-void Unserialize(Stream& is, boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)
-{
- Unserialize(is, boost::get<0>(item), nType, nVersion);
- Unserialize(is, boost::get<1>(item), nType, nVersion);
- Unserialize(is, boost::get<2>(item), nType, nVersion);
- Unserialize(is, boost::get<3>(item), nType, nVersion);
-}
-
-
-
-//
// map
//
template<typename K, typename T, typename Pred, typename A>
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index 6378bd0941..61daa0a3fe 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -9,6 +9,7 @@
#include "sync.h"
#include "utilstrencodings.h"
#include "utilmoneystr.h"
+#include "version.h"
#include <stdint.h>
#include <vector>
@@ -341,4 +342,15 @@ BOOST_AUTO_TEST_CASE(test_FormatParagraph)
BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 4), "test\n test");
}
+BOOST_AUTO_TEST_CASE(test_FormatSubVersion)
+{
+ std::vector<std::string> comments;
+ comments.push_back(std::string("comment1"));
+ std::vector<std::string> comments2;
+ comments2.push_back(std::string("comment1"));
+ comments2.push_back(std::string("comment2"));
+ BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, std::vector<std::string>()),std::string("/Test:0.9.99/"));
+ BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, comments),std::string("/Test:0.9.99(comment1)/"));
+ BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, comments2),std::string("/Test:0.9.99(comment1; comment2)/"));
+}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp
index b9e64c5fe1..81e156f43f 100644
--- a/src/utilstrencodings.cpp
+++ b/src/utilstrencodings.cpp
@@ -9,8 +9,8 @@
#include <errno.h>
#include <limits>
-
-#include <boost/foreach.hpp>
+#include <cstdlib>
+#include <cstring>
using namespace std;
@@ -53,9 +53,9 @@ signed char HexDigit(char c)
bool IsHex(const string& str)
{
- BOOST_FOREACH(char c, str)
+ for(std::string::const_iterator it(str.begin()); it != str.end(); ++it)
{
- if (HexDigit(c) < 0)
+ if (HexDigit(*it) < 0)
return false;
}
return (str.size() > 0) && (str.size()%2 == 0);
diff --git a/src/version.cpp b/src/version.cpp
index 95632fdab7..d12b681e5c 100644
--- a/src/version.cpp
+++ b/src/version.cpp
@@ -8,8 +8,6 @@
#include <string>
-#include <boost/algorithm/string/join.hpp>
-
// 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.
@@ -94,7 +92,13 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
ss << "/";
ss << name << ":" << FormatVersion(nClientVersion);
if (!comments.empty())
- ss << "(" << boost::algorithm::join(comments, "; ") << ")";
+ {
+ std::vector<std::string>::const_iterator it(comments.begin());
+ ss << "(" << *it;
+ for(++it; it != comments.end(); ++it)
+ ss << "; " << *it;
+ ss << ")";
+ }
ss << "/";
return ss.str();
}
diff --git a/src/walletdb.cpp b/src/walletdb.cpp
index 783f766f6f..ffddd8106b 100644
--- a/src/walletdb.cpp
+++ b/src/walletdb.cpp
@@ -185,7 +185,7 @@ bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
{
- return Write(boost::make_tuple(string("acentry"), acentry.strAccount, nAccEntryNum), acentry);
+ return Write(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry);
}
bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
@@ -218,7 +218,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_t(0));
+ ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? string("") : strAccount), uint64_t(0)));
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
fFlags = DB_NEXT;
@@ -977,11 +977,11 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename)
bool CWalletDB::WriteDestData(const std::string &address, const std::string &key, const std::string &value)
{
nWalletDBUpdated++;
- return Write(boost::make_tuple(std::string("destdata"), address, key), value);
+ return Write(std::make_pair(std::string("destdata"), std::make_pair(address, key)), value);
}
bool CWalletDB::EraseDestData(const std::string &address, const std::string &key)
{
nWalletDBUpdated++;
- return Erase(boost::make_tuple(string("destdata"), address, key));
+ return Erase(std::make_pair(std::string("destdata"), std::make_pair(address, key)));
}