xrpld
Loading...
Searching...
No Matches
RelationalDatabase.h
1#pragma once
2
3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/Log.h>
5#include <xrpl/basics/RangeSet.h>
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/core/ServiceRegistry.h>
9#include <xrpl/protocol/AccountID.h>
10#include <xrpl/protocol/ErrorCodes.h>
11#include <xrpl/protocol/LedgerHeader.h>
12#include <xrpl/protocol/LedgerShortcut.h>
13#include <xrpl/protocol/Protocol.h>
14#include <xrpl/protocol/TxMeta.h>
15#include <xrpl/protocol/TxSearched.h>
16
17#include <boost/variant.hpp>
18
19#include <concepts>
20#include <cstddef>
21#include <cstdint>
22#include <limits>
23#include <map>
24#include <memory>
25#include <optional>
26#include <tuple>
27#include <utility>
28#include <variant>
29#include <vector>
30
31namespace xrpl {
32
33class Transaction;
34class Ledger;
35
41
43{
44 uint32_t min;
45 uint32_t max;
46};
47
57
63
65{
66public:
73
79
92
102
107
108 using LedgerSequence = uint32_t;
111
122
131
132 virtual ~RelationalDatabase() = default;
133
141
149
157
164
172 getLedgerInfoByHash(uint256 const& ledgerHash) = 0;
173
180 virtual uint256
181 getHashByIndex(LedgerIndex ledgerIndex) = 0;
182
192
204
213 getTxHistory(LedgerIndex startIndex) = 0;
214
222
230
236 virtual void
238
244 virtual void
246
253 virtual void
255
262 virtual void
264
269 virtual std::size_t
271
277 virtual std::size_t
279
286 virtual CountMinMax
288
295 virtual bool
296 saveValidatedLedger(std::shared_ptr<Ledger const> const& ledger, bool current) = 0;
297
307
317
329 virtual AccountTxs
331
343 virtual AccountTxs
345
357 virtual MetaTxsList
359
372 virtual MetaTxsList
374
389
404
420
436
454 uint256 const& id,
456 ErrorCodeI& ec) = 0;
457
462 virtual uint32_t
464
470 virtual uint32_t
472
478 virtual uint32_t
480
484 virtual void
486
490 virtual void
492};
493
494template <typename T, typename C>
495T
497 requires(std::is_arithmetic_v<T> && std::is_arithmetic_v<C> && std::convertible_to<C, T>)
498{
502 {
503 // This should never happen
504 // LCOV_EXCL_START
505 UNREACHABLE("xrpl::rangeCheckedCast : domain error");
506 JLOG(debugLog().error()) << "rangeCheckedCast domain error:"
507 << " value = " << c
508 << " min = " << std::numeric_limits<T>::lowest()
509 << " max: " << std::numeric_limits<T>::max();
510 // LCOV_EXCL_STOP
511 }
512
513 return static_cast<T>(c);
514}
515
516} // namespace xrpl
virtual void closeTransactionDB()=0
Closes the transaction database.
virtual std::size_t getAccountTransactionCount()=0
getAccountTransactionCount Returns the number of account transactions.
virtual std::pair< MetaTxsList, std::optional< AccountTxMarker > > oldestAccountTxPageB(AccountTxPageOptions const &options)=0
oldestAccountTxPageB Returns the oldest transactions in binary form for the account that matches the ...
virtual std::optional< LedgerIndex > getTransactionsMinLedgerSeq()=0
getTransactionsMinLedgerSeq Returns the minimum ledger sequence stored in the Transactions table.
virtual void closeLedgerDB()=0
Closes the ledger database.
virtual void deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq)=0
deleteTransactionByLedgerSeq Deletes transactions from the ledger with the given sequence.
virtual void deleteBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteBeforeLedgerSeq Deletes all ledgers with a sequence number less than or equal to the given ledg...
virtual std::size_t getTransactionCount()=0
getTransactionCount Returns the number of transactions.
virtual ~RelationalDatabase()=default
virtual std::pair< AccountTxs, std::optional< AccountTxMarker > > newestAccountTxPage(AccountTxPageOptions const &options)=0
newestAccountTxPage Returns the newest transactions for the account that matches the given criteria s...
std::vector< AccountTx > AccountTxs
virtual std::optional< LedgerIndex > getAccountTransactionsMinLedgerSeq()=0
getAccountTransactionsMinLedgerSeq Returns the minimum ledger sequence stored in the AccountTransacti...
virtual std::map< LedgerIndex, LedgerHashPair > getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq)=0
getHashesByIndex Returns hashes of each ledger and its parent for all ledgers within the provided ran...
virtual bool saveValidatedLedger(std::shared_ptr< Ledger const > const &ledger, bool current)=0
saveValidatedLedger Saves a ledger into the database.
virtual std::optional< LedgerHeader > getNewestLedgerInfo()=0
getNewestLedgerInfo Returns the info of the newest saved ledger.
virtual uint32_t getKBUsedAll()=0
getKBUsedAll Returns the amount of space used by all databases.
virtual CountMinMax getLedgerCountMinMax()=0
getLedgerCountMinMax Returns the minimum ledger sequence, maximum ledger sequence and total number of...
virtual void deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteAccountTransactionsBeforeLedgerSeq Deletes all account transactions with a sequence number less...
virtual void deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteTransactionsBeforeLedgerSeq Deletes all transactions with a sequence number less than or equal ...
virtual std::optional< LedgerHeader > getLedgerInfoByHash(uint256 const &ledgerHash)=0
getLedgerInfoByHash Returns the info of the ledger with given hash.
virtual AccountTxs getOldestAccountTxs(AccountTxOptions const &options)=0
getOldestAccountTxs Returns the oldest transactions for the account that matches the given criteria s...
virtual std::variant< AccountTx, TxSearched > getTransaction(uint256 const &id, std::optional< ClosedInterval< uint32_t > > const &range, ErrorCodeI &ec)=0
getTransaction Returns the transaction with the given hash.
virtual std::pair< AccountTxs, std::optional< AccountTxMarker > > oldestAccountTxPage(AccountTxPageOptions const &options)=0
oldestAccountTxPage Returns the oldest transactions for the account that matches the given criteria s...
virtual std::optional< LedgerHeader > getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex)=0
getLimitedOldestLedgerInfo Returns the info of the oldest ledger whose sequence number is greater tha...
virtual uint256 getHashByIndex(LedgerIndex ledgerIndex)=0
getHashByIndex Returns the hash of the ledger with the given sequence.
virtual std::optional< LedgerHeader > getLedgerInfoByIndex(LedgerIndex ledgerSeq)=0
getLedgerInfoByIndex Returns a ledger by its sequence.
virtual std::optional< LedgerIndex > getMinLedgerSeq()=0
getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table.
virtual std::optional< LedgerIndex > getMaxLedgerSeq()=0
getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers table.
virtual MetaTxsList getNewestAccountTxsB(AccountTxOptions const &options)=0
getNewestAccountTxsB Returns the newest transactions in binary form for the account that matches the ...
std::vector< txnMetaLedgerType > MetaTxsList
virtual std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex)=0
getTxHistory Returns the 20 most recent transactions starting from the given number.
virtual std::pair< MetaTxsList, std::optional< AccountTxMarker > > newestAccountTxPageB(AccountTxPageOptions const &options)=0
newestAccountTxPageB Returns the newest transactions in binary form for the account that matches the ...
virtual std::optional< LedgerHeader > getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex)=0
getLimitedNewestLedgerInfo Returns the info of the newest ledger whose sequence number is greater tha...
virtual AccountTxs getNewestAccountTxs(AccountTxOptions const &options)=0
getNewestAccountTxs Returns the newest transactions for the account that matches the given criteria s...
std::variant< LedgerRange, LedgerShortcut, LedgerSequence, LedgerHash > LedgerSpecifier
virtual std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex)=0
getHashesByIndex Returns the hashes of the ledger and its parent as specified by the ledgerIndex.
virtual MetaTxsList getOldestAccountTxsB(AccountTxOptions const &options)=0
getOldestAccountTxsB Returns the oldest transactions in binary form for the account that matches the ...
std::tuple< Blob, Blob, std::uint32_t > txnMetaLedgerType
virtual uint32_t getKBUsedLedger()=0
getKBUsedLedger Returns the amount of space space used by the ledger database.
virtual uint32_t getKBUsedTransaction()=0
getKBUsedTransaction Returns the amount of space used by the transaction database.
std::pair< std::shared_ptr< Transaction >, std::shared_ptr< TxMeta > > AccountTx
T is_arithmetic_v
T lowest(T... args)
T max(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ErrorCodeI
Definition ErrorCodes.h:23
beast::Journal debugLog()
Returns a debug journal.
Definition Log.cpp:399
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:370
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition RangeSet.h:37
T rangeCheckedCast(C c)
DelegateType
Enumeration of possible delegate types that can occur during filtering in account_tx.
@ 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...
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition RangeSet.h:27
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
BaseUInt< 256 > uint256
Definition base_uint.h:580
std::optional< AccountID > counterparty
std::optional< AccountTxMarker > marker
std::optional< LedgerSpecifier > ledger
std::optional< DelegateFilter > delegate
LedgerRange ledgerRange
Ledger sequence range to search.
std::optional< DelegateFilter > delegate
std::variant< AccountTxs, MetaTxsList > transactions
std::optional< AccountTxMarker > marker