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#include <xrpld/app/paths/Pathfinder.h>
22#include <xrpl/protocol/jss.h>
23
24namespace ripple {
25namespace test {
26namespace jtx {
27
28void
29paths::operator()(Env& env, JTx& jt) const
30{
31 auto& jv = jt.jv;
32 auto const from = env.lookup(jv[jss::Account].asString());
33 auto const to = env.lookup(jv[jss::Destination].asString());
34 auto const amount = amountFromJson(sfAmount, jv[jss::Amount]);
35 Pathfinder pf(
36 std::make_shared<RippleLineCache>(
37 env.current(), env.app().journal("RippleLineCache")),
38 from,
39 to,
42 amount,
43 std::nullopt,
44 env.app());
45 if (!pf.findPaths(depth_))
46 return;
47
48 STPath fp;
50 auto const found = pf.getBestPaths(limit_, fp, {}, in_.account);
51
52 // VFALCO TODO API to allow caller to examine the STPathSet
53 // VFALCO isDefault should be renamed to empty()
54 if (!found.isDefault())
55 jv[jss::Paths] = found.getJson(JsonOptions::none);
56}
57
58//------------------------------------------------------------------------------
59
62{
64}
65
66void
68{
69 append_one(account.id());
70}
71
72void
74{
75 auto& jv = create();
76 jv["account"] = toBase58(account);
77}
78
79void
81{
82 auto& jv = create();
83 jv["currency"] = to_string(iou.issue().currency);
84 jv["account"] = toBase58(iou.issue().account);
85}
86
87void
89{
90 auto& jv = create();
91 jv["currency"] = to_string(book.currency);
92 jv["issuer"] = toBase58(book.account);
93}
94
95void
96path::operator()(Env& env, JTx& jt) const
97{
98 jt.jv["Paths"].append(jv_);
99}
100
101} // namespace jtx
102} // namespace test
103} // namespace ripple
Represents a JSON value.
Definition: json_value.h:147
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:891
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:39
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:194
Immutable cryptographic account descriptor.
Definition: Account.h:38
A transaction testing environment.
Definition: Env.h:117
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition: Env.h:325
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
Definition: Env.cpp:162
Application & app()
Definition: Env.h:255
Converts to IOU Issue or STAmount.
Json::Value jv_
Definition: paths.h:58
Json::Value & create()
Definition: paths.cpp:61
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:96
void append_one(Account const &account)
Definition: paths.cpp:67
unsigned int limit_
Definition: paths.h:37
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:29
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
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:106
STAmount amountFromJson(SField const &name, Json::Value const &v)
Definition: STAmount.cpp:900
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:629
Execution context for applying a JSON transaction.
Definition: JTx.h:44
Json::Value jv
Definition: JTx.h:45