rippled
Loading...
Searching...
No Matches
RelationalDatabase.h
1#pragma once
2
3#include <xrpl/basics/RangeSet.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/core/ServiceRegistry.h>
6#include <xrpl/protocol/ErrorCodes.h>
7#include <xrpl/protocol/LedgerHeader.h>
8#include <xrpl/protocol/LedgerShortcut.h>
9#include <xrpl/protocol/TxMeta.h>
10#include <xrpl/protocol/TxSearched.h>
11#include <xrpl/rdb/DatabaseCon.h>
12
13#include <boost/filesystem.hpp>
14#include <boost/variant.hpp>
15
16namespace xrpl {
17
18class Transaction;
19class Ledger;
20
26
28{
29 uint32_t min;
30 uint32_t max;
31};
32
34{
35public:
42
48
58
68
73
74 using LedgerSequence = uint32_t;
77
87
95
96 virtual ~RelationalDatabase() = default;
97
105
113
121
128
136 getLedgerInfoByHash(uint256 const& ledgerHash) = 0;
137
144 virtual uint256
145 getHashByIndex(LedgerIndex ledgerIndex) = 0;
146
156
168
177 getTxHistory(LedgerIndex startIndex) = 0;
178
186
194
200 virtual void
202
208 virtual void
210
217 virtual void
219
226 virtual void
228
233 virtual std::size_t
235
241 virtual std::size_t
243
250 virtual struct CountMinMax
252
259 virtual bool
261
271
281
293 virtual AccountTxs
295
307 virtual AccountTxs
309
321 virtual MetaTxsList
323
336 virtual MetaTxsList
338
353
368
384
400
418
423 virtual uint32_t
425
431 virtual uint32_t
433
439 virtual uint32_t
441
445 virtual void
447
451 virtual void
453};
454
455template <class T, class C>
456T
458{
462 {
463 // This should never happen
464 // LCOV_EXCL_START
465 UNREACHABLE("xrpl::rangeCheckedCast : domain error");
466 JLOG(debugLog().error()) << "rangeCheckedCast domain error:"
467 << " value = " << c << " min = " << std::numeric_limits<T>::lowest()
468 << " max: " << std::numeric_limits<T>::max();
469 // LCOV_EXCL_STOP
470 }
471
472 return static_cast<T>(c);
473}
474
475} // namespace xrpl
virtual void closeTransactionDB()=0
Closes the transaction database.
virtual std::size_t getAccountTransactionCount()=0
getAccountTransactionCount Returns the number of account transactions.
virtual struct CountMinMax getLedgerCountMinMax()=0
getLedgerCountMinMax Returns the minimum ledger sequence, maximum ledger sequence and total number of...
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...
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 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::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 ...
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 std::variant< AccountTx, TxSearched > getTransaction(uint256 const &id, std::optional< ClosedInterval< uint32_t > > const &range, error_code_i &ec)=0
getTransaction Returns the transaction with the given hash.
virtual AccountTxs getNewestAccountTxs(AccountTxOptions const &options)=0
getNewestAccountTxs Returns the newest transactions for the account that matches the given criteria s...
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 ...
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.
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
beast::Journal debugLog()
Returns a debug journal.
Definition Log.cpp:445
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition RangeSet.h:34
@ current
This was a new validation and was added.
base_uint< 256 > uint256
Definition base_uint.h:526
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition RangeSet.h:25
error_code_i
Definition ErrorCodes.h:20
T rangeCheckedCast(C c)
std::optional< AccountTxMarker > marker
std::optional< LedgerSpecifier > ledger
std::variant< AccountTxs, MetaTxsList > transactions
std::optional< AccountTxMarker > marker