rippled
Loading...
Searching...
No Matches
paths.cpp
1#include <test/jtx/paths.h>
2
3#include <xrpld/app/paths/Pathfinder.h>
4
5#include <xrpl/protocol/jss.h>
6
7#include <optional>
8
9namespace xrpl {
10namespace test {
11namespace jtx {
12
13void
14paths::operator()(Env& env, JTx& jt) const
15{
16 auto& jv = jt.jv;
17 auto const from = env.lookup(jv[jss::Account].asString());
18 auto const to = env.lookup(jv[jss::Destination].asString());
19 auto const amount = amountFromJson(sfAmount, jv[jss::Amount]);
20
22 if (jv.isMember(sfDomainID.jsonName))
23 {
24 if (!jv[sfDomainID.jsonName].isString())
25 return;
26 uint256 num;
27 auto const s = jv[sfDomainID.jsonName].asString();
28 if (num.parseHex(s))
29 domain = num;
30 }
31
32 Pathfinder pf(
33 std::make_shared<RippleLineCache>(env.current(), env.app().journal("RippleLineCache")),
34 from,
35 to,
38 amount,
40 domain,
41 env.app());
42 if (!pf.findPaths(depth_))
43 return;
44
45 STPath fp;
47 auto const found = pf.getBestPaths(limit_, fp, {}, in_.account);
48
49 // VFALCO TODO API to allow caller to examine the STPathSet
50 // VFALCO isDefault should be renamed to empty()
51 if (!found.isDefault())
52 jv[jss::Paths] = found.getJson(JsonOptions::none);
53}
54
55//------------------------------------------------------------------------------
56
62
63void
65{
66 append_one(account.id());
67}
68
69void
71{
72 auto& jv = create();
73 jv["account"] = toBase58(account);
74}
75
76void
78{
79 auto& jv = create();
80 jv["currency"] = to_string(iou.issue().currency);
81 jv["account"] = toBase58(iou.issue().account);
82}
83
84void
86{
87 auto& jv = create();
88 jv["currency"] = to_string(book.currency);
89 jv["issuer"] = toBase58(book.account);
90}
91
92void
93path::operator()(Env& env, JTx& jt) const
94{
95 jt.jv["Paths"].append(jv_);
96}
97
98} // namespace jtx
99} // namespace test
100} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
Value & append(Value const &value)
Append value to array at the end.
virtual beast::Journal journal(std::string const &name)=0
Currency currency
Definition Issue.h:15
AccountID account
Definition Issue.h:16
Calculates payment paths.
Definition Pathfinder.h:20
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
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.
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:471
Immutable cryptographic account descriptor.
Definition Account.h:19
A transaction testing environment.
Definition Env.h:97
Application & app()
Definition Env.h:229
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
Definition Env.cpp:136
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:297
Converts to IOU Issue or STAmount.
Set the domain on a JTx.
Definition domain.h:11
Json::Value jv_
Definition paths.h:39
void operator()(Env &, JTx &jt) const
Definition paths.cpp:93
Json::Value & create()
Definition paths.cpp:58
void append_one(Account const &account)
Definition paths.cpp:64
void operator()(Env &, JTx &jt) const
Definition paths.cpp:14
unsigned int limit_
Definition paths.h:19
T is_same_v
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:26
auto const amount
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
STAmount amountFromJson(SField const &name, Json::Value const &v)
Definition STAmount.cpp:948
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:597
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:92
Execution context for applying a JSON transaction.
Definition JTx.h:25
Json::Value jv
Definition JTx.h:26