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
26namespace ripple {
27namespace test {
28namespace jtx {
29
30void
31paths::operator()(Env& env, JTx& jt) const
32{
33 auto& jv = jt.jv;
34 auto const from = env.lookup(jv[jss::Account].asString());
35 auto const to = env.lookup(jv[jss::Destination].asString());
36 auto const amount = amountFromJson(sfAmount, jv[jss::Amount]);
37 Pathfinder pf(
38 std::make_shared<RippleLineCache>(
39 env.current(), env.app().journal("RippleLineCache")),
40 from,
41 to,
44 amount,
45 std::nullopt,
46 env.app());
47 if (!pf.findPaths(depth_))
48 return;
49
50 STPath fp;
52 auto const found = pf.getBestPaths(limit_, fp, {}, in_.account);
53
54 // VFALCO TODO API to allow caller to examine the STPathSet
55 // VFALCO isDefault should be renamed to empty()
56 if (!found.isDefault())
57 jv[jss::Paths] = found.getJson(JsonOptions::none);
58}
59
60//------------------------------------------------------------------------------
61
64{
66}
67
68void
70{
71 append_one(account.id());
72}
73
74void
76{
77 auto& jv = create();
78 jv["account"] = toBase58(account);
79}
80
81void
83{
84 auto& jv = create();
85 jv["currency"] = to_string(iou.issue().currency);
86 jv["account"] = toBase58(iou.issue().account);
87}
88
89void
91{
92 auto& jv = create();
93 jv["currency"] = to_string(book.currency);
94 jv["issuer"] = toBase58(book.account);
95}
96
97void
98path::operator()(Env& env, JTx& jt) const
99{
100 jt.jv["Paths"].append(jv_);
101}
102
103} // namespace jtx
104} // namespace test
105} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:897
virtual beast::Journal journal(std::string const &name)=0
AccountID account
Definition: Issue.h:39
Currency currency
Definition: Issue.h:38
Calculates payment paths.
Definition: Pathfinder.h:40
bool findPaths(int searchLevel, std::function< bool(void)> const &continueCallback={})
Definition: Pathfinder.cpp:198
void computePathRanks(int maxPaths, std::function< bool(void)> const &continueCallback={})
Compute the rankings of the paths.
Definition: Pathfinder.cpp:413
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
Definition: Pathfinder.cpp:569
Json::Value getJson(JsonOptions) const override
Definition: STPathSet.cpp:204
Immutable cryptographic account descriptor.
Definition: Account.h:39
A transaction testing environment.
Definition: Env.h:120
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition: Env.h:330
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
Definition: Env.cpp:158
Application & app()
Definition: Env.h:260
Converts to IOU Issue or STAmount.
Json::Value jv_
Definition: paths.h:60
Json::Value & create()
Definition: paths.cpp:63
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:98
void append_one(Account const &account)
Definition: paths.cpp:69
unsigned int limit_
Definition: paths.h:39
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:31
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:44
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:114
STAmount amountFromJson(SField const &name, Json::Value const &v)
Definition: STAmount.cpp:932
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