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