xrpld
Loading...
Searching...
No Matches
include
xrpl
ledger
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
12
namespace
xrpl
{
13
14
struct
OwnerCounts
15
{
16
std::uint32_t
owner
= 0;
17
std::uint32_t
sponsored
= 0;
18
std::uint32_t
sponsoring
= 0;
19
20
OwnerCounts
() =
default
;
21
OwnerCounts
(
SLE::const_ref
sle)
22
:
owner
(sle->at(sfOwnerCount))
23
,
sponsored
(sle->at(sfSponsoredOwnerCount))
24
,
sponsoring
(sle->at(sfSponsoringOwnerCount))
25
{
26
XRPL_ASSERT(
27
owner
>=
sponsored
,
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
45
if
(x >
std::numeric_limits<std::uint32_t>::max
())
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;
59
return
sponsoring <=>
o.
sponsoring
;
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
xrpl::STLedgerEntry::const_ref
std::shared_ptr< STLedgerEntry const > const & const_ref
Definition
STLedgerEntry.h:34
cstdint
std::uint32_t
limits
std::numeric_limits::max
T max(T... args)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::OwnerCounts::count
std::uint32_t count() const
Definition
OwnerCounts.h:34
xrpl::OwnerCounts::sponsored
std::uint32_t sponsored
Definition
OwnerCounts.h:17
xrpl::OwnerCounts::sponsoring
std::uint32_t sponsoring
Definition
OwnerCounts.h:18
xrpl::OwnerCounts::owner
std::uint32_t owner
Definition
OwnerCounts.h:16
xrpl::OwnerCounts::operator==
bool operator==(OwnerCounts const &o) const
Definition
OwnerCounts.h:63
xrpl::OwnerCounts::OwnerCounts
OwnerCounts()=default
xrpl::OwnerCounts::operator<=>
auto operator<=>(OwnerCounts const &o) const
Definition
OwnerCounts.h:51
xrpl::OwnerCounts::OwnerCounts
OwnerCounts(SLE::const_ref sle)
Definition
OwnerCounts.h:21
Generated by
1.16.1