xrpld
Loading...
Searching...
No Matches
Validation.h
1#pragma once
2
3#include <xrpl/basics/chrono.h>
4#include <xrpl/basics/tagged_integer.h>
5
6#include <csf/ledgers.h>
7
8#include <cstdint>
9#include <optional>
10#include <tuple>
11#include <utility>
12
13namespace xrpl::test::csf {
14
15struct PeerIDTag;
16//< Uniquely identifies a peer
18
27
32{
35
40 bool trusted_ = false;
41 bool full_ = false;
44
45public:
47 using NodeID = PeerID;
48
50 Ledger::ID id,
56 bool full,
59 : ledgerID_{id}
60 , seq_{seq}
62 , seenTime_{seen}
63 , key_{std::move(key)}
65 , full_{full}
68 {
69 }
70
71 [[nodiscard]] Ledger::ID
72 ledgerID() const
73 {
74 return ledgerID_;
75 }
76
77 [[nodiscard]] Ledger::Seq
78 seq() const
79 {
80 return seq_;
81 }
82
83 [[nodiscard]] NetClock::time_point
84 signTime() const
85 {
86 return signTime_;
87 }
88
89 [[nodiscard]] NetClock::time_point
90 seenTime() const
91 {
92 return seenTime_;
93 }
94
95 [[nodiscard]] PeerKey const&
96 key() const
97 {
98 return key_;
99 }
100
101 [[nodiscard]] PeerID const&
102 nodeID() const
103 {
104 return nodeID_;
105 }
106
107 [[nodiscard]] bool
108 trusted() const
109 {
110 return trusted_;
111 }
112
113 [[nodiscard]] bool
114 full() const
115 {
116 return full_;
117 }
118
119 [[nodiscard]] std::uint64_t
120 cookie() const
121 {
122 return cookie_;
123 }
124
125 [[nodiscard]] std::optional<std::uint32_t>
126 loadFee() const
127 {
128 return loadFee_;
129 }
130
131 [[nodiscard]] Validation const&
132 unwrap() const
133 {
134 // For the xrpld implementation in which RCLValidation wraps
135 // STValidation, the csf::Validation has no more specific type it
136 // wraps, so csf::Validation unwraps to itself
137 return *this;
138 }
139
140 [[nodiscard]] auto
141 asTie() const
142 {
143 // trusted is a status set by the receiver, so it is not part of the tie
145 }
146 bool
147 operator==(Validation const& o) const
148 {
149 return asTie() == o.asTie();
150 }
151
152 bool
153 operator<(Validation const& o) const
154 {
155 return asTie() < o.asTie();
156 }
157
158 void
160 {
161 trusted_ = true;
162 }
163
164 void
166 {
167 trusted_ = false;
168 }
169
170 void
172 {
173 seenTime_ = seen;
174 }
175};
176
177} // namespace xrpl::test::csf
std::chrono::time_point< NetClock > time_point
Definition chrono.h:48
A type-safe wrap around standard integral types.
TaggedInteger< std::uint32_t, IdTag > ID
Definition ledgers.h:56
TaggedInteger< std::uint32_t, SeqTag > Seq
Definition ledgers.h:53
Validation of a specific ledger by a specific Peer.
Definition Validation.h:32
std::optional< std::uint32_t > loadFee() const
Definition Validation.h:126
std::optional< std::uint32_t > loadFee_
Definition Validation.h:42
NetClock::time_point seenTime() const
Definition Validation.h:90
bool operator==(Validation const &o) const
Definition Validation.h:147
void setSeen(NetClock::time_point seen)
Definition Validation.h:171
NetClock::time_point signTime_
Definition Validation.h:36
PeerKey const & key() const
Definition Validation.h:96
std::uint64_t cookie() const
Definition Validation.h:120
NetClock::time_point signTime() const
Definition Validation.h:84
PeerID const & nodeID() const
Definition Validation.h:102
NetClock::time_point seenTime_
Definition Validation.h:37
Validation(Ledger::ID id, Ledger::Seq seq, NetClock::time_point sign, NetClock::time_point seen, PeerKey key, PeerID nodeID, bool full, std::optional< std::uint32_t > loadFee=std::nullopt, std::uint64_t cookie=0)
Definition Validation.h:49
bool operator<(Validation const &o) const
Definition Validation.h:153
Ledger::Seq seq() const
Definition Validation.h:78
Ledger::ID ledgerID() const
Definition Validation.h:72
Validation const & unwrap() const
Definition Validation.h:132
STL namespace.
TaggedInteger< std::uint32_t, PeerIDTag > PeerID
Definition Validation.h:17
std::pair< PeerID, std::uint32_t > PeerKey
The current key of a peer.
Definition Validation.h:26
void sign(json::Value &jv, Account const &account, json::Value &sigObject)
Sign automatically into a specific Json field of the jv object.
Definition utility.cpp:40
T tie(T... args)