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