20#include <xrpld/app/main/Application.h>
21#include <xrpld/app/misc/LoadFeeTrack.h>
22#include <xrpld/app/misc/NetworkOPs.h>
23#include <xrpld/app/paths/AccountCurrencies.h>
24#include <xrpld/app/paths/PathRequest.h>
25#include <xrpld/app/paths/PathRequests.h>
26#include <xrpld/app/paths/RippleCalc.h>
27#include <xrpld/app/paths/detail/PathfinderUtils.h>
28#include <xrpld/core/Config.h>
29#include <xrpld/rpc/detail/Tuning.h>
30#include <xrpl/basics/Log.h>
31#include <xrpl/beast/core/LexicalCast.h>
32#include <xrpl/protocol/ErrorCodes.h>
33#include <xrpl/protocol/RPCErr.h>
34#include <xrpl/protocol/UintTypes.h>
50 , wpSubscriber(subscriber)
51 , consumer_(subscriber->getConsumer())
52 , jvStatus(
Json::objectValue)
58 , created_(
std::chrono::steady_clock::now())
73 , fCompletion(completion)
75 , jvStatus(
Json::objectValue)
81 , created_(
std::chrono::steady_clock::now())
109 <<
iIdentifier <<
" complete:" << fast << full <<
" total:"
110 << duration_cast<milliseconds>(steady_clock::now() -
created_).count()
161 mInProgress,
"ripple::PathRequest::updateComplete : in progress");
184 auto const& lrLedger = crCache->getLedger();
223 for (
auto const& currency : usDestCurrID)
230 jvStatus[jss::ledger_index] = lrLedger->seq();
276 if (!jvParams.
isMember(jss::source_account))
279 return PFR_PJ_INVALID;
282 if (!jvParams.
isMember(jss::destination_account))
285 return PFR_PJ_INVALID;
288 if (!jvParams.
isMember(jss::destination_amount))
291 return PFR_PJ_INVALID;
295 parseBase58<AccountID>(jvParams[jss::source_account].asString());
299 return PFR_PJ_INVALID;
303 parseBase58<AccountID>(jvParams[jss::destination_account].asString());
307 return PFR_PJ_INVALID;
313 return PFR_PJ_INVALID;
324 return PFR_PJ_INVALID;
327 if (jvParams.
isMember(jss::send_max))
333 return PFR_PJ_INVALID;
345 return PFR_PJ_INVALID;
349 if (jvParams.
isMember(jss::source_currencies))
351 Json::Value const& jvSrcCurrencies = jvParams[jss::source_currencies];
352 if (!jvSrcCurrencies.
isArray() || jvSrcCurrencies.
size() == 0 ||
356 return PFR_PJ_INVALID;
361 for (
auto const& c : jvSrcCurrencies)
365 if (!c.isObject() || !c.isMember(jss::currency) ||
366 !c[jss::currency].isString() ||
367 !
to_currency(srcCurrencyID, c[jss::currency].asString()))
370 return PFR_PJ_INVALID;
375 if (c.isMember(jss::issuer) &&
376 (!c[jss::issuer].isString() ||
377 !
to_issuer(srcIssuerID, c[jss::issuer].asString())))
380 return PFR_PJ_INVALID;
383 if (srcCurrencyID.
isZero())
388 return PFR_PJ_INVALID;
391 else if (srcIssuerID.
isZero())
399 if (srcCurrencyID ==
saSendMax->getCurrency())
408 return PFR_PJ_INVALID;
416 {srcCurrencyID, srcIssuerID});
421 {srcCurrencyID,
saSendMax->getIssuer()});
438 jvId = jvParams[jss::id];
440 return PFR_PJ_NOCHANGE;
456 jvStatus[jss::status] = jss::success;
475 auto i = currency_map.find(currency);
476 if (i != currency_map.end())
478 auto pathfinder = std::make_unique<Pathfinder>(
487 if (pathfinder->findPaths(level, continueCallback))
488 pathfinder->computePathRanks(
max_paths_, continueCallback);
491 return currency_map[currency] = std::move(pathfinder);
502 if (sourceCurrencies.empty() &&
saSendMax)
504 sourceCurrencies.insert(
saSendMax->issue());
506 if (sourceCurrencies.empty())
510 for (
auto const& c : currencies)
516 sourceCurrencies.insert(
524 for (
auto const& issue : sourceCurrencies)
526 if (continueCallback && !continueCallback())
546 auto ps = pathfinder->getBestPaths(
554 auto const& sourceAccount = [&] {
555 if (!
isXRP(issue.account))
556 return issue.account;
558 if (
isXRP(issue.currency))
568 <<
iIdentifier <<
" Paths found, calling rippleCalc";
574 std::make_unique<PaymentSandbox>(&*cache->getLedger(),
tapNONE);
590 <<
iIdentifier <<
" Trying with an extra path element";
592 ps.push_back(fullLiquidityPath);
594 std::make_unique<PaymentSandbox>(&*cache->getLedger(),
tapNONE);
622 rc.actualAmountIn.setIssuer(sourceAccount);
623 jvEntry[jss::source_amount] =
628 jvEntry[jss::destination_amount] =
650 int const size = sourceCurrencies.size();
663 <<
iIdentifier <<
" update " << (fast ?
"fast" :
"normal");
677 auto& destCurrencies =
680 for (
auto const& c : usCurrencies)
687 newStatus[jss::full_reply] = !fast;
690 newStatus[jss::id] =
jvId;
731 newStatus[jss::alternatives] = std::move(jvArray);
744 else if (!fast &&
full_reply_ == steady_clock::time_point{})
756 <<
iIdentifier <<
" update finished " << (fast ?
"fast" :
"normal");
UInt size() const
Number of values in array or object.
Value & append(const Value &value)
Append value to array at the end.
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
virtual Config & config()=0
virtual LoadFeeTrack & getFeeTrack()=0
A currency issued by an account.
bool isLoadedLocal() const
std::optional< STAmount > saSendMax
std::function< void(void)> fCompletion
static unsigned int const max_paths_
bool findPaths(std::shared_ptr< RippleLineCache > const &, int const, Json::Value &, std::function< bool(void)> const &)
Finds and sets a PathSet in the JSON argument.
Json::Value doClose() override
std::weak_ptr< InfoSub > wpSubscriber
Json::Value doStatus(Json::Value const &) override
std::set< Issue > sciSourceCurrencies
int parseJson(Json::Value const &)
bool needsUpdate(bool newOnly, LedgerIndex index)
PathRequest(Application &app, std::shared_ptr< InfoSub > const &subscriber, int id, PathRequests &, beast::Journal journal)
std::recursive_mutex mLock
std::recursive_mutex mIndexLock
Resource::Consumer & consumer_
std::optional< AccountID > raSrcAccount
InfoSub::pointer getSubscriber() const
Json::Value doUpdate(std::shared_ptr< RippleLineCache > const &, bool fast, std::function< bool(void)> const &continueCallback={})
std::chrono::steady_clock::time_point full_reply_
std::pair< bool, Json::Value > doCreate(std::shared_ptr< RippleLineCache > const &, Json::Value const &)
std::chrono::steady_clock::time_point quick_reply_
std::map< Issue, STPathSet > mContext
std::optional< AccountID > raDstAccount
std::chrono::steady_clock::time_point const created_
std::unique_ptr< Pathfinder > const & getPathFinder(std::shared_ptr< RippleLineCache > const &, hash_map< Currency, std::unique_ptr< Pathfinder > > &, Currency const &, STAmount const &, int const, std::function< bool(void)> const &)
bool isValid(std::shared_ptr< RippleLineCache > const &crCache)
void reportFast(std::chrono::milliseconds ms)
void reportFull(std::chrono::milliseconds ms)
An endpoint that consumes resources.
Disposition charge(Charge const &fee, std::string const &context={})
Apply a load charge to the consumer.
Json::Value getJson(JsonOptions) const override
Currency const & getCurrency() const
AccountID const & getIssuer() const
Issue const & issue() const
std::string getFullText() const override
bool native() const noexcept
static Output rippleCalculate(PaymentSandbox &view, STAmount const &saMaxAmountReq, STAmount const &saDstAmountReq, AccountID const &uDstAccountID, AccountID const &uSrcAccountID, STPathSet const &spsPaths, Logs &l, Input const *const pInputs=nullptr)
JSON (JavaScript Object Notation).
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
static int constexpr max_src_cur
Maximum number of source currencies allowed in a path find request.
static int constexpr max_auto_src_cur
Maximum number of auto source currencies in a path find request.
TER valid(PreclaimContext const &ctx, AccountID const &src)
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string transHuman(TER code)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
STAmount convertAmount(STAmount const &amt, bool all)
bool isXRP(AccountID const &c)
AccountID const & xrpAccount()
Compute AccountID from public key.
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
hash_set< Currency > accountDestCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
hash_set< Currency > accountSourceCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
static std::string const & systemCurrencyCode()
Json::Value rpcError(int iError)
bool amountFromJsonNoThrow(STAmount &result, Json::Value const &jvSource)
std::string to_string(base_uint< Bits, Tag > const &a)
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.