xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
detail
AccountAssets.cpp
1
#include <xrpld/rpc/detail/AccountAssets.h>
2
3
#include <xrpld/rpc/detail/AssetCache.h>
4
#include <xrpld/rpc/detail/TrustLine.h>
5
6
#include <xrpl/basics/UnorderedContainers.h>
7
#include <xrpl/beast/utility/Zero.h>
8
#include <xrpl/protocol/AccountID.h>
9
#include <xrpl/protocol/PathAsset.h>
10
#include <xrpl/protocol/UintTypes.h>
11
12
#include <
memory
>
13
14
namespace
xrpl
{
15
16
HashSet<PathAsset>
17
accountSourceAssets
(
18
AccountID
const
& account,
19
std::shared_ptr<AssetCache>
const
& lrCache,
20
bool
includeXRP)
21
{
22
HashSet<PathAsset>
assets;
23
24
// YYY Only bother if they are above reserve
25
if
(includeXRP)
26
assets.
insert
(
xrpCurrency
());
27
28
if
(
auto
const
lines = lrCache->getRippleLines(account,
LineDirection::Outgoing
))
29
{
30
for
(
auto
const
& rspEntry : *lines)
31
{
32
auto
& saBalance = rspEntry.getBalance();
33
34
// Filter out non
35
if
(saBalance >
beast::kZero
36
// Have IOUs to send.
37
|| (rspEntry.getLimitPeer()
38
// Peer extends credit.
39
&& ((-saBalance) < rspEntry.getLimitPeer())))
// Credit left.
40
{
41
assets.
insert
(saBalance.get<
Issue
>().
currency
);
42
}
43
}
44
}
45
46
assets.
erase
(
badCurrency
());
47
48
if
(
auto
const
mpts = lrCache->getMPTs(account))
49
{
50
for
(
auto
const
& rspEntry : *mpts)
51
{
52
if
(rspEntry.canSend(account))
53
assets.
insert
(rspEntry.getMptID());
54
}
55
}
56
57
return
assets;
58
}
59
60
HashSet<PathAsset>
61
accountDestAssets
(
62
AccountID
const
& account,
63
std::shared_ptr<AssetCache>
const
& lrCache,
64
bool
includeXRP)
65
{
66
HashSet<PathAsset>
assets;
67
68
if
(includeXRP)
69
assets.
insert
(
xrpCurrency
());
70
// Even if account doesn't exist
71
72
if
(
auto
const
lines = lrCache->getRippleLines(account,
LineDirection::Outgoing
))
73
{
74
for
(
auto
const
& rspEntry : *lines)
75
{
76
auto
& saBalance = rspEntry.getBalance();
77
78
if
(saBalance < rspEntry.getLimit())
// Can take more
79
assets.
insert
(saBalance.get<
Issue
>().
currency
);
80
}
81
}
82
83
assets.
erase
(
badCurrency
());
84
85
if
(
auto
const
mpts = lrCache->getMPTs(account))
86
{
87
for
(
auto
const
& rspEntry : *mpts)
88
{
89
// Any cached MPT entry means this account already has an issuance
90
// or MPToken object. A maxed-out issuance does not prevent
91
// receiving existing MPT from another holder.
92
assets.
insert
(rspEntry.getMptID());
93
}
94
}
95
96
return
assets;
97
}
98
99
}
// namespace xrpl
xrpl::Issue
A currency issued by an account.
Definition
Issue.h:18
xrpl::Issue::currency
Currency currency
Definition
Issue.h:20
std::unordered_set::erase
T erase(T... args)
std::unordered_set::insert
T insert(T... args)
memory
beast::kZero
constexpr Zero kZero
Definition
Zero.h:30
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::xrpCurrency
Currency const & xrpCurrency()
XRP currency.
Definition
UintTypes.cpp:99
xrpl::accountDestAssets
HashSet< PathAsset > accountDestAssets(AccountID const &account, std::shared_ptr< AssetCache > const &lrCache, bool includeXRP)
Definition
AccountAssets.cpp:61
xrpl::LineDirection::Outgoing
@ Outgoing
Definition
TrustLine.h:27
xrpl::HashSet
std::unordered_set< Value, Hash, Pred, Allocator > HashSet
Definition
UnorderedContainers.h:51
xrpl::accountSourceAssets
HashSet< PathAsset > accountSourceAssets(AccountID const &account, std::shared_ptr< AssetCache > const &lrCache, bool includeXRP)
Definition
AccountAssets.cpp:17
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::badCurrency
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
Definition
UintTypes.cpp:113
std::shared_ptr
Generated by
1.17.0