From d5bc38f93e8808aeb650a17002f8f3313323e5b1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 13 Dec 2011 20:13:00 -0800 Subject: [PATCH] Convenience functions and avoid a copy.# --- HashedObject.cpp | 23 ++++++++++++++++------- HashedObject.h | 5 +++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/HashedObject.cpp b/HashedObject.cpp index 0fb10a3547..81d6a84e8c 100644 --- a/HashedObject.cpp +++ b/HashedObject.cpp @@ -36,15 +36,16 @@ CREATE TABLE CommittedObjects ( -- used to synch nodes CREATE INDEX ObjectLocate ON CommittedObjects(LedgerIndex, ObjType); */ - -bool HashedObject::store() const +bool HashedObject::store(HashedObjectType type, uint32 index, const std::vector& data, + const uint256& hash) { #ifdef DEBUG - assert(checkHash()); + Serializer s(data); + assert(hash==s.getSHA512Half()); #endif std::string sql="INSERT INTO CommitedObjects (Hash,ObjType,LedgerIndex,Object) VALUES ('"; - sql.append(mHash.GetHex()); - switch(mType) + sql.append(hash.GetHex()); + switch(type) { case LEDGER: sql.append("','L','"); break; case TRANSACTION: sql.append("','T','"); break; @@ -52,11 +53,11 @@ bool HashedObject::store() const case TRANSACTION_NODE: sql.append("','N','"); break; default: sql.append("','U','"); break; } - sql.append(boost::lexical_cast(mLedgerIndex)); + sql.append(boost::lexical_cast(index)); sql.append("',"); std::string obj; - theApp->getDB()->escape(&(mData.front()), mData.size(), obj); + theApp->getDB()->escape(&(data.front()), data.size(), obj); sql.append(obj); sql.append(");"); @@ -65,6 +66,14 @@ bool HashedObject::store() const return db->executeSQL(sql.c_str()); } +bool HashedObject::store() const +{ +#ifdef DEBUG + assert(checkHash()); +#endif + return store(mType, mLedgerIndex, mData, mHash); +} + HashedObject::pointer retrieve(const uint256& hash) { std::string sql="SELECT * from CommitedObjects WHERE Hash='"; diff --git a/HashedObject.h b/HashedObject.h index d8e966aea8..7234082c40 100644 --- a/HashedObject.h +++ b/HashedObject.h @@ -34,7 +34,12 @@ public: bool checkFixHash(); void setHash(); + const std::vector& getData() { return mData; } + bool store() const; + static bool store(HashedObjectType type, uint32 index, const std::vector& data, + const uint256& hash); + static HashedObject::pointer retrieve(const uint256& hash); };