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
149 STAmount const&
151 {
152 return mBalance;
153 }
154
155 STAmount const&
156 getLimit() const
157 {
159 }
160
161 STAmount const&
163 {
164 return !mViewLowest ? mLowLimit : mHighLimit;
165 }
166
168 getJson(int);
169
170protected:
172
175
177
179
181};
182
183// This wrapper is used for the path finder
184class PathFindTrustLine final : public TrustLineBase,
185 public CountedObject<PathFindTrustLine>
186{
188
189public:
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.
204class RPCTrustLine final : public TrustLineBase,
205 public CountedObject<RPCTrustLine>
206{
208
209public:
210 RPCTrustLine() = delete;
211
214 AccountID const& viewAccount);
215
216 Rate 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
234private:
239};
240
241} // namespace ripple
242
243#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:217
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:223
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
std::uint32_t mFlags
Definition: TrustLine.h:178
STAmount const & getLimit() const
Definition: TrustLine.h:156
STAmount const mLowLimit
Definition: TrustLine.h:173
STAmount const & getBalance() const
Definition: TrustLine.h:150
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:162
STAmount const mHighLimit
Definition: TrustLine.h:174
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:144
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
TrustLineBase & operator=(TrustLineBase const &)=delete
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
@ lsfDefaultRipple
@ lsfHighNoRipple
@ lsfHighFreeze
@ lsfLowNoRipple
@ lsfLowFreeze
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