Some cleanups that should make Arthur happy.

This commit is contained in:
JoelKatz
2012-08-28 16:07:44 -07:00
parent 192c64461d
commit e4f7ffe995
7 changed files with 73 additions and 82 deletions

View File

@@ -2,6 +2,7 @@
#include "HashedObject.h"
#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
#include "Serializer.h"
#include "Application.h"
@@ -63,13 +64,12 @@ void HashedObjectStore::bulkWrite()
db->executeSQL("BEGIN TRANSACTION;");
for (std::vector< boost::shared_ptr<HashedObject> >::iterator it = set.begin(), end = set.end(); it != end; ++it)
BOOST_FOREACH(const boost::shared_ptr<HashedObject>& it, set)
{
HashedObject& obj = **it;
if (!SQL_EXISTS(db, boost::str(fExists % obj.getHash().GetHex())))
if (!SQL_EXISTS(db, boost::str(fExists % it->getHash().GetHex())))
{
char type;
switch(obj.getType())
switch(it->getType())
{
case LEDGER: type = 'L'; break;
case TRANSACTION: type = 'T'; break;
@@ -78,8 +78,8 @@ void HashedObjectStore::bulkWrite()
default: type = 'U';
}
std::string rawData;
db->escape(&(obj.getData().front()), obj.getData().size(), rawData);
db->executeSQL(boost::str(fAdd % obj.getHash().GetHex() % type % obj.getIndex() % rawData ));
db->escape(&(it->getData().front()), it->getData().size(), rawData);
db->executeSQL(boost::str(fAdd % it->getHash().GetHex() % type % it->getIndex() % rawData ));
}
}

View File

@@ -444,23 +444,23 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
ourVC.highNode = theApp->getWallet().getNodePublic();
}
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it)
BOOST_FOREACH(const Peer::pointer& it, peerList)
{
if (!*it)
if (!it)
{
Log(lsDEBUG) << "NOP::CS Dead pointer in peer list";
}
else if ((*it)->isConnected())
else if (it->isConnected())
{
uint256 peerLedger = (*it)->getClosedLedgerHash();
uint256 peerLedger = it->getClosedLedgerHash();
if (peerLedger.isNonZero())
{
ValidationCount& vc = ledgers[peerLedger];
if ((vc.nodesUsing == 0) || ((*it)->getNodePublic() > vc.highNode))
vc.highNode = (*it)->getNodePublic();
if ((vc.nodesUsing == 0) || (it->getNodePublic() > vc.highNode))
vc.highNode = it->getNodePublic();
++vc.nodesUsing;
}
else Log(lsTRACE) << "Connected peer announces no LCL " << (*it)->getIP();
else Log(lsTRACE) << "Connected peer announces no LCL " << it->getIP();
}
}
@@ -522,23 +522,19 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
{ // add more peers
int count = 0;
std::vector<Peer::pointer> peers=theApp->getConnectionPool().getPeerVector();
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end();
it != end; ++it)
BOOST_FOREACH(const Peer::pointer& it, peerList)
{
if ((*it)->getClosedLedgerHash() == closedLedger)
if (it->getClosedLedgerHash() == closedLedger)
{
++count;
mAcquiringLedger->peerHas(*it);
mAcquiringLedger->peerHas(it);
}
}
if (!count)
{ // just ask everyone
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end();
it != end; ++it)
{
if ((*it)->isConnected())
mAcquiringLedger->peerHas(*it);
}
BOOST_FOREACH(const Peer::pointer& it, peerList)
if (it->isConnected())
mAcquiringLedger->peerHas(it);
}
return true;
}
@@ -678,12 +674,12 @@ void NetworkOPs::endConsensus(bool correctLCL)
Log(lsTRACE) << "Ledger " << deadLedger.GetHex() << " is now dead";
theApp->getValidations().addDeadLedger(deadLedger);
std::vector<Peer::pointer> peerList = theApp->getConnectionPool().getPeerVector();
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it)
if (*it && ((*it)->getClosedLedgerHash() == deadLedger))
{
Log(lsTRACE) << "Killing obsolete peer status";
(*it)->cycleStatus();
}
BOOST_FOREACH(const Peer::pointer& it, peerList)
if (it && (it->getClosedLedgerHash() == deadLedger))
{
Log(lsTRACE) << "Killing obsolete peer status";
it->cycleStatus();
}
mConsensus = boost::shared_ptr<LedgerConsensus>();
}

View File

