rippled
Loading...
Searching...
No Matches
AccountCurrencies.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/AccountCurrencies.h>
21
22namespace ripple {
23
24hash_set<Currency>
26 AccountID const& account,
28 bool includeXRP)
29{
30 hash_set<Currency> currencies;
31
32 // YYY Only bother if they are above reserve
33 if (includeXRP)
34 currencies.insert(xrpCurrency());
35
36 if (auto const lines =
37 lrCache->getRippleLines(account, LineDirection::outgoing))
38 {
39 for (auto const& rspEntry : *lines)
40 {
41 auto& saBalance = rspEntry.getBalance();
42
43 // Filter out non
44 if (saBalance > beast::zero
45 // Have IOUs to send.
46 ||
47 (rspEntry.getLimitPeer()
48 // Peer extends credit.
49 && ((-saBalance) < rspEntry.getLimitPeer()))) // Credit left.
50 {
51 currencies.insert(saBalance.getCurrency());
52 }
53 }
54 }
55
56 currencies.erase(badCurrency());
57 return currencies;
58}
59
60hash_set<Currency>
62 AccountID const& account,
64 bool includeXRP)
65{
66 hash_set<Currency> currencies;
67
68 if (includeXRP)
69 currencies.insert(xrpCurrency());
70 // Even if account doesn't exist
71
72 if (auto const lines =
73 lrCache->getRippleLines(account, LineDirection::outgoing))
74 {
75 for (auto const& rspEntry : *lines)
76 {
77 auto& saBalance = rspEntry.getBalance();
78
79 if (saBalance < rspEntry.getLimit()) // Can take more
80 currencies.insert(saBalance.getCurrency());
81 }
82 }
83
84 currencies.erase(badCurrency());
85 return currencies;
86}
87
88} // namespace ripple
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:25
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
hash_set< Currency > accountDestCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
hash_set< Currency > accountSourceCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
Currency const & xrpCurrency()
XRP currency.