rippled
Loading...
Searching...
No Matches
RippleCalc.cpp
1#include <xrpld/app/paths/Flow.h>
2#include <xrpld/app/paths/RippleCalc.h>
3#include <xrpld/app/paths/detail/FlowDebugInfo.h>
4
5#include <xrpl/basics/Log.h>
6#include <xrpl/ledger/View.h>
7#include <xrpl/protocol/Feature.h>
8
9namespace ripple {
10namespace path {
11
12RippleCalc::Output
14 PaymentSandbox& view,
15
16 // Compute paths using this ledger entry set. Up to caller to actually
17 // apply to ledger.
18
19 // Issuer:
20 // XRP: xrpAccount()
21 // non-XRP: uSrcAccountID (for any issuer) or another account with
22 // trust node.
23 STAmount const& saMaxAmountReq, // --> -1 = no limit.
24
25 // Issuer:
26 // XRP: xrpAccount()
27 // non-XRP: uDstAccountID (for any issuer) or another account with
28 // trust node.
29 STAmount const& saDstAmountReq,
30
31 AccountID const& uDstAccountID,
32 AccountID const& uSrcAccountID,
33
34 // A set of paths that are included in the transaction that we'll
35 // explore for liquidity.
36 STPathSet const& spsPaths,
37
38 std::optional<uint256> const& domainID,
39 Logs& l,
40 Input const* const pInputs)
41{
42 Output flowOut;
43 PaymentSandbox flowSB(&view);
44 auto j = l.journal("Flow");
45
46 {
47 bool const defaultPaths =
48 !pInputs ? true : pInputs->defaultPathsAllowed;
49
50 bool const partialPayment =
51 !pInputs ? false : pInputs->partialPaymentAllowed;
52
53 auto const limitQuality = [&]() -> std::optional<Quality> {
54 if (pInputs && pInputs->limitQuality &&
55 saMaxAmountReq > beast::zero)
56 return Quality{Amounts(saMaxAmountReq, saDstAmountReq)};
57 return std::nullopt;
58 }();
59
60 auto const sendMax = [&]() -> std::optional<STAmount> {
61 if (saMaxAmountReq >= beast::zero ||
62 saMaxAmountReq.getCurrency() != saDstAmountReq.getCurrency() ||
63 saMaxAmountReq.getIssuer() != uSrcAccountID)
64 {
65 return saMaxAmountReq;
66 }
67 return std::nullopt;
68 }();
69
70 try
71 {
72 flowOut = flow(
73 flowSB,
74 saDstAmountReq,
75 uSrcAccountID,
76 uDstAccountID,
77 spsPaths,
78 defaultPaths,
79 partialPayment,
80 false,
82 limitQuality,
83 sendMax,
84 domainID,
85 j,
86 nullptr);
87 }
88 catch (std::exception& e)
89 {
90 JLOG(j.error()) << "Exception from flow: " << e.what();
91
92 // return a tec so the tx is stored
93 path::RippleCalc::Output exceptResult;
94 exceptResult.setResult(tecINTERNAL);
95 return exceptResult;
96 }
97 }
98
99 j.debug() << "RippleCalc Result> "
100 << " actualIn: " << flowOut.actualAmountIn
101 << ", actualOut: " << flowOut.actualAmountOut
102 << ", result: " << flowOut.result()
103 << ", dstAmtReq: " << saDstAmountReq
104 << ", sendMax: " << saMaxAmountReq;
105
106 flowSB.apply(view);
107 return flowOut;
108}
109
110} // namespace path
111} // namespace ripple
Manages partitions for logging.
Definition Log.h:33
beast::Journal journal(std::string const &name)
Definition Log.cpp:141
A wrapper which makes credits unavailable to balances.
void apply(RawView &to)
Apply changes to base view.
Currency const & getCurrency() const
Definition STAmount.h:483
AccountID const & getIssuer() const
Definition STAmount.h:489
PaymentSandbox & view
Definition RippleCalc.h:100
static Output rippleCalculate(PaymentSandbox &view, STAmount const &saMaxAmountReq, STAmount const &saDstAmountReq, AccountID const &uDstAccountID, AccountID const &uSrcAccountID, STPathSet const &spsPaths, std::optional< uint256 > const &domainID, Logs &l, Input const *const pInputs=nullptr)
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
StrandResult< TInAmt, TOutAmt > flow(PaymentSandbox const &baseView, Strand const &strand, std::optional< TInAmt > const &maxIn, TOutAmt const &out, beast::Journal j)
Request out amount from a strand.
Definition StrandFlow.h:86
@ no
Definition Steps.h:26
@ tecINTERNAL
Definition TER.h:292
void setResult(TER const value)
Definition RippleCalc.h:63
T what(T... args)