rippled
Loading...
Searching...
No Matches
paths.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx/paths.h>
21
22#include <xrpld/app/paths/Pathfinder.h>
23
24#include <xrpl/protocol/jss.h>
25
26#include <optional>
27
28namespace ripple {
29namespace test {
30namespace jtx {
31
32void
33paths::operator()(Env& env, JTx& jt) const
34{
35 auto& jv = jt.jv;
36 auto const from = env.lookup(jv[jss::Account].asString());
37 auto const to = env.lookup(jv[jss::Destination].asString());
38 auto const amount = amountFromJson(sfAmount, jv[jss::Amount]);
39
41 if (jv.isMember(sfDomainID.jsonName))
42 {
43 if (!jv[sfDomainID.jsonName].isString())
44 return;
45 uint256 num;
46 auto const s = jv[sfDomainID.jsonName].asString();
47 if (num.parseHex(s))
48 domain = num;
49 }
50
51 Pathfinder pf(
53 env.current(), env.app().journal("RippleLineCache")),
54 from,
55 to,
58 amount,
60 domain,
61 env.app());
62 if (!pf.findPaths(depth_))
63 return;
64
65 STPath fp;
67 auto const found = pf.getBestPaths(limit_, fp, {}, in_.account);
68
69 // VFALCO TODO API to allow caller to examine the STPathSet
70 // VFALCO isDefault should be renamed to empty()
71 if (!found.isDefault())
72 jv[jss::Paths] = found.getJson(JsonOptions::none);
73}
74
75//------------------------------------------------------------------------------
76
82
83void
85{
86 append_one(account.id());
87}
88
89void
91{
92 auto& jv = create();
93 jv["account"] = toBase58(account);
94}
95
96void
98{
99 auto& jv = create();
100 jv["currency"] = to_string(iou.issue().currency);
101 jv["account"] = toBase58(iou.issue().account);
102}
103
104void
106{
107 auto& jv = create();
108 jv["currency"] = to_string(book.currency);
109 jv["issuer"] = toBase58(book.account);
110}
111
112void
113path::operator()(Env& env, JTx& jt) const
114{
115 jt.jv["Paths"].append(jv_);
116}
117
118} // namespace jtx
119} // namespace test
120} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
Value & append(Value const &value)
Append value to array at the end.
virtual beast::Journal journal(std::string const &name)=0
AccountID account
Definition Issue.h:36
Currency currency
Definition Issue.h:35
Calculates payment paths.
Definition Pathfinder.h:40
bool findPaths(int searchLevel, std::function< bool(void)> const &continueCallback={})
void computePathRanks(int maxPaths, std::function< bool(void)> const &continueCallback={})
Compute the rankings of the paths.
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
Json::Value getJson(JsonOptions) const override
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:503
Immutable cryptographic account descriptor.
Definition Account.h:39
A transaction testing environment.
Definition Env.h:121
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:331
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
Definition Env.cpp:162
Application & app()
Definition Env.h:261
Converts to IOU Issue or STAmount.
Set the domain on a JTx.
Definition domain.h:30
Json::Value jv_
Definition paths.h:60
Json::Value & create()
Definition paths.cpp:78
void operator()(Env &, JTx &jt) const
Definition paths.cpp:113
void append_one(Account const &account)
Definition paths.cpp:84
unsigned int limit_
Definition paths.h:39
void operator()(Env &, JTx &jt) const
Definition paths.cpp:33
T is_same_v
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
STAmount amountFromJson(SField const &name, Json::Value const &v)
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
Execution context for applying a JSON transaction.
Definition JTx.h:45
Json::Value jv
Definition JTx.h:46