xrpld
Loading...
Searching...
No Matches
TrustLine.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/ledger/View.h>
5#include <xrpl/protocol/Rate.h>
6#include <xrpl/protocol/STAmount.h>
7#include <xrpl/protocol/STLedgerEntry.h>
8
9#include <cstdint>
10#include <optional>
11
12namespace xrpl {
13
21enum class LineDirection : bool { Incoming = false, Outgoing = true };
22
34{
35public:
37 operator=(TrustLineBase const&) = delete;
38
39protected:
40 // This class should not be instantiated directly. Use one of the derived
41 // classes.
42 TrustLineBase(SLE::const_ref sle, AccountID const& viewAccount);
43
44 ~TrustLineBase() = default;
45 TrustLineBase(TrustLineBase const&) = default;
47
48public:
50 [[nodiscard]] uint256 const&
51 key() const
52 {
53 return key_;
54 }
55
56 // VFALCO Take off the "get" from each function name
57
58 [[nodiscard]] AccountID const&
60 {
61 return viewLowest_ ? lowLimit_.getIssuer() : highLimit_.getIssuer();
62 }
63
64 [[nodiscard]] AccountID const&
66 {
67 return !viewLowest_ ? lowLimit_.getIssuer() : highLimit_.getIssuer();
68 }
69
70 // True, Provided auth to peer.
71 [[nodiscard]] bool
72 getAuth() const
73 {
74 return (flags_ & (viewLowest_ ? lsfLowAuth : lsfHighAuth)) != 0u;
75 }
76
77 [[nodiscard]] bool
79 {
80 return (flags_ & (!viewLowest_ ? lsfLowAuth : lsfHighAuth)) != 0u;
81 }
82
83 [[nodiscard]] bool
85 {
86 return (flags_ & (viewLowest_ ? lsfLowNoRipple : lsfHighNoRipple)) != 0u;
87 }
88
89 [[nodiscard]] bool
91 {
92 return (flags_ & (!viewLowest_ ? lsfLowNoRipple : lsfHighNoRipple)) != 0u;
93 }
94
95 [[nodiscard]] LineDirection
100
101 [[nodiscard]] LineDirection
106
108 [[nodiscard]] bool
109 getFreeze() const
110 {
111 return (flags_ & (viewLowest_ ? lsfLowFreeze : lsfHighFreeze)) != 0u;
112 }
113
115 [[nodiscard]] bool
117 {
118 return (flags_ & (viewLowest_ ? lsfLowDeepFreeze : lsfHighDeepFreeze)) != 0u;
119 }
120
122 [[nodiscard]] bool
124 {
125 return (flags_ & (!viewLowest_ ? lsfLowFreeze : lsfHighFreeze)) != 0u;
126 }
127
129 [[nodiscard]] bool
131 {
132 return (flags_ & (!viewLowest_ ? lsfLowDeepFreeze : lsfHighDeepFreeze)) != 0u;
133 }
134
135 [[nodiscard]] STAmount const&
137 {
138 return balance_;
139 }
140
141 [[nodiscard]] STAmount const&
142 getLimit() const
143 {
145 }
146
147 [[nodiscard]] STAmount const&
149 {
150 return !viewLowest_ ? lowLimit_ : highLimit_;
151 }
152
154 getJson(int);
155
156protected:
158
161
163
165
167};
168
169// This wrapper is used for the path finder
170class PathFindTrustLine final : public TrustLineBase, public CountedObject<PathFindTrustLine>
171{
173
174public:
176
178 makeItem(AccountID const& accountID, SLE::const_ref sle);
179
181 getItems(AccountID const& accountID, ReadView const& view, LineDirection direction);
182};
183
184// This wrapper is used for the `AccountLines` command and includes the quality
185// in and quality out values.
186class RPCTrustLine final : public TrustLineBase, public CountedObject<RPCTrustLine>
187{
189
190public:
191 RPCTrustLine() = delete;
192
193 RPCTrustLine(SLE::const_ref sle, AccountID const& viewAccount);
194
195 [[nodiscard]] Rate const&
197 {
199 }
200
201 [[nodiscard]] Rate const&
203 {
205 }
206
208 makeItem(AccountID const& accountID, SLE::const_ref sle);
209
211 getItems(AccountID const& accountID, ReadView const& view);
212
213private:
218};
219
220} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
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:196
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, SLE::const_ref sle)
Definition TrustLine.cpp:87
Rate const & getQualityOut() const
Definition TrustLine.h:202
A view into a ledger.
Definition ReadView.h:31
std::shared_ptr< STLedgerEntry const > const & const_ref
AccountID const & getAccountIDPeer() const
Definition TrustLine.h:65
TrustLineBase(SLE::const_ref sle, AccountID const &viewAccount)
Definition TrustLine.cpp:17
bool getNoRipplePeer() const
Definition TrustLine.h:90
json::Value getJson(int)
Definition TrustLine.cpp:30
TrustLineBase(TrustLineBase &&)=default
bool getAuth() const
Definition TrustLine.h:72
STAmount const & getLimit() const
Definition TrustLine.h:142
bool getDeepFreeze() const
Have we set the deep freeze flag on our peer.
Definition TrustLine.h:116
LineDirection getDirection() const
Definition TrustLine.h:96
uint256 const & key() const
Returns the state map key for the ledger entry.
Definition TrustLine.h:51
AccountID const & getAccountID() const
Definition TrustLine.h:59
bool getFreezePeer() const
Has the peer set the freeze flag on us.
Definition TrustLine.h:123
bool getDeepFreezePeer() const
Has the peer set the deep freeze flag on us.
Definition TrustLine.h:130
STAmount const lowLimit_
Definition TrustLine.h:159
STAmount const & getLimitPeer() const
Definition TrustLine.h:148
bool getFreeze() const
Have we set the freeze flag on our peer.
Definition TrustLine.h:109
bool getAuthPeer() const
Definition TrustLine.h:78
~TrustLineBase()=default
STAmount const & getBalance() const
Definition TrustLine.h:136
TrustLineBase & operator=(TrustLineBase const &)=delete
std::uint32_t flags_
Definition TrustLine.h:164
LineDirection getDirectionPeer() const
Definition TrustLine.h:102
TrustLineBase(TrustLineBase const &)=default
bool getNoRipple() const
Definition TrustLine.h:84
STAmount const highLimit_
Definition TrustLine.h:160
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:21
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
BaseUInt< 256 > uint256
Definition base_uint.h:562
Represents a transfer rate.
Definition Rate.h:20