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