xrpld
Loading...
Searching...
No Matches
LedgerHashesEntry.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/ledger/entries/SLEBase.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/LedgerFormats.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STVector256.h>
12
13#include <cstddef>
14#include <optional>
15
16namespace xrpl {
17
18template <typename ViewT>
19class LedgerHashesEntry : public SLEBase<ViewT, ltLEDGER_HASHES>
20{
21public:
23
24 // Inherit base constructors: adopt an existing SLE, or resolve one from a
25 // Keylet against the view.
26 using Base::Base;
27
31 : Base(keylet::skip(), view, j)
32 {
33 }
34
49 [[nodiscard]] std::optional<UInt256>
50 hashAt(std::size_t diff) const
51 {
52 if (!this->exists())
53 return std::nullopt;
54 STVector256 const vec = (*this)->getFieldV256(sfHashes);
55 if (vec.size() > diff)
56 return vec[vec.size() - diff - 1];
57 return std::nullopt;
58 }
59};
60
63
64} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
static Sink & getNullSink()
Returns a Sink which does nothing.
SLEBase< ViewT, ltLEDGER_HASHES > Base
LedgerHashesEntry(Base::ViewRefType view, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
std::optional< UInt256 > hashAt(std::size_t diff) const
Looks up a hash diff slots back from the most recent entry in the sfHashes vector (diff == 0 is the m...
std::conditional_t< kIsWritable, ApplyView &, ReadView const & > ViewRefType
Definition SLEBase.h:106
SLEBase(SLEBase const &)=default
std::size_t size() const
Keylet computation functions.
Definition Indexes.h:40
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
LedgerHashesEntry< ApplyView > LedgerHashesEntryW
LedgerHashesEntry< ReadView > LedgerHashesEntryR