mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Cleanups.
This commit is contained in:
@@ -214,6 +214,16 @@ std::string SerializedTransaction::getSQLInsertHeader()
|
|||||||
return "INSERT INTO Transactions " + getSQLValueHeader() + " VALUES ";
|
return "INSERT INTO Transactions " + getSQLValueHeader() + " VALUES ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string SerializedTransaction::getSQLInsertIgnoreHeader()
|
||||||
|
{
|
||||||
|
return "INSERT OR IGNORE INTO Transactions " + getSQLValueHeader() + " VALUES ";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SerializedTransaction::getSQLInsertReplaceHeader()
|
||||||
|
{
|
||||||
|
return "INSERT OR REPLACE INTO Transactions " + getSQLValueHeader() + " VALUES ";
|
||||||
|
}
|
||||||
|
|
||||||
std::string SerializedTransaction::getMetaSQLInsertHeader()
|
std::string SerializedTransaction::getMetaSQLInsertHeader()
|
||||||
{
|
{
|
||||||
return "INSERT INTO Transactions " + getMetaSQLValueHeader() + " VALUES ";
|
return "INSERT INTO Transactions " + getMetaSQLValueHeader() + " VALUES ";
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ public:
|
|||||||
// SQL Functions
|
// SQL Functions
|
||||||
static std::string getSQLValueHeader();
|
static std::string getSQLValueHeader();
|
||||||
static std::string getSQLInsertHeader();
|
static std::string getSQLInsertHeader();
|
||||||
|
static std::string getSQLInsertIgnoreHeader();
|
||||||
|
static std::string getSQLInsertReplaceHeader();
|
||||||
std::string getSQL(std::string& sql, uint32 inLedger, char status) const;
|
std::string getSQL(std::string& sql, uint32 inLedger, char status) const;
|
||||||
std::string getSQL(uint32 inLedger, char status) const;
|
std::string getSQL(uint32 inLedger, char status) const;
|
||||||
std::string getSQL(Serializer rawTxn, uint32 inLedger, char status) const;
|
std::string getSQL(Serializer rawTxn, uint32 inLedger, char status) const;
|
||||||
|
|||||||
@@ -126,35 +126,25 @@ void Transaction::setStatus(TransStatus ts, uint32 lseq)
|
|||||||
mInLedger = lseq;
|
mInLedger = lseq;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transaction::saveTransaction(const Transaction::pointer& txn)
|
void Transaction::save()
|
||||||
{
|
{
|
||||||
txn->save();
|
if ((mStatus == INVALID) || (mStatus == REMOVED))
|
||||||
}
|
return;
|
||||||
|
|
||||||
bool Transaction::save()
|
|
||||||
{
|
|
||||||
if ((mStatus == INVALID) || (mStatus == REMOVED)) return false;
|
|
||||||
|
|
||||||
char status;
|
char status;
|
||||||
switch (mStatus)
|
switch (mStatus)
|
||||||
{
|
{
|
||||||
case NEW: status = TXN_SQL_NEW; break;
|
case NEW: status = TXN_SQL_NEW; break;
|
||||||
case INCLUDED: status = TXN_SQL_INCLUDED; break;
|
case INCLUDED: status = TXN_SQL_INCLUDED; break;
|
||||||
case CONFLICTED: status = TXN_SQL_CONFLICT; break;
|
case CONFLICTED: status = TXN_SQL_CONFLICT; break;
|
||||||
case COMMITTED: status = TXN_SQL_VALIDATED; break;
|
case COMMITTED: status = TXN_SQL_VALIDATED; break;
|
||||||
case HELD: status = TXN_SQL_HELD; break;
|
case HELD: status = TXN_SQL_HELD; break;
|
||||||
default: status = TXN_SQL_UNKNOWN;
|
default: status = TXN_SQL_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boost::format selStat("SELECT Status FROM Transactions WHERE TransID = '%s';");
|
|
||||||
std::string exists = boost::str(selStat % mTransaction->getTransactionID().GetHex());
|
|
||||||
|
|
||||||
Database *db = theApp->getTxnDB()->getDB();
|
Database *db = theApp->getTxnDB()->getDB();
|
||||||
ScopedLock dbLock(theApp->getTxnDB()->getDBLock());
|
ScopedLock dbLock(theApp->getTxnDB()->getDBLock());
|
||||||
if (SQL_EXISTS(db, exists))
|
db->executeSQL(mTransaction->getSQLInsertReplaceHeader() + mTransaction->getSQL(getLedger(), status) + ";");
|
||||||
return false;
|
|
||||||
return
|
|
||||||
db->executeSQL(mTransaction->getSQLInsertHeader() + mTransaction->getSQL(getLedger(), status) + ";");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction::pointer Transaction::transactionFromSQL(Database* db, bool bValidate)
|
Transaction::pointer Transaction::transactionFromSQL(Database* db, bool bValidate)
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ public:
|
|||||||
void setLedger(uint32 ledger) { mInLedger = ledger; }
|
void setLedger(uint32 ledger) { mInLedger = ledger; }
|
||||||
|
|
||||||
// database functions
|
// database functions
|
||||||
static void saveTransaction(Transaction::ref);
|
void save();
|
||||||
bool save();
|
|
||||||
static Transaction::pointer load(const uint256& id);
|
static Transaction::pointer load(const uint256& id);
|
||||||
static Transaction::pointer findFrom(const RippleAddress& fromID, uint32 seq);
|
static Transaction::pointer findFrom(const RippleAddress& fromID, uint32 seq);
|
||||||
|
|
||||||
|
|||||||
@@ -66,18 +66,23 @@ SerializedTransaction::pointer TransactionMaster::fetch(SHAMapItem::ref item, SH
|
|||||||
return txn;
|
return txn;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveTransactionHelper(Transaction::pointer txn, LoadEvent::pointer)
|
static void saveHelper(Transaction::pointer txn, LoadEvent::pointer l)
|
||||||
{
|
{
|
||||||
Transaction::saveTransaction(txn);
|
txn->save();
|
||||||
|
l.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TransactionMaster::canonicalize(Transaction::pointer& txn, bool may_be_new)
|
bool TransactionMaster::canonicalize(Transaction::pointer& txn, bool may_be_new)
|
||||||
{
|
{
|
||||||
uint256 tid = txn->getID();
|
uint256 tid = txn->getID();
|
||||||
if (!tid) return false;
|
if (!tid)
|
||||||
if (mCache.canonicalize(tid, txn)) return true;
|
return false;
|
||||||
|
|
||||||
|
if (mCache.canonicalize(tid, txn))
|
||||||
|
return true;
|
||||||
|
|
||||||
if (may_be_new)
|
if (may_be_new)
|
||||||
theApp->getAuxService().post(boost::bind(&saveTransactionHelper, txn,
|
theApp->getAuxService().post(boost::bind(saveHelper, txn,
|
||||||
theApp->getJobQueue().getLoadEvent(jtDISK)));
|
theApp->getJobQueue().getLoadEvent(jtDISK)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user