@@ -185,15 +185,13 @@ std::string STObject::getFullText() const
}
else ret = "{";
for (boost::ptr_vector<SerializedType>::const_iterator it = mData.begin(), end = mData.end(); it != end; ++it)
{
if (it->getSType() != STI_NOTPRESENT)
BOOST_FOREACH(const SerializedType& it, mData)
if (it.getSType() != STI_NOTPRESENT)
{
if (!first) ret += ", ";
else first = false;
ret += it->getFullText();
ret += it.getFullText();
}
}
ret += "}";
return ret;
@@ -202,29 +200,29 @@ std::string STObject::getFullText() const
int STObject::getLength() const
{
int ret = 0;
for (boost::ptr_vector<SerializedType>::const_iterator it = mData.begin(), end = mData.end(); it != end; ++it)
ret += it->getLength();
BOOST_FOREACH(const SerializedType& it, mData)
ret += it.getLength();
return ret;
}
void STObject::add(Serializer& s) const
{
for (boost::ptr_vector<SerializedType>::const_iterator it = mData.begin(), end = mData.end(); it != end; ++it)
it->add(s);
BOOST_FOREACH(const SerializedType& it, mData)
it.add(s);
}
std::string STObject::getText() const
{
std::string ret = "{";
bool first = false;
for (boost::ptr_vector<SerializedType>::const_iterator it = mData.begin(), end = mData.end(); it != end; ++it)
BOOST_FOREACH(const SerializedType& it, mData)
{
if (!first)
{
ret += ", ";
first = false;
}
ret += it->getText();
ret += it.getText();
}
ret += "}";
return ret;
@@ -654,14 +652,13 @@ Json::Value STObject::getJson(int options) const
{
Json::Value ret(Json::objectValue);
int index = 1;
for(boost::ptr_vector<SerializedType>::const_iterator it = mData.begin(), end = mData.end(); it != end;
++it, ++index)
BOOST_FOREACH(const SerializedType& it, mData)
{
if (it->getSType() != STI_NOTPRESENT)
if (it.getSType() != STI_NOTPRESENT)
{
if (it->getName() == NULL)
ret[boost::lexical_cast<std::string>(index)] = it->getJson(options);
else ret[it->getName()] = it->getJson(options);
if (it.getName() == NULL)
ret[boost::lexical_cast<std::string>(index)] = it.getJson(options);
else ret[it.getName()] = it.getJson(options);
}
}
return ret;
@@ -672,9 +669,7 @@ Json::Value STVector256::getJson(int options) const
Json::Value ret(Json::arrayValue);
BOOST_FOREACH(std::vector<uint256>::const_iterator::value_type vEntry, mValue)
{
ret.append(vEntry.ToString());
}
return ret;
}

View File

@@ -1,6 +1,8 @@
#include "SerializedTransaction.h"
#include <boost/foreach.hpp>
#include "Application.h"
#include "Log.h"
#include "HashPrefixes.h"
@@ -83,10 +85,9 @@ std::vector<NewcoinAddress> SerializedTransaction::getAffectedAccounts() const
std::vector<NewcoinAddress> accounts;
accounts.push_back(mSourceAccount);
for(boost::ptr_vector<SerializedType>::const_iterator it = mInnerTxn.peekData().begin(),
end = mInnerTxn.peekData().end(); it != end ; ++it)
BOOST_FOREACH(const SerializedType& it, mInnerTxn.peekData())
{
const STAccount* sa = dynamic_cast<const STAccount*>(&*it);
const STAccount* sa = dynamic_cast<const STAccount*>(&it);
if (sa != NULL)
{
bool found = false;

View File

@@ -8,6 +8,7 @@
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <queue>
#include "../json/writer.h"

View File

@@ -4,6 +4,7 @@
#include <boost/make_shared.hpp>
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
bool TransactionMetaNodeEntry::operator<(const TransactionMetaNodeEntry& e) const
{
@@ -167,27 +168,24 @@ void TransactionMetaNode::addRaw(Serializer& s)
s.add8(mType);
s.add256(mNode);
mEntries.sort();
for (boost::ptr_vector<TransactionMetaNodeEntry>::const_iterator it = mEntries.begin(), end = mEntries.end();
it != end; ++it)
it->addRaw(s);
BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries)
it.addRaw(s);
s.add8(TMSEndOfNode);
}
TransactionMetaNodeEntry* TransactionMetaNode::findEntry(int nodeType)
{
for (boost::ptr_vector<TransactionMetaNodeEntry>::iterator it = mEntries.begin(), end = mEntries.end();
it != end; ++it)
if (it->getType() == nodeType)
return &*it;
BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries)
if (it.getType() == nodeType)
return &it;
return NULL;
}
TMNEAmount* TransactionMetaNode::findAmount(int nType)
{
for (boost::ptr_vector<TransactionMetaNodeEntry>::iterator it = mEntries.begin(), end = mEntries.end();
it != end; ++it)
if (it->getType() == nType)
return dynamic_cast<TMNEAmount *>(&*it);
BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries)
if (it.getType() == nType)
return dynamic_cast<TMNEAmount *>(&it);
TMNEAmount* node = new TMNEAmount(nType);
mEntries.push_back(node);
return node;
@@ -200,9 +198,8 @@ void TransactionMetaNode::addNode(TransactionMetaNodeEntry* node)
bool TransactionMetaNode::thread(const uint256& prevTx, uint32 prevLgr)
{
for (boost::ptr_vector<TransactionMetaNodeEntry>::iterator it = mEntries.begin(), end = mEntries.end();
it != end; ++it)
if (it->getType() == TMSThread)
BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries)
if (it.getType() == TMSThread)
return false;
addNode(new TMNEThread(prevTx, prevLgr));
return true;
@@ -210,11 +207,10 @@ bool TransactionMetaNode::thread(const uint256& prevTx, uint32 prevLgr)
bool TransactionMetaNode::addAmount(int nodeType, const STAmount& amount)
{
for (boost::ptr_vector<TransactionMetaNodeEntry>::iterator it = mEntries.begin(), end = mEntries.end();
it != end; ++it)
if (it->getType() == nodeType)
BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries)
if (it.getType() == nodeType)
{
TMNEAmount* a = dynamic_cast<TMNEAmount *>(&*it);
TMNEAmount* a = dynamic_cast<TMNEAmount *>(&it);
assert(a && (a->getAmount() == amount));
return false;
}
@@ -224,11 +220,10 @@ bool TransactionMetaNode::addAmount(int nodeType, const STAmount& amount)
bool TransactionMetaNode::addAccount(int nodeType, const NewcoinAddress& account)
{
for (boost::ptr_vector<TransactionMetaNodeEntry>::iterator it = mEntries.begin(), end = mEntries.end();
it != end; ++it)
if (it->getType() == nodeType)
BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries)
if (it.getType() == nodeType)
{
TMNEAccount* a = dynamic_cast<TMNEAccount *>(&*it);
TMNEAccount* a = dynamic_cast<TMNEAccount *>(&it);
assert(a && (a->getAccount() == account));
return false;
}
@@ -252,9 +247,8 @@ Json::Value TransactionMetaNode::getJson(int v) const
ret["node"] = mNode.GetHex();
Json::Value e = Json::arrayValue;
for (boost::ptr_vector<TransactionMetaNodeEntry>::const_iterator it = mEntries.begin(), end = mEntries.end();
it != end; ++it)
e.append(it->getJson(v));
BOOST_FOREACH(const TransactionMetaNodeEntry& it, mEntries)
e.append(it.getJson(v));
ret["entries"] = e;
return ret;

View File

@@ -1,6 +1,8 @@
#include "ValidationCollection.h"
#include <boost/foreach.hpp>
#include "Application.h"
#include "LedgerTiming.h"
#include "Log.h"
@@ -192,8 +194,8 @@ boost::unordered_map<uint256, int> ValidationCollection::getCurrentValidations()
bool ValidationCollection::isDeadLedger(const uint256& ledger)
{
for (std::list<uint256>::iterator it = mDeadLedgers.begin(), end = mDeadLedgers.end(); it != end; ++it)
if (*it == ledger)
BOOST_FOREACH(const uint256& it, mDeadLedgers)
if (it == ledger)
return true;
return false;
}
@@ -259,10 +261,12 @@ void ValidationCollection::doWrite()
ScopedLock dbl(theApp->getLedgerDB()->getDBLock());
Database *db = theApp->getLedgerDB()->getDB();
db->executeSQL("BEGIN TRANSACTION;");
for (std::vector<SerializedValidation::pointer>::iterator it = vector.begin(); it != vector.end(); ++it)
db->executeSQL(boost::str(insVal % (*it)->getLedgerHash().GetHex()
% (*it)->getSignerPublic().humanNodePublic() % (*it)->getFlags() % (*it)->getCloseTime()
% db->escape(strCopy((*it)->getSignature()))));
BOOST_FOREACH(const SerializedValidation::pointer& it, vector)
db->executeSQL(boost::str(insVal % it->getLedgerHash().GetHex()
% it->getSignerPublic().humanNodePublic() % it->getFlags() % it->getCloseTime()
% db->escape(strCopy(it->getSignature()))));
db->executeSQL("END TRANSACTION;");
}