xrpld
Loading...
Searching...
No Matches
PathRequest.cpp
1#include <xrpld/rpc/detail/PathRequest.h>
2
3#include <xrpld/app/main/Application.h>
4#include <xrpld/core/Config.h>
5#include <xrpld/rpc/detail/AccountAssets.h>
6#include <xrpld/rpc/detail/PathRequestManager.h>
7#include <xrpld/rpc/detail/Pathfinder.h>
8#include <xrpld/rpc/detail/PathfinderUtils.h>
9#include <xrpld/rpc/detail/Tuning.h>
10
11#include <xrpl/basics/Log.h>
12#include <xrpl/basics/UnorderedContainers.h>
13#include <xrpl/basics/base_uint.h>
14#include <xrpl/beast/utility/Journal.h>
15#include <xrpl/beast/utility/Zero.h>
16#include <xrpl/beast/utility/instrumentation.h>
17#include <xrpl/json/json_value.h>
18#include <xrpl/ledger/ApplyView.h>
19#include <xrpl/ledger/PaymentSandbox.h>
20#include <xrpl/protocol/AccountID.h>
21#include <xrpl/protocol/Asset.h>
22#include <xrpl/protocol/ErrorCodes.h>
23#include <xrpl/protocol/Indexes.h>
24#include <xrpl/protocol/LedgerFormats.h>
25#include <xrpl/protocol/PathAsset.h>
26#include <xrpl/protocol/Protocol.h>
27#include <xrpl/protocol/RPCErr.h>
28#include <xrpl/protocol/STAmount.h>
29#include <xrpl/protocol/STPathSet.h>
30#include <xrpl/protocol/SystemParameters.h>
31#include <xrpl/protocol/TER.h>
32#include <xrpl/protocol/UintTypes.h>
33#include <xrpl/protocol/jss.h>
34#include <xrpl/resource/Consumer.h>
35#include <xrpl/server/InfoSub.h>
36#include <xrpl/server/LoadFeeTrack.h>
37#include <xrpl/tx/paths/RippleCalc.h>
38
39#include <algorithm>
40#include <chrono>
41#include <functional>
42#include <memory>
43#include <mutex>
44#include <optional>
45#include <string>
46#include <utility>
47#include <variant>
48
49namespace xrpl {
50
52 Application& app,
53 std::shared_ptr<InfoSub> const& subscriber,
54 int id,
55 PathRequestManager& owner,
56 beast::Journal journal)
57 : app_(app)
58 , journal_(journal)
59 , owner_(owner)
60 , wpSubscriber_(subscriber)
61 , consumer_(subscriber->getConsumer())
62 , jvStatus_(json::ValueType::Object)
63 , lastIndex_(0)
64 , inProgress_(false)
65 , iLevel_(0)
66 , bLastSuccess_(false)
67 , iIdentifier_(id)
68 , created_(std::chrono::steady_clock::now())
69{
70 JLOG(journal_.debug()) << iIdentifier_ << " created";
71}
72
74 Application& app,
75 std::function<void()> completion,
76 resource::Consumer& consumer,
77 int id,
78 PathRequestManager& owner,
79 beast::Journal journal)
80 : app_(app)
81 , journal_(journal)
82 , owner_(owner)
83 , fCompletion_(std::move(completion))
84 , consumer_(consumer)
85 , jvStatus_(json::ValueType::Object)
86 , lastIndex_(0)
87 , inProgress_(false)
88 , iLevel_(0)
89 , bLastSuccess_(false)
90 , iIdentifier_(id)
91 , created_(std::chrono::steady_clock::now())
92{
93 JLOG(journal_.debug()) << iIdentifier_ << " created";
94}
95
97{
98 using namespace std::chrono;
99 auto const stream = journal_.info();
100 if (!stream)
101 return;
102
103 std::string fast, full;
104 if (quickReply_ != steady_clock::time_point{})
105 {
106 fast = " fast:";
108 fast += "ms";
109 }
110 if (fullReply_ != steady_clock::time_point{})
111 {
112 full = " full:";
114 full += "ms";
115 }
116 stream << iIdentifier_ << " complete:" << fast << full
117 << " total:" << duration_cast<milliseconds>(steady_clock::now() - created_).count()
118 << "ms";
119}
120
121bool
123{
125
126 // does this path request still need its first full path
127 return lastIndex_ == 0;
128}
129
130bool
132{
134
135 if (inProgress_)
136 {
137 // Another thread is handling this
138 return false;
139 }
140
141 if (newOnly && (lastIndex_ != 0))
142 {
143 // Only handling new requests, this isn't new
144 return false;
145 }
146
147 if (lastIndex_ >= index)
148 {
149 return false;
150 }
151
152 inProgress_ = true;
153 return true;
154}
155
156bool
158{
159 return bool(fCompletion_);
160}
161
162void
164{
166
167 XRPL_ASSERT(inProgress_, "xrpl::PathRequest::updateComplete : in progress");
168 inProgress_ = false;
169
170 if (fCompletion_)
171 {
172 fCompletion_();
174 }
175}
176
177bool
179{
181 return false;
182
184 {
185 // If send max specified, dst amt must be -1.
187 return false;
188 }
189
190 auto const& lrLedger = crCache->getLedger();
191
192 if (!lrLedger->exists(keylet::account(*raSrcAccount_)))
193 {
194 // Source account does not exist.
196 return false;
197 }
198
199 auto const sleDest = lrLedger->read(keylet::account(*raDstAccount_));
200
201 json::Value& jvDestCur = (jvStatus_[jss::destination_currencies] = json::ValueType::Array);
202
203 if (!sleDest)
204 {
206 if (!saDstAmount_.native())
207 {
208 // Only XRP can be send to a non-existent account.
210 return false;
211 }
212
213 if (!convertAll_ && saDstAmount_ < STAmount(lrLedger->fees().reserve))
214 {
215 // Payment must meet reserve.
217 return false;
218 }
219 }
220 else
221 {
222 bool const disallowXRP(sleDest->isFlag(lsfDisallowXRP));
223
224 auto const destAssets = accountDestAssets(*raDstAccount_, crCache, !disallowXRP);
225
226 for (auto const& asset : destAssets)
227 jvDestCur.append(to_string(asset));
228
229 jvStatus_[jss::destination_tag] = (sleDest->getFlags() & lsfRequireDestTag);
230 }
231
232 jvStatus_[jss::ledger_hash] = to_string(lrLedger->header().hash);
233 jvStatus_[jss::ledger_index] = lrLedger->seq();
234 return true;
235}
236
237/* If this is a normal path request, we want to run it once "fast" now
238 to give preliminary results.
239
240 If this is a legacy path request, we are only going to run it once,
241 and we can't run it in full now, so we don't want to run it at all.
242
243 If there's an error, we need to be sure to return it to the caller
244 in all cases.
245*/
248{
249 bool valid = false;
250
251 if (parseJson(value) != PFR_PJ_INVALID)
252 {
253 valid = isValid(cache);
254 if (!hasCompletion() && valid)
255 doUpdate(cache, true);
256 }
257
258 if (auto const stream = journal_.debug())
259 {
260 if (valid)
261 {
262 // NOLINTNEXTLINE(bugprone-unchecked-optional-access) isValid() ensures it is set
263 stream << iIdentifier_ << " valid: " << toBase58(*raSrcAccount_);
264 stream << iIdentifier_ << " deliver: " << saDstAmount_.getFullText();
265 }
266 else
267 {
268 stream << iIdentifier_ << " invalid";
269 }
270 }
271
272 return {valid, jvStatus_};
273}
274
275int
277{
278 if (!jvParams.isMember(jss::source_account))
279 {
281 return PFR_PJ_INVALID;
282 }
283
284 if (!jvParams.isMember(jss::destination_account))
285 {
287 return PFR_PJ_INVALID;
288 }
289
290 if (!jvParams.isMember(jss::destination_amount))
291 {
293 return PFR_PJ_INVALID;
294 }
295
296 raSrcAccount_ = parseBase58<AccountID>(jvParams[jss::source_account].asString());
297 if (!raSrcAccount_)
298 {
300 return PFR_PJ_INVALID;
301 }
302
303 raDstAccount_ = parseBase58<AccountID>(jvParams[jss::destination_account].asString());
304 if (!raDstAccount_)
305 {
307 return PFR_PJ_INVALID;
308 }
309
310 if (!amountFromJsonNoThrow(saDstAmount_, jvParams[jss::destination_amount]))
311 {
313 return PFR_PJ_INVALID;
314 }
315
316 convertAll_ = saDstAmount_ == STAmount(saDstAmount_.asset(), 1u, 0, true);
317
319 {
321 return PFR_PJ_INVALID;
322 }
323
324 if (jvParams.isMember(jss::send_max))
325 {
326 // Send_max requires destination amount to be -1.
327 if (!convertAll_)
328 {
330 return PFR_PJ_INVALID;
331 }
332
333 saSendMax_.emplace();
334 if (!amountFromJsonNoThrow(*saSendMax_, jvParams[jss::send_max]) ||
335 !validAsset(saSendMax_->asset()) ||
337 *saSendMax_ != STAmount(saSendMax_->asset(), 1u, 0, true)))
338 {
340 return PFR_PJ_INVALID;
341 }
342 }
343
344 if (jvParams.isMember(jss::source_currencies))
345 {
346 json::Value const& jvSrcCurrencies = jvParams[jss::source_currencies];
347 if (!jvSrcCurrencies.isArray() || jvSrcCurrencies.size() == 0 ||
348 jvSrcCurrencies.size() > rpc::tuning::kMaxSrcCur)
349 {
351 return PFR_PJ_INVALID;
352 }
353
354 sciSourceAssets_.clear();
355
356 for (auto const& c : jvSrcCurrencies)
357 {
358 // Mandatory currency or MPT
359 if (!validJSONAsset(c) || !c.isObject())
360 {
362 return PFR_PJ_INVALID;
363 }
364
365 PathAsset srcPathAsset;
366 if (c.isMember(jss::currency))
367 {
368 Currency currency;
369 if (!c[jss::currency].isString() ||
370 !toCurrency(currency, c[jss::currency].asString()))
371 {
373 return PFR_PJ_INVALID;
374 }
375 srcPathAsset = currency;
376 }
377 else
378 {
379 UInt192 u;
380 if (!c[jss::mpt_issuance_id].isString() ||
381 !u.parseHex(c[jss::mpt_issuance_id].asString()))
382 {
384 return PFR_PJ_INVALID;
385 }
386 srcPathAsset = u;
387 }
388
389 // Optional issuer
390 AccountID srcIssuerID;
391 if (c.isMember(jss::issuer) &&
392 (c.isMember(jss::mpt_issuance_id) || !c[jss::issuer].isString() ||
393 !toIssuer(srcIssuerID, c[jss::issuer].asString())))
394 {
396 return PFR_PJ_INVALID;
397 }
398
399 if (srcPathAsset.holds<Currency>())
400 {
401 if (srcPathAsset.get<Currency>().isZero())
402 {
403 if (srcIssuerID.isNonZero())
404 {
406 return PFR_PJ_INVALID;
407 }
408 }
409 else if (srcIssuerID.isZero())
410 {
411 srcIssuerID = *raSrcAccount_;
412 }
413 }
414
415 if (saSendMax_)
416 {
417 // If the assets don't match, ignore the source asset.
418 if (srcPathAsset == saSendMax_->asset())
419 {
420 auto const status = srcPathAsset.visit(
421 [&](Currency const& currency) {
422 // If neither is the source and they are not equal,
423 // then the source issuer is illegal. srcIssuerID
424 // comes from the optional IOU source_currencies
425 // issuer field, so this reconciliation is IOU-only.
426 if (srcIssuerID != *raSrcAccount_ &&
427 saSendMax_->getIssuer() != *raSrcAccount_ &&
428 srcIssuerID != saSendMax_->getIssuer())
429 {
431 return PFR_PJ_INVALID;
432 }
433
434 // If both are the source, use the source.
435 // Otherwise, use the one that's not the source.
436 if (srcIssuerID != *raSrcAccount_)
437 {
438 sciSourceAssets_.insert(Issue{currency, srcIssuerID});
439 }
440 else if (saSendMax_->getIssuer() != *raSrcAccount_)
441 {
442 sciSourceAssets_.insert(Issue{currency, saSendMax_->getIssuer()});
443 }
444 else
445 {
446 sciSourceAssets_.insert(Issue{currency, *raSrcAccount_});
447 }
448 return PFR_PJ_NOCHANGE;
449 },
450 [&](MPTID const& mpt) {
451 sciSourceAssets_.insert(mpt);
452 return PFR_PJ_NOCHANGE;
453 });
454 if (status == PFR_PJ_INVALID)
455 return status;
456 }
457 }
458 else
459 {
460 srcPathAsset.visit(
461 [&](Currency const& currency) {
462 sciSourceAssets_.insert(Issue{currency, srcIssuerID});
463 },
464 [&](MPTID const& mpt) { sciSourceAssets_.insert(MPTIssue{mpt}); });
465 }
466 }
467 }
468
469 if (jvParams.isMember(jss::id))
470 jvId_ = jvParams[jss::id];
471
472 if (jvParams.isMember(jss::domain))
473 {
474 UInt256 num;
475 if (!jvParams[jss::domain].isString() || !num.parseHex(jvParams[jss::domain].asString()))
476 {
478 return PFR_PJ_INVALID;
479 }
480
481 domain_ = num;
482 }
483
484 return PFR_PJ_NOCHANGE;
485}
486
489{
490 JLOG(journal_.debug()) << iIdentifier_ << " closed";
491 std::scoped_lock const sl(lock_);
492 jvStatus_[jss::closed] = true;
493 return jvStatus_;
494}
495
498{
499 std::scoped_lock const sl(lock_);
500 jvStatus_[jss::status] = jss::success;
501 return jvStatus_;
502}
503
504void
506{
507 JLOG(journal_.info()) << iIdentifier_ << " aborting early";
508}
509
512 std::shared_ptr<AssetCache> const& cache,
514 PathAsset const& currency,
515 STAmount const& dstAmount,
516 int const level,
517 std::function<bool()> const& continueCallback)
518{
519 auto const i = currencyMap.find(currency);
520 if (i != currencyMap.end())
521 return i->second;
522 // NOLINTBEGIN(bugprone-unchecked-optional-access) isValid() ensures both are set
523 auto pathfinder = std::make_unique<Pathfinder>(
524 cache,
527 currency,
528 std::nullopt,
529 dstAmount,
531 domain_,
532 app_);
533 // NOLINTEND(bugprone-unchecked-optional-access)
534 if (pathfinder->findPaths(level, continueCallback))
535 {
536 pathfinder->computePathRanks(kMaxPaths, continueCallback);
537 }
538 else
539 {
540 pathfinder.reset(); // It's a bad request - clear it.
541 }
542 return currencyMap[currency] = std::move(pathfinder);
543}
544
545bool
547 std::shared_ptr<AssetCache> const& cache,
548 int const level,
549 json::Value& jvArray,
550 std::function<bool()> const& continueCallback)
551{
552 auto sourceAssets = sciSourceAssets_;
553 if (sourceAssets.empty() && saSendMax_)
554 {
555 sourceAssets.insert(saSendMax_->asset());
556 }
557 if (sourceAssets.empty())
558 {
559 // NOLINTBEGIN(bugprone-unchecked-optional-access) isValid() ensures both are set
560 auto const assets = accountSourceAssets(*raSrcAccount_, cache, true);
561 bool const sameAccount = *raSrcAccount_ == *raDstAccount_;
562 // NOLINTEND(bugprone-unchecked-optional-access)
563 for (auto const& asset : assets)
564 {
565 if (!std::visit(
566 [&]<typename TAsset>(TAsset const& a) {
567 if (!sameAccount || a != saDstAmount_.asset())
568 {
569 if (sourceAssets.size() >= rpc::tuning::kMaxAutoSrcCur)
570 return false;
572 {
573 sourceAssets.insert(
574 Issue{a, a.isZero() ? xrpAccount() : *raSrcAccount_});
575 }
576 else
577 {
578 sourceAssets.insert(MPTIssue{a});
579 }
580 }
581 return true;
582 },
583 asset.value()))
584 {
585 return false;
586 }
587 }
588 }
589
590 auto const dstAmount = convertAmount(saDstAmount_, convertAll_);
592 for (auto const& asset : sourceAssets)
593 {
594 if (continueCallback && !continueCallback())
595 break;
596 JLOG(journal_.debug()) << iIdentifier_
597 << " Trying to find paths: " << STAmount(asset, 1).getFullText();
598
599 auto& pathfinder =
600 getPathFinder(cache, currencyMap, PathAsset(asset), dstAmount, level, continueCallback);
601 if (!pathfinder)
602 {
603 JLOG(journal_.debug()) << iIdentifier_ << " No paths found";
604 continue;
605 }
606
607 STPath fullLiquidityPath;
608 auto ps = pathfinder->getBestPaths(
609 kMaxPaths, fullLiquidityPath, context_[asset], asset.getIssuer(), continueCallback);
610 context_[asset] = ps;
611
612 auto const& sourceAccount = [&] {
613 if (!isXRP(asset.getIssuer()))
614 return asset.getIssuer();
615
616 if (isXRP(asset))
617 return xrpAccount();
618
619 return *raSrcAccount_;
620 }();
621
622 STAmount const saMaxAmount = [&] {
623 if (saSendMax_)
624 return *saSendMax_;
625 return asset.visit(
626 [&](Issue const& issue) {
627 return STAmount(Issue{issue.currency, sourceAccount}, 1u, 0, true);
628 },
629 [](MPTIssue const& issue) { return STAmount(issue, 1u, 0, true); });
630 }();
631
632 JLOG(journal_.debug()) << iIdentifier_ << " Paths found, calling rippleCalc";
633
635 if (convertAll_)
636 rcInput.partialPaymentAllowed = true;
637 auto sandbox = std::make_unique<PaymentSandbox>(&*cache->getLedger(), TapNone);
639 *sandbox,
640 saMaxAmount, // --> Amount to send is unlimited
641 // to get an estimate.
642 dstAmount, // --> Amount to deliver.
643 // NOLINTBEGIN(bugprone-unchecked-optional-access) isValid() ensures both are set
644 *raDstAccount_, // --> Account to deliver to.
645 *raSrcAccount_, // --> Account sending from.
646 // NOLINTEND(bugprone-unchecked-optional-access)
647 ps, // --> Path set.
648 domain_, // --> Domain.
649 app_,
650 &rcInput);
651
652 if (!convertAll_ && !fullLiquidityPath.empty() &&
653 (rc.result() == terNO_LINE || rc.result() == tecPATH_PARTIAL))
654 {
655 JLOG(journal_.debug()) << iIdentifier_ << " Trying with an extra path element";
656
657 ps.pushBack(fullLiquidityPath);
658 sandbox = std::make_unique<PaymentSandbox>(&*cache->getLedger(), TapNone);
660 *sandbox,
661 saMaxAmount, // --> Amount to send is unlimited
662 // to get an estimate.
663 dstAmount, // --> Amount to deliver.
664 // NOLINTBEGIN(bugprone-unchecked-optional-access) isValid() ensures both are set
665 *raDstAccount_, // --> Account to deliver to.
666 *raSrcAccount_, // --> Account sending from.
667 // NOLINTEND(bugprone-unchecked-optional-access)
668 ps, // --> Path set.
669 domain_, // --> Domain.
670 app_);
671
672 if (!isTesSuccess(rc.result()))
673 {
674 JLOG(journal_.warn())
675 << iIdentifier_ << " Failed with covering path " << transHuman(rc.result());
676 }
677 else
678 {
679 JLOG(journal_.debug())
680 << iIdentifier_ << " Extra path element gives " << transHuman(rc.result());
681 }
682 }
683
684 if (rc.result() == tesSUCCESS)
685 {
687 if (rc.actualAmountIn.holds<Issue>())
688 rc.actualAmountIn.get<Issue>().account = sourceAccount;
689 jvEntry[jss::source_amount] = rc.actualAmountIn.getJson(JsonOptions::Values::None);
690 jvEntry[jss::paths_computed] = ps.getJson(JsonOptions::Values::None);
691
692 if (convertAll_)
693 {
694 jvEntry[jss::destination_amount] =
695 rc.actualAmountOut.getJson(JsonOptions::Values::None);
696 }
697
698 if (hasCompletion())
699 {
700 // Old ripple_path_find API requires this
701 jvEntry[jss::paths_canonical] = json::ValueType::Array;
702 }
703
704 jvArray.append(jvEntry);
705 }
706 else
707 {
708 JLOG(journal_.debug())
709 << iIdentifier_ << " rippleCalc returns " << transHuman(rc.result());
710 }
711 }
712
713 /* The resource fee is based on the number of source currencies used.
714 The minimum cost is 50 and the maximum is 400. The cost increases
715 after four source currencies, 50 - (4 * 4) = 34.
716 */
717 int const size = sourceAssets.size();
718 consumer_.charge({std::clamp((size * size) + 34, 50, 400), "path update"});
719 return true;
720}
721
724 std::shared_ptr<AssetCache> const& cache,
725 bool fast,
726 std::function<bool()> const& continueCallback)
727{
728 using namespace std::chrono;
729 JLOG(journal_.debug()) << iIdentifier_ << " update " << (fast ? "fast" : "normal");
730
731 {
732 std::scoped_lock const sl(lock_);
733
734 if (!isValid(cache))
735 return jvStatus_;
736 }
737
739
740 if (hasCompletion())
741 {
742 // Old ripple_path_find API gives destination_currencies
743 auto& destAssets = (newStatus[jss::destination_currencies] = json::ValueType::Array);
744 // NOLINTNEXTLINE(bugprone-unchecked-optional-access) isValid() ensures both are set
745 auto const assets = accountDestAssets(*raDstAccount_, cache, true);
746 for (auto const& asset : assets)
747 destAssets.append(to_string(asset));
748 }
749
750 // NOLINTBEGIN(bugprone-unchecked-optional-access) isValid() ensures both are set
751 newStatus[jss::source_account] = toBase58(*raSrcAccount_);
752 newStatus[jss::destination_account] = toBase58(*raDstAccount_);
753 // NOLINTEND(bugprone-unchecked-optional-access)
754 newStatus[jss::destination_amount] = saDstAmount_.getJson(JsonOptions::Values::None);
755 newStatus[jss::full_reply] = !fast;
756
757 if (jvId_)
758 newStatus[jss::id] = jvId_;
759
760 bool const loaded = app_.getFeeTrack().isLoadedLocal();
761
762 if (iLevel_ == 0)
763 {
764 // first pass
765 if (loaded || fast)
766 {
767 iLevel_ = app_.config().pathSearchFast;
768 }
769 else
770 {
771 iLevel_ = app_.config().pathSearch;
772 }
773 }
774 else if ((iLevel_ == app_.config().pathSearchFast) && !fast)
775 {
776 // leaving fast pathfinding
777 iLevel_ = app_.config().pathSearch;
778 if (loaded && (iLevel_ > app_.config().pathSearchFast))
779 --iLevel_;
780 }
781 else if (bLastSuccess_)
782 {
783 // decrement, if possible
784 if (iLevel_ > app_.config().pathSearch ||
785 (loaded && (iLevel_ > app_.config().pathSearchFast)))
786 --iLevel_;
787 }
788 else
789 {
790 // adjust as needed
791 if (!loaded && (iLevel_ < app_.config().pathSearchMax))
792 ++iLevel_;
793 if (loaded && (iLevel_ > app_.config().pathSearchFast))
794 --iLevel_;
795 }
796
797 JLOG(journal_.debug()) << iIdentifier_ << " processing at level " << iLevel_;
798
800 if (findPaths(cache, iLevel_, jvArray, continueCallback))
801 {
802 bLastSuccess_ = jvArray.size() != 0;
803 newStatus[jss::alternatives] = std::move(jvArray);
804 }
805 else
806 {
807 bLastSuccess_ = false;
808 newStatus = rpcError(RpcInternal);
809 }
810
811 if (fast && quickReply_ == steady_clock::time_point{})
812 {
815 }
816 else if (!fast && fullReply_ == steady_clock::time_point{})
817 {
820 }
821
822 {
823 std::scoped_lock const sl(lock_);
824 jvStatus_ = newStatus;
825 }
826
827 JLOG(journal_.debug()) << iIdentifier_ << " update finished " << (fast ? "fast" : "normal");
828 return newStatus;
829}
830
833{
834 return wpSubscriber_.lock();
835}
836
837} // namespace xrpl
T clamp(T... args)
A generic endpoint for log messages.
Definition Journal.h:44
Represents a JSON value.
Definition json_value.h:121
bool isArray() const
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
bool isZero() const
Definition base_uint.h:563
bool isNonZero() const
Definition base_uint.h:568
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:526
std::shared_ptr< InfoSub > pointer
Definition InfoSub.h:92
A currency issued by an account.
Definition Issue.h:18
Currency currency
Definition Issue.h:20
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition PathAsset.h:52
constexpr bool holds() const
Definition PathAsset.h:78
T const & get() const
json::Value jvId_
PathRequest(Application &app, std::shared_ptr< InfoSub > const &subscriber, int id, PathRequestManager &, beast::Journal journal)
LedgerIndex lastIndex_
std::recursive_mutex lock_
void doAborting() const
std::chrono::steady_clock::time_point quickReply_
json::Value doUpdate(std::shared_ptr< AssetCache > const &, bool fast, std::function< bool()> const &continueCallback={})
int parseJson(json::Value const &)
static unsigned int const kMaxPaths
int const iIdentifier_
bool isValid(std::shared_ptr< AssetCache > const &crCache)
PathRequestManager & owner_
json::Value jvStatus_
std::optional< UInt256 > domain_
std::chrono::steady_clock::time_point const created_
bool needsUpdate(bool newOnly, LedgerIndex index)
STAmount saDstAmount_
resource::Consumer & consumer_
json::Value doClose() override
std::recursive_mutex indexLock_
std::function< void()> fCompletion_
std::weak_ptr< InfoSub > wpSubscriber_
InfoSub::pointer getSubscriber() const
json::Value doStatus(json::Value const &) override
std::optional< STAmount > saSendMax_
beast::Journal journal_
Application & app_
~PathRequest() override
std::chrono::steady_clock::time_point fullReply_
std::set< Asset > sciSourceAssets_
std::optional< AccountID > raDstAccount_
std::unique_ptr< Pathfinder > const & getPathFinder(std::shared_ptr< AssetCache > const &, HashMap< PathAsset, std::unique_ptr< Pathfinder > > &, PathAsset const &, STAmount const &, int const, std::function< bool()> const &)
bool findPaths(std::shared_ptr< AssetCache > const &, int const, json::Value &, std::function< bool()> const &)
Finds and sets a PathSet in the JSON argument.
std::pair< bool, json::Value > doCreate(std::shared_ptr< AssetCache > const &, json::Value const &)
std::optional< AccountID > raSrcAccount_
std::map< Asset, STPathSet > context_
std::string getFullText() const override
bool empty() const
Definition STPathSet.h:532
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)
An endpoint that consumes resources.
Definition Consumer.h:20
T count(T... args)
T duration_cast(T... args)
T is_same_v
T make_unique(T... args)
constexpr Zero kZero
Definition Zero.h:30
JSON (JavaScript Object Notation).
Definition json_errors.h:5
@ Array
array value (ordered list)
Definition json_value.h:32
@ Object
object value (collection of name/value pairs).
Definition json_value.h:33
STL namespace.
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
static constexpr int kMaxSrcCur
Maximum number of source currencies allowed in a path find request.
static constexpr int kMaxAutoSrcCur
Maximum number of auto source currencies in a path find request.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_LINE
Definition TER.h:221
@ RpcDstAmtMalformed
Definition ErrorCodes.h:89
@ RpcInternal
Definition ErrorCodes.h:113
@ RpcSrcActMalformed
Definition ErrorCodes.h:103
@ RpcActNotFound
Definition ErrorCodes.h:53
@ RpcDstActMalformed
Definition ErrorCodes.h:86
@ RpcDomainMalformed
Definition ErrorCodes.h:141
@ RpcSrcActMissing
Definition ErrorCodes.h:104
@ RpcDstActMissing
Definition ErrorCodes.h:87
@ RpcSrcCurMalformed
Definition ErrorCodes.h:107
@ RpcDstAmtMissing
Definition ErrorCodes.h:90
@ RpcSendmaxMalformed
Definition ErrorCodes.h:102
@ RpcSrcIsrMalformed
Definition ErrorCodes.h:108
@ RpcSrcActNotFound
Definition ErrorCodes.h:105
STAmount convertAmount(STAmount const &amt, bool all)
bool isXRP(AccountID const &c)
Definition AccountID.h:84
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:409
bool validJSONAsset(json::Value const &jv)
Definition Asset.cpp:51
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:42
std::string transHuman(TER code)
Definition TER.cpp:268
bool toCurrency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition UintTypes.cpp:65
bool validAsset(Asset const &asset)
Definition Asset.h:331
BaseUInt< 192 > UInt192
Definition base_uint.h:582
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
HashSet< PathAsset > accountDestAssets(AccountID const &account, std::shared_ptr< AssetCache > const &lrCache, bool includeXRP)
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
BaseUInt< 256 > UInt256
Definition base_uint.h:581
bool amountFromJsonNoThrow(STAmount &result, json::Value const &jvSource)
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition UintTypes.h:54
HashSet< PathAsset > accountSourceAssets(AccountID const &account, std::shared_ptr< AssetCache > const &lrCache, bool includeXRP)
@ TapNone
Definition ApplyView.h:28
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
bool isTesSuccess(TER x) noexcept
Definition TER.h:686
AccountID const & xrpAccount()
Compute AccountID from public key.
@ tecPATH_PARTIAL
Definition TER.h:293
static std::string const & systemCurrencyCode()
std::unordered_map< Key, Value, Hash, Pred, Allocator > HashMap
bool toIssuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
@ tesSUCCESS
Definition TER.h:253
T size(T... args)
T to_string(T... args)
T visit(T... args)