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