rippled
Loading...
Searching...
No Matches
Credit.cpp
1#include <xrpl/ledger/ReadView.h>
2#include <xrpl/protocol/AmountConversions.h>
3#include <xrpl/protocol/Indexes.h>
4#include <xrpl/protocol/STAmount.h>
5
6namespace ripple {
7
8STAmount
10 ReadView const& view,
11 AccountID const& account,
12 AccountID const& issuer,
13 Currency const& currency)
14{
15 STAmount result(Issue{currency, account});
16
17 auto sleRippleState = view.read(keylet::line(account, issuer, currency));
18
19 if (sleRippleState)
20 {
21 result = sleRippleState->getFieldAmount(
22 account < issuer ? sfLowLimit : sfHighLimit);
23 result.setIssuer(account);
24 }
25
26 XRPL_ASSERT(
27 result.getIssuer() == account,
28 "ripple::creditLimit : result issuer match");
29 XRPL_ASSERT(
30 result.getCurrency() == currency,
31 "ripple::creditLimit : result currency match");
32 return result;
33}
34
35IOUAmount
37 ReadView const& v,
38 AccountID const& acc,
39 AccountID const& iss,
40 Currency const& cur)
41{
42 return toAmount<IOUAmount>(creditLimit(v, acc, iss, cur));
43}
44
45STAmount
47 ReadView const& view,
48 AccountID const& account,
49 AccountID const& issuer,
50 Currency const& currency)
51{
52 STAmount result(Issue{currency, account});
53
54 auto sleRippleState = view.read(keylet::line(account, issuer, currency));
55
56 if (sleRippleState)
57 {
58 result = sleRippleState->getFieldAmount(sfBalance);
59 if (account < issuer)
60 result.negate();
61 result.setIssuer(account);
62 }
63
64 XRPL_ASSERT(
65 result.getIssuer() == account,
66 "ripple::creditBalance : result issuer match");
67 XRPL_ASSERT(
68 result.getCurrency() == currency,
69 "ripple::creditBalance : result currency match");
70 return result;
71}
72
73} // namespace ripple
A currency issued by an account.
Definition Issue.h:14
A view into a ledger.
Definition ReadView.h:32
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Keylet line(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:225
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
STAmount creditLimit(ReadView const &view, AccountID const &account, AccountID const &issuer, Currency const &currency)
Calculate the maximum amount of IOUs that an account can hold.
Definition Credit.cpp:9
IOUAmount toAmount< IOUAmount >(STAmount const &amt)
STAmount creditBalance(ReadView const &view, AccountID const &account, AccountID const &issuer, Currency const &currency)
Returns the amount of IOUs issued by issuer that are held by an account.
Definition Credit.cpp:46
IOUAmount creditLimit2(ReadView const &v, AccountID const &acc, AccountID const &iss, Currency const &cur)
Definition Credit.cpp:36