rippled
Loading...
Searching...
No Matches
RelationalDatabase.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2020 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_RDB_RELATIONALDATABASE_H_INCLUDED
21#define RIPPLE_APP_RDB_RELATIONALDATABASE_H_INCLUDED
22
23#include <xrpld/app/ledger/Ledger.h>
24#include <xrpld/app/main/Application.h>
25#include <xrpld/app/misc/Transaction.h>
26#include <xrpld/core/Config.h>
27#include <xrpld/core/DatabaseCon.h>
28#include <xrpld/rpc/detail/RPCHelpers.h>
29
30#include <xrpl/beast/utility/instrumentation.h>
31
32#include <boost/filesystem.hpp>
33#include <boost/variant.hpp>
34
35namespace ripple {
36
42
44{
45 uint32_t min;
46 uint32_t max;
47};
48
50{
51public:
58
64
74
84
85 using AccountTx =
90
91 using LedgerSequence = uint32_t;
96
106
114
124 init(Application& app, Config const& config, JobQueue& jobQueue);
125
126 virtual ~RelationalDatabase() = default;
127
135
143
151
158
166 getLedgerInfoByHash(uint256 const& ledgerHash) = 0;
167
174 virtual uint256
175 getHashByIndex(LedgerIndex ledgerIndex) = 0;
176
186
198
207 getTxHistory(LedgerIndex startIndex) = 0;
208
215 virtual bool
216 ledgerDbHasSpace(Config const& config) = 0;
217
224 virtual bool
225 transactionDbHasSpace(Config const& config) = 0;
226};
227
228template <class T, class C>
229T
231{
232 if ((c > std::numeric_limits<T>::max()) ||
237 {
238 // This should never happen
239 // LCOV_EXCL_START
240 UNREACHABLE("ripple::rangeCheckedCast : domain error");
241 JLOG(debugLog().error())
242 << "rangeCheckedCast domain error:"
243 << " value = " << c << " min = " << std::numeric_limits<T>::lowest()
244 << " max: " << std::numeric_limits<T>::max();
245 // LCOV_EXCL_STOP
246 }
247
248 return static_cast<T>(c);
249}
250
251} // namespace ripple
252
253#endif
A pool of threads to perform work.
Definition JobQueue.h:58
virtual std::optional< LedgerInfo > getNewestLedgerInfo()=0
getNewestLedgerInfo Returns the info of the newest saved ledger.
virtual ~RelationalDatabase()=default
virtual std::optional< LedgerInfo > getLedgerInfoByIndex(LedgerIndex ledgerSeq)=0
getLedgerInfoByIndex Returns a ledger by its sequence.
virtual std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex)=0
getTxHistory Returns the 20 most recent transactions starting from the given number.
virtual bool transactionDbHasSpace(Config const &config)=0
transactionDbHasSpace Checks if the transaction database has available space.
virtual std::optional< LedgerIndex > getMaxLedgerSeq()=0
getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers table.
virtual bool ledgerDbHasSpace(Config const &config)=0
ledgerDbHasSpace Checks if the ledger database has available space.
static std::unique_ptr< RelationalDatabase > init(Application &app, Config const &config, JobQueue &jobQueue)
init Creates and returns an appropriate RelationalDatabase instance based on configuration.
virtual std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex)=0
getHashesByIndex Returns the hashes of the ledger and its parent as specified by the ledgerIndex.
virtual std::optional< LedgerIndex > getMinLedgerSeq()=0
getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table.
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 std::optional< LedgerInfo > getLedgerInfoByHash(uint256 const &ledgerHash)=0
getLedgerInfoByHash Returns the info of the ledger with given hash.
virtual uint256 getHashByIndex(LedgerIndex ledgerIndex)=0
getHashByIndex Returns the hash of the ledger with the given sequence.
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:25
base_uint< 256 > uint256
Definition base_uint.h:558
T rangeCheckedCast(C c)
beast::Journal debugLog()
Returns a debug journal.
Definition Log.cpp:476
std::optional< AccountTxMarker > marker
std::optional< LedgerSpecifier > ledger
std::optional< AccountTxMarker > marker
std::variant< AccountTxs, MetaTxsList > transactions