xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
ledger
entries
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
16
namespace
xrpl
{
17
18
template
<
typename
ViewT>
19
class
LedgerHashesEntry
:
public
SLEBase
<ViewT, ltLEDGER_HASHES>
20
{
21
public
:
22
using
Base
=
SLEBase<ViewT, ltLEDGER_HASHES>
;
23
24
// Inherit base constructors: adopt an existing SLE, or resolve one from a
25
// Keylet against the view.
26
using
Base::Base;
27
28
explicit
LedgerHashesEntry
(
29
Base::ViewRefType
view,
30
beast::Journal
j =
beast::Journal
{
beast::Journal::getNullSink
()})
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
61
using
LedgerHashesEntryR
=
LedgerHashesEntry<ReadView>
;
62
using
LedgerHashesEntryW
=
LedgerHashesEntry<ApplyView>
;
63
64
}
// namespace xrpl
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition
beast_Journal.cpp:63
xrpl::LedgerHashesEntry
Definition
LedgerHashesEntry.h:20
xrpl::LedgerHashesEntry::Base
SLEBase< ViewT, ltLEDGER_HASHES > Base
Definition
LedgerHashesEntry.h:22
xrpl::LedgerHashesEntry::LedgerHashesEntry
LedgerHashesEntry(Base::ViewRefType view, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
Definition
LedgerHashesEntry.h:28
xrpl::LedgerHashesEntry::hashAt
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...
Definition
LedgerHashesEntry.h:50
xrpl::SLEBase< ViewT, ltLEDGER_HASHES >::exists
bool exists() const
Definition
SLEBase.h:227
xrpl::SLEBase::ViewRefType
std::conditional_t< kIsWritable, ApplyView &, ReadView const & > ViewRefType
Definition
SLEBase.h:106
xrpl::SLEBase< ViewT, ltLEDGER_HASHES >::SLEBase
SLEBase(SLEBase const &)=default
xrpl::STVector256
Definition
STVector256.h:17
xrpl::STVector256::size
std::size_t size() const
Definition
STVector256.h:153
cstddef
xrpl::keylet
Keylet computation functions.
Definition
Indexes.h:40
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::LedgerHashesEntryW
LedgerHashesEntry< ApplyView > LedgerHashesEntryW
Definition
LedgerHashesEntry.h:62
xrpl::LedgerHashesEntryR
LedgerHashesEntry< ReadView > LedgerHashesEntryR
Definition
LedgerHashesEntry.h:61
optional
std::size_t
Generated by
1.17.0