1#include <xrpld/app/rdb/Wallet.h>
3#include <boost/format.hpp>
25 std::string const sql =
"SELECT RawData FROM " + dbTable +
";";
26 soci::blob sociRawData(session);
27 soci::statement st = (session.prepare << sql, soci::into(sociRawData));
32 convert(sociRawData, serialized);
37 JLOG(j.
warn()) <<
"Unverifiable manifest in db";
45 JLOG(j.
warn()) <<
"Malformed manifest in database";
56 soci::blob rawData(session);
58 session <<
"INSERT INTO " << dbTable <<
" (RawData) VALUES (:rawData);", soci::use(rawData);
63 soci::session& session,
69 soci::transaction tr(session);
70 session <<
"DELETE FROM " << dbTable;
71 for (
auto const& v : map)
75 if (!v.second.revoked() && !isTrusted(v.second.masterKey))
77 JLOG(j.
info()) <<
"Untrusted manifest in cache not saved to db";
89 soci::transaction tr(session);
97 session <<
"DELETE FROM NodeIdentity;";
105 boost::optional<std::string> pubKO, priKO;
107 (session.prepare <<
"SELECT PublicKey, PrivateKey FROM NodeIdentity;",
126 boost::format(
"INSERT INTO NodeIdentity (PublicKey,PrivateKey) "
127 "VALUES ('%s','%s');") %
130 return {newpublicKey, newsecretKey};
139 boost::optional<std::string> valPubKey, valDesc;
144 (session.prepare <<
"SELECT PublicKey, Description FROM PeerReservations;",
145 soci::into(valPubKey),
146 soci::into(valDesc));
150 if (!valPubKey || !valDesc)
159 JLOG(j.
warn()) <<
"load: not a public key: " << valPubKey;
172 session <<
"INSERT INTO PeerReservations (PublicKey, Description) "
173 "VALUES (:nodeId, :desc) "
174 "ON CONFLICT (PublicKey) DO UPDATE SET "
175 "Description=excluded.Description",
176 soci::use(sNodeId), soci::use(description);
183 session <<
"DELETE FROM PeerReservations WHERE PublicKey = :nodeId", soci::use(sNodeId);
189 soci::transaction tr(session);
191 "SELECT count(*) FROM sqlite_master "
192 "WHERE type='table' AND name='FeatureVotes'";
194 boost::optional<int> featureVotesCount;
195 session << sql, soci::into(featureVotesCount);
196 bool exists =
static_cast<bool>(*featureVotesCount);
201 session <<
"CREATE TABLE FeatureVotes ( "
202 "AmendmentHash CHARACTER(64) NOT NULL, "
203 "AmendmentName TEXT, "
204 "Veto INTEGER NOT NULL );";
212 soci::session& session,
214 boost::optional<std::string> amendment_hash,
215 boost::optional<std::string> amendment_name,
216 boost::optional<AmendmentVote> vote)>
const& callback)
219 auto intToVote = [](boost::optional<int>
const& dbVote) -> boost::optional<AmendmentVote> {
220 return safe_cast<AmendmentVote>(dbVote.value_or(1));
223 soci::transaction tr(session);
225 "SELECT AmendmentHash, AmendmentName, Veto FROM "
226 "( SELECT AmendmentHash, AmendmentName, Veto, RANK() OVER "
227 "( PARTITION BY AmendmentHash ORDER BY ROWID DESC ) "
228 "as rnk FROM FeatureVotes ) WHERE rnk = 1";
230 boost::optional<std::string> amendment_hash;
231 boost::optional<std::string> amendment_name;
232 boost::optional<int> vote_to_veto;
234 (session.prepare << sql, soci::into(amendment_hash), soci::into(amendment_name), soci::into(vote_to_veto));
238 callback(amendment_hash, amendment_name, intToVote(vote_to_veto));
245 soci::transaction tr(session);
247 "INSERT INTO FeatureVotes (AmendmentHash, AmendmentName, Veto) VALUES "
250 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.
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
std::pair< PublicKey, SecretKey > getNodeIdentity(Application &app, boost::program_options::variables_map const &cmdline)
The cryptographic credentials identifying this server instance.
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
void voteAmendment(soci::session &session, uint256 const &amendment, std::string const &name, AmendmentVote vote)
voteAmendment Set the veto value for a particular amendment.
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 addValidatorManifest(soci::session &session, std::string const &serialized)
addValidatorManifest Saves the manifest of a validator to the database.
std::unordered_set< PeerReservation, beast::uhash<>, KeyEqual > getPeerReservationTable(soci::session &session, beast::Journal j)
getPeerReservationTable Returns the peer reservation table.
constexpr auto WalletDBName
void deletePeerReservation(soci::session &session, PublicKey const &nodeId)
deletePeerReservation Deletes an entry from the peer reservation table.
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
std::unique_ptr< DatabaseCon > makeWalletDB(DatabaseCon::Setup const &setup, beast::Journal j)
makeWalletDB Opens the wallet database and returns it.
void insertPeerReservation(soci::session &session, PublicKey const &nodeId, std::string const &description)
insertPeerReservation Adds an entry to the peer reservation table.
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.
bool createFeatureVotes(soci::session &session)
createFeatureVotes Creates the FeatureVote table if it does not exist.
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::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 clearNodeIdentity(soci::session &session)
Delete any saved public/private key associated with this node.
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.
constexpr std::array< char const *, 6 > WalletDBInit
void convert(soci::blob &from, std::vector< std::uint8_t > &to)