20#include <xrpld/app/rdb/Wallet.h> 
   22#include <boost/format.hpp> 
   47    soci::session& session,
 
   53    std::string const sql = 
"SELECT RawData FROM " + dbTable + 
";";
 
   54    soci::blob sociRawData(session);
 
   55    soci::statement st = (session.prepare << sql, soci::into(sociRawData));
 
   60        convert(sociRawData, serialized);
 
   65                JLOG(j.
warn()) << 
"Unverifiable manifest in db";
 
   73            JLOG(j.
warn()) << 
"Malformed manifest in database";
 
 
   80    soci::session& session,
 
   87    soci::blob rawData(session);
 
   89    session << 
"INSERT INTO " << dbTable << 
" (RawData) VALUES (:rawData);",
 
 
   95    soci::session& session,
 
  101    soci::transaction tr(session);
 
  102    session << 
"DELETE FROM " << dbTable;
 
  103    for (
auto const& v : map)
 
  107        if (!v.second.revoked() && !isTrusted(v.second.masterKey))
 
  109            JLOG(j.
info()) << 
"Untrusted manifest in cache not saved to db";
 
 
  121    soci::transaction tr(session);
 
  122    saveManifest(session, 
"ValidatorManifests", serialized);
 
 
  129    session << 
"DELETE FROM NodeIdentity;";
 
 
  137        boost::optional<std::string> pubKO, priKO;
 
  140                 << 
"SELECT PublicKey, PrivateKey FROM NodeIdentity;",
 
  146            auto const sk = parseBase58<SecretKey>(
 
  148            auto const pk = parseBase58<PublicKey>(
 
  161        boost::format(
"INSERT INTO NodeIdentity (PublicKey,PrivateKey) " 
  162                      "VALUES ('%s','%s');") %
 
  166    return {newpublicKey, newsecretKey};
 
 
  175    boost::optional<std::string> valPubKey, valDesc;
 
  181             << 
"SELECT PublicKey, Description FROM PeerReservations;",
 
  182         soci::into(valPubKey),
 
  183         soci::into(valDesc));
 
  187        if (!valPubKey || !valDesc)
 
  193        auto const optNodeId =
 
  197            JLOG(j.
warn()) << 
"load: not a public key: " << valPubKey;
 
 
  208    soci::session& session,
 
  213    session << 
"INSERT INTO PeerReservations (PublicKey, Description) " 
  214               "VALUES (:nodeId, :desc) " 
  215               "ON CONFLICT (PublicKey) DO UPDATE SET " 
  216               "Description=excluded.Description",
 
  217        soci::use(sNodeId), soci::use(description);
 
 
  224    session << 
"DELETE FROM PeerReservations WHERE PublicKey = :nodeId",
 
 
  231    soci::transaction tr(session);
 
  233        "SELECT count(*) FROM sqlite_master " 
  234        "WHERE type='table' AND name='FeatureVotes'";
 
  236    boost::optional<int> featureVotesCount;
 
  237    session << sql, soci::into(featureVotesCount);
 
  238    bool exists = 
static_cast<bool>(*featureVotesCount);
 
  243        session << 
"CREATE TABLE  FeatureVotes ( " 
  244                   "AmendmentHash      CHARACTER(64) NOT NULL, " 
  245                   "AmendmentName      TEXT, " 
  246                   "Veto               INTEGER NOT NULL );";
 
 
  254    soci::session& session,
 
  256        boost::optional<std::string> amendment_hash,
 
  257        boost::optional<std::string> amendment_name,
 
  258        boost::optional<AmendmentVote> vote)> 
const& callback)
 
  261    auto intToVote = [](boost::optional<int> 
const& dbVote)
 
  262        -> boost::optional<AmendmentVote> {
 
  263        return safe_cast<AmendmentVote>(dbVote.value_or(1));
 
  266    soci::transaction tr(session);
 
  268        "SELECT AmendmentHash, AmendmentName, Veto FROM " 
  269        "( SELECT AmendmentHash, AmendmentName, Veto, RANK() OVER " 
  270        "(  PARTITION BY AmendmentHash ORDER BY ROWID DESC ) " 
  271        "as rnk FROM FeatureVotes ) WHERE rnk = 1";
 
  273    boost::optional<std::string> amendment_hash;
 
  274    boost::optional<std::string> amendment_name;
 
  275    boost::optional<int> vote_to_veto;
 
  277        (session.prepare << sql,
 
  278         soci::into(amendment_hash),
 
  279         soci::into(amendment_name),
 
  280         soci::into(vote_to_veto));
 
  284        callback(amendment_hash, amendment_name, intToVote(vote_to_veto));
 
 
  290    soci::session& session,
 
  295    soci::transaction tr(session);
 
  297        "INSERT INTO FeatureVotes (AmendmentHash, AmendmentName, Veto) VALUES " 
  300    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::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
 
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
 
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::unordered_set< PeerReservation, beast::uhash<>, KeyEqual > getPeerReservationTable(soci::session &session, beast::Journal j)
getPeerReservationTable Returns the peer reservation table.
 
void insertPeerReservation(soci::session &session, PublicKey const &nodeId, std::string const &description)
insertPeerReservation Adds an entry to the peer reservation table.
 
void addValidatorManifest(soci::session &session, std::string const &serialized)
addValidatorManifest Saves the manifest of a validator to the database.
 
std::pair< PublicKey, SecretKey > getNodeIdentity(Application &app, boost::program_options::variables_map const &cmdline)
The cryptographic credentials identifying this server instance.
 
bool createFeatureVotes(soci::session &session)
createFeatureVotes Creates the FeatureVote table if it does not exist.
 
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 convert(soci::blob &from, std::vector< std::uint8_t > &to)
 
constexpr std::array< char const  *, 6 > WalletDBInit
 
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
 
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.
 
void clearNodeIdentity(soci::session &session)
Delete any saved public/private key associated with this node.
 
std::unique_ptr< DatabaseCon > makeWalletDB(DatabaseCon::Setup const &setup, beast::Journal j)
makeWalletDB Opens the wallet database and returns it.
 
std::string to_string(base_uint< Bits, Tag > const &a)
 
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
 
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.
 
void deletePeerReservation(soci::session &session, PublicKey const &nodeId)
deletePeerReservation Deletes an entry from the peer reservation table.
 
static void saveManifest(soci::session &session, std::string const &dbTable, std::string const &serialized)
 
void voteAmendment(soci::session &session, uint256 const &amendment, std::string const &name, AmendmentVote vote)
voteAmendment Set the veto value for a particular amendment.
 
constexpr auto WalletDBName