rippled
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 <ripple/basics/CountedObject.h>
24 #include <ripple/ledger/View.h>
25 #include <ripple/protocol/Rate.h>
26 #include <ripple/protocol/STAmount.h>
27 #include <ripple/protocol/STLedgerEntry.h>
28 
29 #include <cstdint>
30 #include <optional>
31 
32 namespace ripple {
33 
41 enum class LineDirection : bool { incoming = false, outgoing = true };
42 
54 {
55 protected:
56  // This class should not be instantiated directly. Use one of the derived
57  // classes.
59  std::shared_ptr<SLE const> const& sle,
60  AccountID const& viewAccount);
61 
62  ~TrustLineBase() = default;
63  TrustLineBase(TrustLineBase const&) = default;
65  operator=(TrustLineBase const&) = delete;
66  TrustLineBase(TrustLineBase&&) = default;
67 
68 public:
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&
79  getAccountID() 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
98  getAuthPeer() const
99  {
100  return mFlags & (!mViewLowest ? lsfLowAuth : lsfHighAuth);
101  }
102 
103  bool
105  {
106  return mFlags & lsfDefaultRipple;
107  }
108 
109  bool
110  getNoRipple() const
111  {
113  }
114 
115  bool
117  {
119  }
120 
122  getDirection() const
123  {
126  }
127 
130  {
133  }
134 
136  bool
137  getFreeze() const
138  {
140  }
141 
143  bool
145  {
147  }
148 
149  STAmount const&
150  getBalance() const
151  {
152  return mBalance;
153  }
154 
155  STAmount const&
156  getLimit() const
157  {
158  return mViewLowest ? mLowLimit : mHighLimit;
159  }
160 
161  STAmount const&
162  getLimitPeer() const
163  {
164  return !mViewLowest ? mLowLimit : mHighLimit;
165  }
166 
168  getJson(int);
169 
170 protected:
172 
175 
177 
179 
181 };
182 
183 // This wrapper is used for the path finder
184 class PathFindTrustLine final : public TrustLineBase,
185  public CountedObject<PathFindTrustLine>
186 {
188 
189 public:
190  PathFindTrustLine() = delete;
191 
193  makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
194 
196  getItems(
197  AccountID const& accountID,
198  ReadView const& view,
199  LineDirection direction);
200 };
201 
202 // This wrapper is used for the `AccountLines` command and includes the quality
203 // in and quality out values.
204 class RPCTrustLine final : public TrustLineBase,
205  public CountedObject<RPCTrustLine>
206 {
208 
209 public:
210  RPCTrustLine() = delete;
211 
212  RPCTrustLine(
213  std::shared_ptr<SLE const> const& sle,
214  AccountID const& viewAccount);
215 
216  Rate const&
217  getQualityIn() const
218  {
220  }
221 
222  Rate const&
224  {
226  }
227 
229  makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
230 
232  getItems(AccountID const& accountID, ReadView const& view);
233 
234 private:
239 };
240 
241 } // namespace ripple
242 
243 #endif
ripple::TrustLineBase::getDirection
LineDirection getDirection() const
Definition: TrustLine.h:122
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::TrustLineBase::getNoRipplePeer
bool getNoRipplePeer() const
Definition: TrustLine.h:116
std::shared_ptr
STL class.
ripple::LineDirection
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition: TrustLine.h:41
ripple::Rate
Represents a transfer rate.
Definition: Rate.h:37
ripple::RPCTrustLine::getQualityOut
Rate const & getQualityOut() const
Definition: TrustLine.h:223
ripple::lsfLowAuth
@ lsfLowAuth
Definition: LedgerFormats.h:254
ripple::TrustLineBase::TrustLineBase
TrustLineBase(std::shared_ptr< SLE const > const &sle, AccountID const &viewAccount)
Definition: TrustLine.cpp:28
ripple::lsfLowNoRipple
@ lsfLowNoRipple
Definition: LedgerFormats.h:256
std::vector
STL class.
ripple::TrustLineBase::getBalance
STAmount const & getBalance() const
Definition: TrustLine.h:150
ripple::TrustLineBase::getJson
Json::Value getJson(int)
Definition: TrustLine.cpp:43
ripple::TrustLineBase::getAccountIDPeer
AccountID const & getAccountIDPeer() const
Definition: TrustLine.h:85
ripple::RPCTrustLine
Definition: TrustLine.h:204
ripple::TrustLineBase::getLimit
STAmount const & getLimit() const
Definition: TrustLine.h:156
ripple::TrustLineBase::~TrustLineBase
~TrustLineBase()=default
ripple::TrustLineBase::getAuth
bool getAuth() const
Definition: TrustLine.h:92
ripple::PathFindTrustLine::makeItem
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition: TrustLine.cpp:52
ripple::lsfHighAuth
@ lsfHighAuth
Definition: LedgerFormats.h:255
ripple::TrustLineBase::mFlags
std::uint32_t mFlags
Definition: TrustLine.h:178
ripple::STAmount::getIssuer
AccountID const & getIssuer() const
Definition: STAmount.h:359
ripple::base_uint< 160, detail::AccountIDTag >
ripple::lsfDefaultRipple
@ lsfDefaultRipple
Definition: LedgerFormats.h:232
ripple::TrustLineBase::mHighLimit
const STAmount mHighLimit
Definition: TrustLine.h:174
ripple::TrustLineBase::getDirectionPeer
LineDirection getDirectionPeer() const
Definition: TrustLine.h:129
ripple::TrustLineBase::key
uint256 const & key() const
Returns the state map key for the ledger entry.
Definition: TrustLine.h:71
ripple::RPCTrustLine::lowQualityOut_
Rate lowQualityOut_
Definition: TrustLine.h:236
ripple::LineDirection::outgoing
@ outgoing
ripple::RPCTrustLine::getQualityIn
Rate const & getQualityIn() const
Definition: TrustLine.h:217
ripple::STAmount
Definition: STAmount.h:45
ripple::TrustLineBase::mBalance
STAmount mBalance
Definition: TrustLine.h:176
cstdint
ripple::LineDirection::incoming
@ incoming
ripple::TrustLineBase::getLimitPeer
STAmount const & getLimitPeer() const
Definition: TrustLine.h:162
std::uint32_t
ripple::PathFindTrustLine::PathFindTrustLine
PathFindTrustLine()=delete
ripple::TrustLineBase::getNoRipple
bool getNoRipple() const
Definition: TrustLine.h:110
ripple::lsfHighNoRipple
@ lsfHighNoRipple
Definition: LedgerFormats.h:257
ripple::TrustLineBase::key_
uint256 key_
Definition: TrustLine.h:171
ripple::lsfHighFreeze
@ lsfHighFreeze
Definition: LedgerFormats.h:259
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::TrustLineBase::mViewLowest
bool mViewLowest
Definition: TrustLine.h:180
ripple::TrustLineBase::getAccountID
AccountID const & getAccountID() const
Definition: TrustLine.h:79
ripple::TrustLineBase::getAuthPeer
bool getAuthPeer() const
Definition: TrustLine.h:98
ripple::RPCTrustLine::makeItem
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition: TrustLine.cpp:110
ripple::TrustLineBase::getFreezePeer
bool getFreezePeer() const
Has the peer set the freeze flag on us.
Definition: TrustLine.h:144
ripple::TrustLineBase::getDefaultRipple
bool getDefaultRipple() const
Definition: TrustLine.h:104
optional
ripple::RPCTrustLine::RPCTrustLine
RPCTrustLine()=delete
ripple::TrustLineBase::operator=
TrustLineBase & operator=(TrustLineBase const &)=delete
ripple::lsfLowFreeze
@ lsfLowFreeze
Definition: LedgerFormats.h:258
ripple::TrustLineBase::getFreeze
bool getFreeze() const
Have we set the freeze flag on our peer.
Definition: TrustLine.h:137
ripple::PathFindTrustLine::getItems
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view, LineDirection direction)
Definition: TrustLine.cpp:89
ripple::RPCTrustLine::highQualityIn_
Rate highQualityIn_
Definition: TrustLine.h:237
ripple::RPCTrustLine::lowQualityIn_
Rate lowQualityIn_
Definition: TrustLine.h:235
ripple::PathFindTrustLine
Definition: TrustLine.h:184
ripple::RPCTrustLine::highQualityOut_
Rate highQualityOut_
Definition: TrustLine.h:238
ripple::TrustLineBase
Wraps a trust line SLE for convenience.
Definition: TrustLine.h:53
ripple::TrustLineBase::mLowLimit
const STAmount mLowLimit
Definition: TrustLine.h:173
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::RPCTrustLine::getItems
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition: TrustLine.cpp:120