xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
detail
TrustLine.cpp
1
#include <xrpld/rpc/detail/TrustLine.h>
2
3
#include <xrpl/json/json_value.h>
4
#include <xrpl/ledger/ReadView.h>
5
#include <xrpl/ledger/helpers/DirectoryHelpers.h>
6
#include <xrpl/protocol/AccountID.h>
7
#include <xrpl/protocol/LedgerFormats.h>
8
#include <xrpl/protocol/SField.h>
9
#include <xrpl/protocol/STAmount.h>
10
#include <xrpl/protocol/STLedgerEntry.h>
11
12
#include <
optional
>
13
#include <
vector
>
14
15
namespace
xrpl
{
16
17
TrustLineBase::TrustLineBase
(
SLE::ConstRef
sle,
AccountID
const
& viewAccount)
18
:
key_
(sle->
key
())
19
,
lowLimit_
(sle->getFieldAmount(sfLowLimit))
20
,
highLimit_
(sle->getFieldAmount(sfHighLimit))
21
,
balance_
(sle->getFieldAmount(sfBalance))
22
,
flags_
(sle->getFieldU32(sfFlags))
23
,
viewLowest_
(
lowLimit_
.getIssuer() == viewAccount)
24
{
25
if
(!
viewLowest_
)
26
balance_
.negate();
27
}
28
29
json::Value
30
TrustLineBase::getJson
(
int
)
31
{
32
json::Value
ret(
json::ValueType::Object
);
33
ret[
"low_id"
] =
to_string
(
lowLimit_
.getIssuer());
34
ret[
"high_id"
] =
to_string
(
highLimit_
.getIssuer());
35
return
ret;
36
}
37
38
std::optional<PathFindTrustLine>
39
PathFindTrustLine::makeItem
(
AccountID
const
& accountID,
SLE::ConstRef
sle)
40
{
41
if
(!sle || sle->getType() != ltRIPPLE_STATE)
42
return
{};
43
return
std::optional
{
PathFindTrustLine
{sle, accountID}};
44
}
45
46
namespace
detail
{
47
template
<
class
T>
48
std::vector<T>
49
getTrustLineItems
(
50
AccountID
const
& accountID,
51
ReadView
const
& view,
52
LineDirection
direction =
LineDirection::Outgoing
)
53
{
54
std::vector<T>
items;
55
forEachItem
(view, accountID, [&items, &accountID, &direction](
SLE::ConstRef
sleCur) {
56
auto
ret = T::makeItem(accountID, sleCur);
57
if
(ret && (direction ==
LineDirection::Outgoing
|| !ret->getNoRipple()))
58
items.
push_back
(std::move(*ret));
59
});
60
// This list may be around for a while, so free up any unneeded
61
// capacity
62
items.
shrink_to_fit
();
63
64
return
items;
65
}
66
}
// namespace detail
67
68
std::vector<PathFindTrustLine>
69
PathFindTrustLine::getItems
(
70
AccountID
const
& accountID,
71
ReadView
const
& view,
72
LineDirection
direction)
73
{
74
return
detail::getTrustLineItems<PathFindTrustLine>
(accountID, view, direction);
75
}
76
77
RPCTrustLine::RPCTrustLine
(
SLE::ConstRef
sle,
AccountID
const
& viewAccount)
78
:
TrustLineBase
(sle, viewAccount)
79
,
lowQualityIn_
(sle->getFieldU32(sfLowQualityIn))
80
,
lowQualityOut_
(sle->getFieldU32(sfLowQualityOut))
81
,
highQualityIn_
(sle->getFieldU32(sfHighQualityIn))
82
,
highQualityOut_
(sle->getFieldU32(sfHighQualityOut))
83
{
84
}
85
86
std::optional<RPCTrustLine>
87
RPCTrustLine::makeItem
(
AccountID
const
& accountID,
SLE::ConstRef
sle)
88
{
89
if
(!sle || sle->getType() != ltRIPPLE_STATE)
90
return
{};
91
return
std::optional
{
RPCTrustLine
{sle, accountID}};
92
}
93
94
std::vector<RPCTrustLine>
95
RPCTrustLine::getItems
(
AccountID
const
& accountID,
ReadView
const
& view)
96
{
97
return
detail::getTrustLineItems<RPCTrustLine>
(accountID, view);
98
}
99
100
}
// namespace xrpl
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::PathFindTrustLine::makeItem
static std::optional< PathFindTrustLine > makeItem(AccountID const &accountID, SLE::ConstRef sle)
Definition
TrustLine.cpp:39
xrpl::PathFindTrustLine::getItems
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view, LineDirection direction)
Definition
TrustLine.cpp:69
xrpl::PathFindTrustLine::PathFindTrustLine
PathFindTrustLine()=delete
xrpl::RPCTrustLine::RPCTrustLine
RPCTrustLine()=delete
xrpl::RPCTrustLine::getItems
static std::vector< RPCTrustLine > getItems(AccountID const &accountID, ReadView const &view)
Definition
TrustLine.cpp:95
xrpl::RPCTrustLine::makeItem
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, SLE::ConstRef sle)
Definition
TrustLine.cpp:87
xrpl::RPCTrustLine::TrustLineBase
TrustLineBase(SLE::ConstRef sle, AccountID const &viewAccount)
Definition
TrustLine.cpp:17
xrpl::RPCTrustLine::lowQualityOut_
Rate lowQualityOut_
Definition
TrustLine.h:232
xrpl::RPCTrustLine::highQualityOut_
Rate highQualityOut_
Definition
TrustLine.h:234
xrpl::RPCTrustLine::lowQualityIn_
Rate lowQualityIn_
Definition
TrustLine.h:231
xrpl::RPCTrustLine::highQualityIn_
Rate highQualityIn_
Definition
TrustLine.h:233
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
xrpl::STLedgerEntry::ConstRef
std::shared_ptr< STLedgerEntry const > const & ConstRef
Definition
STLedgerEntry.h:37
xrpl::TrustLineBase::getJson
json::Value getJson(int)
Definition
TrustLine.cpp:30
xrpl::TrustLineBase::key
UInt256 const & key() const
Returns the state map key for the ledger entry.
Definition
TrustLine.h:60
xrpl::TrustLineBase::key_
UInt256 key_
Definition
TrustLine.h:174
xrpl::TrustLineBase::lowLimit_
STAmount const lowLimit_
Definition
TrustLine.h:176
xrpl::TrustLineBase::TrustLineBase
TrustLineBase(SLE::ConstRef sle, AccountID const &viewAccount)
Definition
TrustLine.cpp:17
xrpl::TrustLineBase::viewLowest_
bool viewLowest_
Definition
TrustLine.h:183
xrpl::TrustLineBase::flags_
std::uint32_t flags_
Definition
TrustLine.h:181
xrpl::TrustLineBase::balance_
STAmount balance_
Definition
TrustLine.h:179
xrpl::TrustLineBase::highLimit_
STAmount const highLimit_
Definition
TrustLine.h:177
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl::detail
Definition
base_uint.h:37
xrpl::detail::getTrustLineItems
std::vector< T > getTrustLineItems(AccountID const &accountID, ReadView const &view, LineDirection direction=LineDirection::Outgoing)
Definition
TrustLine.cpp:49
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::forEachItem
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(SLE::ConstRef)> const &f)
Iterate all items in the given directory.
Definition
DirectoryHelpers.cpp:63
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::LineDirection
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition
TrustLine.h:27
xrpl::LineDirection::Outgoing
@ Outgoing
Definition
TrustLine.h:27
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
optional
std::vector::push_back
T push_back(T... args)
std::vector::shrink_to_fit
T shrink_to_fit(T... args)
vector
Generated by
1.17.0