1#include <xrpl/rdb/DBInit.h>
2#include <xrpl/server/Wallet.h>
4#include <boost/format.hpp>
26 std::string const sql =
"SELECT RawData FROM " + dbTable +
";";
27 soci::blob sociRawData(session);
28 soci::statement st = (session.prepare << sql, soci::into(sociRawData));
33 convert(sociRawData, serialized);
38 JLOG(j.
warn()) <<
"Unverifiable manifest in db";
46 JLOG(j.
warn()) <<
"Malformed manifest in database";
57 soci::blob rawData(session);
59 session <<
"INSERT INTO " << dbTable <<
" (RawData) VALUES (:rawData);", soci::use(rawData);
64 soci::session& session,
70 soci::transaction tr(session);
71 session <<
"DELETE FROM " << dbTable;
72 for (
auto const& v : map)
76 if (!v.second.revoked() && !isTrusted(v.second.masterKey))
78 JLOG(j.
info()) <<
"Untrusted manifest in cache not saved to db";
90 soci::transaction tr(session);
98 session <<
"DELETE FROM NodeIdentity;";
106 boost::optional<std::string> pubKO, priKO;
108 (session.prepare <<
"SELECT PublicKey, PrivateKey FROM NodeIdentity;",
127 boost::format(
"INSERT INTO NodeIdentity (PublicKey,PrivateKey) "
128 "VALUES ('%s','%s');") %
131 return {newpublicKey, newsecretKey};
140 boost::optional<std::string> valPubKey, valDesc;
145 (session.prepare <<
"SELECT PublicKey, Description FROM PeerReservations;",
146 soci::into(valPubKey),
147 soci::into(valDesc));
151 if (!valPubKey || !valDesc)
160 JLOG(j.
warn()) <<
"load: not a public key: " << valPubKey;
173 session <<
"INSERT INTO PeerReservations (PublicKey, Description) "
174 "VALUES (:nodeId, :desc) "
175 "ON CONFLICT (PublicKey) DO UPDATE SET "
176 "Description=excluded.Description",
177 soci::use(sNodeId), soci::use(description);
184 session <<
"DELETE FROM PeerReservations WHERE PublicKey = :nodeId", soci::use(sNodeId);
190 soci::transaction tr(session);
192 "SELECT count(*) FROM sqlite_master "
193 "WHERE type='table' AND name='FeatureVotes'";
195 boost::optional<int> featureVotesCount;
196 session << sql, soci::into(featureVotesCount);
197 bool exists =
static_cast<bool>(*featureVotesCount);
202 session <<
"CREATE TABLE FeatureVotes ( "
203 "AmendmentHash CHARACTER(64) NOT NULL, "
204 "AmendmentName TEXT, "
205 "Veto INTEGER NOT NULL );";
213 soci::session& session,
215 boost::optional<std::string> amendment_hash,
216 boost::optional<std::string> amendment_name,
217 boost::optional<AmendmentVote> vote)>
const& callback)
220 auto intToVote = [](boost::optional<int>
const& dbVote) -> boost::optional<AmendmentVote> {
221 return safe_cast<AmendmentVote>(dbVote.value_or(1));
224 soci::transaction tr(session);
226 "SELECT AmendmentHash, AmendmentName, Veto FROM "
227 "( SELECT AmendmentHash, AmendmentName, Veto, RANK() OVER "
228 "( PARTITION BY AmendmentHash ORDER BY ROWID DESC ) "
229 "as rnk FROM FeatureVotes ) WHERE rnk = 1";
231 boost::optional<std::string> amendment_hash;
232 boost::optional<std::string> amendment_name;
233 boost::optional<int> vote_to_veto;
235 (session.prepare << sql, soci::into(amendment_hash), soci::into(amendment_name), soci::into(vote_to_veto));
239 callback(amendment_hash, amendment_name, intToVote(vote_to_veto));
246 soci::transaction tr(session);
248 "INSERT INTO FeatureVotes (AmendmentHash, AmendmentName, Veto) VALUES "
251 sql +=
"', '" + name;
A generic endpoint for log messages.
Remembers manifests with the highest sequence number.
ManifestDisposition applyManifest(Manifest m)
Add manifest to cache.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void getManifests(soci::session &session, std::string const &dbTable, ManifestCache &mCache, beast::Journal j)
getManifests Loads a manifest from the wallet database and stores it in the cache.
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
void saveManifests(soci::session &session, std::string const &dbTable, std::function< bool(PublicKey const &)> const &isTrusted, hash_map< PublicKey, Manifest > const &map, beast::Journal j)
saveManifests Saves all given manifests to the database.
std::string to_string(base_uint< Bits, Tag > const &a)
static void saveManifest(soci::session &session, std::string const &dbTable, std::string const &serialized)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
void deletePeerReservation(soci::session &session, PublicKey const &nodeId)
deletePeerReservation Deletes an entry from the peer reservation table.
std::pair< PublicKey, SecretKey > getNodeIdentity(soci::session &session)
Returns a stable public and private key for this node.
void insertPeerReservation(soci::session &session, PublicKey const &nodeId, std::string const &description)
insertPeerReservation Adds an entry to the peer reservation table.
std::unordered_set< PeerReservation, beast::uhash<>, KeyEqual > getPeerReservationTable(soci::session &session, beast::Journal j)
getPeerReservationTable Returns the peer reservation table.
constexpr auto WalletDBName
void addValidatorManifest(soci::session &session, std::string const &serialized)
addValidatorManifest Saves the manifest of a validator to the database.
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
void readAmendments(soci::session &session, std::function< void(boost::optional< std::string > amendment_hash, boost::optional< std::string > amendment_name, boost::optional< AmendmentVote > vote)> const &callback)
readAmendments Reads all amendments from the FeatureVotes table.
std::unique_ptr< DatabaseCon > makeWalletDB(DatabaseCon::Setup const &setup, beast::Journal j)
makeWalletDB Opens the wallet database and returns it.
bool createFeatureVotes(soci::session &session)
createFeatureVotes Creates the FeatureVote table if it does not exist.
void clearNodeIdentity(soci::session &session)
Delete any saved public/private key associated with this node.
constexpr std::array< char const *, 6 > WalletDBInit
std::unique_ptr< DatabaseCon > makeTestWalletDB(DatabaseCon::Setup const &setup, std::string const &dbname, beast::Journal j)
makeTestWalletDB Opens a test wallet database with an arbitrary name.
void voteAmendment(soci::session &session, uint256 const &amendment, std::string const &name, AmendmentVote vote)
voteAmendment Set the veto value for a particular amendment.
void convert(soci::blob &from, std::vector< std::uint8_t > &to)