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
22#include <xrpl/protocol/STAmount.h>
23
24#include <memory>
25
26namespace ripple {
27
30 AccountID const& viewAccount)
31 : key_(sle->key())
32 , mLowLimit(sle->getFieldAmount(sfLowLimit))
33 , mHighLimit(sle->getFieldAmount(sfHighLimit))
34 , mBalance(sle->getFieldAmount(sfBalance))
35 , mFlags(sle->getFieldU32(sfFlags))
36 , mViewLowest(mLowLimit.getIssuer() == viewAccount)
37{
38 if (!mViewLowest)
40}
41
44{
46 ret["low_id"] = to_string(mLowLimit.getIssuer());
47 ret["high_id"] = to_string(mHighLimit.getIssuer());
48 return ret;
49}
50
53 AccountID const& accountID,
55{
56 if (!sle || sle->getType() != ltRIPPLE_STATE)
57 return {};
58 return std::optional{PathFindTrustLine{sle, accountID}};
59}
60
61namespace detail {
62template <class T>
65 AccountID const& accountID,
66 ReadView const& view,
68{
69 std::vector<T> items;
71 view,
72 accountID,
73 [&items, &accountID, &direction](
74 std::shared_ptr<SLE const> const& sleCur) {
75 auto ret = T::makeItem(accountID, sleCur);
76 if (ret &&
77 (direction == LineDirection::outgoing || !ret->getNoRipple()))
78 items.push_back(std::move(*ret));
79 });
80 // This list may be around for a while, so free up any unneeded
81 // capacity
82 items.shrink_to_fit();
83
84 return items;
85}
86} // namespace detail
87
90 AccountID const& accountID,
91 ReadView const& view,
92 LineDirection direction)
93{
94 return detail::getTrustLineItems<PathFindTrustLine>(
95 accountID, view, direction);
96}
97
100 AccountID const& viewAccount)
101 : TrustLineBase(sle, viewAccount)
102 , lowQualityIn_(sle->getFieldU32(sfLowQualityIn))
103 , lowQualityOut_(sle->getFieldU32(sfLowQualityOut))
104 , highQualityIn_(sle->getFieldU32(sfHighQualityIn))
105 , highQualityOut_(sle->getFieldU32(sfHighQualityOut))
106{
107}
108
111 AccountID const& accountID,
113{
114 if (!sle || sle->getType() != ltRIPPLE_STATE)
115 return {};
116 return std::optional{RPCTrustLine{sle, accountID}};
117}
118
120RPCTrustLine::getItems(AccountID const& accountID, ReadView const& view)
121{
122 return detail::getTrustLineItems<RPCTrustLine>(accountID, view);
123}
124
125} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
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
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, std::shared_ptr< SLE const > const &sle)
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
A view into a ledger.
Definition ReadView.h:51
AccountID const & getIssuer() const
Definition STAmount.h:508
Wraps a trust line SLE for convenience.
Definition TrustLine.h:54
STAmount const mLowLimit
Definition TrustLine.h:181
TrustLineBase(std::shared_ptr< SLE const > const &sle, AccountID const &viewAccount)
Definition TrustLine.cpp:28
STAmount const mHighLimit
Definition TrustLine.h:182
Json::Value getJson(int)
Definition TrustLine.cpp:43
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
std::vector< T > getTrustLineItems(AccountID const &accountID, ReadView const &view, LineDirection direction=LineDirection::outgoing)
Definition TrustLine.cpp:64
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
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:653
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
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)