rippled
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 <ripple/app/paths/AccountCurrencies.h>
21 
22 namespace ripple {
23 
24 hash_set<Currency>
26  AccountID const& account,
27  std::shared_ptr<RippleLineCache> const& lrCache,
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 
60 hash_set<Currency>
62  AccountID const& account,
63  std::shared_ptr<RippleLineCache> const& lrCache,
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
ripple::badCurrency
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
Definition: UintTypes.cpp:135
std::shared_ptr
STL class.
std::unordered_set
STL class.
ripple::accountDestCurrencies
hash_set< Currency > accountDestCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
Definition: AccountCurrencies.cpp:61
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::LineDirection::outgoing
@ outgoing
std::unordered_set::erase
T erase(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::unordered_set::insert
T insert(T... args)
ripple::RippleLineCache::getRippleLines
std::shared_ptr< std::vector< PathFindTrustLine > > getRippleLines(AccountID const &accountID, LineDirection direction)
Find the trust lines associated with an account.
Definition: RippleLineCache.cpp:42
ripple::accountSourceCurrencies
hash_set< Currency > accountSourceCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
Definition: AccountCurrencies.cpp:25
ripple::xrpCurrency
Currency const & xrpCurrency()
XRP currency.
Definition: UintTypes.cpp:121