rippled
Loading...
Searching...
No Matches
TrustLine.cpp
1#include <xrpld/app/paths/TrustLine.h>
2
3#include <xrpl/protocol/STAmount.h>
4
5#include <memory>
6
7namespace ripple {
8
11 AccountID const& viewAccount)
12 : key_(sle->key())
13 , mLowLimit(sle->getFieldAmount(sfLowLimit))
14 , mHighLimit(sle->getFieldAmount(sfHighLimit))
15 , mBalance(sle->getFieldAmount(sfBalance))
16 , mFlags(sle->getFieldU32(sfFlags))
17 , mViewLowest(mLowLimit.getIssuer() == viewAccount)
18{
19 if (!mViewLowest)
21}
22
25{
27 ret["low_id"] = to_string(mLowLimit.getIssuer());
28 ret["high_id"] = to_string(mHighLimit.getIssuer());
29 return ret;
30}
31
34 AccountID const& accountID,
36{
37 if (!sle || sle->getType() != ltRIPPLE_STATE)
38 return {};
39 return std::optional{PathFindTrustLine{sle, accountID}};
40}
41
42namespace detail {
43template <class T>
46 AccountID const& accountID,
47 ReadView const& view,
49{
50 std::vector<T> items;
52 view,
53 accountID,
54 [&items, &accountID, &direction](
55 std::shared_ptr<SLE const> const& sleCur) {
56 auto ret = T::makeItem(accountID, sleCur);
57 if (ret &&
58 (direction == LineDirection::outgoing || !ret->getNoRipple()))
59 items.push_back(std::move(*ret));
60 });
61 // This list may be around for a while, so free up any unneeded
62 // capacity
63 items.shrink_to_fit();
64
65 return items;
66}
67} // namespace detail
68
71 AccountID const& accountID,
72 ReadView const& view,
73 LineDirection direction)
74{
75 return detail::getTrustLineItems<PathFindTrustLine>(
76 accountID, view, direction);
77}
78
81 AccountID const& viewAccount)
82 : TrustLineBase(sle, viewAccount)
83 , lowQualityIn_(sle->getFieldU32(sfLowQualityIn))
84 , lowQualityOut_(sle->getFieldU32(sfLowQualityOut))
85 , highQualityIn_(sle->getFieldU32(sfHighQualityIn))
86 , highQualityOut_(sle->getFieldU32(sfHighQualityOut))
87{
88}
89
92 AccountID const& accountID,
94{
95 if (!sle || sle->getType() != ltRIPPLE_STATE)
96 return {};
97 return std::optional{RPCTrustLine{sle, accountID}};
98}
99
101RPCTrustLine::getItems(AccountID const& accountID, ReadView const& view)
102{
103 return detail::getTrustLineItems<RPCTrustLine>(accountID, view);
104}
105
106} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view, LineDirection direction)
Definition TrustLine.cpp:70
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition TrustLine.cpp:33
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition TrustLine.cpp:91
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
A view into a ledger.
Definition ReadView.h:32
AccountID const & getIssuer() const
Definition STAmount.h:489
Wraps a trust line SLE for convenience.
Definition TrustLine.h:35
STAmount const mLowLimit
Definition TrustLine.h:162
TrustLineBase(std::shared_ptr< SLE const > const &sle, AccountID const &viewAccount)
Definition TrustLine.cpp:9
STAmount const mHighLimit
Definition TrustLine.h:163
Json::Value getJson(int)
Definition TrustLine.cpp:24
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:26
std::vector< T > getTrustLineItems(AccountID const &accountID, ReadView const &view, LineDirection direction=LineDirection::outgoing)
Definition TrustLine.cpp:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
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:637
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition TrustLine.h:22
T push_back(T... args)
T shrink_to_fit(T... args)