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>
29#include <xrpl/basics/BasicConfig.h>
30#include <xrpl/basics/StringUtilities.h>
31#include <xrpl/json/to_string.h>
33#include <boost/range/adaptor/transformed.hpp>
34#include <soci/sqlite3/soci-sqlite3.h>
49 "Need to modify switch statement if enum is modified");
56 return "Transactions";
58 return "AccountTransactions";
60 UNREACHABLE(
"ripple::detail::to_string : invalid TableType");
73 auto lgr{std::make_unique<DatabaseCon>(
75 lgr->getSession() << boost::str(
76 boost::format(
"PRAGMA cache_size=-%d;") %
82 auto tx{std::make_unique<DatabaseCon>(
84 tx->getSession() << boost::str(
85 boost::format(
"PRAGMA cache_size=-%d;") %
97 (tx->getSession().prepare
98 << (
"PRAGMA table_info(AccountTransactions);"),
103 soci::into(dflt_value, ind),
111 return {std::move(lgr), std::move(tx),
false};
116 return {std::move(lgr), std::move(tx),
true};
119 return {std::move(lgr), {},
true};
127 boost::optional<LedgerIndex> m;
128 session << query, soci::into(m);
137 boost::optional<LedgerIndex> m;
138 session << query, soci::into(m);
145 session <<
"DELETE FROM " <<
to_string(type)
146 <<
" WHERE LedgerSeq == " << ledgerSeq <<
";";
151 soci::session& session,
155 session <<
"DELETE FROM " <<
to_string(type) <<
" WHERE LedgerSeq < "
163 session <<
"SELECT COUNT(*) AS rows "
175 session <<
"SELECT COUNT(*) AS rows, "
176 "MIN(LedgerSeq) AS first, "
177 "MAX(LedgerSeq) AS last "
194 auto j = app.
journal(
"Ledger");
195 auto seq = ledger->info().seq;
198 JLOG(j.trace()) <<
"saveValidatedLedger " << (
current ?
"" :
"fromAcquire ")
201 if (!ledger->info().accountHash.isNonZero())
203 JLOG(j.fatal()) <<
"AH is zero: " <<
getJson({*ledger, {}});
204 UNREACHABLE(
"ripple::detail::saveValidatedLedger : zero account hash");
207 if (ledger->info().accountHash != ledger->stateMap().getHash().as_uint256())
209 JLOG(j.fatal()) <<
"sAL: " << ledger->info().accountHash
210 <<
" != " << ledger->stateMap().getHash();
211 JLOG(j.fatal()) <<
"saveAcceptedLedger: seq=" << seq
214 "ripple::detail::saveValidatedLedger : mismatched account hash");
218 ledger->info().txHash == ledger->txMap().getHash().as_uint256(),
219 "ripple::detail::saveValidatedLedger : transaction hash match");
225 addRaw(ledger->info(), s);
236 aLedger = std::make_shared<AcceptedLedger>(ledger, app);
238 ledger->info().hash, aLedger);
243 JLOG(j.warn()) <<
"An accepted ledger was missing nodes";
252 static boost::format deleteLedger(
253 "DELETE FROM Ledgers WHERE LedgerSeq = %u;");
254 static boost::format deleteTrans1(
255 "DELETE FROM Transactions WHERE LedgerSeq = %u;");
256 static boost::format deleteTrans2(
257 "DELETE FROM AccountTransactions WHERE LedgerSeq = %u;");
258 static boost::format deleteAcctTrans(
259 "DELETE FROM AccountTransactions WHERE TransID = '%s';");
263 *db << boost::str(deleteLedger % seq);
270 soci::transaction tr(*db);
272 *db << boost::str(deleteTrans1 % seq);
273 *db << boost::str(deleteTrans2 % seq);
277 for (
auto const& acceptedLedgerTx : *aLedger)
287 auto const& accts = acceptedLedgerTx->getAffected();
292 "INSERT INTO AccountTransactions "
293 "(TransID, Account, LedgerSeq, TxnSeq) VALUES ");
301 for (
auto const& account : accts)
321 JLOG(j.trace()) <<
"ActTx: " << sql;
324 else if (
auto const& sleTxn = acceptedLedgerTx->getTxn();
329 JLOG(j.warn()) <<
"Transaction in ledger " << seq
330 <<
" affects no accounts";
336 acceptedLedgerTx->getTxn()->getMetaSQL(
337 seq, acceptedLedgerTx->getEscMeta()) +
348 R
"sql(INSERT OR REPLACE INTO Ledgers
349 (LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,
350 CloseTimeRes,CloseFlags,AccountSetHash,TransSetHash)
352 (:ledgerHash,:ledgerSeq,:prevHash,:totalCoins,:closingTime,:prevClosingTime,
353 :closeTimeRes,:closeFlags,:accountSetHash,:transSetHash);)sql");
357 soci::transaction tr(*db);
359 auto const hash =
to_string(ledger->info().hash);
360 auto const parentHash =
to_string(ledger->info().parentHash);
361 auto const drops =
to_string(ledger->info().drops);
362 auto const closeTime =
363 ledger->info().closeTime.time_since_epoch().count();
364 auto const parentCloseTime =
365 ledger->info().parentCloseTime.time_since_epoch().count();
366 auto const closeTimeResolution =
367 ledger->info().closeTimeResolution.count();
368 auto const closeFlags = ledger->info().closeFlags;
369 auto const accountHash =
to_string(ledger->info().accountHash);
370 auto const txHash =
to_string(ledger->info().txHash);
372 *db << addLedger, soci::use(hash), soci::use(seq),
373 soci::use(parentHash), soci::use(drops), soci::use(closeTime),
374 soci::use(parentCloseTime), soci::use(closeTimeResolution),
375 soci::use(closeFlags), soci::use(accountHash),
395 soci::session& session,
400 boost::optional<std::string> hash, parentHash, accountHash, txHash;
401 boost::optional<std::uint64_t> seq, drops, closeTime, parentCloseTime,
402 closeTimeResolution, closeFlags;
406 "LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
408 "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
409 "LedgerSeq FROM Ledgers " +
412 session << sql, soci::into(hash), soci::into(parentHash),
413 soci::into(accountHash), soci::into(txHash), soci::into(drops),
414 soci::into(closeTime), soci::into(parentCloseTime),
415 soci::into(closeTimeResolution), soci::into(closeFlags),
418 if (!session.got_data())
420 JLOG(j.
debug()) <<
"Ledger not found: " << sqlSuffix;
429 if (hash && !info.hash.parseHex(*hash))
431 JLOG(j.
debug()) <<
"Hash parse error for ledger: " << sqlSuffix;
435 if (parentHash && !info.parentHash.parseHex(*parentHash))
437 JLOG(j.
debug()) <<
"parentHash parse error for ledger: " << sqlSuffix;
441 if (accountHash && !info.accountHash.parseHex(*accountHash))
443 JLOG(j.
debug()) <<
"accountHash parse error for ledger: " << sqlSuffix;
447 if (txHash && !info.txHash.parseHex(*txHash))
449 JLOG(j.
debug()) <<
"txHash parse error for ledger: " << sqlSuffix;
453 info.seq = rangeCheckedCast<std::uint32_t>(seq.value_or(0));
454 info.drops =
drops.value_or(0);
455 info.closeTime = time_point{duration{closeTime.value_or(0)}};
456 info.parentCloseTime = time_point{duration{parentCloseTime.value_or(0)}};
457 info.closeFlags = closeFlags.value_or(0);
458 info.closeTimeResolution = duration{closeTimeResolution.value_or(0)};
465 soci::session& session,
470 s <<
"WHERE LedgerSeq = " << ledgerSeq;
478 s <<
"ORDER BY LedgerSeq DESC LIMIT 1";
484 soci::session& session,
490 " ORDER BY LedgerSeq ASC LIMIT 1";
496 soci::session& session,
502 " ORDER BY LedgerSeq DESC LIMIT 1";
508 soci::session& session,
513 s <<
"WHERE LedgerHash = '" << ledgerHash <<
"'";
523 "SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
530 boost::optional<std::string> lh;
531 session << sql, soci::into(lh);
533 if (!session.got_data() || !lh)
549 soci::session& session,
554 boost::optional<std::string> lhO, phO;
556 session <<
"SELECT LedgerHash,PrevHash FROM Ledgers "
557 "INDEXED BY SeqLedger WHERE LedgerSeq = :ls;",
558 soci::into(lhO), soci::into(phO), soci::use(ledgerIndex);
562 auto stream = j.
trace();
563 JLOG(stream) <<
"Don't have ledger " << ledgerIndex;
567 LedgerHashPair hashes;
568 if (!hashes.ledgerHash.parseHex(*lhO) || !hashes.parentHash.parseHex(*phO))
570 auto stream = j.
trace();
571 JLOG(stream) <<
"Error parse hashes for ledger " << ledgerIndex;
580 soci::session& session,
586 "SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
588 sql.
append(
" AND LedgerSeq <= ");
595 boost::optional<std::string> ph;
597 (session.prepare << sql,
609 JLOG(j.
warn()) <<
"Error parsed hash for ledger seq: " << ls;
613 JLOG(j.
warn()) <<
"Null prev hash for ledger seq: " << ls;
617 JLOG(j.
warn()) <<
"Error parsed prev hash for ledger seq: " << ls;
625 soci::session& session,
632 "SELECT LedgerSeq, Status, RawTxn "
633 "FROM Transactions ORDER BY LedgerSeq DESC LIMIT %u,%u;") %
634 startIndex % quantity);
641 boost::optional<std::uint64_t> ledgerSeq;
642 boost::optional<std::string> status;
643 soci::blob sociRawTxnBlob(session);
648 (session.prepare << sql,
649 soci::into(ledgerSeq),
651 soci::into(sociRawTxnBlob, rti));
656 if (soci::i_ok == rti)
657 convert(sociRawTxnBlob, rawTxn);
662 ledgerSeq, status, rawTxn, app))
694 RelationalDatabase::AccountTxOptions
const& options,
709 else if (options.limit == UINT32_MAX)
711 numberOfResults = binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH;
713 else if (!options.bUnlimited)
716 binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH, options.limit);
720 numberOfResults = options.limit;
726 if (options.maxLedger)
728 maxClause = boost::str(
729 boost::format(
"AND AccountTransactions.LedgerSeq <= '%u'") %
733 if (options.minLedger)
735 minClause = boost::str(
736 boost::format(
"AND AccountTransactions.LedgerSeq >= '%u'") %
744 boost::format(
"SELECT %s FROM AccountTransactions "
745 "WHERE Account = '%s' %s %s LIMIT %u, %u;") %
746 selection %
toBase58(options.account) % maxClause % minClause %
747 options.offset % numberOfResults);
752 "AccountTransactions INNER JOIN Transactions "
753 "ON Transactions.TransID = AccountTransactions.TransID "
754 "WHERE Account = '%s' %s %s "
755 "ORDER BY AccountTransactions.LedgerSeq %s, "
756 "AccountTransactions.TxnSeq %s, AccountTransactions.TransID %s "
758 selection %
toBase58(options.account) % maxClause % minClause %
759 (descending ?
"DESC" :
"ASC") % (descending ?
"DESC" :
"ASC") %
760 (descending ?
"DESC" :
"ASC") % options.offset % numberOfResults);
761 JLOG(j.
trace()) <<
"txSQL query: " << sql;
788 soci::session& session,
791 RelationalDatabase::AccountTxOptions
const& options,
799 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
811 boost::optional<std::uint64_t> ledgerSeq;
812 boost::optional<std::string>
status;
813 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
814 soci::indicator rti, tmi;
815 Blob rawTxn, txnMeta;
818 (session.prepare << sql,
819 soci::into(ledgerSeq),
821 soci::into(sociTxnBlob, rti),
822 soci::into(sociTxnMetaBlob, tmi));
827 if (soci::i_ok == rti)
832 if (soci::i_ok == tmi)
833 convert(sociTxnMetaBlob, txnMeta);
843 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
846 <<
"Recovering ledger " << seq <<
", txn " << txn->getID();
856 std::make_shared<TxMeta>(
857 txn->getID(), txn->getLedger(), txnMeta));
868 soci::session& session,
871 RelationalDatabase::AccountTxOptions
const& options,
879 soci::session& session,
910 soci::session& session,
912 RelationalDatabase::AccountTxOptions
const& options,
920 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
933 boost::optional<std::uint64_t> ledgerSeq;
934 boost::optional<std::string>
status;
935 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
936 soci::indicator rti, tmi;
939 (session.prepare << sql,
940 soci::into(ledgerSeq),
942 soci::into(sociTxnBlob, rti),
943 soci::into(sociTxnMetaBlob, tmi));
949 if (soci::i_ok == rti)
952 if (soci::i_ok == tmi)
953 convert(sociTxnMetaBlob, txnMeta);
956 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
958 ret.
emplace_back(std::move(rawTxn), std::move(txnMeta), seq);
968 soci::session& session,
970 RelationalDatabase::AccountTxOptions
const& options,
978 soci::session& session,
1007 soci::session& session,
1012 RelationalDatabase::AccountTxPageOptions
const& options,
1018 bool lookingForMarker = options.marker.has_value();
1022 if (options.limit == 0 || options.limit == UINT32_MAX ||
1023 (options.limit > page_length && !options.bAdmin))
1024 numberOfResults = page_length;
1026 numberOfResults = options.limit;
1036 if (lookingForMarker)
1038 findLedger = options.marker->ledgerSeq;
1039 findSeq = options.marker->txnSeq;
1045 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1046 Status,RawTxn,TxnMeta
1047 FROM AccountTransactions INNER JOIN Transactions
1048 ON Transactions.TransID = AccountTransactions.TransID
1049 AND AccountTransactions.Account = '%s' WHERE
1056 const char*
const order =
forward ?
"ASC" :
"DESC";
1058 if (findLedger == 0)
1062 prefix + (R
"(AccountTransactions.LedgerSeq BETWEEN %u AND %u
1063 ORDER BY AccountTransactions.LedgerSeq %s,
1064 AccountTransactions.TxnSeq %s
1066 toBase58(options.account) % options.minLedger % options.maxLedger %
1067 order % order % queryLimit);
1073 forward ? findLedger + 1 : options.minLedger;
1075 forward ? options.maxLedger : findLedger - 1;
1077 auto b58acct =
toBase58(options.account);
1080 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1081 Status,RawTxn,TxnMeta
1082 FROM AccountTransactions, Transactions WHERE
1083 (AccountTransactions.TransID = Transactions.TransID AND
1084 AccountTransactions.Account = '%s' AND
1085 AccountTransactions.LedgerSeq BETWEEN %u AND %u)
1087 SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,Status,RawTxn,TxnMeta
1088 FROM AccountTransactions, Transactions WHERE
1089 (AccountTransactions.TransID = Transactions.TransID AND
1090 AccountTransactions.Account = '%s' AND
1091 AccountTransactions.LedgerSeq = %u AND
1092 AccountTransactions.TxnSeq %s %u)
1093 ORDER BY AccountTransactions.LedgerSeq %s,
1094 AccountTransactions.TxnSeq %s
1097 b58acct % minLedger % maxLedger % b58acct % findLedger % compare %
1098 findSeq % order % order % queryLimit);
1106 boost::optional<std::uint64_t> ledgerSeq;
1107 boost::optional<std::uint32_t> txnSeq;
1108 boost::optional<std::string>
status;
1109 soci::blob txnData(session);
1110 soci::blob txnMeta(session);
1111 soci::indicator dataPresent, metaPresent;
1113 soci::statement st =
1114 (session.prepare << sql,
1115 soci::into(ledgerSeq),
1118 soci::into(txnData, dataPresent),
1119 soci::into(txnMeta, metaPresent));
1125 if (lookingForMarker)
1127 if (findLedger == ledgerSeq.value_or(0) &&
1128 findSeq == txnSeq.value_or(0))
1130 lookingForMarker =
false;
1135 else if (numberOfResults == 0)
1138 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
1143 if (dataPresent == soci::i_ok)
1148 if (metaPresent == soci::i_ok)
1154 if (rawMeta.size() == 0)
1155 onUnsavedLedger(ledgerSeq.value_or(0));
1160 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
1163 std::move(rawMeta));
1177 return {newmarker, total};
1182 soci::session& session,
1191 session, onUnsavedLedger, onTransaction, options, page_length,
true);
1196 soci::session& session,
1205 session, onUnsavedLedger, onTransaction, options, page_length,
false);
1210 soci::session& session,
1217 "SELECT LedgerSeq,Status,RawTxn,TxnMeta "
1218 "FROM Transactions WHERE TransID='";
1224 boost::optional<std::uint64_t> ledgerSeq;
1225 boost::optional<std::string> status;
1226 Blob rawTxn, rawMeta;
1228 soci::blob sociRawTxnBlob(session), sociRawMetaBlob(session);
1229 soci::indicator txn, meta;
1231 session << sql, soci::into(ledgerSeq), soci::into(status),
1232 soci::into(sociRawTxnBlob, txn), soci::into(sociRawMetaBlob, meta);
1234 auto const got_data = session.got_data();
1236 if ((!got_data || txn != soci::i_ok || meta != soci::i_ok) && !
range)
1242 soci::indicator rti;
1245 <<
"SELECT COUNT(DISTINCT LedgerSeq) FROM Transactions WHERE "
1246 "LedgerSeq BETWEEN "
1247 <<
range->first() <<
" AND " <<
range->last() <<
";",
1248 soci::into(count, rti);
1250 if (!session.got_data() || rti != soci::i_ok)
1253 return count == (
range->last() -
range->first() + 1)
1258 convert(sociRawTxnBlob, rawTxn);
1259 convert(sociRawMetaBlob, rawMeta);
1268 return std::pair{std::move(txn),
nullptr};
1271 rangeCheckedCast<std::uint32_t>(ledgerSeq.value());
1273 auto txMeta = std::make_shared<TxMeta>(
id, inLedger, rawMeta);
1275 return std::pair{std::move(txn), std::move(txMeta)};
1279 JLOG(app.journal(
"Ledger").warn())
1280 <<
"Unable to deserialize transaction from raw SQL value. Error: "
1292 boost::filesystem::space_info
space =
1293 boost::filesystem::space(config.legacy(
"database_path"));
1297 JLOG(j.
fatal()) <<
"Remaining free disk space is less than 512MB";
1301 if (config.useTxTables())
1304 boost::filesystem::path dbPath = dbSetup.dataDir /
TxDBName;
1305 boost::system::error_code ec;
1307 boost::filesystem::file_size(dbPath, ec);
1311 <<
"Error checking transaction db file size: " << ec.message();
1315 static auto const pageSize = [&] {
1317 session <<
"PRAGMA page_size;", soci::into(ps);
1320 static auto const maxPages = [&] {
1322 session <<
"PRAGMA max_page_count;", soci::into(mp);
1326 session <<
"PRAGMA page_count;", soci::into(pageCount);
1329 safe_cast<std::uint64_t>(freePages) * pageSize;
1331 <<
"Transaction DB pathname: " << dbPath.string()
1332 <<
"; file size: " << dbSize.
value_or(-1) <<
" bytes"
1333 <<
"; SQLite page size: " << pageSize <<
" bytes"
1334 <<
"; Free pages: " << freePages <<
"; Free space: " << freeSpace
1336 <<
"Note that this does not take into account available disk "
1342 <<
"Free SQLite space for transaction db is less than "
1343 "512MB. To fix this, rippled must be executed with the "
1344 "vacuum parameter before restarting. "
1345 "Note that this activity can take multiple days, "
1346 "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