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