20 #include <ripple/app/main/Application.h>
21 #include <ripple/app/misc/LoadFeeTrack.h>
22 #include <ripple/app/misc/NetworkOPs.h>
23 #include <ripple/app/paths/AccountCurrencies.h>
24 #include <ripple/app/paths/PathRequest.h>
25 #include <ripple/app/paths/PathRequests.h>
26 #include <ripple/app/paths/RippleCalc.h>
27 #include <ripple/basics/Log.h>
28 #include <ripple/beast/core/LexicalCast.h>
29 #include <ripple/core/Config.h>
30 #include <ripple/net/RPCErr.h>
31 #include <ripple/protocol/ErrorCodes.h>
32 #include <ripple/protocol/UintTypes.h>
33 #include <ripple/rpc/impl/Tuning.h>
34 #include <boost/algorithm/clamp.hpp>
35 #include <boost/optional.hpp>
49 , wpSubscriber(subscriber)
50 , consumer_(subscriber->getConsumer())
51 , jvStatus(
Json::objectValue)
57 , created_(
std::chrono::steady_clock::now())
72 , fCompletion(completion)
74 , jvStatus(
Json::objectValue)
80 , created_(
std::chrono::steady_clock::now())
108 <<
iIdentifier <<
" complete:" << fast << full <<
" total:"
109 << duration_cast<milliseconds>(steady_clock::now() -
created_).count()
182 auto const& lrLedger = crCache->getLedger();
221 for (
auto const& currency : usDestCurrID)
228 jvStatus[jss::ledger_index] = lrLedger->seq();
274 if (!jvParams.
isMember(jss::source_account))
277 return PFR_PJ_INVALID;
280 if (!jvParams.
isMember(jss::destination_account))
283 return PFR_PJ_INVALID;
286 if (!jvParams.
isMember(jss::destination_amount))
289 return PFR_PJ_INVALID;
293 parseBase58<AccountID>(jvParams[jss::source_account].asString());
297 return PFR_PJ_INVALID;
301 parseBase58<AccountID>(jvParams[jss::destination_account].asString());
305 return PFR_PJ_INVALID;
311 return PFR_PJ_INVALID;
322 return PFR_PJ_INVALID;
325 if (jvParams.
isMember(jss::send_max))
331 return PFR_PJ_INVALID;
343 return PFR_PJ_INVALID;
347 if (jvParams.
isMember(jss::source_currencies))
349 Json::Value const& jvSrcCurrencies = jvParams[jss::source_currencies];
350 if (!jvSrcCurrencies.
isArray() || jvSrcCurrencies.
size() == 0 ||
354 return PFR_PJ_INVALID;
359 for (
auto const& c : jvSrcCurrencies)
363 if (!c.isObject() || !c.isMember(jss::currency) ||
364 !c[jss::currency].isString() ||
365 !
to_currency(srcCurrencyID, c[jss::currency].asString()))
368 return PFR_PJ_INVALID;
373 if (c.isMember(jss::issuer) &&
374 (!c[jss::issuer].isString() ||
375 !
to_issuer(srcIssuerID, c[jss::issuer].asString())))
378 return PFR_PJ_INVALID;
381 if (srcCurrencyID.
isZero())
386 return PFR_PJ_INVALID;
389 else if (srcIssuerID.
isZero())
397 if (srcCurrencyID ==
saSendMax->getCurrency())
406 return PFR_PJ_INVALID;
414 {srcCurrencyID, srcIssuerID});
419 {srcCurrencyID,
saSendMax->getIssuer()});
436 jvId = jvParams[jss::id];
438 return PFR_PJ_NOCHANGE;
454 jvStatus[jss::status] = jss::success;
466 auto i = currency_map.find(currency);
467 if (i != currency_map.end())
469 auto pathfinder = std::make_unique<Pathfinder>(
478 if (pathfinder->findPaths(level))
482 return currency_map[currency] = std::move(pathfinder);
492 if (sourceCurrencies.empty())
496 for (
auto const& c : currencies)
502 sourceCurrencies.insert(
513 for (
auto const& issue : sourceCurrencies)
520 cache, currency_map, issue.currency, dst_amount, level);
529 auto ps = pathfinder->getBestPaths(
533 auto& sourceAccount = !
isXRP(issue.account)
537 STAmount({issue.currency, sourceAccount}, 1u, 0,
true));
540 <<
iIdentifier <<
" Paths found, calling rippleCalc";
546 std::make_unique<PaymentSandbox>(&*cache->getLedger(),
tapNONE);
562 <<
iIdentifier <<
" Trying with an extra path element";
564 ps.push_back(fullLiquidityPath);
566 std::make_unique<PaymentSandbox>(&*cache->getLedger(),
tapNONE);
594 rc.actualAmountIn.setIssuer(sourceAccount);
595 jvEntry[jss::source_amount] =
600 jvEntry[jss::destination_amount] =
622 int const size = sourceCurrencies.size();
624 {boost::algorithm::clamp(size * size + 34, 50, 400),
"path update"});
633 <<
iIdentifier <<
" update " << (fast ?
"fast" :
"normal");
647 auto& destCurrencies =
650 for (
auto const& c : usCurrencies)
654 newStatus[jss::source_account] =
656 newStatus[jss::destination_account] =
659 newStatus[jss::full_reply] = !fast;
662 newStatus[jss::id] =
jvId;
703 newStatus[jss::alternatives] = std::move(jvArray);
716 else if (!fast &&
full_reply_ == steady_clock::time_point{})
Json::Value doClose(Json::Value const &)
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
static std::string const & systemCurrencyCode()
bool to_currency(Currency ¤cy, std::string const &code)
Tries to convert a string to a Currency, returns true on success.
bool amountFromJsonNoThrow(STAmount &result, Json::Value const &jvSource)
std::map< Issue, STPathSet > mContext
std::unique_ptr< Pathfinder > const & getPathFinder(std::shared_ptr< RippleLineCache > const &, hash_map< Currency, std::unique_ptr< Pathfinder >> &, Currency const &, STAmount const &, int const)
@ arrayValue
array value (ordered list)
hash_set< Currency > accountDestCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
Json::Value getJson(JsonOptions) const override
boost::optional< AccountID > raDstAccount
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::chrono::steady_clock::time_point full_reply_
std::recursive_mutex mIndexLock
std::string to_string(ListDisposition disposition)
Resource::Consumer & consumer_
std::function< void(void)> fCompletion
virtual AccountIDCache const & accountIDCache() const =0
virtual LoadFeeTrack & getFeeTrack()=0
std::chrono::steady_clock::time_point quick_reply_
bool isLoadedLocal() const
std::string getFullText() const override
JSON (JavaScript Object Notation).
Value & append(const Value &value)
Append value to array at the end.
@ objectValue
object value (collection of name/value pairs).
PathRequest(Application &app, std::shared_ptr< InfoSub > const &subscriber, int id, PathRequests &, beast::Journal journal)
static unsigned const int max_paths_
Keylet account(AccountID const &id) noexcept
AccountID root.
std::set< Issue > sciSourceCurrencies
static constexpr int max_src_cur
Maximum number of source currencies allowed in a path find request.
virtual Config & config()=0
InfoSub::pointer getSubscriber()
AccountID const & xrpAccount()
Compute AccountID from public key.
UInt size() const
Number of values in array or object.
bool findPaths(std::shared_ptr< RippleLineCache > const &, int const, Json::Value &)
Finds and sets a PathSet in the JSON argument.
bool isXRP(AccountID const &c)
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
bool isValid(std::shared_ptr< RippleLineCache > const &crCache)
Json::Value rpcError(int iError, Json::Value jvResult)
std::string transHuman(TER code)
Currency const & getCurrency() const
AccountID const & getIssuer() const
std::pair< bool, Json::Value > doCreate(std::shared_ptr< RippleLineCache > const &, Json::Value const &)
bool native() const noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void reportFast(std::chrono::milliseconds ms)
std::recursive_mutex mLock
const std::chrono::steady_clock::time_point created_
Json::Value doUpdate(std::shared_ptr< RippleLineCache > const &, bool fast)
std::weak_ptr< InfoSub > wpSubscriber
Json::Value doStatus(Json::Value const &)
Issue const & issue() const
static constexpr int max_auto_src_cur
Maximum number of auto source currencies in a path find request.
An endpoint that consumes resources.
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)
void reportFull(std::chrono::milliseconds ms)
boost::optional< STAmount > saSendMax
hash_set< Currency > accountSourceCurrencies(AccountID const &account, std::shared_ptr< RippleLineCache > const &lrCache, bool includeXRP)
static const int cMaxOffset
Disposition charge(Charge const &fee)
Apply a load charge to the consumer.
bool needsUpdate(bool newOnly, LedgerIndex index)
int parseJson(Json::Value const &)
static const std::uint64_t cMaxValue
boost::optional< AccountID > raSrcAccount
std::string toBase58(AccountID const &) const
Return ripple::toBase58 for the AccountID.
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.