mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Save txn metadata into transaction database.
This commit is contained in:
@@ -369,7 +369,8 @@ void Ledger::saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer event)
|
|||||||
static boost::format deleteLedger("DELETE FROM Ledgers WHERE LedgerSeq = %d;");
|
static boost::format deleteLedger("DELETE FROM Ledgers WHERE LedgerSeq = %d;");
|
||||||
static boost::format AcctTransExists("SELECT LedgerSeq FROM AccountTransactions WHERE TransId = '%s';");
|
static boost::format AcctTransExists("SELECT LedgerSeq FROM AccountTransactions WHERE TransId = '%s';");
|
||||||
static boost::format transExists("SELECT Status FROM Transactions WHERE TransID = '%s';");
|
static boost::format transExists("SELECT Status FROM Transactions WHERE TransID = '%s';");
|
||||||
static boost::format updateTx("UPDATE Transactions SET LedgerSeq = %d, Status = '%c' WHERE TransID = '%s';");
|
static boost::format
|
||||||
|
updateTx("UPDATE Transactions SET LedgerSeq = %d, Status = '%c', TxnMeta = %s WHERE TransID = '%s';");
|
||||||
static boost::format addLedger("INSERT INTO Ledgers "
|
static boost::format addLedger("INSERT INTO Ledgers "
|
||||||
"(LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,CloseTimeRes,CloseFlags,"
|
"(LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,CloseTimeRes,CloseFlags,"
|
||||||
"AccountSetHash,TransSetHash) VALUES ('%s','%u','%s','%s','%u','%u','%d','%u','%s','%s');");
|
"AccountSetHash,TransSetHash) VALUES ('%s','%u','%s','%s','%u','%u','%d','%u','%s','%s');");
|
||||||
@@ -397,14 +398,20 @@ void Ledger::saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer event)
|
|||||||
for (SHAMapItem::pointer item = txSet.peekFirstItem(type); !!item;
|
for (SHAMapItem::pointer item = txSet.peekFirstItem(type); !!item;
|
||||||
item = txSet.peekNextItem(item->getTag(), type))
|
item = txSet.peekNextItem(item->getTag(), type))
|
||||||
{
|
{
|
||||||
SerializedTransaction::pointer txn = getSTransaction(item, type);
|
assert(type == SHAMapTreeNode::tnTRANSACTION_MD);
|
||||||
assert(txn);
|
SerializerIterator sit(item->peekSerializer());
|
||||||
|
Serializer rawTxn(sit.getVL());
|
||||||
|
std::string escMeta(sqlEscape(sit.getVL()));
|
||||||
|
|
||||||
|
SerializerIterator txnIt(rawTxn);
|
||||||
|
SerializedTransaction txn(txnIt);
|
||||||
|
assert(txn.getTransactionID() == item->getTag());
|
||||||
|
|
||||||
// Make sure transaction is in AccountTransactions.
|
// Make sure transaction is in AccountTransactions.
|
||||||
if (!SQL_EXISTS(db, boost::str(AcctTransExists % item->getTag().GetHex())))
|
if (!SQL_EXISTS(db, boost::str(AcctTransExists % item->getTag().GetHex())))
|
||||||
{
|
{
|
||||||
// Transaction not in AccountTransactions
|
// Transaction not in AccountTransactions
|
||||||
std::vector<RippleAddress> accts = txn->getAffectedAccounts();
|
std::vector<RippleAddress> accts = txn.getAffectedAccounts();
|
||||||
|
|
||||||
std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq) VALUES ";
|
std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq) VALUES ";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
@@ -417,7 +424,7 @@ void Ledger::saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer event)
|
|||||||
sql += "('";
|
sql += "('";
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
sql += txn->getTransactionID().GetHex();
|
sql += txn.getTransactionID().GetHex();
|
||||||
sql += "','";
|
sql += "','";
|
||||||
sql += it->humanAccountID();
|
sql += it->humanAccountID();
|
||||||
sql += "',";
|
sql += "',";
|
||||||
@@ -429,19 +436,20 @@ void Ledger::saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer event)
|
|||||||
db->executeSQL(sql); // may already be in there
|
db->executeSQL(sql); // may already be in there
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SQL_EXISTS(db, boost::str(transExists % txn->getTransactionID().GetHex())))
|
if (SQL_EXISTS(db, boost::str(transExists % txn.getTransactionID().GetHex())))
|
||||||
{
|
{
|
||||||
// In Transactions, update LedgerSeq and Status.
|
// In Transactions, update LedgerSeq, metadata and Status.
|
||||||
db->executeSQL(boost::str(updateTx
|
db->executeSQL(boost::str(updateTx
|
||||||
% getLedgerSeq()
|
% getLedgerSeq()
|
||||||
% TXN_SQL_VALIDATED
|
% TXN_SQL_VALIDATED
|
||||||
% txn->getTransactionID().GetHex()));
|
% escMeta
|
||||||
|
% txn.getTransactionID().GetHex()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Not in Transactions, insert the whole thing..
|
// Not in Transactions, insert the whole thing..
|
||||||
db->executeSQL(
|
db->executeSQL(
|
||||||
txn->getSQLInsertHeader() + txn->getSQL(getLedgerSeq(), TXN_SQL_VALIDATED) + ";");
|
txn.getMetaSQLInsertHeader() + txn.getMetaSQL(getLedgerSeq(), escMeta) + ";");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db->executeSQL("COMMIT TRANSACTION;");
|
db->executeSQL("COMMIT TRANSACTION;");
|
||||||
|
|||||||
Reference in New Issue
Block a user