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 xrpl {
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 = !pInputs ? true : pInputs->defaultPathsAllowed;
48
49 bool const partialPayment = !pInputs ? false : pInputs->partialPaymentAllowed;
50
51 auto const limitQuality = [&]() -> std::optional<Quality> {
52 if (pInputs && pInputs->limitQuality && saMaxAmountReq > beast::zero)
53 return Quality{Amounts(saMaxAmountReq, saDstAmountReq)};
54 return std::nullopt;
55 }();
56
57 auto const sendMax = [&]() -> std::optional<STAmount> {
58 if (saMaxAmountReq >= beast::zero || saMaxAmountReq.getCurrency() != saDstAmountReq.getCurrency() ||
59 saMaxAmountReq.getIssuer() != uSrcAccountID)
60 {
61 return saMaxAmountReq;
62 }
63 return std::nullopt;
64 }();
65
66 try
67 {
68 flowOut = flow(
69 flowSB,
70 saDstAmountReq,
71 uSrcAccountID,
72 uDstAccountID,
73 spsPaths,
74 defaultPaths,
75 partialPayment,
76 false,
78 limitQuality,
79 sendMax,
80 domainID,
81 j,
82 nullptr);
83 }
84 catch (std::exception& e)
85 {
86 JLOG(j.error()) << "Exception from flow: " << e.what();
87
88 // return a tec so the tx is stored
89 path::RippleCalc::Output exceptResult;
90 exceptResult.setResult(tecINTERNAL);
91 return exceptResult;
92 }
93 }
94
95 j.debug() << "RippleCalc Result> "
96 << " actualIn: " << flowOut.actualAmountIn << ", actualOut: " << flowOut.actualAmountOut
97 << ", result: " << flowOut.result() << ", dstAmtReq: " << saDstAmountReq
98 << ", sendMax: " << saMaxAmountReq;
99
100 flowSB.apply(view);
101 return flowOut;
102}
103
104} // namespace path
105} // namespace xrpl
Manages partitions for logging.
Definition Log.h:33
beast::Journal journal(std::string const &name)
Definition Log.cpp:134
A wrapper which makes credits unavailable to balances.
void apply(RawView &to)
Apply changes to base view.
Currency const & getCurrency() const
Definition STAmount.h:461
AccountID const & getIssuer() const
Definition STAmount.h:467
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)
PaymentSandbox & view
Definition RippleCalc.h:100
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:82
@ tecINTERNAL
Definition TER.h:292
@ no
Definition Steps.h:26
void setResult(TER const value)
Definition RippleCalc.h:63
T what(T... args)