mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 12:05:53 +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);
|
CREATE INDEX ObjectLocate ON CommittedObjects(LedgerIndex, ObjType);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
bool HashedObject::store(HashedObjectType type, uint32 index, const std::vector<unsigned char>& data,
|
||||||
bool HashedObject::store() const
|
const uint256& hash)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
assert(checkHash());
|
Serializer s(data);
|
||||||
|
assert(hash==s.getSHA512Half());
|
||||||
#endif
|
#endif
|
||||||
std::string sql="INSERT INTO CommitedObjects (Hash,ObjType,LedgerIndex,Object) VALUES ('";
|
std::string sql="INSERT INTO CommitedObjects (Hash,ObjType,LedgerIndex,Object) VALUES ('";
|
||||||
sql.append(mHash.GetHex());
|
sql.append(hash.GetHex());
|
||||||
switch(mType)
|
switch(type)
|
||||||
{
|
{
|
||||||
case LEDGER: sql.append("','L','"); break;
|
case LEDGER: sql.append("','L','"); break;
|
||||||
case TRANSACTION: sql.append("','T','"); break;
|
case TRANSACTION: sql.append("','T','"); break;
|
||||||
@@ -52,11 +53,11 @@ bool HashedObject::store() const
|
|||||||
case TRANSACTION_NODE: sql.append("','N','"); break;
|
case TRANSACTION_NODE: sql.append("','N','"); break;
|
||||||
default: sql.append("','U','"); break;
|
default: sql.append("','U','"); break;
|
||||||
}
|
}
|
||||||
sql.append(boost::lexical_cast<std::string>(mLedgerIndex));
|
sql.append(boost::lexical_cast<std::string>(index));
|
||||||
sql.append("',");
|
sql.append("',");
|
||||||
|
|
||||||
std::string obj;
|
std::string obj;
|
||||||
theApp->getDB()->escape(&(mData.front()), mData.size(), obj);
|
theApp->getDB()->escape(&(data.front()), data.size(), obj);
|
||||||
sql.append(obj);
|
sql.append(obj);
|
||||||
sql.append(");");
|
sql.append(");");
|
||||||
|
|
||||||
@@ -65,6 +66,14 @@ bool HashedObject::store() const
|
|||||||
return db->executeSQL(sql.c_str());
|
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)
|
HashedObject::pointer retrieve(const uint256& hash)
|
||||||
{
|
{
|
||||||
std::string sql="SELECT * from CommitedObjects WHERE Hash='";
|
std::string sql="SELECT * from CommitedObjects WHERE Hash='";
|
||||||
|
|||||||
@@ -34,7 +34,12 @@ public:
|
|||||||
bool checkFixHash();
|
bool checkFixHash();
|
||||||
void setHash();
|
void setHash();
|
||||||
|
|
||||||
|
const std::vector<unsigned char>& getData() { return mData; }
|
||||||
|
|
||||||
bool store() const;
|
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);
|
static HashedObject::pointer retrieve(const uint256& hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user