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 xrpl {
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(account < issuer ? sfLowLimit : sfHighLimit);
22 result.setIssuer(account);
23 }
24
25 XRPL_ASSERT(result.getIssuer() == account, "xrpl::creditLimit : result issuer match");
26 XRPL_ASSERT(result.getCurrency() == currency, "xrpl::creditLimit : result currency match");
27 return result;
28}
29
30IOUAmount
31creditLimit2(ReadView const& v, AccountID const& acc, AccountID const& iss, Currency const& cur)
32{
33 return toAmount<IOUAmount>(creditLimit(v, acc, iss, cur));
34}
35
36STAmount
38 ReadView const& view,
39 AccountID const& account,
40 AccountID const& issuer,
41 Currency const& currency)
42{
43 STAmount result(Issue{currency, account});
44
45 auto sleRippleState = view.read(keylet::line(account, issuer, currency));
46
47 if (sleRippleState)
48 {
49 result = sleRippleState->getFieldAmount(sfBalance);
50 if (account < issuer)
51 result.negate();
52 result.setIssuer(account);
53 }
54
55 XRPL_ASSERT(result.getIssuer() == account, "xrpl::creditBalance : result issuer match");
56 XRPL_ASSERT(result.getCurrency() == currency, "xrpl::creditBalance : result currency match");
57 return result;
58}
59
60} // namespace xrpl
A currency issued by an account.
Definition Issue.h:13
A view into a ledger.
Definition ReadView.h:31
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:220
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
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 creditLimit2(ReadView const &v, AccountID const &acc, AccountID const &iss, Currency const &cur)
Definition Credit.cpp:31
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:37
IOUAmount toAmount< IOUAmount >(STAmount const &amt)