xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
rdb
DBInit.h
1
#pragma once
2
3
#include <
array
>
4
#include <
cstdint
>
5
#include <format>
6
#include <
string
>
7
#include <
string_view
>
8
9
namespace
xrpl
{
10
12
13
// These pragmas are built at startup and applied to all database
14
// connections, unless otherwise noted.
15
//
16
// They are exposed as functions rather than as format-string constants so
17
// that the un-substituted template can never reach sqlite: an unrecognized
18
// pragma value is silently ignored, so forgetting to interpolate would
19
// leave the setting at its default instead of failing loudly.
20
[[nodiscard]]
inline
std::string
21
commonDbPragmaJournal
(
std::string_view
journalMode)
22
{
23
return
std::format
(
"PRAGMA journal_mode={};"
, journalMode);
24
}
25
26
[[nodiscard]]
inline
std::string
27
commonDbPragmaSync
(
std::string_view
synchronous)
28
{
29
return
std::format
(
"PRAGMA synchronous={};"
, synchronous);
30
}
31
32
[[nodiscard]]
inline
std::string
33
commonDbPragmaTemp
(
std::string_view
tempStore)
34
{
35
return
std::format
(
"PRAGMA temp_store={};"
, tempStore);
36
}
37
38
// A warning will be logged if any lower-safety sqlite tuning settings
39
// are used and at least this much ledger history is configured. This
40
// includes full history nodes. This is because such a large amount of
41
// data will be more difficult to recover if a rare failure occurs,
42
// which are more likely with some of the other available tuning settings.
43
inline
constexpr
std::uint32_t
kSqliteTuningCutoff
= 10'000'000;
44
45
// Ledger database holds ledgers and ledger confirmations
46
inline
constexpr
auto
kLgrDbName
{
"ledger.db"
};
47
48
inline
constexpr
std::array<char const*, 5>
kLgrDbInit
{
49
{
"BEGIN TRANSACTION;"
,
50
51
"CREATE TABLE IF NOT EXISTS Ledgers ( \
52
LedgerHash CHARACTER(64) PRIMARY KEY, \
53
LedgerSeq BIGINT UNSIGNED, \
54
PrevHash CHARACTER(64), \
55
TotalCoins BIGINT UNSIGNED, \
56
ClosingTime BIGINT UNSIGNED, \
57
PrevClosingTime BIGINT UNSIGNED, \
58
CloseTimeRes BIGINT UNSIGNED, \
59
CloseFlags BIGINT UNSIGNED, \
60
AccountSetHash CHARACTER(64), \
61
TransSetHash CHARACTER(64) \
62
);"
,
63
"CREATE INDEX IF NOT EXISTS SeqLedger ON Ledgers(LedgerSeq);"
,
64
65
// Old table and indexes no longer needed
66
"DROP TABLE IF EXISTS Validations;"
,
67
68
"END TRANSACTION;"
}};
69
71
72
// Transaction database holds transactions and public keys
73
inline
constexpr
auto
kTxDbName
{
"transaction.db"
};
74
75
inline
constexpr
std::array<char const*, 8>
kTxDbInit
{
76
{
"BEGIN TRANSACTION;"
,
77
78
"CREATE TABLE IF NOT EXISTS Transactions ( \
79
TransID CHARACTER(64) PRIMARY KEY, \
80
TransType CHARACTER(24), \
81
FromAcct CHARACTER(35), \
82
FromSeq BIGINT UNSIGNED, \
83
LedgerSeq BIGINT UNSIGNED, \
84
Status CHARACTER(1), \
85
RawTxn BLOB, \
86
TxnMeta BLOB \
87
);"
,
88
"CREATE INDEX IF NOT EXISTS TxLgrIndex ON \
89
Transactions(LedgerSeq);"
,
90
91
"CREATE TABLE IF NOT EXISTS AccountTransactions ( \
92
TransID CHARACTER(64), \
93
Account CHARACTER(64), \
94
LedgerSeq BIGINT UNSIGNED, \
95
TxnSeq INTEGER \
96
);"
,
97
"CREATE INDEX IF NOT EXISTS AcctTxIDIndex ON \
98
AccountTransactions(TransID);"
,
99
"CREATE INDEX IF NOT EXISTS AcctTxIndex ON \
100
AccountTransactions(Account, LedgerSeq, TxnSeq, TransID);"
,
101
"CREATE INDEX IF NOT EXISTS AcctLgrIndex ON \
102
AccountTransactions(LedgerSeq, Account, TransID);"
,
103
104
"END TRANSACTION;"
}};
105
107
108
inline
constexpr
auto
kWalletDbName
{
"wallet.db"
};
109
110
inline
constexpr
std::array<char const*, 6>
kWalletDbInit
{
111
{
"BEGIN TRANSACTION;"
,
112
113
// A node's identity must be persisted, including
114
// for clustering purposes. This table holds one
115
// entry: the server's unique identity, but the
116
// value can be overriden by specifying a node
117
// identity in the config file using a [node_seed]
118
// entry.
119
"CREATE TABLE IF NOT EXISTS NodeIdentity ( \
120
PublicKey CHARACTER(53), \
121
PrivateKey CHARACTER(52) \
122
);"
,
123
124
// Peer reservations
125
"CREATE TABLE IF NOT EXISTS PeerReservations ( \
126
PublicKey CHARACTER(53) UNIQUE NOT NULL, \
127
Description CHARACTER(64) NOT NULL \
128
);"
,
129
130
// Validator Manifests
131
"CREATE TABLE IF NOT EXISTS ValidatorManifests ( \
132
RawData BLOB NOT NULL \
133
);"
,
134
135
"CREATE TABLE IF NOT EXISTS PublisherManifests ( \
136
RawData BLOB NOT NULL \
137
);"
,
138
139
"END TRANSACTION;"
}};
140
141
}
// namespace xrpl
array
std::string
std::string_view
cstdint
std::format
T format(T... args)
std::uint32_t
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::kLgrDbInit
constexpr std::array< char const *, 5 > kLgrDbInit
Definition
DBInit.h:48
xrpl::kSqliteTuningCutoff
constexpr std::uint32_t kSqliteTuningCutoff
Definition
DBInit.h:43
xrpl::kTxDbInit
constexpr std::array< char const *, 8 > kTxDbInit
Definition
DBInit.h:75
xrpl::kWalletDbName
constexpr auto kWalletDbName
Definition
DBInit.h:108
xrpl::commonDbPragmaJournal
std::string commonDbPragmaJournal(std::string_view journalMode)
Definition
DBInit.h:21
xrpl::kLgrDbName
constexpr auto kLgrDbName
Definition
DBInit.h:46
xrpl::kWalletDbInit
constexpr std::array< char const *, 6 > kWalletDbInit
Definition
DBInit.h:110
xrpl::commonDbPragmaTemp
std::string commonDbPragmaTemp(std::string_view tempStore)
Definition
DBInit.h:33
xrpl::kTxDbName
constexpr auto kTxDbName
Definition
DBInit.h:73
xrpl::commonDbPragmaSync
std::string commonDbPragmaSync(std::string_view synchronous)
Definition
DBInit.h:27
string
string_view
Generated by
1.17.0