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 xrpl {
8
10 : key_(sle->key())
11 , mLowLimit(sle->getFieldAmount(sfLowLimit))
12 , mHighLimit(sle->getFieldAmount(sfHighLimit))
13 , mBalance(sle->getFieldAmount(sfBalance))
14 , mFlags(sle->getFieldU32(sfFlags))
15 , mViewLowest(mLowLimit.getIssuer() == viewAccount)
16{
17 if (!mViewLowest)
19}
20
23{
25 ret["low_id"] = to_string(mLowLimit.getIssuer());
26 ret["high_id"] = to_string(mHighLimit.getIssuer());
27 return ret;
28}
29
32{
33 if (!sle || sle->getType() != ltRIPPLE_STATE)
34 return {};
35 return std::optional{PathFindTrustLine{sle, accountID}};
36}
37
38namespace detail {
39template <class T>
42{
43 std::vector<T> items;
44 forEachItem(view, accountID, [&items, &accountID, &direction](std::shared_ptr<SLE const> const& sleCur) {
45 auto ret = T::makeItem(accountID, sleCur);
46 if (ret && (direction == LineDirection::outgoing || !ret->getNoRipple()))
47 items.push_back(std::move(*ret));
48 });
49 // This list may be around for a while, so free up any unneeded
50 // capacity
51 items.shrink_to_fit();
52
53 return items;
54}
55} // namespace detail
56
58PathFindTrustLine::getItems(AccountID const& accountID, ReadView const& view, LineDirection direction)
59{
60 return detail::getTrustLineItems<PathFindTrustLine>(accountID, view, direction);
61}
62
64 : TrustLineBase(sle, viewAccount)
65 , lowQualityIn_(sle->getFieldU32(sfLowQualityIn))
66 , lowQualityOut_(sle->getFieldU32(sfLowQualityOut))
67 , highQualityIn_(sle->getFieldU32(sfHighQualityIn))
68 , highQualityOut_(sle->getFieldU32(sfHighQualityOut))
69{
70}
71
74{
75 if (!sle || sle->getType() != ltRIPPLE_STATE)
76 return {};
77 return std::optional{RPCTrustLine{sle, accountID}};
78}
79
81RPCTrustLine::getItems(AccountID const& accountID, ReadView const& view)
82{
83 return detail::getTrustLineItems<RPCTrustLine>(accountID, view);
84}
85
86} // namespace xrpl
Represents a JSON value.
Definition json_value.h:131
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view, LineDirection direction)
Definition TrustLine.cpp:58
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition TrustLine.cpp:31
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition TrustLine.cpp:81
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
Definition TrustLine.cpp:73
A view into a ledger.
Definition ReadView.h:32
void negate()
Definition STAmount.h:531
AccountID const & getIssuer() const
Definition STAmount.h:467
Wraps a trust line SLE for convenience.
Definition TrustLine.h:35
STAmount const mHighLimit
Definition TrustLine.h:159
Json::Value getJson(int)
Definition TrustLine.cpp:22
TrustLineBase(std::shared_ptr< SLE const > const &sle, AccountID const &viewAccount)
Definition TrustLine.cpp:9
STAmount const mLowLimit
Definition TrustLine.h:158
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:27
std::vector< T > getTrustLineItems(AccountID const &accountID, ReadView const &view, LineDirection direction=LineDirection::outgoing)
Definition TrustLine.cpp:41
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:598
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:598
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)