xrpld
Loading...
Searching...
No Matches
OwnerCounts.h
1#pragma once
2
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/protocol/LedgerFormats.h>
5#include <xrpl/protocol/SField.h>
6#include <xrpl/protocol/STInteger.h> // IWYU pragma: keep
7#include <xrpl/protocol/STLedgerEntry.h>
8
9#include <cstdint>
10#include <limits>
11
12namespace xrpl {
13
15{
19
20 OwnerCounts() = default;
22 : owner(sle->at(sfOwnerCount))
23 , sponsored(sle->at(sfSponsoredOwnerCount))
24 , sponsoring(sle->at(sfSponsoringOwnerCount))
25 {
26 XRPL_ASSERT(
28 "xrpl::OwnerCounts : OwnerCount must be greater than or equal to "
29 "SponsoredOwnerCount");
30 XRPL_ASSERT(sle->getType() == ltACCOUNT_ROOT, "xrpl::OwnerCounts : sle is AccountRoot");
31 }
32
33 [[nodiscard]] std::uint32_t
34 count() const
35 {
36 std::int64_t const x = static_cast<std::int64_t>(owner) - sponsored + sponsoring;
37 if (x < 0)
38 {
39 // LCOV_EXCL_START
40 UNREACHABLE("xrpl::OwnerCounts::count : count less than zero");
41 return 0;
42 // LCOV_EXCL_STOP
43 }
44
46 return std::numeric_limits<std::uint32_t>::max(); // LCOV_EXCL_LINE
47 return static_cast<std::uint32_t>(x);
48 }
49
50 auto
51 operator<=>(OwnerCounts const& o) const
52 {
53 if (auto cmp = count() <=> o.count(); cmp != 0) // NOLINT(modernize-use-nullptr)
54 return cmp;
55 if (auto cmp = owner <=> o.owner; cmp != 0) // NOLINT(modernize-use-nullptr)
56 return cmp;
57 if (auto cmp = sponsored <=> o.sponsored; cmp != 0) // NOLINT(modernize-use-nullptr)
58 return cmp;
60 }
61
62 bool
63 operator==(OwnerCounts const& o) const
64 {
65 return this == &o ||
66 (owner == o.owner && sponsored == o.sponsored && sponsoring == o.sponsoring);
67 }
68};
69
70} // namespace xrpl
std::shared_ptr< STLedgerEntry const > const & const_ref
T max(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::uint32_t count() const
Definition OwnerCounts.h:34
std::uint32_t sponsored
Definition OwnerCounts.h:17
std::uint32_t sponsoring
Definition OwnerCounts.h:18
std::uint32_t owner
Definition OwnerCounts.h:16
bool operator==(OwnerCounts const &o) const
Definition OwnerCounts.h:63
OwnerCounts()=default
auto operator<=>(OwnerCounts const &o) const
Definition OwnerCounts.h:51
OwnerCounts(SLE::const_ref sle)
Definition OwnerCounts.h:21