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/misc/Manifest.h>
26#include <xrpld/app/rdb/RelationalDatabase.h>
27#include <xrpld/app/rdb/backend/detail/Node.h>
28#include <xrpld/core/DatabaseCon.h>
29#include <xrpld/core/SociDB.h>
30#include <xrpl/basics/BasicConfig.h>
31#include <xrpl/basics/StringUtilities.h>
32#include <xrpl/json/to_string.h>
33#include <boost/algorithm/string.hpp>
34#include <boost/range/adaptor/transformed.hpp>
35#include <soci/sqlite3/soci-sqlite3.h>
50 "Need to modify switch statement if enum is modified");
57 return "Transactions";
59 return "AccountTransactions";
61 UNREACHABLE(
"ripple::detail::to_string : invalid TableType");
74 auto lgr{std::make_unique<DatabaseCon>(
76 lgr->getSession() << boost::str(
77 boost::format(
"PRAGMA cache_size=-%d;") %
83 auto tx{std::make_unique<DatabaseCon>(
85 tx->getSession() << boost::str(
86 boost::format(
"PRAGMA cache_size=-%d;") %
98 (tx->getSession().prepare
99 << (
"PRAGMA table_info(AccountTransactions);"),
104 soci::into(dflt_value, ind),
112 return {std::move(lgr), std::move(tx),
false};
117 return {std::move(lgr), std::move(tx),
true};
120 return {std::move(lgr), {},
true};
128 boost::optional<LedgerIndex> m;
129 session << query, soci::into(m);
138 boost::optional<LedgerIndex> m;
139 session << query, soci::into(m);
146 session <<
"DELETE FROM " <<
to_string(type)
147 <<
" WHERE LedgerSeq == " << ledgerSeq <<
";";
152 soci::session& session,
156 session <<
"DELETE FROM " <<
to_string(type) <<
" WHERE LedgerSeq < "
164 session <<
"SELECT COUNT(*) AS rows "
176 session <<
"SELECT COUNT(*) AS rows, "
177 "MIN(LedgerSeq) AS first, "
178 "MAX(LedgerSeq) AS last "
195 auto j = app.
journal(
"Ledger");
196 auto seq = ledger->info().seq;
199 JLOG(j.trace()) <<
"saveValidatedLedger " << (
current ?
"" :
"fromAcquire ")
202 if (!ledger->info().accountHash.isNonZero())
204 JLOG(j.fatal()) <<
"AH is zero: " <<
getJson({*ledger, {}});
205 UNREACHABLE(
"ripple::detail::saveValidatedLedger : zero account hash");
208 if (ledger->info().accountHash != ledger->stateMap().getHash().as_uint256())
210 JLOG(j.fatal()) <<
"sAL: " << ledger->info().accountHash
211 <<
" != " << ledger->stateMap().getHash();
212 JLOG(j.fatal()) <<
"saveAcceptedLedger: seq=" << seq
215 "ripple::detail::saveValidatedLedger : mismatched account hash");
219 ledger->info().txHash == ledger->txMap().getHash().as_uint256(),
220 "ripple::detail::saveValidatedLedger : transaction hash match");
226 addRaw(ledger->info(), s);
237 aLedger = std::make_shared<AcceptedLedger>(ledger, app);
239 ledger->info().hash, aLedger);
244 JLOG(j.warn()) <<
"An accepted ledger was missing nodes";
253 static boost::format deleteLedger(
254 "DELETE FROM Ledgers WHERE LedgerSeq = %u;");
255 static boost::format deleteTrans1(
256 "DELETE FROM Transactions WHERE LedgerSeq = %u;");
257 static boost::format deleteTrans2(
258 "DELETE FROM AccountTransactions WHERE LedgerSeq = %u;");
259 static boost::format deleteAcctTrans(
260 "DELETE FROM AccountTransactions WHERE TransID = '%s';");
264 *db << boost::str(deleteLedger % seq);
271 soci::transaction tr(*db);
273 *db << boost::str(deleteTrans1 % seq);
274 *db << boost::str(deleteTrans2 % seq);
278 for (
auto const& acceptedLedgerTx : *aLedger)
288 auto const& accts = acceptedLedgerTx->getAffected();
293 "INSERT INTO AccountTransactions "
294 "(TransID, Account, LedgerSeq, TxnSeq) VALUES ");
302 for (
auto const& account : accts)
322 JLOG(j.trace()) <<
"ActTx: " << sql;
325 else if (
auto const& sleTxn = acceptedLedgerTx->getTxn();
330 JLOG(j.warn()) <<
"Transaction in ledger " << seq
331 <<
" affects no accounts";
337 acceptedLedgerTx->getTxn()->getMetaSQL(
338 seq, acceptedLedgerTx->getEscMeta()) +
349 R
"sql(INSERT OR REPLACE INTO Ledgers
350 (LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,
351 CloseTimeRes,CloseFlags,AccountSetHash,TransSetHash)
353 (:ledgerHash,:ledgerSeq,:prevHash,:totalCoins,:closingTime,:prevClosingTime,
354 :closeTimeRes,:closeFlags,:accountSetHash,:transSetHash);)sql");
358 soci::transaction tr(*db);
360 auto const hash =
to_string(ledger->info().hash);
361 auto const parentHash =
to_string(ledger->info().parentHash);
362 auto const drops =
to_string(ledger->info().drops);
363 auto const closeTime =
364 ledger->info().closeTime.time_since_epoch().count();
365 auto const parentCloseTime =
366 ledger->info().parentCloseTime.time_since_epoch().count();
367 auto const closeTimeResolution =
368 ledger->info().closeTimeResolution.count();
369 auto const closeFlags = ledger->info().closeFlags;
370 auto const accountHash =
to_string(ledger->info().accountHash);
371 auto const txHash =
to_string(ledger->info().txHash);
373 *db << addLedger, soci::use(hash), soci::use(seq),
374 soci::use(parentHash), soci::use(drops), soci::use(closeTime),
375 soci::use(parentCloseTime), soci::use(closeTimeResolution),
376 soci::use(closeFlags), soci::use(accountHash),
396 soci::session& session,
401 boost::optional<std::string> hash, parentHash, accountHash, txHash;
402 boost::optional<std::uint64_t> seq, drops, closeTime, parentCloseTime,
403 closeTimeResolution, closeFlags;
407 "LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
409 "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
410 "LedgerSeq FROM Ledgers " +
413 session << sql, soci::into(hash), soci::into(parentHash),
414 soci::into(accountHash), soci::into(txHash), soci::into(drops),
415 soci::into(closeTime), soci::into(parentCloseTime),
416 soci::into(closeTimeResolution), soci::into(closeFlags),
419 if (!session.got_data())
421 JLOG(j.
debug()) <<
"Ledger not found: " << sqlSuffix;
430 if (hash && !info.hash.parseHex(*hash))
432 JLOG(j.
debug()) <<
"Hash parse error for ledger: " << sqlSuffix;
436 if (parentHash && !info.parentHash.parseHex(*parentHash))
438 JLOG(j.
debug()) <<
"parentHash parse error for ledger: " << sqlSuffix;
442 if (accountHash && !info.accountHash.parseHex(*accountHash))
444 JLOG(j.
debug()) <<
"accountHash parse error for ledger: " << sqlSuffix;
448 if (txHash && !info.txHash.parseHex(*txHash))
450 JLOG(j.
debug()) <<
"txHash parse error for ledger: " << sqlSuffix;
454 info.seq = rangeCheckedCast<std::uint32_t>(seq.value_or(0));
455 info.drops =
drops.value_or(0);
456 info.closeTime = time_point{duration{closeTime.value_or(0)}};
457 info.parentCloseTime = time_point{duration{parentCloseTime.value_or(0)}};
458 info.closeFlags = closeFlags.value_or(0);
459 info.closeTimeResolution = duration{closeTimeResolution.value_or(0)};
466 soci::session& session,
471 s <<
"WHERE LedgerSeq = " << ledgerSeq;
479 s <<
"ORDER BY LedgerSeq DESC LIMIT 1";
485 soci::session& session,
491 " ORDER BY LedgerSeq ASC LIMIT 1";
497 soci::session& session,
503 " ORDER BY LedgerSeq DESC LIMIT 1";
509 soci::session& session,
514 s <<
"WHERE LedgerHash = '" << ledgerHash <<
"'";
524 "SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
531 boost::optional<std::string> lh;
532 session << sql, soci::into(lh);
534 if (!session.got_data() || !lh)
550 soci::session& session,
555 boost::optional<std::string> lhO, phO;
557 session <<
"SELECT LedgerHash,PrevHash FROM Ledgers "
558 "INDEXED BY SeqLedger WHERE LedgerSeq = :ls;",
559 soci::into(lhO), soci::into(phO), soci::use(ledgerIndex);
563 auto stream = j.
trace();
564 JLOG(stream) <<
"Don't have ledger " << ledgerIndex;
568 LedgerHashPair hashes;
569 if (!hashes.ledgerHash.parseHex(*lhO) || !hashes.parentHash.parseHex(*phO))
571 auto stream = j.
trace();
572 JLOG(stream) <<
"Error parse hashes for ledger " << ledgerIndex;
581 soci::session& session,
587 "SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
589 sql.
append(
" AND LedgerSeq <= ");
596 boost::optional<std::string> ph;
598 (session.prepare << sql,
610 JLOG(j.
warn()) <<
"Error parsed hash for ledger seq: " << ls;
614 JLOG(j.
warn()) <<
"Null prev hash for ledger seq: " << ls;
618 JLOG(j.
warn()) <<
"Error parsed prev hash for ledger seq: " << ls;
626 soci::session& session,
633 "SELECT LedgerSeq, Status, RawTxn "
634 "FROM Transactions ORDER BY LedgerSeq DESC LIMIT %u,%u;") %
635 startIndex % quantity);
642 boost::optional<std::uint64_t> ledgerSeq;
643 boost::optional<std::string> status;
644 soci::blob sociRawTxnBlob(session);
649 (session.prepare << sql,
650 soci::into(ledgerSeq),
652 soci::into(sociRawTxnBlob, rti));
657 if (soci::i_ok == rti)
658 convert(sociRawTxnBlob, rawTxn);
663 ledgerSeq, status, rawTxn, app))
695 RelationalDatabase::AccountTxOptions
const& options,
710 else if (options.limit == UINT32_MAX)
712 numberOfResults = binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH;
714 else if (!options.bUnlimited)
717 binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH, options.limit);
721 numberOfResults = options.limit;
727 if (options.maxLedger)
729 maxClause = boost::str(
730 boost::format(
"AND AccountTransactions.LedgerSeq <= '%u'") %
734 if (options.minLedger)
736 minClause = boost::str(
737 boost::format(
"AND AccountTransactions.LedgerSeq >= '%u'") %
745 boost::format(
"SELECT %s FROM AccountTransactions "
746 "WHERE Account = '%s' %s %s LIMIT %u, %u;") %
747 selection %
toBase58(options.account) % maxClause % minClause %
748 options.offset % numberOfResults);
753 "AccountTransactions INNER JOIN Transactions "
754 "ON Transactions.TransID = AccountTransactions.TransID "
755 "WHERE Account = '%s' %s %s "
756 "ORDER BY AccountTransactions.LedgerSeq %s, "
757 "AccountTransactions.TxnSeq %s, AccountTransactions.TransID %s "
759 selection %
toBase58(options.account) % maxClause % minClause %
760 (descending ?
"DESC" :
"ASC") % (descending ?
"DESC" :
"ASC") %
761 (descending ?
"DESC" :
"ASC") % options.offset % numberOfResults);
762 JLOG(j.
trace()) <<
"txSQL query: " << sql;
789 soci::session& session,
792 RelationalDatabase::AccountTxOptions
const& options,
800 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
812 boost::optional<std::uint64_t> ledgerSeq;
813 boost::optional<std::string>
status;
814 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
815 soci::indicator rti, tmi;
816 Blob rawTxn, txnMeta;
819 (session.prepare << sql,
820 soci::into(ledgerSeq),
822 soci::into(sociTxnBlob, rti),
823 soci::into(sociTxnMetaBlob, tmi));
828 if (soci::i_ok == rti)
833 if (soci::i_ok == tmi)
834 convert(sociTxnMetaBlob, txnMeta);
844 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
847 <<
"Recovering ledger " << seq <<
", txn " << txn->getID();
857 std::make_shared<TxMeta>(
858 txn->getID(), txn->getLedger(), txnMeta));
869 soci::session& session,
872 RelationalDatabase::AccountTxOptions
const& options,
880 soci::session& session,
911 soci::session& session,
913 RelationalDatabase::AccountTxOptions
const& options,
921 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
934 boost::optional<std::uint64_t> ledgerSeq;
935 boost::optional<std::string>
status;
936 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
937 soci::indicator rti, tmi;
940 (session.prepare << sql,
941 soci::into(ledgerSeq),
943 soci::into(sociTxnBlob, rti),
944 soci::into(sociTxnMetaBlob, tmi));
950 if (soci::i_ok == rti)
953 if (soci::i_ok == tmi)
954 convert(sociTxnMetaBlob, txnMeta);
957 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
959 ret.
emplace_back(std::move(rawTxn), std::move(txnMeta), seq);
969 soci::session& session,
971 RelationalDatabase::AccountTxOptions
const& options,
979 soci::session& session,
1008 soci::session& session,
1013 RelationalDatabase::AccountTxPageOptions
const& options,
1019 bool lookingForMarker = options.marker.has_value();
1023 if (options.limit == 0 || options.limit == UINT32_MAX ||
1024 (options.limit > page_length && !options.bAdmin))
1025 numberOfResults = page_length;
1027 numberOfResults = options.limit;
1037 if (lookingForMarker)
1039 findLedger = options.marker->ledgerSeq;
1040 findSeq = options.marker->txnSeq;
1046 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1047 Status,RawTxn,TxnMeta
1048 FROM AccountTransactions INNER JOIN Transactions
1049 ON Transactions.TransID = AccountTransactions.TransID
1050 AND AccountTransactions.Account = '%s' WHERE
1057 const char*
const order =
forward ?
"ASC" :
"DESC";
1059 if (findLedger == 0)
1063 prefix + (R
"(AccountTransactions.LedgerSeq BETWEEN %u AND %u
1064 ORDER BY AccountTransactions.LedgerSeq %s,
1065 AccountTransactions.TxnSeq %s
1067 toBase58(options.account) % options.minLedger % options.maxLedger %
1068 order % order % queryLimit);
1074 forward ? findLedger + 1 : options.minLedger;
1076 forward ? options.maxLedger : findLedger - 1;
1078 auto b58acct =
toBase58(options.account);
1081 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1082 Status,RawTxn,TxnMeta
1083 FROM AccountTransactions, Transactions WHERE
1084 (AccountTransactions.TransID = Transactions.TransID AND
1085 AccountTransactions.Account = '%s' AND
1086 AccountTransactions.LedgerSeq BETWEEN %u AND %u)
1088 SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,Status,RawTxn,TxnMeta
1089 FROM AccountTransactions, Transactions WHERE
1090 (AccountTransactions.TransID = Transactions.TransID AND
1091 AccountTransactions.Account = '%s' AND
1092 AccountTransactions.LedgerSeq = %u AND
1093 AccountTransactions.TxnSeq %s %u)
1094 ORDER BY AccountTransactions.LedgerSeq %s,
1095 AccountTransactions.TxnSeq %s
1098 b58acct % minLedger % maxLedger % b58acct % findLedger % compare %
1099 findSeq % order % order % queryLimit);
1107 boost::optional<std::uint64_t> ledgerSeq;
1108 boost::optional<std::uint32_t> txnSeq;
1109 boost::optional<std::string>
status;
1110 soci::blob txnData(session);
1111 soci::blob txnMeta(session);
1112 soci::indicator dataPresent, metaPresent;
1114 soci::statement st =
1115 (session.prepare << sql,
1116 soci::into(ledgerSeq),
1119 soci::into(txnData, dataPresent),
1120 soci::into(txnMeta, metaPresent));
1126 if (lookingForMarker)
1128 if (findLedger == ledgerSeq.value_or(0) &&
1129 findSeq == txnSeq.value_or(0))
1131 lookingForMarker =
false;
1136 else if (numberOfResults == 0)
1139 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
1144 if (dataPresent == soci::i_ok)
1149 if (metaPresent == soci::i_ok)
1155 if (rawMeta.size() == 0)
1156 onUnsavedLedger(ledgerSeq.value_or(0));
1161 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
1164 std::move(rawMeta));
1178 return {newmarker, total};
1183 soci::session& session,
1192 session, onUnsavedLedger, onTransaction, options, page_length,
true);
1197 soci::session& session,
1206 session, onUnsavedLedger, onTransaction, options, page_length,
false);
1211 soci::session& session,
1218 "SELECT LedgerSeq,Status,RawTxn,TxnMeta "
1219 "FROM Transactions WHERE TransID='";
1225 boost::optional<std::uint64_t> ledgerSeq;
1226 boost::optional<std::string> status;
1227 Blob rawTxn, rawMeta;
1229 soci::blob sociRawTxnBlob(session), sociRawMetaBlob(session);
1230 soci::indicator txn, meta;
1232 session << sql, soci::into(ledgerSeq), soci::into(status),
1233 soci::into(sociRawTxnBlob, txn), soci::into(sociRawMetaBlob, meta);
1235 auto const got_data = session.got_data();
1237 if ((!got_data || txn != soci::i_ok || meta != soci::i_ok) && !
range)
1243 soci::indicator rti;
1246 <<
"SELECT COUNT(DISTINCT LedgerSeq) FROM Transactions WHERE "
1247 "LedgerSeq BETWEEN "
1248 <<
range->first() <<
" AND " <<
range->last() <<
";",
1249 soci::into(count, rti);
1251 if (!session.got_data() || rti != soci::i_ok)
1254 return count == (
range->last() -
range->first() + 1)
1259 convert(sociRawTxnBlob, rawTxn);
1260 convert(sociRawMetaBlob, rawMeta);
1269 return std::pair{std::move(txn),
nullptr};
1272 rangeCheckedCast<std::uint32_t>(ledgerSeq.value());
1274 auto txMeta = std::make_shared<TxMeta>(
id, inLedger, rawMeta);
1276 return std::pair{std::move(txn), std::move(txMeta)};
1280 JLOG(app.journal(
"Ledger").warn())
1281 <<
"Unable to deserialize transaction from raw SQL value. Error: "
1293 boost::filesystem::space_info
space =
1294 boost::filesystem::space(config.legacy(
"database_path"));
1298 JLOG(j.
fatal()) <<
"Remaining free disk space is less than 512MB";
1302 if (config.useTxTables())
1305 boost::filesystem::path dbPath = dbSetup.dataDir /
TxDBName;
1306 boost::system::error_code ec;
1308 boost::filesystem::file_size(dbPath, ec);
1312 <<
"Error checking transaction db file size: " << ec.message();
1316 static auto const pageSize = [&] {
1318 session <<
"PRAGMA page_size;", soci::into(ps);
1321 static auto const maxPages = [&] {
1323 session <<
"PRAGMA max_page_count;", soci::into(mp);
1327 session <<
"PRAGMA page_count;", soci::into(pageCount);
1330 safe_cast<std::uint64_t>(freePages) * pageSize;
1332 <<
"Transaction DB pathname: " << dbPath.string()
1333 <<
"; file size: " << dbSize.
value_or(-1) <<
" bytes"
1334 <<
"; SQLite page size: " << pageSize <<
" bytes"
1335 <<
"; Free pages: " << freePages <<
"; Free space: " << freeSpace
1337 <<
"Note that this does not take into account available disk "
1343 <<
"Free SQLite space for transaction db is less than "
1344 "512MB. To fix this, rippled must be executed with the "
1345 "vacuum parameter before restarting. "
1346 "Note that this activity can take multiple days, "
1347 "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)
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