20#include <xrpld/app/ledger/AcceptedLedger.h>
21#include <xrpld/app/ledger/LedgerMaster.h>
22#include <xrpld/app/ledger/LedgerToJson.h>
23#include <xrpld/app/ledger/PendingSaves.h>
24#include <xrpld/app/ledger/TransactionMaster.h>
25#include <xrpld/app/rdb/RelationalDatabase.h>
26#include <xrpld/app/rdb/backend/detail/Node.h>
27#include <xrpld/core/DatabaseCon.h>
28#include <xrpld/core/SociDB.h>
30#include <xrpl/basics/BasicConfig.h>
31#include <xrpl/basics/StringUtilities.h>
32#include <xrpl/json/to_string.h>
34#include <boost/range/adaptor/transformed.hpp>
36#include <soci/sqlite3/soci-sqlite3.h>
51 "Need to modify switch statement if enum is modified");
58 return "Transactions";
60 return "AccountTransactions";
63 UNREACHABLE(
"ripple::detail::to_string : invalid TableType");
79 lgr->getSession() << boost::str(
80 boost::format(
"PRAGMA cache_size=-%d;") %
88 tx->getSession() << boost::str(
89 boost::format(
"PRAGMA cache_size=-%d;") %
101 (tx->getSession().prepare
102 << (
"PRAGMA table_info(AccountTransactions);"),
107 soci::into(dflt_value, ind),
115 return {std::move(lgr), std::move(tx),
false};
120 return {std::move(lgr), std::move(tx),
true};
123 return {std::move(lgr), {},
true};
131 boost::optional<LedgerIndex> m;
132 session << query, soci::into(m);
141 boost::optional<LedgerIndex> m;
142 session << query, soci::into(m);
149 session <<
"DELETE FROM " <<
to_string(type)
150 <<
" WHERE LedgerSeq == " << ledgerSeq <<
";";
155 soci::session& session,
159 session <<
"DELETE FROM " <<
to_string(type) <<
" WHERE LedgerSeq < "
167 session <<
"SELECT COUNT(*) AS rows "
179 session <<
"SELECT COUNT(*) AS rows, "
180 "MIN(LedgerSeq) AS first, "
181 "MAX(LedgerSeq) AS last "
198 auto j = app.
journal(
"Ledger");
199 auto seq = ledger->info().seq;
202 JLOG(j.trace()) <<
"saveValidatedLedger " << (
current ?
"" :
"fromAcquire ")
205 if (!ledger->info().accountHash.isNonZero())
208 JLOG(j.fatal()) <<
"AH is zero: " <<
getJson({*ledger, {}});
209 UNREACHABLE(
"ripple::detail::saveValidatedLedger : zero account hash");
213 if (ledger->info().accountHash != ledger->stateMap().getHash().as_uint256())
216 JLOG(j.fatal()) <<
"sAL: " << ledger->info().accountHash
217 <<
" != " << ledger->stateMap().getHash();
218 JLOG(j.fatal()) <<
"saveAcceptedLedger: seq=" << seq
221 "ripple::detail::saveValidatedLedger : mismatched account hash");
226 ledger->info().txHash == ledger->txMap().getHash().as_uint256(),
227 "ripple::detail::saveValidatedLedger : transaction hash match");
233 addRaw(ledger->info(), s);
246 ledger->info().hash, aLedger);
251 JLOG(j.warn()) <<
"An accepted ledger was missing nodes";
260 static boost::format deleteLedger(
261 "DELETE FROM Ledgers WHERE LedgerSeq = %u;");
262 static boost::format deleteTrans1(
263 "DELETE FROM Transactions WHERE LedgerSeq = %u;");
264 static boost::format deleteTrans2(
265 "DELETE FROM AccountTransactions WHERE LedgerSeq = %u;");
266 static boost::format deleteAcctTrans(
267 "DELETE FROM AccountTransactions WHERE TransID = '%s';");
271 *db << boost::str(deleteLedger % seq);
278 soci::transaction tr(*db);
280 *db << boost::str(deleteTrans1 % seq);
281 *db << boost::str(deleteTrans2 % seq);
285 for (
auto const& acceptedLedgerTx : *aLedger)
295 auto const& accts = acceptedLedgerTx->getAffected();
300 "INSERT INTO AccountTransactions "
301 "(TransID, Account, LedgerSeq, TxnSeq) VALUES ");
309 for (
auto const& account : accts)
329 JLOG(j.trace()) <<
"ActTx: " << sql;
332 else if (
auto const& sleTxn = acceptedLedgerTx->getTxn();
337 JLOG(j.warn()) <<
"Transaction in ledger " << seq
338 <<
" affects no accounts";
344 acceptedLedgerTx->getTxn()->getMetaSQL(
345 seq, acceptedLedgerTx->getEscMeta()) +
351 acceptedLedgerTx->getTxnSeq(),
360 R
"sql(INSERT OR REPLACE INTO Ledgers
361 (LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,
362 CloseTimeRes,CloseFlags,AccountSetHash,TransSetHash)
364 (:ledgerHash,:ledgerSeq,:prevHash,:totalCoins,:closingTime,:prevClosingTime,
365 :closeTimeRes,:closeFlags,:accountSetHash,:transSetHash);)sql");
369 soci::transaction tr(*db);
371 auto const hash =
to_string(ledger->info().hash);
372 auto const parentHash =
to_string(ledger->info().parentHash);
373 auto const drops =
to_string(ledger->info().drops);
374 auto const closeTime =
375 ledger->info().closeTime.time_since_epoch().count();
376 auto const parentCloseTime =
377 ledger->info().parentCloseTime.time_since_epoch().count();
378 auto const closeTimeResolution =
379 ledger->info().closeTimeResolution.count();
380 auto const closeFlags = ledger->info().closeFlags;
381 auto const accountHash =
to_string(ledger->info().accountHash);
382 auto const txHash =
to_string(ledger->info().txHash);
384 *db << addLedger, soci::use(hash), soci::use(seq),
385 soci::use(parentHash), soci::use(drops), soci::use(closeTime),
386 soci::use(parentCloseTime), soci::use(closeTimeResolution),
387 soci::use(closeFlags), soci::use(accountHash),
407 soci::session& session,
412 boost::optional<std::string> hash, parentHash, accountHash, txHash;
413 boost::optional<std::uint64_t> seq, drops, closeTime, parentCloseTime,
414 closeTimeResolution, closeFlags;
418 "LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
420 "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
421 "LedgerSeq FROM Ledgers " +
424 session << sql, soci::into(hash), soci::into(parentHash),
425 soci::into(accountHash), soci::into(txHash), soci::into(drops),
426 soci::into(closeTime), soci::into(parentCloseTime),
427 soci::into(closeTimeResolution), soci::into(closeFlags),
430 if (!session.got_data())
432 JLOG(j.
debug()) <<
"Ledger not found: " << sqlSuffix;
441 if (hash && !info.hash.parseHex(*hash))
443 JLOG(j.
debug()) <<
"Hash parse error for ledger: " << sqlSuffix;
447 if (parentHash && !info.parentHash.parseHex(*parentHash))
449 JLOG(j.
debug()) <<
"parentHash parse error for ledger: " << sqlSuffix;
453 if (accountHash && !info.accountHash.parseHex(*accountHash))
455 JLOG(j.
debug()) <<
"accountHash parse error for ledger: " << sqlSuffix;
459 if (txHash && !info.txHash.parseHex(*txHash))
461 JLOG(j.
debug()) <<
"txHash parse error for ledger: " << sqlSuffix;
465 info.seq = rangeCheckedCast<std::uint32_t>(seq.value_or(0));
466 info.drops =
drops.value_or(0);
467 info.closeTime = time_point{duration{closeTime.value_or(0)}};
468 info.parentCloseTime = time_point{duration{parentCloseTime.value_or(0)}};
469 info.closeFlags = closeFlags.value_or(0);
470 info.closeTimeResolution = duration{closeTimeResolution.value_or(0)};
477 soci::session& session,
482 s <<
"WHERE LedgerSeq = " << ledgerSeq;
490 s <<
"ORDER BY LedgerSeq DESC LIMIT 1";
496 soci::session& session,
502 " ORDER BY LedgerSeq ASC LIMIT 1";
508 soci::session& session,
514 " ORDER BY LedgerSeq DESC LIMIT 1";
520 soci::session& session,
525 s <<
"WHERE LedgerHash = '" << ledgerHash <<
"'";
535 "SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
542 boost::optional<std::string> lh;
543 session << sql, soci::into(lh);
545 if (!session.got_data() || !lh)
561 soci::session& session,
566 boost::optional<std::string> lhO, phO;
568 session <<
"SELECT LedgerHash,PrevHash FROM Ledgers "
569 "INDEXED BY SeqLedger WHERE LedgerSeq = :ls;",
570 soci::into(lhO), soci::into(phO), soci::use(ledgerIndex);
574 auto stream = j.
trace();
575 JLOG(stream) <<
"Don't have ledger " << ledgerIndex;
579 LedgerHashPair hashes;
580 if (!hashes.ledgerHash.parseHex(*lhO) || !hashes.parentHash.parseHex(*phO))
582 auto stream = j.
trace();
583 JLOG(stream) <<
"Error parse hashes for ledger " << ledgerIndex;
592 soci::session& session,
598 "SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
600 sql.
append(
" AND LedgerSeq <= ");
607 boost::optional<std::string> ph;
609 (session.prepare << sql,
621 JLOG(j.
warn()) <<
"Error parsed hash for ledger seq: " << ls;
625 JLOG(j.
warn()) <<
"Null prev hash for ledger seq: " << ls;
629 JLOG(j.
warn()) <<
"Error parsed prev hash for ledger seq: " << ls;
637 soci::session& session,
644 "SELECT LedgerSeq, Status, RawTxn "
645 "FROM Transactions ORDER BY LedgerSeq DESC LIMIT %u,%u;") %
646 startIndex % quantity);
653 boost::optional<std::uint64_t> ledgerSeq;
654 boost::optional<std::string> status;
655 soci::blob sociRawTxnBlob(session);
660 (session.prepare << sql,
661 soci::into(ledgerSeq),
663 soci::into(sociRawTxnBlob, rti));
668 if (soci::i_ok == rti)
669 convert(sociRawTxnBlob, rawTxn);
674 ledgerSeq, status, rawTxn, app))
706 RelationalDatabase::AccountTxOptions
const& options,
721 else if (options.limit == UINT32_MAX)
723 numberOfResults = binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH;
725 else if (!options.bUnlimited)
728 binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH, options.limit);
732 numberOfResults = options.limit;
738 if (options.maxLedger)
740 maxClause = boost::str(
741 boost::format(
"AND AccountTransactions.LedgerSeq <= '%u'") %
745 if (options.minLedger)
747 minClause = boost::str(
748 boost::format(
"AND AccountTransactions.LedgerSeq >= '%u'") %
756 boost::format(
"SELECT %s FROM AccountTransactions "
757 "WHERE Account = '%s' %s %s LIMIT %u, %u;") %
758 selection %
toBase58(options.account) % maxClause % minClause %
759 options.offset % numberOfResults);
764 "AccountTransactions INNER JOIN Transactions "
765 "ON Transactions.TransID = AccountTransactions.TransID "
766 "WHERE Account = '%s' %s %s "
767 "ORDER BY AccountTransactions.LedgerSeq %s, "
768 "AccountTransactions.TxnSeq %s, AccountTransactions.TransID %s "
770 selection %
toBase58(options.account) % maxClause % minClause %
771 (descending ?
"DESC" :
"ASC") % (descending ?
"DESC" :
"ASC") %
772 (descending ?
"DESC" :
"ASC") % options.offset % numberOfResults);
773 JLOG(j.
trace()) <<
"txSQL query: " << sql;
800 soci::session& session,
803 RelationalDatabase::AccountTxOptions
const& options,
811 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
823 boost::optional<std::uint64_t> ledgerSeq;
824 boost::optional<std::string>
status;
825 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
826 soci::indicator rti, tmi;
827 Blob rawTxn, txnMeta;
830 (session.prepare << sql,
831 soci::into(ledgerSeq),
833 soci::into(sociTxnBlob, rti),
834 soci::into(sociTxnMetaBlob, tmi));
839 if (soci::i_ok == rti)
844 if (soci::i_ok == tmi)
845 convert(sociTxnMetaBlob, txnMeta);
855 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
858 <<
"Recovering ledger " << seq <<
", txn " << txn->getID();
869 txn->getID(), txn->getLedger(), txnMeta));
880 soci::session& session,
883 RelationalDatabase::AccountTxOptions
const& options,
891 soci::session& session,
922 soci::session& session,
924 RelationalDatabase::AccountTxOptions
const& options,
932 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
945 boost::optional<std::uint64_t> ledgerSeq;
946 boost::optional<std::string>
status;
947 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
948 soci::indicator rti, tmi;
951 (session.prepare << sql,
952 soci::into(ledgerSeq),
954 soci::into(sociTxnBlob, rti),
955 soci::into(sociTxnMetaBlob, tmi));
961 if (soci::i_ok == rti)
964 if (soci::i_ok == tmi)
965 convert(sociTxnMetaBlob, txnMeta);
968 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
970 ret.
emplace_back(std::move(rawTxn), std::move(txnMeta), seq);
980 soci::session& session,
982 RelationalDatabase::AccountTxOptions
const& options,
990 soci::session& session,
1019 soci::session& session,
1024 RelationalDatabase::AccountTxPageOptions
const& options,
1030 bool lookingForMarker = options.marker.has_value();
1034 if (options.limit == 0 || options.limit == UINT32_MAX ||
1035 (options.limit > page_length && !options.bAdmin))
1036 numberOfResults = page_length;
1038 numberOfResults = options.limit;
1048 if (lookingForMarker)
1050 findLedger = options.marker->ledgerSeq;
1051 findSeq = options.marker->txnSeq;
1057 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1058 Status,RawTxn,TxnMeta
1059 FROM AccountTransactions INNER JOIN Transactions
1060 ON Transactions.TransID = AccountTransactions.TransID
1061 AND AccountTransactions.Account = '%s' WHERE
1068 char const*
const order =
forward ?
"ASC" :
"DESC";
1070 if (findLedger == 0)
1074 prefix + (R
"(AccountTransactions.LedgerSeq BETWEEN %u AND %u
1075 ORDER BY AccountTransactions.LedgerSeq %s,
1076 AccountTransactions.TxnSeq %s
1078 toBase58(options.account) % options.minLedger % options.maxLedger %
1079 order % order % queryLimit);
1085 forward ? findLedger + 1 : options.minLedger;
1087 forward ? options.maxLedger : findLedger - 1;
1089 auto b58acct =
toBase58(options.account);
1092 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1093 Status,RawTxn,TxnMeta
1094 FROM AccountTransactions, Transactions WHERE
1095 (AccountTransactions.TransID = Transactions.TransID AND
1096 AccountTransactions.Account = '%s' AND
1097 AccountTransactions.LedgerSeq BETWEEN %u AND %u)
1099 SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,Status,RawTxn,TxnMeta
1100 FROM AccountTransactions, Transactions WHERE
1101 (AccountTransactions.TransID = Transactions.TransID AND
1102 AccountTransactions.Account = '%s' AND
1103 AccountTransactions.LedgerSeq = %u AND
1104 AccountTransactions.TxnSeq %s %u)
1105 ORDER BY AccountTransactions.LedgerSeq %s,
1106 AccountTransactions.TxnSeq %s
1109 b58acct % minLedger % maxLedger % b58acct % findLedger % compare %
1110 findSeq % order % order % queryLimit);
1118 boost::optional<std::uint64_t> ledgerSeq;
1119 boost::optional<std::uint32_t> txnSeq;
1120 boost::optional<std::string>
status;
1121 soci::blob txnData(session);
1122 soci::blob txnMeta(session);
1123 soci::indicator dataPresent, metaPresent;
1125 soci::statement st =
1126 (session.prepare << sql,
1127 soci::into(ledgerSeq),
1130 soci::into(txnData, dataPresent),
1131 soci::into(txnMeta, metaPresent));
1137 if (lookingForMarker)
1139 if (findLedger == ledgerSeq.value_or(0) &&
1140 findSeq == txnSeq.value_or(0))
1142 lookingForMarker =
false;
1147 else if (numberOfResults == 0)
1150 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
1155 if (dataPresent == soci::i_ok)
1160 if (metaPresent == soci::i_ok)
1166 if (rawMeta.size() == 0)
1167 onUnsavedLedger(ledgerSeq.value_or(0));
1172 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
1175 std::move(rawMeta));
1189 return {newmarker, total};
1194 soci::session& session,
1203 session, onUnsavedLedger, onTransaction, options, page_length,
true);
1208 soci::session& session,
1217 session, onUnsavedLedger, onTransaction, options, page_length,
false);
1222 soci::session& session,
1229 "SELECT LedgerSeq,Status,RawTxn,TxnMeta "
1230 "FROM Transactions WHERE TransID='";
1236 boost::optional<std::uint64_t> ledgerSeq;
1237 boost::optional<std::string> status;
1238 Blob rawTxn, rawMeta;
1240 soci::blob sociRawTxnBlob(session), sociRawMetaBlob(session);
1241 soci::indicator txn, meta;
1243 session << sql, soci::into(ledgerSeq), soci::into(status),
1244 soci::into(sociRawTxnBlob, txn), soci::into(sociRawMetaBlob, meta);
1246 auto const got_data = session.got_data();
1248 if ((!got_data || txn != soci::i_ok || meta != soci::i_ok) && !
range)
1254 soci::indicator rti;
1257 <<
"SELECT COUNT(DISTINCT LedgerSeq) FROM Transactions WHERE "
1258 "LedgerSeq BETWEEN "
1259 <<
range->first() <<
" AND " <<
range->last() <<
";",
1260 soci::into(count, rti);
1262 if (!session.got_data() || rti != soci::i_ok)
1265 return count == (
range->last() -
range->first() + 1)
1270 convert(sociRawTxnBlob, rawTxn);
1271 convert(sociRawMetaBlob, rawMeta);
1280 return std::pair{std::move(txn),
nullptr};
1283 rangeCheckedCast<std::uint32_t>(ledgerSeq.value());
1287 return std::pair{std::move(txn), std::move(txMeta)};
1291 JLOG(app.journal(
"Ledger").warn())
1292 <<
"Unable to deserialize transaction from raw SQL value. Error: "
1304 boost::filesystem::space_info
space =
1305 boost::filesystem::space(config.legacy(
"database_path"));
1309 JLOG(j.
fatal()) <<
"Remaining free disk space is less than 512MB";
1313 if (config.useTxTables())
1316 boost::filesystem::path dbPath = dbSetup.dataDir /
TxDBName;
1317 boost::system::error_code ec;
1319 boost::filesystem::file_size(dbPath, ec);
1323 <<
"Error checking transaction db file size: " << ec.message();
1327 static auto const pageSize = [&] {
1329 session <<
"PRAGMA page_size;", soci::into(ps);
1332 static auto const maxPages = [&] {
1334 session <<
"PRAGMA max_page_count;", soci::into(mp);
1338 session <<
"PRAGMA page_count;", soci::into(pageCount);
1341 safe_cast<std::uint64_t>(freePages) * pageSize;
1343 <<
"Transaction DB pathname: " << dbPath.string()
1344 <<
"; file size: " << dbSize.
value_or(-1) <<
" bytes"
1345 <<
"; SQLite page size: " << pageSize <<
" bytes"
1346 <<
"; Free pages: " << freePages <<
"; Free space: " << freeSpace
1348 <<
"Note that this does not take into account available disk "
1354 <<
"Free SQLite space for transaction db is less than "
1355 "512MB. To fix this, rippled must be executed with the "
1356 "vacuum parameter before restarting. "
1357 "Note that this activity can take multiple days, "
1358 "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