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 
45 {
46 protected:
47  // This class should not be instantiated directly. Use one of the derived
48  // classes.
50  std::shared_ptr<SLE const> const& sle,
51  AccountID const& viewAccount);
52 
53  ~TrustLineBase() = default;
54  TrustLineBase(TrustLineBase const&) = default;
56  operator=(TrustLineBase const&) = delete;
57  TrustLineBase(TrustLineBase&&) = default;
58 
59 public:
61  uint256 const&
62  key() const
63  {
64  return key_;
65  }
66 
67  // VFALCO Take off the "get" from each function name
68 
69  AccountID const&
70  getAccountID() const
71  {
73  }
74 
75  AccountID const&
77  {
79  }
80 
81  // True, Provided auth to peer.
82  bool
83  getAuth() const
84  {
86  }
87 
88  bool
89  getAuthPeer() const
90  {
91  return mFlags & (!mViewLowest ? lsfLowAuth : lsfHighAuth);
92  }
93 
94  bool
96  {
97  return mFlags & lsfDefaultRipple;
98  }
99 
100  bool
101  getNoRipple() const
102  {
104  }
105 
106  bool
108  {
110  }
111 
113  bool
114  getFreeze() const
115  {
117  }
118 
120  bool
122  {
124  }
125 
126  STAmount const&
127  getBalance() const
128  {
129  return mBalance;
130  }
131 
132  STAmount const&
133  getLimit() const
134  {
135  return mViewLowest ? mLowLimit : mHighLimit;
136  }
137 
138  STAmount const&
139  getLimitPeer() const
140  {
141  return !mViewLowest ? mLowLimit : mHighLimit;
142  }
143 
145  getJson(int);
146 
147 protected:
149 
152 
154 
156 
158 };
159 
160 // This wrapper is used for the path finder
161 class PathFindTrustLine final : public TrustLineBase,
162  public CountedObject<PathFindTrustLine>
163 {
165 
166 public:
167  PathFindTrustLine() = delete;
168 
170  makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
171 
173  getItems(AccountID const& accountID, ReadView const& view);
174 };
175 
176 // This wrapper is used for the `AccountLines` command and includes the quality
177 // in and quality out values.
178 class RPCTrustLine final : public TrustLineBase,
179  public CountedObject<RPCTrustLine>
180 {
182 
183 public:
184  RPCTrustLine() = delete;
185 
186  RPCTrustLine(
187  std::shared_ptr<SLE const> const& sle,
188  AccountID const& viewAccount);
189 
190  Rate const&
191  getQualityIn() const
192  {
194  }
195 
196  Rate const&
198  {
200  }
201 
203  makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
204 
206  getItems(AccountID const& accountID, ReadView const& view);
207 
208 private:
213 };
214 
215 } // namespace ripple
216 
217 #endif
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::TrustLineBase::getNoRipplePeer
bool getNoRipplePeer() const
Definition: TrustLine.h:107
std::shared_ptr
STL class.
ripple::Rate
Represents a transfer rate.
Definition: Rate.h:37
ripple::RPCTrustLine::getQualityOut
Rate const & getQualityOut() const
Definition: TrustLine.h:197
ripple::lsfLowAuth
@ lsfLowAuth
Definition: LedgerFormats.h:243
ripple::TrustLineBase::TrustLineBase
TrustLineBase(std::shared_ptr< SLE const > const &sle, AccountID const &viewAccount)
Definition: TrustLine.cpp:28
ripple::lsfLowNoRipple
@ lsfLowNoRipple
Definition: LedgerFormats.h:245
std::vector
STL class.
ripple::TrustLineBase::getBalance
STAmount const & getBalance() const
Definition: TrustLine.h:127
ripple::TrustLineBase::getJson
Json::Value getJson(int)
Definition: TrustLine.cpp:43
ripple::TrustLineBase::getAccountIDPeer
AccountID const & getAccountIDPeer() const
Definition: TrustLine.h:76
ripple::RPCTrustLine
Definition: TrustLine.h:178
ripple::TrustLineBase::getLimit
STAmount const & getLimit() const
Definition: TrustLine.h:133
ripple::TrustLineBase::~TrustLineBase
~TrustLineBase()=default
ripple::TrustLineBase::getAuth
bool getAuth() const
Definition: TrustLine.h:83
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:244
ripple::TrustLineBase::mFlags
std::uint32_t mFlags
Definition: TrustLine.h:155
ripple::STAmount::getIssuer
AccountID const & getIssuer() const
Definition: STAmount.h:351
ripple::base_uint< 160, detail::AccountIDTag >
ripple::lsfDefaultRipple
@ lsfDefaultRipple
Definition: LedgerFormats.h:232
ripple::PathFindTrustLine::getItems
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition: TrustLine.cpp:81
ripple::TrustLineBase::mHighLimit
const STAmount mHighLimit
Definition: TrustLine.h:151
ripple::TrustLineBase::key
uint256 const & key() const
Returns the state map key for the ledger entry.
Definition: TrustLine.h:62
ripple::RPCTrustLine::lowQualityOut_
Rate lowQualityOut_
Definition: TrustLine.h:210
ripple::RPCTrustLine::getQualityIn
Rate const & getQualityIn() const
Definition: TrustLine.h:191
ripple::STAmount
Definition: STAmount.h:44
ripple::TrustLineBase::mBalance
STAmount mBalance
Definition: TrustLine.h:153
cstdint
ripple::TrustLineBase::getLimitPeer
STAmount const & getLimitPeer() const
Definition: TrustLine.h:139
std::uint32_t
ripple::PathFindTrustLine::PathFindTrustLine
PathFindTrustLine()=delete
ripple::TrustLineBase::getNoRipple
bool getNoRipple() const
Definition: TrustLine.h:101
ripple::lsfHighNoRipple
@ lsfHighNoRipple
Definition: LedgerFormats.h:246
ripple::TrustLineBase::key_
uint256 key_
Definition: TrustLine.h:148
ripple::lsfHighFreeze
@ lsfHighFreeze
Definition: LedgerFormats.h:248
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:192
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:157
ripple::TrustLineBase::getAccountID
AccountID const & getAccountID() const
Definition: TrustLine.h:70
ripple::TrustLineBase::getAuthPeer
bool getAuthPeer() const
Definition: TrustLine.h:89
ripple::RPCTrustLine::makeItem
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition: TrustLine.cpp:98
ripple::TrustLineBase::getFreezePeer
bool getFreezePeer() const
Has the peer set the freeze flag on us.
Definition: TrustLine.h:121
ripple::TrustLineBase::getDefaultRipple
bool getDefaultRipple() const
Definition: TrustLine.h:95
optional
ripple::RPCTrustLine::RPCTrustLine
RPCTrustLine()=delete
ripple::TrustLineBase::operator=
TrustLineBase & operator=(TrustLineBase const &)=delete
ripple::lsfLowFreeze
@ lsfLowFreeze
Definition: LedgerFormats.h:247
ripple::TrustLineBase::getFreeze
bool getFreeze() const
Have we set the freeze flag on our peer.
Definition: TrustLine.h:114
ripple::RPCTrustLine::highQualityIn_
Rate highQualityIn_
Definition: TrustLine.h:211
ripple::RPCTrustLine::lowQualityIn_
Rate lowQualityIn_
Definition: TrustLine.h:209
ripple::PathFindTrustLine
Definition: TrustLine.h:161
ripple::RPCTrustLine::highQualityOut_
Rate highQualityOut_
Definition: TrustLine.h:212
ripple::TrustLineBase
Wraps a trust line SLE for convenience.
Definition: TrustLine.h:44
ripple::TrustLineBase::mLowLimit
const STAmount mLowLimit
Definition: TrustLine.h:150
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:108