diff --git a/src/HashedObject.cpp b/src/HashedObject.cpp index 8303a9b49..52fe5899c 100644 --- a/src/HashedObject.cpp +++ b/src/HashedObject.cpp @@ -86,18 +86,18 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash) uint32 index; std::vector data; data.reserve(8192); - if(1) + { ScopedLock sl(theApp->getHashNodeDB()->getDBLock()); Database* db=theApp->getHashNodeDB()->getDB(); - if(!db->executeSQL(sql.c_str()) || !db->startIterRows() || !db->getNextRow()) + if(!db->executeSQL(sql.c_str()) || !db->startIterRows()) return HashedObject::pointer(); std::string type; - db->getStr("ObjType", type); + db->getStr("ObjType", type); if(type.size()==0) return HashedObject::pointer(); - + index=db->getBigInt("LedgerIndex"); int size=db->getBinary("Object", NULL, 0); @@ -105,7 +105,7 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash) db->getBinary("Object", &(data.front()), size); db->endIterRows(); } - + HashedObjectType htype=UNKNOWN; switch(type[0]) { @@ -114,7 +114,7 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash) case 'A': htype=ACCOUNT_NODE; break; case 'N': htype=TRANSACTION_NODE; break; } - + HashedObject::pointer obj(new HashedObject(htype, index, data)); obj->mHash=hash; #ifdef DEBUG @@ -122,3 +122,4 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash) #endif return obj; } +// vim:ts=4 diff --git a/src/Ledger.cpp b/src/Ledger.cpp index c3c1d8804..5ce71db74 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -269,7 +269,8 @@ Ledger::pointer Ledger::getSQL(const std::string& sql) { ScopedLock sl(theApp->getLedgerDB()->getDBLock()); Database *db = theApp->getLedgerDB()->getDB(); - if (!db->executeSQL(sql.c_str()) || !db->startIterRows() || !db->getNextRow()) + + if (!db->executeSQL(sql) || !db->startIterRows()) return Ledger::pointer(); db->getStr("LedgerHash", hash); @@ -285,7 +286,7 @@ Ledger::pointer Ledger::getSQL(const std::string& sql) ledgerSeq = db->getBigInt("LedgerSeq"); db->endIterRows(); } - + Ledger::pointer ret=boost::make_shared(prevHash, transHash, accountHash, totCoins, closingTime, ledgerSeq); if (ret->getHash() != ledgerHash) { @@ -425,3 +426,4 @@ bool Ledger::isAcquiringAS(void) { return mAccountStateMap->isSynching(); } +// vim:ts=4 diff --git a/src/PubKeyCache.cpp b/src/PubKeyCache.cpp index 47ed41dc7..540237449 100644 --- a/src/PubKeyCache.cpp +++ b/src/PubKeyCache.cpp @@ -19,11 +19,11 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id) std::vector data; data.reserve(65); // our public keys are actually 33 bytes int pkSize; - if(1) + { // is it in the database ScopedLock sl(theApp->getTxnDB()->getDBLock()); Database* db=theApp->getTxnDB()->getDB(); - if(!db->executeSQL(sql.c_str()) || !db->startIterRows() || !db->getNextRow()) + if(!db->executeSQL(sql.c_str()) || !db->startIterRows()) return CKey::pointer(); pkSize=db->getBinary("PubKey", &(data.front()), data.size()); db->endIterRows(); @@ -36,7 +36,6 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id) return CKey::pointer(); } - if(1) { // put it in cache (okay if we race with another retriever) boost::mutex::scoped_lock sl(mLock); mCache.insert(std::make_pair(id, ckp)); @@ -46,7 +45,6 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id) CKey::pointer PubKeyCache::store(const NewcoinAddress& id, CKey::pointer key) { // stored if needed, returns cached copy (possibly the original) - if(1) { boost::mutex::scoped_lock sl(mLock); std::pair::iterator, bool> pit(mCache.insert(std::make_pair(id, key))); @@ -74,3 +72,4 @@ void PubKeyCache::clear() boost::mutex::scoped_lock sl(mLock); mCache.empty(); } +// vim:ts=4 diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 94361ef10..6d0f7c4fb 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -225,7 +225,7 @@ bool Transaction::save() const theApp->getTxnDB()->getDB()->escape(static_cast(s.getDataPtr()), s.getLength(), rawTxn); sql.append(rawTxn); sql.append(");"); - + ScopedLock sl(theApp->getTxnDB()->getDBLock()); Database* db = theApp->getTxnDB()->getDB(); return db->executeSQL(sql.c_str()); @@ -237,12 +237,11 @@ Transaction::pointer Transaction::transactionFromSQL(const std::string& sql) std::string status; rawTxn.reserve(2048); - if(1) { ScopedLock sl(theApp->getTxnDB()->getDBLock()); Database* db = theApp->getTxnDB()->getDB(); - if (!db->executeSQL(sql.c_str(), true) || !db->startIterRows() || !db->getNextRow()) + if (!db->executeSQL(sql, true) || !db->startIterRows()) return Transaction::pointer(); db->getStr("Status", status); @@ -258,7 +257,7 @@ Transaction::pointer Transaction::transactionFromSQL(const std::string& sql) Transaction::pointer tr = boost::make_shared(txn, true); TransStatus st(INVALID); - switch(status[0]) + switch (status[0]) { case 'N': st = NEW; break; case 'A': st = INCLUDED; break; @@ -382,3 +381,4 @@ Json::Value Transaction::getJson(bool decorate, bool paid, bool credited) const return ret; } +// vim:ts=4 diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index 340ac6457..22e87c500 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -50,24 +50,18 @@ bool ValidationCollection::hasValidation(uint32 ledgerIndex,uint160& hanko,uint3 db->escape(hanko.begin(),hanko.GetSerializeSize(),hankoStr); string sql=strprintf("SELECT ValidationID,seqnum from Validations where LedgerIndex=%d and hanko=%s", ledgerIndex,hankoStr.c_str()); - if(db->executeSQL(sql.c_str())) + if(db->executeSQL(sql) && db->startIterRows()) { - if(db->startIterRows()) + uint32 currentSeqNum=db->getInt(1); + if(currentSeqNum>=seqnum) { - if(db->getNextRow()) - { - uint32 currentSeqNum=db->getInt(1); - if(currentSeqNum>=seqnum) - { - db->endIterRows(); - return(true); - } - // delete the old validation we were storing - sql=strprintf("DELETE FROM Validations where ValidationID=%d",db->getInt(0)); - db->endIterRows(); - db->executeSQL(sql.c_str()); - } + db->endIterRows(); + return(true); } + // delete the old validation we were storing + sql=strprintf("DELETE FROM Validations where ValidationID=%d",db->getInt(0)); + db->endIterRows(); + db->executeSQL(sql); } return(false); } @@ -191,7 +185,6 @@ void ValidationCollection::getValidations(uint32 ledgerIndex,vector& groups=mIndexGroups[ledgerIndex]; Group empty; @@ -228,6 +220,7 @@ bool ValidationCollection::getConsensusLedger(uint32 ledgerIndex, uint256& ourHa } } } - + return(ret); } +// vim:ts=4 diff --git a/src/Wallet.cpp b/src/Wallet.cpp index 426e84700..8a19099e8 100644 --- a/src/Wallet.cpp +++ b/src/Wallet.cpp @@ -190,7 +190,7 @@ LocalAccountFamily::pointer LocalAccountFamily::readFamily(const NewcoinAddress& ScopedLock sl(theApp->getWalletDB()->getDBLock()); Database *db=theApp->getWalletDB()->getDB(); - if(!db->executeSQL(sql.c_str()) || !db->startIterRows() || !db->getNextRow()) + if(!db->executeSQL(sql.c_str()) || !db->startIterRows()) return LocalAccountFamily::pointer(); db->getStr("Comment", comment); @@ -456,8 +456,7 @@ void Wallet::load() if(!db->startIterRows()) return; - while(db->getNextRow()) - { + do { std::string strGenerator, strComment; db->getStr("FamilyGenerator", strGenerator); @@ -476,7 +475,8 @@ void Wallet::load() f->setComment(strComment); } else assert(false); - } + } while(db->getNextRow()); + db->endIterRows(); }