xrpld
Loading...
Searching...
No Matches
AmendmentsEntry.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/ledger/ApplyView.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/ledger/entries/SLEBase.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/LedgerFormats.h>
11#include <xrpl/protocol/SField.h>
12
13#include <map>
14#include <set>
15
16namespace xrpl {
17
18template <typename ViewT>
19class AmendmentsEntry : public SLEBase<ViewT, ltAMENDMENTS>
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::amendments(), view, j)
32 {
33 }
34
40 [[nodiscard]] std::set<UInt256>
42 {
43 std::set<UInt256> amendments;
44
45 if (this->exists() && (*this)->isFieldPresent(sfAmendments))
46 {
47 auto const& v = (*this)->getFieldV256(sfAmendments);
48 amendments.insert_range(v);
49 }
50
51 return amendments;
52 }
53
62 {
64
65 if (this->exists() && (*this)->isFieldPresent(sfMajorities))
66 {
67 using TimePoint = NetClock::time_point;
68 using Duration = TimePoint::duration;
69
70 auto const majorities = (*this)->getFieldArray(sfMajorities);
71
72 for (auto const& m : majorities)
73 {
74 ret[m.getFieldH256(sfAmendment)] = TimePoint(Duration(m.getFieldU32(sfCloseTime)));
75 }
76 }
77
78 return ret;
79 }
80};
81
84
85} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
static Sink & getNullSink()
Returns a Sink which does nothing.
SLEBase< ViewT, ltAMENDMENTS > Base
std::set< UInt256 > enabledAmendments() const
Returns the set of amendments this entry reports as enabled.
AmendmentsEntry(Base::ViewRefType view, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
std::map< UInt256, NetClock::time_point > majorityAmendments() const
Returns a map of amendments that have achieved majority, to the time majority was reached.
std::chrono::time_point< NetClock > time_point
Definition chrono.h:48
std::conditional_t< kIsWritable, ApplyView &, ReadView const & > ViewRefType
Definition SLEBase.h:106
SLEBase(SLEBase const &)=default
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
AmendmentsEntry< ReadView > AmendmentsEntryR
AmendmentsEntry< ApplyView > AmendmentsEntryW