rippled
Loading...
Searching...
No Matches
TrustLine.cpp
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#include <xrpld/app/paths/TrustLine.h>
21#include <xrpl/protocol/STAmount.h>
22
23#include <memory>
24
25namespace ripple {
26
29 AccountID const& viewAccount)
30 : key_(sle->key())
31 , mLowLimit(sle->getFieldAmount(sfLowLimit))
32 , mHighLimit(sle->getFieldAmount(sfHighLimit))
33 , mBalance(sle->getFieldAmount(sfBalance))
34 , mFlags(sle->getFieldU32(sfFlags))
35 , mViewLowest(mLowLimit.getIssuer() == viewAccount)
36{
37 if (!mViewLowest)
39}
40
43{
45 ret["low_id"] = to_string(mLowLimit.getIssuer());
46 ret["high_id"] = to_string(mHighLimit.getIssuer());
47 return ret;
48}
49
52 AccountID const& accountID,
54{
55 if (!sle || sle->getType() != ltRIPPLE_STATE)
56 return {};
57 return std::optional{PathFindTrustLine{sle, accountID}};
59
60namespace detail {
61template <class T>
64 AccountID const& accountID,
65 ReadView const& view,
67{
68 std::vector<T> items;
70 view,
71 accountID,
72 [&items, &accountID, &direction](
73 std::shared_ptr<SLE const> const& sleCur) {
74 auto ret = T::makeItem(accountID, sleCur);
75 if (ret &&
76 (direction == LineDirection::outgoing || !ret->getNoRipple()))
77 items.push_back(std::move(*ret));
78 });
79 // This list may be around for a while, so free up any unneeded
80 // capacity
81 items.shrink_to_fit();
82
83 return items;
84}
85} // namespace detail
86
89 AccountID const& accountID,
90 ReadView const& view,
91 LineDirection direction)
92{
93 return detail::getTrustLineItems<PathFindTrustLine>(
94 accountID, view, direction);
95}
96
99 AccountID const& viewAccount)
100 : TrustLineBase(sle, viewAccount)
101 , lowQualityIn_(sle->getFieldU32(sfLowQualityIn))
102 , lowQualityOut_(sle->getFieldU32(sfLowQualityOut))
103 , highQualityIn_(sle->getFieldU32(sfHighQualityIn))
104 , highQualityOut_(sle->getFieldU32(sfHighQualityOut))
105{
106}
107
110 AccountID const& accountID,
112{
113 if (!sle || sle->getType() != ltRIPPLE_STATE)
114 return {};
115 return std::optional{RPCTrustLine{sle, accountID}};
116}
117
119RPCTrustLine::getItems(AccountID const& accountID, ReadView const& view)
120{
121 return detail::getTrustLineItems<RPCTrustLine>(accountID, view);
122}
123
124} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view, LineDirection direction)
Definition: TrustLine.cpp:88
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition: TrustLine.cpp:51
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition: TrustLine.cpp:109
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition: TrustLine.cpp:119
A view into a ledger.
Definition: ReadView.h:51
AccountID const & getIssuer() const
Definition: STAmount.h:499
Wraps a trust line SLE for convenience.
Definition: TrustLine.h:54
STAmount const mLowLimit
Definition: TrustLine.h:187
TrustLineBase(std::shared_ptr< SLE const > const &sle, AccountID const &viewAccount)
Definition: TrustLine.cpp:27
STAmount const mHighLimit
Definition: TrustLine.h:188
Json::Value getJson(int)
Definition: TrustLine.cpp:42
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:44
std::vector< T > getTrustLineItems(AccountID const &accountID, ReadView const &view, LineDirection direction=LineDirection::outgoing)
Definition: TrustLine.cpp:63
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
Definition: View.cpp:543
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition: TrustLine.h:41
T push_back(T... args)
T shrink_to_fit(T... args)