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#include <xrpl/basics/CountedObject.h>
25#include <xrpl/protocol/Rate.h>
26#include <xrpl/protocol/STAmount.h>
27#include <xrpl/protocol/STLedgerEntry.h>
28
29#include <cstdint>
30#include <optional>
31
32namespace ripple {
33
41enum class LineDirection : bool { incoming = false, outgoing = true };
42
54{
55protected:
56 // This class should not be instantiated directly. Use one of the derived
57 // classes.
60 AccountID const& viewAccount);
61
62 ~TrustLineBase() = default;
63 TrustLineBase(TrustLineBase const&) = default;
65 operator=(TrustLineBase const&) = delete;
67
68public:
70 uint256 const&
71 key() const
72 {
73 return key_;
74 }
75
76 // VFALCO Take off the "get" from each function name
77
78 AccountID const&
80 {
82 }
83
84 AccountID const&
86 {
88 }
89
90 // True, Provided auth to peer.
91 bool
92 getAuth() const
93 {
95 }
96
97 bool
99 {
101 }
102
103 bool
105 {
106 return mFlags & lsfDefaultRipple;
107 }
108
109 bool
111 {
113 }
114
115 bool
117 {
119 }
120
123 {
126 }
127
130 {
133 }
134
136 bool
137 getFreeze() const
138 {
140 }
141
143 bool
145 {
147 }
148
150 bool
152 {
154 }
155
157 bool
159 {
161 }
162
163 STAmount const&
165 {
166 return mBalance;
167 }
168
169 STAmount const&
170 getLimit() const
171 {
173 }
174
175 STAmount const&
177 {
178 return !mViewLowest ? mLowLimit : mHighLimit;
179 }
180
182 getJson(int);
183
184protected:
186
189
191
193
195};
196
197// This wrapper is used for the path finder
198class PathFindTrustLine final : public TrustLineBase,
199 public CountedObject<PathFindTrustLine>
200{
202
203public:
205
207 makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
208
210 getItems(
211 AccountID const& accountID,
212 ReadView const& view,
213 LineDirection direction);
214};
215
216// This wrapper is used for the `AccountLines` command and includes the quality
217// in and quality out values.
218class RPCTrustLine final : public TrustLineBase,
219 public CountedObject<RPCTrustLine>
220{
222
223public:
224 RPCTrustLine() = delete;
225
228 AccountID const& viewAccount);
229
230 Rate const&
232 {
234 }
235
236 Rate const&
238 {
240 }
241
243 makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
244
246 getItems(AccountID const& accountID, ReadView const& view);
247
248private:
253};
254
255} // namespace ripple
256
257#endif
Represents a JSON value.
Definition: json_value.h:147
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:231
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:237
A view into a ledger.
Definition: ReadView.h:55
AccountID const & getIssuer() const
Definition: STAmount.h:499
Wraps a trust line SLE for convenience.
Definition: TrustLine.h:54
bool getDefaultRipple() const
Definition: TrustLine.h:104
bool getDeepFreeze() const
Have we set the deep freeze flag on our peer.
Definition: TrustLine.h:144
std::uint32_t mFlags
Definition: TrustLine.h:192
STAmount const & getLimit() const
Definition: TrustLine.h:170
STAmount const mLowLimit
Definition: TrustLine.h:187
STAmount const & getBalance() const
Definition: TrustLine.h:164
bool getAuthPeer() const
Definition: TrustLine.h:98
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:79
uint256 const & key() const
Returns the state map key for the ledger entry.
Definition: TrustLine.h:71
STAmount const & getLimitPeer() const
Definition: TrustLine.h:176
STAmount const mHighLimit
Definition: TrustLine.h:188
bool getNoRipplePeer() const
Definition: TrustLine.h:116
bool getNoRipple() const
Definition: TrustLine.h:110
Json::Value getJson(int)
Definition: TrustLine.cpp:43
bool getFreezePeer() const
Has the peer set the freeze flag on us.
Definition: TrustLine.h:151
AccountID const & getAccountIDPeer() const
Definition: TrustLine.h:85
bool getFreeze() const
Have we set the freeze flag on our peer.
Definition: TrustLine.h:137
TrustLineBase(TrustLineBase const &)=default
LineDirection getDirectionPeer() const
Definition: TrustLine.h:129
bool getAuth() const
Definition: TrustLine.h:92
LineDirection getDirection() const
Definition: TrustLine.h:122
bool getDeepFreezePeer() const
Has the peer set the deep freeze flag on us.
Definition: TrustLine.h:158
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:41
Represents a transfer rate.
Definition: Rate.h:38