1#include <xrpld/app/rdb/backend/detail/Node.h>
3#include <xrpld/app/ledger/AcceptedLedger.h>
4#include <xrpld/app/ledger/LedgerMaster.h>
5#include <xrpld/app/ledger/LedgerPersistence.h>
6#include <xrpld/app/ledger/LedgerToJson.h>
7#include <xrpld/app/ledger/TransactionMaster.h>
8#include <xrpld/core/Config.h>
10#include <xrpl/basics/Blob.h>
11#include <xrpl/basics/ByteUtilities.h>
12#include <xrpl/basics/Log.h>
13#include <xrpl/basics/RangeSet.h>
14#include <xrpl/basics/Slice.h>
15#include <xrpl/basics/base_uint.h>
16#include <xrpl/basics/chrono.h>
17#include <xrpl/basics/contract.h>
18#include <xrpl/basics/safe_cast.h>
19#include <xrpl/beast/utility/Journal.h>
20#include <xrpl/beast/utility/instrumentation.h>
21#include <xrpl/config/Constants.h>
22#include <xrpl/core/NetworkIDService.h>
23#include <xrpl/core/StartUpType.h>
24#include <xrpl/json/to_string.h>
25#include <xrpl/ledger/PendingSaves.h>
26#include <xrpl/nodestore/NodeObject.h>
27#include <xrpl/protocol/AccountID.h>
28#include <xrpl/protocol/ErrorCodes.h>
29#include <xrpl/protocol/HashPrefix.h>
30#include <xrpl/protocol/LedgerHeader.h>
31#include <xrpl/protocol/Protocol.h>
32#include <xrpl/protocol/SField.h>
33#include <xrpl/protocol/STTx.h>
34#include <xrpl/protocol/Serializer.h>
35#include <xrpl/protocol/TxMeta.h>
36#include <xrpl/protocol/TxSearched.h>
37#include <xrpl/protocol/XRPAmount.h>
38#include <xrpl/rdb/DBInit.h>
39#include <xrpl/rdb/DatabaseCon.h>
40#include <xrpl/rdb/RelationalDatabase.h>
41#include <xrpl/rdb/SociDB.h>
43#include <boost/optional/optional.hpp>
44#include <boost/system/detail/error_code.hpp>
46#include <soci/blob-exchange.h>
48#include <soci/boost-optional.h>
50#include <soci/soci-backend.h>
51#include <soci/statement.h>
52#include <soci/transaction.h>
84 static_assert(
kTableTypeCount == 3,
"Need to modify switch statement if enum is modified");
91 return "Transactions";
93 return "AccountTransactions";
96 UNREACHABLE(
"xrpl::detail::toString : invalid TableType");
133 soci::indicator ind = soci::i_null;
135 (tx->getSession().prepare <<
"PRAGMA table_info(AccountTransactions);",
140 soci::into(dfltValue, ind),
149 .ledgerDb = std::move(lgr),
150 .transactionDb = std::move(tx),
157 return {.ledgerDb = std::move(lgr), .transactionDb = std::move(tx), .valid =
true};
160 return {.ledgerDb = std::move(lgr), .transactionDb = {}, .valid =
true};
168 boost::optional<LedgerIndex> m;
169 session << query, soci::into(m);
178 boost::optional<LedgerIndex> m;
179 session << query, soci::into(m);
186 session <<
"DELETE FROM " <<
toString(type) <<
" WHERE LedgerSeq == " << ledgerSeq <<
";";
192 session <<
"DELETE FROM " <<
toString(type) <<
" WHERE LedgerSeq < " << ledgerSeq <<
";";
199 session <<
"SELECT COUNT(*) AS rows "
211 session <<
"SELECT COUNT(*) AS rows, "
212 "MIN(LedgerSeq) AS first, "
213 "MAX(LedgerSeq) AS last "
231 auto seq = ledger->header().seq;
234 JLOG(j.trace()) <<
"saveValidatedLedger " << (current ?
"" :
"fromAcquire ") << seq;
236 if (!ledger->header().accountHash.isNonZero())
239 JLOG(j.fatal()) <<
"AH is zero: " <<
getJson({*ledger, {}});
240 UNREACHABLE(
"xrpl::detail::saveValidatedLedger : zero account hash");
244 if (ledger->header().accountHash != ledger->stateMap().getHash().asUInt256())
247 JLOG(j.fatal()) <<
"sAL: " << ledger->header().accountHash
248 <<
" != " << ledger->stateMap().getHash();
249 JLOG(j.fatal()) <<
"saveAcceptedLedger: seq=" << seq <<
", current=" << current;
250 UNREACHABLE(
"xrpl::detail::saveValidatedLedger : mismatched account hash");
255 ledger->header().txHash == ledger->txMap().getHash().asUInt256(),
256 "xrpl::detail::saveValidatedLedger : transaction hash match");
262 addRaw(ledger->header(), s);
279 JLOG(j.warn()) <<
"An accepted ledger was missing nodes";
288 static constexpr char const* kDeleteLedger =
"DELETE FROM Ledgers WHERE LedgerSeq = {};";
289 static constexpr char const* kDeleteTranS1 =
290 "DELETE FROM Transactions WHERE LedgerSeq = {};";
291 static constexpr char const* kDeleteTranS2 =
292 "DELETE FROM AccountTransactions WHERE LedgerSeq = {};";
293 static constexpr char const* kDeleteAcctTrans =
294 "DELETE FROM AccountTransactions WHERE TransID = '{}';";
306 JLOG(j.fatal()) <<
"TxTables db isn't available";
311 auto db = txnDB->checkoutDb();
313 soci::transaction tr(*db);
320 for (
auto const& acceptedLedgerTx : *aLedger)
322 UInt256 const transactionID = acceptedLedgerTx->getTransactionID();
329 auto const& accts = acceptedLedgerTx->getAffected();
334 "INSERT INTO AccountTransactions "
335 "(TransID, Account, LedgerSeq, TxnSeq) VALUES ");
343 for (
auto const& account : accts)
365 JLOG(j.trace()) <<
"ActTx: " << sql;
368 else if (
auto const& sleTxn = acceptedLedgerTx->getTxn(); !
isPseudoTx(*sleTxn))
372 JLOG(j.warn()) <<
"Transaction in ledger " << seq <<
" affects no accounts";
378 acceptedLedgerTx->getTxn()->getMetaSQL(
379 seq, acceptedLedgerTx->getEscMeta()) +
385 acceptedLedgerTx->getTxnSeq(),
394 R
"sql(INSERT OR REPLACE INTO Ledgers
395 (LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,
396 CloseTimeRes,CloseFlags,AccountSetHash,TransSetHash)
398 (:ledgerHash,:ledgerSeq,:prevHash,:totalCoins,:closingTime,:prevClosingTime,
399 :closeTimeRes,:closeFlags,:accountSetHash,:transSetHash);)sql");
403 soci::transaction tr(*db);
405 auto const hash =
to_string(ledger->header().hash);
406 auto const parentHash =
to_string(ledger->header().parentHash);
407 auto const drops =
to_string(ledger->header().drops);
408 auto const closeTime = ledger->header().closeTime.time_since_epoch().count();
409 auto const parentCloseTime =
410 ledger->header().parentCloseTime.time_since_epoch().count();
411 auto const closeTimeResolution = ledger->header().closeTimeResolution.count();
412 auto const closeFlags = ledger->header().closeFlags;
413 auto const accountHash =
to_string(ledger->header().accountHash);
414 auto const txHash =
to_string(ledger->header().txHash);
416 *db << kAddLedger, soci::use(hash), soci::use(seq), soci::use(parentHash),
417 soci::use(drops), soci::use(closeTime), soci::use(parentCloseTime),
418 soci::use(closeTimeResolution), soci::use(closeFlags), soci::use(accountHash),
440 boost::optional<std::string> hash, parentHash, accountHash, txHash;
441 boost::optional<std::uint64_t> seq, drops, closeTime, parentCloseTime, closeTimeResolution,
446 "LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
448 "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
449 "LedgerSeq FROM Ledgers " +
452 session << sql, soci::into(hash), soci::into(parentHash), soci::into(accountHash),
453 soci::into(txHash), soci::into(drops), soci::into(closeTime), soci::into(parentCloseTime),
454 soci::into(closeTimeResolution), soci::into(closeFlags), soci::into(seq);
456 if (!session.got_data())
458 JLOG(j.
debug()) <<
"Ledger not found: " << sqlSuffix;
469 JLOG(j.
debug()) <<
"Hash parse error for ledger: " << sqlSuffix;
475 JLOG(j.
debug()) <<
"parentHash parse error for ledger: " << sqlSuffix;
481 JLOG(j.
debug()) <<
"accountHash parse error for ledger: " << sqlSuffix;
487 JLOG(j.
debug()) <<
"txHash parse error for ledger: " << sqlSuffix;
492 info.
drops = drops.value_or(0);
493 info.
closeTime = time_point{duration{closeTime.value_or(0)}};
494 info.
parentCloseTime = time_point{duration{parentCloseTime.value_or(0)}};
505 s <<
"WHERE LedgerSeq = " << ledgerSeq;
513 s <<
"ORDER BY LedgerSeq DESC LIMIT 1";
522 " ORDER BY LedgerSeq ASC LIMIT 1";
531 " ORDER BY LedgerSeq DESC LIMIT 1";
539 s <<
"WHERE LedgerHash = '" << ledgerHash <<
"'";
548 std::string sql =
"SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
555 boost::optional<std::string> lh;
556 session << sql, soci::into(lh);
558 if (!session.got_data() || !lh)
576 boost::optional<std::string> lhO, phO;
578 session <<
"SELECT LedgerHash,PrevHash FROM Ledgers "
579 "INDEXED BY SeqLedger WHERE LedgerSeq = :ls;",
580 soci::into(lhO), soci::into(phO), soci::use(ledgerIndex);
584 auto const stream = j.
trace();
585 JLOG(stream) <<
"Don't have ledger " << ledgerIndex;
589 LedgerHashPair hashes;
590 if (!hashes.ledgerHash.parseHex(*lhO) || !hashes.parentHash.parseHex(*phO))
592 auto const stream = j.
trace();
593 JLOG(stream) <<
"Error parse hashes for ledger " << ledgerIndex;
603 std::string sql =
"SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
605 sql.
append(
" AND LedgerSeq <= ");
612 boost::optional<std::string> ph;
613 soci::statement st = (session.prepare << sql, soci::into(ls), soci::into(lh), soci::into(ph));
622 JLOG(j.
warn()) <<
"Error parsed hash for ledger seq: " << ls;
626 JLOG(j.
warn()) <<
"Null prev hash for ledger seq: " << ls;
630 JLOG(j.
warn()) <<
"Error parsed prev hash for ledger seq: " << ls;
640 "SELECT LedgerSeq, Status, RawTxn "
641 "FROM Transactions ORDER BY LedgerSeq DESC LIMIT {},{};",
650 boost::optional<std::uint64_t> ledgerSeq;
651 boost::optional<std::string> status;
652 soci::blob sociRawTxnBlob(session);
653 soci::indicator rti = soci::i_null;
657 (session.prepare << sql,
658 soci::into(ledgerSeq),
660 soci::into(sociRawTxnBlob, rti));
665 if (soci::i_ok == rti)
667 convert(sociRawTxnBlob, rawTxn);
721 else if (options.
limit == UINT32_MAX)
723 numberOfResults = binary ? kBinaryPageLength : kNonbinaryPageLength;
728 std::min(binary ? kBinaryPageLength : kNonbinaryPageLength, options.
limit);
732 numberOfResults = options.
limit;
755 "SELECT {} FROM AccountTransactions "
756 "WHERE Account = '{}' {} {} LIMIT {}, {};",
766 char const*
const order = descending ?
"DESC" :
"ASC";
769 "AccountTransactions INNER JOIN Transactions "
770 "ON Transactions.TransID = AccountTransactions.TransID "
771 "WHERE Account = '{}' {} {} "
772 "ORDER BY AccountTransactions.LedgerSeq {}, "
773 "AccountTransactions.TxnSeq {}, AccountTransactions.TransID {} "
785 JLOG(j.
trace()) <<
"txSQL query: " << sql;
812 soci::session& session,
823 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
835 boost::optional<std::uint64_t> ledgerSeq;
836 boost::optional<std::string> status;
837 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
838 soci::indicator rti = soci::i_null, tmi = soci::i_null;
839 Blob rawTxn, txnMeta;
842 (session.prepare << sql,
843 soci::into(ledgerSeq),
845 soci::into(sociTxnBlob, rti),
846 soci::into(sociTxnMetaBlob, tmi));
851 if (soci::i_ok == rti)
860 if (soci::i_ok == tmi)
862 convert(sociTxnMetaBlob, txnMeta);
875 JLOG(j.
warn()) <<
"Recovering ledger " << seq <<
", txn " << txn->getID();
895 soci::session& session,
898 RelationalDatabase::AccountTxOptions
const& options,
901 return getAccountTxs(session, app, ledgerMaster, options,
false, j);
906 soci::session& session,
912 return getAccountTxs(session, app, ledgerMaster, options,
true, j);
937 soci::session& session,
947 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta",
960 boost::optional<std::uint64_t> ledgerSeq;
961 boost::optional<std::string> status;
962 soci::blob sociTxnBlob(session), sociTxnMetaBlob(session);
963 soci::indicator rti = soci::i_null, tmi = soci::i_null;
966 (session.prepare << sql,
967 soci::into(ledgerSeq),
969 soci::into(sociTxnBlob, rti),
970 soci::into(sociTxnMetaBlob, tmi));
976 if (soci::i_ok == rti)
979 if (soci::i_ok == tmi)
980 convert(sociTxnMetaBlob, txnMeta);
984 ret.
emplace_back(std::move(rawTxn), std::move(txnMeta), seq);
994 soci::session& session,
995 Application
const& app,
996 RelationalDatabase::AccountTxOptions
const& options,
1004 soci::session& session,
1024 Blob const& rawData,
1038 switch (filter.
type)
1043 bool const isDelegated = (txOwner == contextAccount) && (txSigner != contextAccount);
1052 bool const isActingAsDelegate =
1053 (txSigner == contextAccount) && (txOwner != contextAccount);
1054 if (!isActingAsDelegate)
1084 soci::session& session,
1093 bool const hasDelegateFilter = options.
delegate.has_value();
1094 bool lookingForMarker = options.
marker.has_value();
1098 if (options.
limit == 0 || options.
limit == UINT32_MAX ||
1101 numberOfResults = pageLength;
1105 numberOfResults = options.
limit;
1116 if (lookingForMarker)
1118 findLedger = options.
marker->ledgerSeq;
1119 findSeq = options.
marker->txnSeq;
1128 char const*
const order = forward ?
"ASC" :
"DESC";
1130 if (findLedger == 0)
1133 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1134 Status,RawTxn,TxnMeta
1135 FROM AccountTransactions INNER JOIN Transactions
1136 ON Transactions.TransID = AccountTransactions.TransID
1137 AND AccountTransactions.Account = '{}' WHERE
1138 AccountTransactions.LedgerSeq BETWEEN {} AND {}
1139 ORDER BY AccountTransactions.LedgerSeq {},
1140 AccountTransactions.TxnSeq {}
1151 char const*
const compare = forward ?
">=" :
"<=";
1157 R
"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
1158 Status,RawTxn,TxnMeta
1159 FROM AccountTransactions, Transactions WHERE
1160 (AccountTransactions.TransID = Transactions.TransID AND
1161 AccountTransactions.Account = '{}' AND
1162 AccountTransactions.LedgerSeq BETWEEN {} AND {})
1164 SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,Status,RawTxn,TxnMeta
1165 FROM AccountTransactions, Transactions WHERE
1166 (AccountTransactions.TransID = Transactions.TransID AND
1167 AccountTransactions.Account = '{}' AND
1168 AccountTransactions.LedgerSeq = {} AND
1169 AccountTransactions.TxnSeq {} {})
1170 ORDER BY AccountTransactions.LedgerSeq {},
1171 AccountTransactions.TxnSeq {}
1196 boost::optional<std::uint64_t> ledgerSeq;
1197 boost::optional<std::uint32_t> txnSeq;
1198 boost::optional<std::string> status;
1199 soci::blob txnData(session);
1200 soci::blob txnMeta(session);
1201 soci::indicator dataPresent = soci::i_null, metaPresent = soci::i_null;
1203 soci::statement st =
1204 (session.prepare << sql,
1205 soci::into(ledgerSeq),
1208 soci::into(txnData, dataPresent),
1209 soci::into(txnMeta, metaPresent));
1215 if (hasDelegateFilter)
1220 .txnSeq = txnSeq.value_or(0),
1224 if (lookingForMarker)
1226 if (findLedger == ledgerSeq.value_or(0) && findSeq == txnSeq.value_or(0))
1228 lookingForMarker =
false;
1231 if (hasDelegateFilter)
1240 if (!hasDelegateFilter && numberOfResults == 0)
1244 .txnSeq = txnSeq.value_or(0),
1249 if (dataPresent == soci::i_ok)
1258 if (metaPresent == soci::i_ok)
1267 if (hasDelegateFilter)
1269 if (rawData.
empty() ||
1277 if (numberOfResults == 0)
1279 newmarker = lastEmitted;
1285 if (rawMeta.
empty())
1286 onUnsavedLedger(ledgerSeq.value_or(0));
1294 std::move(rawMeta));
1305 if (hasDelegateFilter)
1309 .txnSeq = txnSeq.value_or(0),
1316 if (hasDelegateFilter && !newmarker && !lookingForMarker && fetchedRows == queryLimit)
1317 newmarker = lastScanned;
1320 return {newmarker, total};
1323std::pair<std::optional<RelationalDatabase::AccountTxMarker>,
int>
1325 soci::session& session,
1326 std::function<
void(std::uint32_t)>
const& onUnsavedLedger,
1327 std::function<
void(std::uint32_t, std::string
const&,
Blob&&,
Blob&&)>
const& onTransaction,
1328 RelationalDatabase::AccountTxPageOptions
const& options,
1329 std::uint32_t pageLength)
1331 return accountTxPage(session, onUnsavedLedger, onTransaction, options, pageLength,
true);
1334std::pair<std::optional<RelationalDatabase::AccountTxMarker>,
int>
1336 soci::session& session,
1337 std::function<
void(std::uint32_t)>
const& onUnsavedLedger,
1338 std::function<
void(std::uint32_t, std::string
const&,
Blob&&,
Blob&&)>
const& onTransaction,
1339 RelationalDatabase::AccountTxPageOptions
const& options,
1340 std::uint32_t pageLength)
1342 return accountTxPage(session, onUnsavedLedger, onTransaction, options, pageLength,
false);
1345std::variant<RelationalDatabase::AccountTx, TxSearched>
1347 soci::session& session,
1354 "SELECT LedgerSeq,Status,RawTxn,TxnMeta "
1355 "FROM Transactions WHERE TransID='";
1361 boost::optional<std::uint64_t> ledgerSeq;
1362 boost::optional<std::string>
status;
1363 Blob rawTxn, rawMeta;
1365 soci::blob sociRawTxnBlob(session), sociRawMetaBlob(session);
1366 soci::indicator txn = soci::i_null, meta = soci::i_null;
1368 session << sql, soci::into(ledgerSeq), soci::into(status), soci::into(sociRawTxnBlob, txn),
1369 soci::into(sociRawMetaBlob, meta);
1371 auto const gotData = session.got_data();
1373 if ((!gotData || txn != soci::i_ok || meta != soci::i_ok) && !
range)
1379 soci::indicator rti = soci::i_null;
1381 session <<
"SELECT COUNT(DISTINCT LedgerSeq) FROM Transactions WHERE "
1382 "LedgerSeq BETWEEN "
1383 <<
range->first() <<
" AND " <<
range->last() <<
";",
1384 soci::into(count, rti);
1386 if (!session.got_data() || rti != soci::i_ok)
1394 convert(sociRawMetaBlob, rawMeta);
1402 return std::pair{std::move(txn),
nullptr};
1408 return std::pair{std::move(txn), std::move(txMeta)};
1410 catch (std::exception& e)
1412 JLOG(app.getJournal(
"Ledger").warn())
1413 <<
"Unable to deserialize transaction from raw SQL value. Error: " << e.
what();
1422dbHasSpace(soci::session& session, Config
const& config, beast::Journal j)
1424 std::filesystem::space_info
const space =
1429 JLOG(j.
fatal()) <<
"Remaining free disk space is less than 512MB";
1433 if (config.useTxTables())
1436 std::filesystem::path
const dbPath = dbSetup.dataDir /
kTxDbName;
1441 JLOG(j.
error()) <<
"Error checking transaction db file size: " << ec.
message();
1445 static auto const kPageSize = [&] {
1446 std::uint32_t ps = 0;
1447 session <<
"PRAGMA page_size;", soci::into(ps);
1450 static auto const kMaxPages = [&] {
1451 std::uint32_t mp = 0;
1452 session <<
"PRAGMA max_page_count;", soci::into(mp);
1455 std::uint32_t pageCount = 0;
1456 session <<
"PRAGMA page_count;", soci::into(pageCount);
1457 std::uint32_t
const freePages = kMaxPages - pageCount;
1459 JLOG(j.
info()) <<
"Transaction DB pathname: " << dbPath.
string()
1460 <<
"; file size: " << dbSize.
value_or(-1) <<
" bytes"
1461 <<
"; SQLite page size: " << kPageSize <<
" bytes"
1462 <<
"; Free pages: " << freePages <<
"; Free space: " << freeSpace
1464 <<
"Note that this does not take into account available disk "
1469 JLOG(j.
fatal()) <<
"Free SQLite space for transaction db is less than "
1470 "512MB. To fix this, xrpld must be executed with the "
1471 "vacuum parameter before restarting. "
1472 "Note that this activity can take multiple days, "
1473 "depending on database size.";
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
virtual Config & config()=0
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
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()
Tracks the current ledger and any ledgers in the process of closing.
std::shared_ptr< Ledger const > getLedgerBySeq(std::uint32_t index)
Finds a ledger by sequence, preferring the validated chain.
void failedSave(std::uint32_t seq, UInt256 const &hash)
Marks a ledger no longer resident after its save failed, and starts fetching it again.
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
virtual std::uint32_t getNetworkID() const noexcept=0
Get the configured network ID.
void finishWork(LedgerIndex seq)
Finish working on a ledger.
std::vector< AccountTx > AccountTxs
bool isFieldPresent(SField const &field) const
AccountID getAccountID(SField const &field) const
static std::string const & getMetaSQLInsertReplaceHeader()
virtual PendingSaves & getPendingSaves()=0
virtual beast::Journal getJournal(std::string const &name)=0
virtual TransactionMaster & getMasterTransaction()=0
virtual NetworkIDService & getNetworkIDService()=0
virtual node_store::Database & getNodeStore()=0
virtual TaggedCache< UInt256, AcceptedLedger > & getAcceptedLedgerCache()=0
virtual LedgerMaster & getLedgerMaster()=0
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)
virtual void store(NodeObjectType type, Blob &&data, UInt256 const &hash, std::uint32_t ledgerSeq)=0
Store the object.
T emplace_back(T... args)
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 pageLength, bool forward)
accountTxPage Searches for the oldest or newest transactions for the account that matches the given c...
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 pageLength)
newestAccountTxPage Searches newest transactions for given account which match given criteria startin...
constexpr int kTableTypeCount
bool saveValidatedLedger(DatabaseCon &ldgDB, std::unique_ptr< DatabaseCon > const &txnDB, Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
saveValidatedLedger Saves ledger into database.
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 pageLength)
oldestAccountTxPage Searches oldest transactions for given account which match given criteria startin...
void deleteBeforeLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteBeforeLedgerSeq Deletes all entries in given table for the ledgers with given sequence and all ...
std::optional< LedgerIndex > getMinLedgerSeq(soci::session &session, TableType type)
getMinLedgerSeq Returns minimum ledger sequence in given table.
std::optional< LedgerIndex > getMaxLedgerSeq(soci::session &session, TableType type)
getMaxLedgerSeq Returns maximum 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< 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.
std::optional< LedgerHeader > getNewestLedgerInfo(soci::session &session, beast::Journal j)
getNewestLedgerInfo Returns info of newest saved ledger.
std::optional< LedgerHeader > getLimitedOldestLedgerInfo(soci::session &session, LedgerIndex ledgerFirstIndex, beast::Journal j)
getLimitedOldestLedgerInfo Returns info of oldest ledger from ledgers with sequences greater or equal...
DatabasePairValid makeLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup, beast::Journal j)
makeLedgerDBs Opens ledger and transactions databases.
std::variant< RelationalDatabase::AccountTx, TxSearched > getTransaction(soci::session &session, Application &app, UInt256 const &id, std::optional< ClosedInterval< uint32_t > > const &range, ErrorCodeI &ec)
getTransaction Returns transaction with given hash.
RelationalDatabase::CountMinMax getRowsMinMax(soci::session &session, TableType type)
getRowsMinMax Returns minimum ledger sequence, maximum ledger sequence and total number of rows in gi...
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...
static std::optional< LedgerHeader > 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< LedgerHeader > getLedgerInfoByHash(soci::session &session, UInt256 const &ledgerHash, beast::Journal j)
getLedgerInfoByHash Returns info of ledger with given hash.
static bool passesDelegateFilter(Blob const &rawData, DelegateFilter const &filter, AccountID const &contextAccount)
Determines whether a transaction should be included in account_tx results based on a delegation filte...
std::size_t getRows(soci::session &session, TableType type)
getRows Returns number of rows in given table.
std::optional< LedgerHeader > getLedgerInfoByIndex(soci::session &session, LedgerIndex ledgerSeq, beast::Journal j)
getLedgerInfoByIndex Returns ledger by its sequence.
void deleteByLedgerSeq(soci::session &session, TableType type, LedgerIndex ledgerSeq)
deleteByLedgerSeq Deletes all entries in given table for the ledger with given sequence.
static std::pair< std::vector< RelationalDatabase::TxnMetaLedgerType >, int > getAccountTxsB(soci::session &session, Application const &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 ...
UInt256 getHashByIndex(soci::session &session, LedgerIndex ledgerIndex)
getHashByIndex Returns hash of ledger with given sequence.
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...
bool dbHasSpace(soci::session &session, Config const &config, beast::Journal j)
dbHasSpace Checks if given database has available space.
std::optional< LedgerHeader > getLimitedNewestLedgerInfo(soci::session &session, LedgerIndex ledgerFirstIndex, beast::Journal j)
getLimitedNewestLedgerInfo Returns info of newest ledger from ledgers with sequences greater or equal...
static std::string transactionsSQL(Application const &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::pair< std::vector< RelationalDatabase::TxnMetaLedgerType >, int > getNewestAccountTxsB(soci::session &session, Application const &app, RelationalDatabase::AccountTxOptions const &options, beast::Journal j)
getNewestAccountTxsB Returns newest transactions in binary form for given account which match given c...
std::pair< std::vector< RelationalDatabase::TxnMetaLedgerType >, int > getOldestAccountTxsB(soci::session &session, Application const &app, RelationalDatabase::AccountTxOptions const &options, beast::Journal j)
getOldestAccountTxsB Returns oldest transactions in binary form for given account which match given c...
static std::string toString(TableType type)
to_string Returns the name of a table according to its TableType.
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...
constexpr std::array< char const *, 5 > kLgrDbInit
bool pendSaveValidated(ServiceRegistry ®istry, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger.
std::uint32_t LedgerIndex
A ledger index.
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
constexpr std::array< char const *, 8 > kTxDbInit
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
constexpr Dest safeCast(Src s) noexcept
constexpr auto kLgrDbName
std::string to_string(BaseUInt< Bits, Tag > const &a)
@ Authorizer
This account signed and submitted transactions on behalf of another account (this account is the sign...
@ Actor
Another account signed and submitted transactions on behalf of this account (this account is the owne...
Slice makeSlice(std::array< T, N > const &a)
constexpr auto megabytes(T value) noexcept
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
json::Value getJson(LedgerFill const &fill)
Return a new json::Value representing the ledger with given options.
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
constexpr auto kilobytes(T value) noexcept
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
@ LedgerMaster
ledger master data for signing
DatabaseCon::Setup setupDatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
std::vector< unsigned char > Blob
Storage for linear binary data.
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
void convert(soci::blob &from, std::vector< std::uint8_t > &to)
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
std::array< std::string, 4 > txPragma
std::array< std::string, 1 > lgrPragma
std::optional< AccountID > counterparty
LedgerRange ledgerRange
Ledger sequence range to search.
AccountID const & account
AccountID const & account
std::optional< AccountTxMarker > marker
std::optional< DelegateFilter > delegate
LedgerIndex minLedgerSequence
LedgerIndex maxLedgerSequence
static constexpr auto kDatabasePath