rippled
Loading...
Searching...
No Matches
TrustLine.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_PATHS_RIPPLESTATE_H_INCLUDED
21#define RIPPLE_APP_PATHS_RIPPLESTATE_H_INCLUDED
22
23#include <xrpld/ledger/View.h>
24
25#include <xrpl/basics/CountedObject.h>
26#include <xrpl/protocol/Rate.h>
27#include <xrpl/protocol/STAmount.h>
28#include <xrpl/protocol/STLedgerEntry.h>
29
30#include <cstdint>
31#include <optional>
32
33namespace ripple {
34
42enum class LineDirection : bool { incoming = false, outgoing = true };
43
55{
56protected:
57 // This class should not be instantiated directly. Use one of the derived
58 // classes.
61 AccountID const& viewAccount);
62
63 ~TrustLineBase() = default;
64 TrustLineBase(TrustLineBase const&) = default;
66 operator=(TrustLineBase const&) = delete;
68
69public:
71 uint256 const&
72 key() const
73 {
74 return key_;
75 }
76
77 // VFALCO Take off the "get" from each function name
78
79 AccountID const&
81 {
83 }
84
85 AccountID const&
87 {
89 }
90
91 // True, Provided auth to peer.
92 bool
93 getAuth() const
94 {
96 }
97
98 bool
100 {
102 }
103
104 bool
106 {
107 return mFlags & lsfDefaultRipple;
108 }
109
110 bool
112 {
114 }
115
116 bool
118 {
120 }
121
124 {
127 }
128
131 {
134 }
135
137 bool
138 getFreeze() const
139 {
141 }
142
144 bool
146 {
148 }
149
151 bool
153 {
155 }
156
158 bool
160 {
162 }
163
164 STAmount const&
166 {
167 return mBalance;
168 }
169
170 STAmount const&
171 getLimit() const
172 {
174 }
175
176 STAmount const&
178 {
179 return !mViewLowest ? mLowLimit : mHighLimit;
180 }
181
183 getJson(int);
184
185protected:
187
190
192
194
196};
197
198// This wrapper is used for the path finder
199class PathFindTrustLine final : public TrustLineBase,
200 public CountedObject<PathFindTrustLine>
201{
203
204public:
206
208 makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
209
211 getItems(
212 AccountID const& accountID,
213 ReadView const& view,
214 LineDirection direction);
215};
216
217// This wrapper is used for the `AccountLines` command and includes the quality
218// in and quality out values.
219class RPCTrustLine final : public TrustLineBase,
220 public CountedObject<RPCTrustLine>
221{
223
224public:
225 RPCTrustLine() = delete;
226
229 AccountID const& viewAccount);
230
231 Rate const&
233 {
235 }
236
237 Rate const&
239 {
241 }
242
244 makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
245
247 getItems(AccountID const& accountID, ReadView const& view);
248
249private:
254};
255
256} // namespace ripple
257
258#endif
Represents a JSON value.
Definition: json_value.h:148
Tracks the number of instances of an object.
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view, LineDirection direction)
Definition: TrustLine.cpp:89
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition: TrustLine.cpp:52
Rate const & getQualityIn() const
Definition: TrustLine.h:232
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition: TrustLine.cpp:110
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition: TrustLine.cpp:120
Rate const & getQualityOut() const
Definition: TrustLine.h:238
A view into a ledger.
Definition: ReadView.h:52
AccountID const & getIssuer() const
Definition: STAmount.h:499
Wraps a trust line SLE for convenience.
Definition: TrustLine.h:55
bool getDefaultRipple() const
Definition: TrustLine.h:105
bool getDeepFreeze() const
Have we set the deep freeze flag on our peer.
Definition: TrustLine.h:145
std::uint32_t mFlags
Definition: TrustLine.h:193
STAmount const & getLimit() const
Definition: TrustLine.h:171
STAmount const mLowLimit
Definition: TrustLine.h:188
STAmount const & getBalance() const
Definition: TrustLine.h:165
bool getAuthPeer() const
Definition: TrustLine.h:99
TrustLineBase(std::shared_ptr< SLE const > const &sle, AccountID const &viewAccount)
Definition: TrustLine.cpp:28
TrustLineBase(TrustLineBase &&)=default
AccountID const & getAccountID() const
Definition: TrustLine.h:80
uint256 const & key() const
Returns the state map key for the ledger entry.
Definition: TrustLine.h:72
STAmount const & getLimitPeer() const
Definition: TrustLine.h:177
STAmount const mHighLimit
Definition: TrustLine.h:189
bool getNoRipplePeer() const
Definition: TrustLine.h:117
bool getNoRipple() const
Definition: TrustLine.h:111
Json::Value getJson(int)
Definition: TrustLine.cpp:43
bool getFreezePeer() const
Has the peer set the freeze flag on us.
Definition: TrustLine.h:152
AccountID const & getAccountIDPeer() const
Definition: TrustLine.h:86
bool getFreeze() const
Have we set the freeze flag on our peer.
Definition: TrustLine.h:138
TrustLineBase(TrustLineBase const &)=default
LineDirection getDirectionPeer() const
Definition: TrustLine.h:130
bool getAuth() const
Definition: TrustLine.h:93
LineDirection getDirection() const
Definition: TrustLine.h:123
bool getDeepFreezePeer() const
Has the peer set the deep freeze flag on us.
Definition: TrustLine.h:159
TrustLineBase & operator=(TrustLineBase const &)=delete
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
@ lsfHighDeepFreeze
@ lsfDefaultRipple
@ lsfHighNoRipple
@ lsfHighFreeze
@ lsfLowNoRipple
@ lsfLowFreeze
@ lsfLowDeepFreeze
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition: TrustLine.h:42
Represents a transfer rate.
Definition: Rate.h:40