xrpld
Loading...
Searching...
No Matches
TrustLine.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/json/json_value.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/LedgerFormats.h>
9#include <xrpl/protocol/Rate.h>
10#include <xrpl/protocol/STAmount.h>
11#include <xrpl/protocol/STLedgerEntry.h>
12
13#include <cstdint>
14#include <optional>
15#include <vector>
16
17namespace xrpl {
18
27enum class LineDirection : bool { Incoming = false, Outgoing = true };
28
41{
42public:
44 operator=(TrustLineBase const&) = delete;
45
46protected:
47 // This class should not be instantiated directly. Use one of the derived
48 // classes.
49 TrustLineBase(SLE::const_ref sle, AccountID const& viewAccount);
50
51 ~TrustLineBase() = default;
52 TrustLineBase(TrustLineBase const&) = default;
54
55public:
59 [[nodiscard]] uint256 const&
60 key() const
61 {
62 return key_;
63 }
64
65 // VFALCO Take off the "get" from each function name
66
67 [[nodiscard]] AccountID const&
69 {
70 return viewLowest_ ? lowLimit_.getIssuer() : highLimit_.getIssuer();
71 }
72
73 [[nodiscard]] AccountID const&
75 {
76 return !viewLowest_ ? lowLimit_.getIssuer() : highLimit_.getIssuer();
77 }
78
79 // True, Provided auth to peer.
80 [[nodiscard]] bool
81 getAuth() const
82 {
83 return (flags_ & (viewLowest_ ? lsfLowAuth : lsfHighAuth)) != 0u;
84 }
85
86 [[nodiscard]] bool
88 {
89 return (flags_ & (!viewLowest_ ? lsfLowAuth : lsfHighAuth)) != 0u;
90 }
91
92 [[nodiscard]] bool
94 {
95 return (flags_ & (viewLowest_ ? lsfLowNoRipple : lsfHighNoRipple)) != 0u;
96 }
97
98 [[nodiscard]] bool
100 {
101 return (flags_ & (!viewLowest_ ? lsfLowNoRipple : lsfHighNoRipple)) != 0u;
102 }
103
104 [[nodiscard]] LineDirection
109
110 [[nodiscard]] LineDirection
115
119 [[nodiscard]] bool
120 getFreeze() const
121 {
122 return (flags_ & (viewLowest_ ? lsfLowFreeze : lsfHighFreeze)) != 0u;
123 }
124
128 [[nodiscard]] bool
130 {
131 return (flags_ & (viewLowest_ ? lsfLowDeepFreeze : lsfHighDeepFreeze)) != 0u;
132 }
133
137 [[nodiscard]] bool
139 {
140 return (flags_ & (!viewLowest_ ? lsfLowFreeze : lsfHighFreeze)) != 0u;
141 }
142
146 [[nodiscard]] bool
148 {
149 return (flags_ & (!viewLowest_ ? lsfLowDeepFreeze : lsfHighDeepFreeze)) != 0u;
150 }
151
152 [[nodiscard]] STAmount const&
154 {
155 return balance_;
156 }
157
158 [[nodiscard]] STAmount const&
159 getLimit() const
160 {
162 }
163
164 [[nodiscard]] STAmount const&
166 {
167 return !viewLowest_ ? lowLimit_ : highLimit_;
168 }
169
171 getJson(int);
172
173protected:
175
178
180
182
184};
185
186// This wrapper is used for the path finder
187class PathFindTrustLine final : public TrustLineBase, public CountedObject<PathFindTrustLine>
188{
190
191public:
193
195 makeItem(AccountID const& accountID, SLE::const_ref sle);
196
198 getItems(AccountID const& accountID, ReadView const& view, LineDirection direction);
199};
200
201// This wrapper is used for the `AccountLines` command and includes the quality
202// in and quality out values.
203class RPCTrustLine final : public TrustLineBase, public CountedObject<RPCTrustLine>
204{
206
207public:
208 RPCTrustLine() = delete;
209
210 RPCTrustLine(SLE::const_ref sle, AccountID const& viewAccount);
211
212 [[nodiscard]] Rate const&
214 {
216 }
217
218 [[nodiscard]] Rate const&
220 {
222 }
223
225 makeItem(AccountID const& accountID, SLE::const_ref sle);
226
228 getItems(AccountID const& accountID, ReadView const& view);
229
230private:
235};
236
237} // namespace xrpl
Represents a JSON value.
Definition json_value.h:117
TrustLineBase(SLE::const_ref sle, AccountID const &viewAccount)
Definition TrustLine.cpp:17
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view, LineDirection direction)
Definition TrustLine.cpp:69
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, SLE::const_ref sle)
Definition TrustLine.cpp:39
TrustLineBase(SLE::const_ref sle, AccountID const &viewAccount)
Definition TrustLine.cpp:17
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition TrustLine.cpp:95
Rate const & getQualityIn() const
Definition TrustLine.h:213
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, SLE::const_ref sle)
Definition TrustLine.cpp:87
Rate const & getQualityOut() const
Definition TrustLine.h:219
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry const > const & const_ref
AccountID const & getAccountIDPeer() const
Definition TrustLine.h:74
TrustLineBase(SLE::const_ref sle, AccountID const &viewAccount)
Definition TrustLine.cpp:17
bool getNoRipplePeer() const
Definition TrustLine.h:99
json::Value getJson(int)
Definition TrustLine.cpp:30
TrustLineBase(TrustLineBase &&)=default
bool getAuth() const
Definition TrustLine.h:81
STAmount const & getLimit() const
Definition TrustLine.h:159
bool getDeepFreeze() const
Have we set the deep freeze flag on our peer.
Definition TrustLine.h:129
LineDirection getDirection() const
Definition TrustLine.h:105
uint256 const & key() const
Returns the state map key for the ledger entry.
Definition TrustLine.h:60
AccountID const & getAccountID() const
Definition TrustLine.h:68
bool getFreezePeer() const
Has the peer set the freeze flag on us.
Definition TrustLine.h:138
bool getDeepFreezePeer() const
Has the peer set the deep freeze flag on us.
Definition TrustLine.h:147
STAmount const lowLimit_
Definition TrustLine.h:176
STAmount const & getLimitPeer() const
Definition TrustLine.h:165
bool getFreeze() const
Have we set the freeze flag on our peer.
Definition TrustLine.h:120
bool getAuthPeer() const
Definition TrustLine.h:87
~TrustLineBase()=default
STAmount const & getBalance() const
Definition TrustLine.h:153
TrustLineBase & operator=(TrustLineBase const &)=delete
std::uint32_t flags_
Definition TrustLine.h:181
LineDirection getDirectionPeer() const
Definition TrustLine.h:111
TrustLineBase(TrustLineBase const &)=default
bool getNoRipple() const
Definition TrustLine.h:93
STAmount const highLimit_
Definition TrustLine.h:177
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition TrustLine.h:27
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
BaseUInt< 256 > uint256
Definition base_uint.h:580
Represents a transfer rate.
Definition Rate.h:21