rippled
Loading...
Searching...
No Matches
AccountCurrencies.cpp
1#include <xrpld/app/paths/AccountCurrencies.h>
2
3namespace xrpl {
4
5hash_set<Currency>
6accountSourceCurrencies(AccountID const& account, std::shared_ptr<RippleLineCache> const& lrCache, bool includeXRP)
7{
8 hash_set<Currency> currencies;
9
10 // YYY Only bother if they are above reserve
11 if (includeXRP)
12 currencies.insert(xrpCurrency());
13
14 if (auto const lines = lrCache->getRippleLines(account, LineDirection::outgoing))
15 {
16 for (auto const& rspEntry : *lines)
17 {
18 auto& saBalance = rspEntry.getBalance();
19
20 // Filter out non
21 if (saBalance > beast::zero
22 // Have IOUs to send.
23 || (rspEntry.getLimitPeer()
24 // Peer extends credit.
25 && ((-saBalance) < rspEntry.getLimitPeer()))) // Credit left.
26 {
27 currencies.insert(saBalance.getCurrency());
28 }
29 }
30 }
31
32 currencies.erase(badCurrency());
33 return currencies;
34}
35
36hash_set<Currency>
37accountDestCurrencies(AccountID const& account, std::shared_ptr<RippleLineCache> const& lrCache, bool includeXRP)
38{
39 hash_set<Currency> currencies;
40
41 if (includeXRP)
42 currencies.insert(xrpCurrency());
43 // Even if account doesn't exist
44
45 if (auto const lines = lrCache->getRippleLines(account, LineDirection::outgoing))
46 {
47 for (auto const& rspEntry : *lines)
48 {
49 auto& saBalance = rspEntry.getBalance();
50
51 if (saBalance < rspEntry.getLimit()) // Can take more
52 currencies.insert(saBalance.getCurrency());
53 }
54 }
55
56 currencies.erase(badCurrency());
57 return currencies;
58}
59
60} // namespace xrpl
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
hash_set< Currency > accountSourceCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
Currency const & xrpCurrency()
XRP currency.
Definition UintTypes.cpp:96
hash_set< Currency > accountDestCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...