1#include <xrpld/app/ledger/AcceptedLedger.h>
2#include <xrpld/app/ledger/LedgerMaster.h>
3#include <xrpld/app/ledger/LedgerToJson.h>
4#include <xrpld/app/ledger/PendingSaves.h>
5#include <xrpld/app/ledger/TransactionMaster.h>
6#include <xrpld/app/rdb/RelationalDatabase.h>
7#include <xrpld/app/rdb/backend/detail/Node.h>
8#include <xrpld/core/DatabaseCon.h>
9#include <xrpld/core/SociDB.h>
11#include <xrpl/basics/BasicConfig.h>
12#include <xrpl/basics/StringUtilities.h>
13#include <xrpl/json/to_string.h>
15#include <boost/range/adaptor/transformed.hpp>
17#include <soci/sqlite3/soci-sqlite3.h>
32 "Need to modify switch statement if enum is modified");
39 return "Transactions";
41 return "AccountTransactions";
44 UNREACHABLE(
"ripple::detail::to_string : invalid TableType");
60 lgr->getSession() << boost::str(
61 boost::format(
"PRAGMA cache_size=-%d;") %
69 tx->getSession() << boost::str(
70 boost::format(
"PRAGMA cache_size=-%d;") %
82 (tx->getSession().prepare
83 << (
"PRAGMA table_info(AccountTransactions);"),
88 soci::into(dflt_value, ind),
96 return {std::move(lgr), std::move(tx),
false};
101 return {std::move(lgr), std::move(tx),
true};
104 return {std::move(lgr), {},
true};
112 boost::optional<LedgerIndex> m;
113 session << query, soci::into(m);
122 boost::optional<LedgerIndex> m;
123 session << query, soci::into(m);
130 session <<
"DELETE FROM " <<
to_string(type)
131 <<
" WHERE LedgerSeq == " << ledgerSeq <<
";";
136 soci::session& session,
140 session <<
"DELETE FROM " <<
to_string(type) <<
" WHERE LedgerSeq < "
148 session <<
"SELECT COUNT(*) AS rows "
160 session <<
"SELECT COUNT(*) AS rows, "
161 "MIN(LedgerSeq) AS first, "
162 "MAX(LedgerSeq) AS last "
179 auto j = app.
journal(
"Ledger");
180 auto seq = ledger->info().seq;
183 JLOG(j.trace()) <<
"saveValidatedLedger " << (
current ?
"" :
"fromAcquire ")
186 if (!ledger->info().accountHash.isNonZero())
189 JLOG(j.fatal()) <<
"AH is zero: " <<
getJson({*ledger, {}});
190 UNREACHABLE(
"ripple::detail::saveValidatedLedger : zero account hash");
194 if (ledger->info().accountHash != ledger->stateMap().getHash().as_uint256())
197 JLOG(j.fatal()) <<
"sAL: " << ledger->info().accountHash
198 <<
" != " << ledger->stateMap().getHash();
199 JLOG(j.fatal()) <<
"saveAcceptedLedger: seq=" << seq
202 "ripple::detail::saveValidatedLedger : mismatched account hash");
207 ledger->info().txHash == ledger->txMap().getHash().as_uint256(),
208 "ripple::detail::saveValidatedLedger : transaction hash match");
214 addRaw(ledger->info(), s);
227 ledger->info().hash, aLedger);
232 JLOG(j.warn()) <<
"An accepted ledger was missing nodes";
241 static boost::format deleteLedger(
242 "DELETE FROM Ledgers WHERE LedgerSeq = %u;");
243 static boost::format deleteTrans1(
244 "DELETE FROM Transactions WHERE LedgerSeq = %u;");
245 static boost::format deleteTrans2(
246 "DELETE FROM AccountTransactions WHERE LedgerSeq = %u;");
247 static boost::format deleteAcctTrans(
248 "DELETE FROM AccountTransactions WHERE TransID = '%s';");
252 *db << boost::str(deleteLedger % seq);
259 soci::transaction tr(*db);
261 *db << boost::str(deleteTrans1 % seq);
262 *db << boost::str(deleteTrans2 % seq);
266 for (
auto const& acceptedLedgerTx : *aLedger)
276 auto const& accts = acceptedLedgerTx->getAffected();
281 "INSERT INTO AccountTransactions "
282 "(TransID, Account, LedgerSeq, TxnSeq) VALUES ");
290 for (
auto const& account : accts)
310 JLOG(j.trace()) <<
"ActTx: " << sql;
313 else if (
auto const& sleTxn = acceptedLedgerTx->getTxn();
318 JLOG(j.warn()) <<
"Transaction in ledger " << seq
319 <<
" affects no accounts";
325 acceptedLedgerTx->getTxn()->getMetaSQL(
326 seq, acceptedLedgerTx->getEscMeta()) +
332 acceptedLedgerTx->getTxnSeq(),
341 R
"sql(INSERT OR REPLACE INTO Ledgers
342 (LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,
343 CloseTimeRes,CloseFlags,AccountSetHash,TransSetHash)
345 (:ledgerHash,:ledgerSeq,:prevHash,:totalCoins,:closingTime,:prevClosingTime,
346 :closeTimeRes,:closeFlags,:accountSetHash,:transSetHash);)sql");
350 soci::transaction tr(*db);
352 auto const hash =
to_string(ledger->info().hash);
353 auto const parentHash =
to_string(ledger->info().parentHash);
354 auto const drops =
to_string(ledger->info().drops);
355 auto const closeTime =
356 ledger->info().closeTime.time_since_epoch().count();
357 auto const parentCloseTime =
358 ledger->info().parentCloseTime.time_since_epoch().count();
359 auto const closeTimeResolution =
360 ledger->info().closeTimeResolution.count();
361 auto const closeFlags = ledger->info().closeFlags;
362 auto const accountHash =
to_string(ledger->info().accountHash);
363 auto const txHash =
to_string(ledger->info().txHash);
365 *db << addLedger, soci::use(hash), soci::use(seq),
366 soci::use(parentHash), soci::use(drops), soci::use(closeTime),
367 soci::use(parentCloseTime), soci::use(closeTimeResolution),
368 soci::use(closeFlags), soci::use(accountHash),
388 soci::session& session,
393 boost::optional<std::string> hash, parentHash, accountHash, txHash;
394 boost::optional<std::uint64_t> seq, drops, closeTime, parentCloseTime,
395 closeTimeResolution, closeFlags;
399 "LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
401 "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
402 "LedgerSeq FROM Ledgers " +
405 session << sql, soci::into(hash), soci::into(parentHash),
406 soci::into(accountHash), soci::into(txHash), soci::into(drops),
407 soci::into(closeTime), soci::into(parentCloseTime),
408 soci::into(closeTimeResolution), soci::into(closeFlags),
411 if (!session.got_data())
413 JLOG(j.
debug()) <<
"Ledger not found: " << sqlSuffix;
422 if (hash && !info.hash.parseHex(*hash))
424 JLOG(j.
debug()) <<
"Hash parse error for ledger: " << sqlSuffix;
428 if (parentHash && !info.parentHash.parseHex(*parentHash))
430 JLOG(j.
debug()) <<
"parentHash parse error for ledger: " << sqlSuffix;
434 if (accountHash && !info.accountHash.parseHex(*accountHash))
436 JLOG(j.
debug()) <<
"accountHash parse error for ledger: " << sqlSuffix;
440 if (txHash && !info.txHash.parseHex(*txHash))
442 JLOG(j.
debug()) <<
"txHash parse error for ledger: " << sqlSuffix;
446 info.seq = rangeCheckedCast<std::uint32_t>(seq.value_or(0));
447 info.drops =
drops.value_or(0);
448 info.closeTime = time_point{duration{closeTime.value_or(0)}};
449 info.parentCloseTime = time_point{duration{parentCloseTime.value_or(0)}};
450 info.closeFlags = closeFlags.value_or(0);
451 info.closeTimeResolution = duration{closeTimeResolution.value_or(0)};
458 soci::session& session,
463 s <<
"WHERE LedgerSeq = " << ledgerSeq;
471 s <<
"ORDER BY LedgerSeq DESC LIMIT 1";
477 soci::session& session,
483 " ORDER BY LedgerSeq ASC LIMIT 1";
489 soci::session& session,
495 " ORDER BY LedgerSeq DESC LIMIT 1";
501 soci::session& session,
506 s <<
"WHERE LedgerHash = '" << ledgerHash <<
"'";
516 "SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
523 boost::optional<std::string> lh;
524 session << sql, soci::into(lh);
526 if (!session.got_data() || !lh)
542 soci::session& session,
547 boost::optional<std::string> lhO, phO;
549 session <<
"SELECT LedgerHash,PrevHash FROM Ledgers "
550 "INDEXED BY SeqLedger WHERE LedgerSeq = :ls;",
551 soci::into(lhO), soci::into(phO), soci::use(ledgerIndex);
555 auto stream = j.
trace();
556 JLOG(stream) <<
"Don't have ledger " << ledgerIndex;
560 LedgerHashPair hashes;
561 if (!hashes.ledgerHash.parseHex(*lhO) || !hashes.parentHash.parseHex(*phO))
563 auto stream = j.
trace();
564 JLOG(stream) <<
"Error parse hashes for ledger " << ledgerIndex;
573 soci::session& session,
579 "SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
581 sql.
append(
" AND LedgerSeq <= ");
588 boost::optional<std::string> ph;
590 (session.prepare << sql,
602 JLOG(j.
warn()) <<
"Error parsed hash for ledger seq: " << ls;
606 JLOG(j.
warn()) <<
"Null prev hash for ledger seq: " << ls;
610 JLOG(j.
warn()) <<
"Error parsed prev hash for ledger seq: " << ls;
618 soci::session& session,
625 "SELECT LedgerSeq, Status, RawTxn "
626 "FROM Transactions ORDER BY LedgerSeq DESC LIMIT %u,%u;") %
627 startIndex % quantity);
634 boost::optional<std::uint64_t> ledgerSeq;
635 boost::optional<std::string> status;
636 soci::blob sociRawTxnBlob(session);
641 (session.prepare << sql,
642 soci::into(ledgerSeq),
644 soci::into(sociRawTxnBlob, rti));
649 if (soci::i_ok == rti)
650 convert(sociRawTxnBlob, rawTxn);
655 ledgerSeq, status, rawTxn, app))
687 RelationalDatabase::AccountTxOptions
const& options,
702 else if (options.limit == UINT32_MAX)
704 numberOfResults = binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH;
706 else if (!options.bUnlimited)
709 binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH, options.limit);
713 numberOfResults = options.limit;
719 if (options.maxLedger)
721 maxClause = boost::str(
722 boost::format(
"AND AccountTransactions.LedgerSeq <= '%u'") %
726 if (options.minLedger)
728 minClause = boost::str(
729 boost::format(
"AND AccountTransactions.LedgerSeq >= '%u'") %
737 boost::format(
"SELECT %s FROM AccountTransactions "
738 "WHERE Account = '%s' %s %s LIMIT %u, %u;") %
739 selection %
toBase58(options.account) % maxClause % minClause %
740 options.offset % numberOfResults);
745 "AccountTransactions INNER JOIN Transactions "
746 "ON Transactions.TransID = AccountTransactions.TransID "
747 "WHERE Account = '%s' %s %s "
748 "ORDER BY AccountTransactions.LedgerSeq %s, "
749 "AccountTransactions.TxnSeq %s, AccountTransactions.TransID %s "
751 selection %
toBase58(options.account) % maxClause % minClause %
752 (descending ?
"DESC" :
"ASC") % (descending ?
"DESC" :
"ASC") %
753 (descending ?
"DESC" :
"ASC") % options.offset % numberOfResults);
754 JLOG(j.
trace()) <<
"txSQL query: " << sql;
781 soci::session& session,
784 RelationalDatabase::AccountTxOptions
const& options,
792 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
804 boost::optional<std::uint64_t> ledgerSeq;
805 boost::optional<std::string>
status;
806 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
807 soci::indicator rti, tmi;
808 Blob rawTxn, txnMeta;
811 (session.prepare << sql,
812 soci::into(ledgerSeq),
814 soci::into(sociTxnBlob, rti),
815 soci::into(sociTxnMetaBlob, tmi));
820 if (soci::i_ok == rti)
825 if (soci::i_ok == tmi)
826 convert(sociTxnMetaBlob, txnMeta);
836 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
839 <<
"Recovering ledger " << seq <<
", txn " << txn->getID();
850 txn->getID(), txn->getLedger(), txnMeta));
861 soci::session& session,
864 RelationalDatabase::AccountTxOptions
const& options,
872 soci::session& session,
903 soci::session& session,
905 RelationalDatabase::AccountTxOptions
const& options,
913 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
926 boost::optional<std::uint64_t> ledgerSeq;
927 boost::optional<std::string>
status;
928 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
929 soci::indicator rti, tmi;
932 (session.prepare << sql,
933 soci::into(ledgerSeq),
935 soci::into(sociTxnBlob, rti),
936 soci::into(sociTxnMetaBlob, tmi));
942 if (soci::i_ok == rti)
945 if (soci::i_ok == tmi)
946 convert(sociTxnMetaBlob, txnMeta);
949 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
951 ret.
emplace_back(std::move(rawTxn), std::move(txnMeta), seq);
961 soci::session& session,
963 RelationalDatabase::AccountTxOptions
const& options,
971 soci::session& session,
1000 soci::session& session,
1005 RelationalDatabase::AccountTxPageOptions
const& options,
1011 bool lookingForMarker = options.marker.has_value();
1015 if (options.limit == 0 || options.limit == UINT32_MAX ||
1016 (options.limit > page_length && !options.bAdmin))
1017 numberOfResults = page_length;
1019 numberOfResults = options.limit;
1029 if (lookingForMarker)
1031 findLedger = options.marker->ledgerSeq;
1032 findSeq = options.marker->txnSeq;
1038 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1039 Status,RawTxn,TxnMeta
1040 FROM AccountTransactions INNER JOIN Transactions
1041 ON Transactions.TransID = AccountTransactions.TransID
1042 AND AccountTransactions.Account = '%s' WHERE
1049 char const*
const order =
forward ?
"ASC" :
"DESC";
1051 if (findLedger == 0)
1055 prefix + (R
"(AccountTransactions.LedgerSeq BETWEEN %u AND %u
1056 ORDER BY AccountTransactions.LedgerSeq %s,
1057 AccountTransactions.TxnSeq %s
1059 toBase58(options.account) % options.minLedger % options.maxLedger %
1060 order % order % queryLimit);
1066 forward ? findLedger + 1 : options.minLedger;
1068 forward ? options.maxLedger : findLedger - 1;
1070 auto b58acct =
toBase58(options.account);
1073 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1074 Status,RawTxn,TxnMeta
1075 FROM AccountTransactions, Transactions WHERE
1076 (AccountTransactions.TransID = Transactions.TransID AND
1077 AccountTransactions.Account = '%s' AND
1078 AccountTransactions.LedgerSeq BETWEEN %u AND %u)
1080 SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,Status,RawTxn,TxnMeta
1081 FROM AccountTransactions, Transactions WHERE
1082 (AccountTransactions.TransID = Transactions.TransID AND
1083 AccountTransactions.Account = '%s' AND
1084 AccountTransactions.LedgerSeq = %u AND
1085 AccountTransactions.TxnSeq %s %u)
1086 ORDER BY AccountTransactions.LedgerSeq %s,
1087 AccountTransactions.TxnSeq %s
1090 b58acct % minLedger % maxLedger % b58acct % findLedger % compare %
1091 findSeq % order % order % queryLimit);
1099 boost::optional<std::uint64_t> ledgerSeq;
1100 boost::optional<std::uint32_t> txnSeq;
1101 boost::optional<std::string>
status;
1102 soci::blob txnData(session);
1103 soci::blob txnMeta(session);
1104 soci::indicator dataPresent, metaPresent;
1106 soci::statement st =
1107 (session.prepare << sql,
1108 soci::into(ledgerSeq),
1111 soci::into(txnData, dataPresent),
1112 soci::into(txnMeta, metaPresent));
1118 if (lookingForMarker)
1120 if (findLedger == ledgerSeq.value_or(0) &&
1121 findSeq == txnSeq.value_or(0))
1123 lookingForMarker =
false;
1128 else if (numberOfResults == 0)
1131 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
1136 if (dataPresent == soci::i_ok)
1141 if (metaPresent == soci::i_ok)
1147 if (rawMeta.size() == 0)
1148 onUnsavedLedger(ledgerSeq.value_or(0));
1153 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
1156 std::move(rawMeta));
1170 return {newmarker, total};
1175 soci::session& session,
1184 session, onUnsavedLedger, onTransaction, options, page_length,
true);
1189 soci::session& session,
1198 session, onUnsavedLedger, onTransaction, options, page_length,
false);
1203 soci::session& session,
1210 "SELECT LedgerSeq,Status,RawTxn,TxnMeta "
1211 "FROM Transactions WHERE TransID='";
1217 boost::optional<std::uint64_t> ledgerSeq;
1218 boost::optional<std::string> status;
1219 Blob rawTxn, rawMeta;
1221 soci::blob sociRawTxnBlob(session), sociRawMetaBlob(session);
1222 soci::indicator txn, meta;
1224 session << sql, soci::into(ledgerSeq), soci::into(status),
1225 soci::into(sociRawTxnBlob, txn), soci::into(sociRawMetaBlob, meta);
1227 auto const got_data = session.got_data();
1229 if ((!got_data || txn != soci::i_ok || meta != soci::i_ok) && !
range)
1235 soci::indicator rti;
1238 <<
"SELECT COUNT(DISTINCT LedgerSeq) FROM Transactions WHERE "
1239 "LedgerSeq BETWEEN "
1240 <<
range->first() <<
" AND " <<
range->last() <<
";",
1241 soci::into(count, rti);
1243 if (!session.got_data() || rti != soci::i_ok)
1246 return count == (
range->last() -
range->first() + 1)
1251 convert(sociRawTxnBlob, rawTxn);
1252 convert(sociRawMetaBlob, rawMeta);
1261 return std::pair{std::move(txn),
nullptr};
1264 rangeCheckedCast<std::uint32_t>(ledgerSeq.value());
1268 return std::pair{std::move(txn), std::move(txMeta)};
1272 JLOG(app.journal(
"Ledger").warn())
1273 <<
"Unable to deserialize transaction from raw SQL value. Error: "
1285 boost::filesystem::space_info
space =
1286 boost::filesystem::space(config.legacy(
"database_path"));
1290 JLOG(j.
fatal()) <<
"Remaining free disk space is less than 512MB";
1294 if (config.useTxTables())
1297 boost::filesystem::path dbPath = dbSetup.dataDir /
TxDBName;
1298 boost::system::error_code ec;
1300 boost::filesystem::file_size(dbPath, ec);
1304 <<
"Error checking transaction db file size: " << ec.message();
1308 static auto const pageSize = [&] {
1310 session <<
"PRAGMA page_size;", soci::into(ps);
1313 static auto const maxPages = [&] {
1315 session <<
"PRAGMA max_page_count;", soci::into(mp);
1319 session <<
"PRAGMA page_count;", soci::into(pageCount);
1322 safe_cast<std::uint64_t>(freePages) * pageSize;
1324 <<
"Transaction DB pathname: " << dbPath.string()
1325 <<
"; file size: " << dbSize.
value_or(-1) <<
" bytes"
1326 <<
"; SQLite page size: " << pageSize <<
" bytes"
1327 <<
"; Free pages: " << freePages <<
"; Free space: " << freeSpace
1329 <<
"Note that this does not take into account available disk "
1335 <<
"Free SQLite space for transaction db is less than "
1336 "512MB. To fix this, rippled must be executed with the "
1337 "vacuum parameter before restarting. "
1338 "Note that this activity can take multiple days, "
1339 "depending on database size.";
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
virtual Config & config()=0
virtual beast::Journal journal(std::string const &name)=0
virtual NodeStore::Database & getNodeStore()=0
virtual TaggedCache< uint256, AcceptedLedger > & getAcceptedLedgerCache()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual TransactionMaster & getMasterTransaction()=0
virtual PendingSaves & pendingSaves()=0
int getValueFor(SizedItem item, std::optional< std::size_t > node=std::nullopt) const
Retrieve the default value for the item at the specified node size.
LockedSociSession checkoutDb()
void failedSave(std::uint32_t seq, uint256 const &hash)
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
virtual void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t ledgerSeq)=0
Store the object.
void finishWork(LedgerIndex seq)
Finish working on a ledger.
std::vector< AccountTx > AccountTxs
static std::string const & getMetaSQLInsertReplaceHeader()
bool inLedger(uint256 const &hash, std::uint32_t ledger, std::optional< uint32_t > tseq, std::optional< uint32_t > netID)
static Transaction::pointer transactionFromSQL(boost::optional< std::uint64_t > const &ledgerSeq, boost::optional< std::string > const &status, Blob const &rawTxn, Application &app)
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
T emplace_back(T... args)
int compare(SemanticVersion const &lhs, SemanticVersion const &rhs)
Compare two SemanticVersions against each other.
static std::pair< std::vector< RelationalDatabase::txnMetaLedgerType >, int > getAccountTxsB(soci::session &session, Application &app, RelationalDatabase::AccountTxOptions const &options, bool descending, beast::Journal j)
getAccountTxsB Returns the oldest or newest transactions in binary form for the account that matches ...
RelationalDatabase::CountMinMax getRowsMinMax(soci::session &session, TableType type)
getRowsMinMax Returns minimum ledger sequence, maximum ledger sequence and total number of rows in gi...
uint256 getHashByIndex(soci::session &session, LedgerIndex ledgerIndex)
getHashByIndex Returns hash of ledger with given sequence.
std::optional< LedgerInfo > getLimitedNewestLedgerInfo(soci::session &session, LedgerIndex ledgerFirstIndex, beast::Journal j)
getLimitedNewestLedgerInfo Returns info of newest ledger from ledgers with sequences greather or equa...
static std::string to_string(TableType type)
to_string Returns the name of a table according to its TableType.
std::pair< std::optional< RelationalDatabase::AccountTxMarker >, int > newestAccountTxPage(soci::session &session, std::function< void(std::uint32_t)> const &onUnsavedLedger, std::function< void(std::uint32_t, std::string const &, Blob &&, Blob &&)> const &onTransaction, RelationalDatabase::AccountTxPageOptions const &options, std::uint32_t page_length)
newestAccountTxPage Searches newest transactions for given account which match given criteria startin...
std::optional< LedgerInfo > getNewestLedgerInfo(soci::session &session, beast::Journal j)
getNewestLedgerInfo Returns info of newest saved ledger.
static std::pair< RelationalDatabase::AccountTxs, int > getAccountTxs(soci::session &session, Application &app, LedgerMaster &ledgerMaster, RelationalDatabase::AccountTxOptions const &options, bool descending, beast::Journal j)
getAccountTxs Returns the oldest or newest transactions for the account that matches the given criter...
std::pair< std::optional< RelationalDatabase::AccountTxMarker >, int > oldestAccountTxPage(soci::session &session, std::function< void(std::uint32_t)> const &onUnsavedLedger, std::function< void(std::uint32_t, std::string const &, Blob &&, Blob &&)> const &onTransaction, RelationalDatabase::AccountTxPageOptions const &options, std::uint32_t page_length)
oldestAccountTxPage Searches oldest transactions for given account which match given criteria startin...
DatabasePairValid makeLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup, beast::Journal j)
makeLedgerDBs Opens ledger and transactions databases.
void deleteByLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteByLedgerSeq Deletes all entries in given table for the ledger with given sequence.
std::size_t getRows(soci::session &session, TableType type)
getRows Returns number of rows in given table.
void deleteBeforeLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteBeforeLedgerSeq Deletes all entries in given table for the ledgers with given sequence and all ...
bool saveValidatedLedger(DatabaseCon &ldgDB, DatabaseCon &txnDB, Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
saveValidatedLedger Saves ledger into database.
std::pair< RelationalDatabase::AccountTxs, int > getOldestAccountTxs(soci::session &session, Application &app, LedgerMaster &ledgerMaster, RelationalDatabase::AccountTxOptions const &options, beast::Journal j)
getOldestAccountTxs Returns oldest transactions for given account which match given criteria starting...
std::pair< std::vector< std::shared_ptr< Transaction > >, int > getTxHistory(soci::session &session, Application &app, LedgerIndex startIndex, int quantity)
getTxHistory Returns given number of most recent transactions starting from given number of entry.
constexpr int TableTypeCount
std::optional< LedgerInfo > getLimitedOldestLedgerInfo(soci::session &session, LedgerIndex ledgerFirstIndex, beast::Journal j)
getLimitedOldestLedgerInfo Returns info of oldest ledger from ledgers with sequences greather or equa...
std::pair< std::vector< RelationalDatabase::txnMetaLedgerType >, int > getOldestAccountTxsB(soci::session &session, Application &app, RelationalDatabase::AccountTxOptions const &options, beast::Journal j)
getOldestAccountTxsB Returns oldest transactions in binary form for given account which match given c...
std::optional< LedgerInfo > getLedgerInfoByIndex(soci::session &session, LedgerIndex ledgerSeq, beast::Journal j)
getLedgerInfoByIndex Returns ledger by its sequence.
bool dbHasSpace(soci::session &session, Config const &config, beast::Journal j)
dbHasSpace Checks if given database has available space.
std::optional< LedgerInfo > getLedgerInfoByHash(soci::session &session, uint256 const &ledgerHash, beast::Journal j)
getLedgerInfoByHash Returns info of ledger with given hash.
static std::string transactionsSQL(Application &app, std::string selection, RelationalDatabase::AccountTxOptions const &options, bool descending, bool binary, bool count, beast::Journal j)
transactionsSQL Returns a SQL query for selecting the oldest or newest transactions in decoded or bin...
std::optional< LedgerIndex > getMinLedgerSeq(soci::session &session, TableType type)
getMinLedgerSeq Returns minimum ledger sequence in given table.
std::pair< RelationalDatabase::AccountTxs, int > getNewestAccountTxs(soci::session &session, Application &app, LedgerMaster &ledgerMaster, RelationalDatabase::AccountTxOptions const &options, beast::Journal j)
getNewestAccountTxs Returns newest transactions for given account which match given criteria starting...
std::pair< std::vector< RelationalDatabase::txnMetaLedgerType >, int > getNewestAccountTxsB(soci::session &session, Application &app, RelationalDatabase::AccountTxOptions const &options, beast::Journal j)
getNewestAccountTxsB Returns newest transactions in binary form for given account which match given c...
static std::optional< LedgerInfo > getLedgerInfo(soci::session &session, std::string const &sqlSuffix, beast::Journal j)
getLedgerInfo Returns the info of the ledger retrieved from the database by using the provided SQL qu...
std::optional< LedgerHashPair > getHashesByIndex(soci::session &session, LedgerIndex ledgerIndex, beast::Journal j)
getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequenc...
std::optional< LedgerIndex > getMaxLedgerSeq(soci::session &session, TableType type)
getMaxLedgerSeq Returns maximum ledger sequence in given table.
static std::pair< std::optional< RelationalDatabase::AccountTxMarker >, int > accountTxPage(soci::session &session, std::function< void(std::uint32_t)> const &onUnsavedLedger, std::function< void(std::uint32_t, std::string const &, Blob &&, Blob &&)> const &onTransaction, RelationalDatabase::AccountTxPageOptions const &options, std::uint32_t page_length, bool forward)
accountTxPage Searches for the oldest or newest transactions for the account that matches the given c...
std::variant< RelationalDatabase::AccountTx, TxSearched > getTransaction(soci::session &session, Application &app, uint256 const &id, std::optional< ClosedInterval< uint32_t > > const &range, error_code_i &ec)
getTransaction Returns transaction with given hash.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::array< char const *, 8 > TxDBInit
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::uint32_t LedgerIndex
A ledger index.
constexpr auto megabytes(T value) noexcept
DatabaseCon::Setup setup_DatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
void convert(soci::blob &from, std::vector< std::uint8_t > &to)
@ current
This was a new validation and was added.
constexpr std::array< char const *, 5 > LgrDBInit
constexpr auto kilobytes(T value) noexcept
std::vector< unsigned char > Blob
Storage for linear binary data.
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
@ ledgerMaster
ledger master data for signing
@ transactionID
transaction plus signature to give transaction ID
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
bool pendSaveValidated(Application &app, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger Returns false on error.
std::array< std::string, 1 > lgrPragma
Config::StartUpType startUp
std::array< std::string, 4 > txPragma
LedgerIndex maxLedgerSequence
LedgerIndex minLedgerSequence