mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Convenience functions and avoid a copy.#
This commit is contained in:
@@ -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<unsigned char>& 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<std::string>(mLedgerIndex));
|
||||
sql.append(boost::lexical_cast<std::string>(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='";
|
||||
|
||||
@@ -34,7 +34,12 @@ public:
|
||||
bool checkFixHash();
|
||||
void setHash();
|
||||
|
||||
const std::vector<unsigned char>& getData() { return mData; }
|
||||
|
||||
bool store() const;
|
||||
static bool store(HashedObjectType type, uint32 index, const std::vector<unsigned char>& data,
|
||||
const uint256& hash);
|
||||
|
||||
static HashedObject::pointer retrieve(const uint256& hash);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user