xrpld
Loading...
Searching...
No Matches
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
14namespace xrpl {
15
18 AccountID const& account,
19 std::shared_ptr<AssetCache> const& lrCache,
20 bool includeXRP)
21{
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.isZeroBalance() && !rspEntry.isMaxedOut())
53 assets.insert(rspEntry.getMptID());
54 }
55 }
56
57 return assets;
58}
59
62 AccountID const& account,
63 std::shared_ptr<AssetCache> const& lrCache,
64 bool includeXRP)
65{
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 if (rspEntry.isZeroBalance() && !rspEntry.isMaxedOut())
90 assets.insert(rspEntry.getMptID());
91 }
92 }
93
94 return assets;
95}
96
97} // namespace xrpl
A currency issued by an account.
Definition Issue.h:13
Currency currency
Definition Issue.h:15
T erase(T... args)
T insert(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::unordered_set< Value, Hash, Pred, Allocator > hash_set
hash_set< PathAsset > accountDestAssets(AccountID const &account, std::shared_ptr< AssetCache > const &lrCache, bool includeXRP)
Currency const & xrpCurrency()
XRP currency.
Definition UintTypes.cpp:99
hash_set< PathAsset > accountSourceAssets(AccountID const &account, std::shared_ptr< AssetCache > const &lrCache, bool includeXRP)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...