xrpld
Loading...
Searching...
No Matches
STAccount.h
1#pragma once
2
3#include <xrpl/basics/Buffer.h>
4#include <xrpl/basics/CountedObject.h>
5#include <xrpl/protocol/AccountID.h>
6#include <xrpl/protocol/SField.h>
7#include <xrpl/protocol/STBase.h>
8#include <xrpl/protocol/Serializer.h>
9
10#include <cstddef>
11#include <string>
12
13namespace xrpl {
14
15class STAccount final : public STBase, public CountedObject<STAccount>
16{
17private:
18 // The original implementation of STAccount kept the value in an STBlob.
19 // But an STAccount is always 160 bits, so we can store it with less
20 // overhead in an xrpl::uint160. However, so the serialized format of the
21 // STAccount stays unchanged, we serialize and deserialize like an STBlob.
24
25public:
27
28 STAccount();
29
30 STAccount(SField const& n);
31 STAccount(SField const& n, Buffer const& v);
32 STAccount(SerialIter& sit, SField const& name);
33 STAccount(SField const& n, AccountID const& v);
34
35 [[nodiscard]] SerializedTypeID
36 getSType() const override;
37
38 [[nodiscard]] std::string
39 getText() const override;
40
41 void
42 add(Serializer& s) const override;
43
44 [[nodiscard]] bool
45 isEquivalent(STBase const& t) const override;
46
47 [[nodiscard]] bool
48 isDefault() const override;
49
52
53 [[nodiscard]] AccountID const&
54 value() const noexcept;
55
56 void
57 setValue(AccountID const& v);
58
59private:
60 STBase*
61 copy(std::size_t n, void* buf) const override;
62 STBase*
63 move(std::size_t n, void* buf) override;
64
65 friend class detail::STVar;
66};
67
68inline STAccount&
69STAccount::operator=(AccountID const& value)
70{
72 return *this;
73}
74
75inline AccountID const&
76STAccount::value() const noexcept
77{
78 return value_;
79}
80
81inline void
83{
84 value_ = v;
85 default_ = false;
86}
87
88inline bool
89operator==(STAccount const& lhs, STAccount const& rhs)
90{
91 return lhs.value() == rhs.value();
92}
93
94inline auto
95operator<(STAccount const& lhs, STAccount const& rhs)
96{
97 return lhs.value() < rhs.value();
98}
99
100inline bool
101operator==(STAccount const& lhs, AccountID const& rhs)
102{
103 return lhs.value() == rhs;
104}
105
106inline auto
107operator<(STAccount const& lhs, AccountID const& rhs)
108{
109 return lhs.value() < rhs;
110}
111
112inline auto
113operator<(AccountID const& lhs, STAccount const& rhs)
114{
115 return lhs < rhs.value();
116}
117
118} // namespace xrpl
Like std::vector<char> but better.
Definition Buffer.h:19
Identifies fields.
Definition SField.h:132
bool isDefault() const override
Definition STAccount.cpp:92
bool isEquivalent(STBase const &t) const override
Definition STAccount.cpp:85
AccountID value_type
Definition STAccount.h:26
AccountID value_
Definition STAccount.h:22
void add(Serializer &s) const override
Definition STAccount.cpp:72
STBase * move(std::size_t n, void *buf) override
Definition STAccount.cpp:60
void setValue(AccountID const &v)
Definition STAccount.h:82
friend class detail::STVar
Definition STAccount.h:65
SerializedTypeID getSType() const override
Definition STAccount.cpp:66
STAccount & operator=(AccountID const &value)
Definition STAccount.h:69
STBase * copy(std::size_t n, void *buf) const override
Definition STAccount.cpp:54
std::string getText() const override
Definition STAccount.cpp:98
AccountID const & value() const noexcept
Definition STAccount.h:76
bool operator==(STBase const &t) const
Definition STBase.cpp:36
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:212
SerializedTypeID
Definition SField.h:94
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34