Merge pull request #5082
5f4bcf6
boost: drop boost dependency in version.cpp. (Cory Fields)352058e
boost: drop boost dependency in utilstrencodings.cpp (Cory Fields)e1c9467
boost: drop boost dependency in core.cpp (Cory Fields)e405aa4
boost: remove CPrivKey dependency from CECKey (Cory Fields)5295506
boost: drop dependency on tuple in serialization (Cory Fields)1d9b86d
boost: drop dependency on is_fundamental in serialization (Cory Fields)
This commit is contained in:
commit
e8f6d54f1f
7 changed files with 74 additions and 135 deletions
23
src/core.cpp
23
src/core.cpp
|
@ -7,8 +7,6 @@
|
||||||
|
|
||||||
#include "tinyformat.h"
|
#include "tinyformat.h"
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
std::string COutPoint::ToString() const
|
std::string COutPoint::ToString() const
|
||||||
{
|
{
|
||||||
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
|
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 CTransaction::GetValueOut() const
|
||||||
{
|
{
|
||||||
CAmount nValueOut = 0;
|
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;
|
nValueOut += it->nValue;
|
||||||
if (!MoneyRange(txout.nValue) || !MoneyRange(nValueOut))
|
if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut))
|
||||||
throw std::runtime_error("CTransaction::GetValueOut() : value out of range");
|
throw std::runtime_error("CTransaction::GetValueOut() : value out of range");
|
||||||
}
|
}
|
||||||
return nValueOut;
|
return nValueOut;
|
||||||
|
@ -139,10 +137,9 @@ unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const
|
||||||
// risk encouraging people to create junk outputs to redeem later.
|
// risk encouraging people to create junk outputs to redeem later.
|
||||||
if (nTxSize == 0)
|
if (nTxSize == 0)
|
||||||
nTxSize = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
|
nTxSize = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
for (std::vector<CTxIn>::const_iterator it(vin.begin()); it != vin.end(); ++it)
|
||||||
BOOST_FOREACH(const CTxIn& txin, vin)
|
|
||||||
{
|
{
|
||||||
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)
|
if (nTxSize > offset)
|
||||||
nTxSize -= offset;
|
nTxSize -= offset;
|
||||||
}
|
}
|
||||||
|
@ -263,8 +260,8 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
|
||||||
*/
|
*/
|
||||||
vMerkleTree.clear();
|
vMerkleTree.clear();
|
||||||
vMerkleTree.reserve(vtx.size() * 2 + 16); // Safe upper bound for the number of total nodes.
|
vMerkleTree.reserve(vtx.size() * 2 + 16); // Safe upper bound for the number of total nodes.
|
||||||
BOOST_FOREACH(const CTransaction& tx, vtx)
|
for (std::vector<CTransaction>::const_iterator it(vtx.begin()); it != vtx.end(); ++it)
|
||||||
vMerkleTree.push_back(tx.GetHash());
|
vMerkleTree.push_back(it->GetHash());
|
||||||
int j = 0;
|
int j = 0;
|
||||||
bool mutated = false;
|
bool mutated = false;
|
||||||
for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
|
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)
|
if (nIndex == -1)
|
||||||
return 0;
|
return 0;
|
||||||
BOOST_FOREACH(const uint256& otherside, vMerkleBranch)
|
for (std::vector<uint256>::const_iterator it(vMerkleBranch.begin()); it != vMerkleBranch.end(); ++it)
|
||||||
{
|
{
|
||||||
if (nIndex & 1)
|
if (nIndex & 1)
|
||||||
hash = Hash(BEGIN(otherside), END(otherside), BEGIN(hash), END(hash));
|
hash = Hash(BEGIN(*it), END(*it), BEGIN(hash), END(hash));
|
||||||
else
|
else
|
||||||
hash = Hash(BEGIN(hash), END(hash), BEGIN(otherside), END(otherside));
|
hash = Hash(BEGIN(hash), END(hash), BEGIN(*it), END(*it));
|
||||||
nIndex >>= 1;
|
nIndex >>= 1;
|
||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
|
|
33
src/key.cpp
33
src/key.cpp
|
@ -179,19 +179,17 @@ public:
|
||||||
BN_clear_free(&bn);
|
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);
|
EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
|
||||||
int nSize = i2d_ECPrivateKey(pkey, NULL);
|
return i2d_ECPrivateKey(pkey, NULL);
|
||||||
assert(nSize);
|
}
|
||||||
privkey.resize(nSize);
|
int GetPrivKey(unsigned char* privkey, bool fCompressed) {
|
||||||
unsigned char* pbegin = &privkey[0];
|
EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
|
||||||
int nSize2 = i2d_ECPrivateKey(pkey, &pbegin);
|
return i2d_ECPrivateKey(pkey, &privkey);
|
||||||
assert(nSize == nSize2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetPrivKey(const CPrivKey &privkey, bool fSkipCheck=false) {
|
bool SetPrivKey(const unsigned char* privkey, size_t size, bool fSkipCheck=false) {
|
||||||
const unsigned char* pbegin = &privkey[0];
|
if (d2i_ECPrivateKey(&pkey, &privkey, size)) {
|
||||||
if (d2i_ECPrivateKey(&pkey, &pbegin, privkey.size())) {
|
|
||||||
if(fSkipCheck)
|
if(fSkipCheck)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -424,7 +422,7 @@ bool CKey::SetPrivKey(const CPrivKey &privkey, bool fCompressedIn) {
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
CECKey key;
|
CECKey key;
|
||||||
if (!key.SetPrivKey(privkey))
|
if (!key.SetPrivKey(&privkey[0], privkey.size()))
|
||||||
return false;
|
return false;
|
||||||
key.GetSecretBytes(vch);
|
key.GetSecretBytes(vch);
|
||||||
#endif
|
#endif
|
||||||
|
@ -436,16 +434,21 @@ bool CKey::SetPrivKey(const CPrivKey &privkey, bool fCompressedIn) {
|
||||||
CPrivKey CKey::GetPrivKey() const {
|
CPrivKey CKey::GetPrivKey() const {
|
||||||
assert(fValid);
|
assert(fValid);
|
||||||
CPrivKey privkey;
|
CPrivKey privkey;
|
||||||
|
int privkeylen, ret;
|
||||||
#ifdef USE_SECP256K1
|
#ifdef USE_SECP256K1
|
||||||
privkey.resize(279);
|
privkey.resize(279);
|
||||||
int privkeylen = 279;
|
privkeylen = 279;
|
||||||
int ret = secp256k1_ecdsa_privkey_export(begin(), (unsigned char*)&privkey[0], &privkeylen, fCompressed);
|
ret = secp256k1_ecdsa_privkey_export(begin(), (unsigned char*)&privkey[0], &privkeylen, fCompressed);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
privkey.resize(privkeylen);
|
privkey.resize(privkeylen);
|
||||||
#else
|
#else
|
||||||
CECKey key;
|
CECKey key;
|
||||||
key.SetSecretBytes(vch);
|
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
|
#endif
|
||||||
return privkey;
|
return privkey;
|
||||||
}
|
}
|
||||||
|
@ -517,7 +520,7 @@ bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) {
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
CECKey key;
|
CECKey key;
|
||||||
if (!key.SetPrivKey(privkey, fSkipCheck))
|
if (!key.SetPrivKey(&privkey[0], privkey.size(), fSkipCheck))
|
||||||
return false;
|
return false;
|
||||||
key.GetSecretBytes(vch);
|
key.GetSecretBytes(vch);
|
||||||
#endif
|
#endif
|
||||||
|
|
115
src/serialize.h
115
src/serialize.h
|
@ -20,9 +20,6 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/tuple/tuple.hpp>
|
|
||||||
#include <boost/type_traits/is_fundamental.hpp>
|
|
||||||
|
|
||||||
class CAutoFile;
|
class CAutoFile;
|
||||||
class CDataStream;
|
class CDataStream;
|
||||||
class CScript;
|
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);
|
template<typename Stream, typename C> void Unserialize(Stream& is, std::basic_string<C>& str, int, int=0);
|
||||||
|
|
||||||
// vector
|
// vector
|
||||||
template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::true_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 boost::false_type&);
|
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 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 unsigned char&);
|
||||||
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&);
|
||||||
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> 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 unsigned char&);
|
||||||
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&);
|
||||||
template<typename Stream, typename T, typename A> inline void Unserialize(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);
|
||||||
|
|
||||||
// others derived from vector
|
// 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 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);
|
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
|
// 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 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);
|
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
|
// vector
|
||||||
//
|
//
|
||||||
template<typename T, typename A>
|
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));
|
return (GetSizeOfCompactSize(v.size()) + v.size() * sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename A>
|
template<typename T, typename A, typename V>
|
||||||
unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&)
|
unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const V&)
|
||||||
{
|
{
|
||||||
unsigned int nSize = GetSizeOfCompactSize(v.size());
|
unsigned int nSize = GetSizeOfCompactSize(v.size());
|
||||||
for (typename std::vector<T, A>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
|
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>
|
template<typename T, typename A>
|
||||||
inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion)
|
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>
|
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());
|
WriteCompactSize(os, v.size());
|
||||||
if (!v.empty())
|
if (!v.empty())
|
||||||
os.write((char*)&v[0], v.size() * sizeof(T));
|
os.write((char*)&v[0], v.size() * sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream, typename T, typename A>
|
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 boost::false_type&)
|
void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const V&)
|
||||||
{
|
{
|
||||||
WriteCompactSize(os, v.size());
|
WriteCompactSize(os, v.size());
|
||||||
for (typename std::vector<T, A>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
|
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>
|
template<typename Stream, typename T, typename A>
|
||||||
inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion)
|
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>
|
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
|
// Limit size per read so bogus size value won't cause out of memory
|
||||||
v.clear();
|
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>
|
template<typename Stream, typename T, typename A, typename V>
|
||||||
void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&)
|
void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const V&)
|
||||||
{
|
{
|
||||||
v.clear();
|
v.clear();
|
||||||
unsigned int nSize = ReadCompactSize(is);
|
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>
|
template<typename Stream, typename T, typename A>
|
||||||
inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion)
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -669,71 +657,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
|
// map
|
||||||
//
|
//
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "utilstrencodings.h"
|
#include "utilstrencodings.h"
|
||||||
#include "utilmoneystr.h"
|
#include "utilmoneystr.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -341,4 +342,15 @@ BOOST_AUTO_TEST_CASE(test_FormatParagraph)
|
||||||
BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 4), "test\n test");
|
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()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <cstdlib>
|
||||||
#include <boost/foreach.hpp>
|
#include <cstring>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -53,9 +53,9 @@ signed char HexDigit(char c)
|
||||||
|
|
||||||
bool IsHex(const string& str)
|
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 false;
|
||||||
}
|
}
|
||||||
return (str.size() > 0) && (str.size()%2 == 0);
|
return (str.size() > 0) && (str.size()%2 == 0);
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <boost/algorithm/string/join.hpp>
|
|
||||||
|
|
||||||
// Name of client reported in the 'version' message. Report the same name
|
// 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
|
// for both bitcoind and bitcoin-qt, to make it harder for attackers to
|
||||||
// target servers or GUI users specifically.
|
// target servers or GUI users specifically.
|
||||||
|
@ -94,7 +92,13 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
|
||||||
ss << "/";
|
ss << "/";
|
||||||
ss << name << ":" << FormatVersion(nClientVersion);
|
ss << name << ":" << FormatVersion(nClientVersion);
|
||||||
if (!comments.empty())
|
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 << "/";
|
ss << "/";
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
|
||||||
|
|
||||||
bool CWalletDB::WriteAccountingEntry(const uint64_t 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);
|
return Write(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
|
bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
|
||||||
|
@ -218,7 +218,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountin
|
||||||
// Read next record
|
// Read next record
|
||||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||||
if (fFlags == DB_SET_RANGE)
|
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);
|
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
||||||
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
|
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
|
||||||
fFlags = DB_NEXT;
|
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)
|
bool CWalletDB::WriteDestData(const std::string &address, const std::string &key, const std::string &value)
|
||||||
{
|
{
|
||||||
nWalletDBUpdated++;
|
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)
|
bool CWalletDB::EraseDestData(const std::string &address, const std::string &key)
|
||||||
{
|
{
|
||||||
nWalletDBUpdated++;
|
nWalletDBUpdated++;
|
||||||
return Erase(boost::make_tuple(string("destdata"), address, key));
|
return Erase(std::make_pair(std::string("destdata"), std::make_pair(address, key)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue