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 ripple {
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(
34 env.current(), env.app().journal("RippleLineCache")),
35 from,
36 to,
39 amount,
41 domain,
42 env.app());
43 if (!pf.findPaths(depth_))
44 return;
45
46 STPath fp;
48 auto const found = pf.getBestPaths(limit_, fp, {}, in_.account);
49
50 // VFALCO TODO API to allow caller to examine the STPathSet
51 // VFALCO isDefault should be renamed to empty()
52 if (!found.isDefault())
53 jv[jss::Paths] = found.getJson(JsonOptions::none);
54}
55
56//------------------------------------------------------------------------------
57
63
64void
66{
67 append_one(account.id());
68}
69
70void
72{
73 auto& jv = create();
74 jv["account"] = toBase58(account);
75}
76
77void
79{
80 auto& jv = create();
81 jv["currency"] = to_string(iou.issue().currency);
82 jv["account"] = toBase58(iou.issue().account);
83}
84
85void
87{
88 auto& jv = create();
89 jv["currency"] = to_string(book.currency);
90 jv["issuer"] = toBase58(book.account);
91}
92
93void
94path::operator()(Env& env, JTx& jt) const
95{
96 jt.jv["Paths"].append(jv_);
97}
98
99} // namespace jtx
100} // namespace test
101} // namespace ripple
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
AccountID account
Definition Issue.h:17
Currency currency
Definition Issue.h:16
Calculates payment paths.
Definition Pathfinder.h:21
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:484
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:102
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:312
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
Definition Env.cpp:144
Application & app()
Definition Env.h:242
Converts to IOU Issue or STAmount.
Set the domain on a JTx.
Definition domain.h:11
Json::Value jv_
Definition paths.h:41
Json::Value & create()
Definition paths.cpp:59
void operator()(Env &, JTx &jt) const
Definition paths.cpp:94
void append_one(Account const &account)
Definition paths.cpp:65
unsigned int limit_
Definition paths.h:20
void operator()(Env &, JTx &jt) const
Definition paths.cpp:14
T is_same_v
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
STAmount amountFromJson(SField const &name, Json::Value const &v)
Definition STAmount.cpp:987
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
Execution context for applying a JSON transaction.
Definition JTx.h:26
Json::Value jv
Definition JTx.h:27