rippled
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 <ripple/app/paths/Pathfinder.h>
21 #include <ripple/protocol/jss.h>
22 #include <test/jtx/paths.h>
23 
24 namespace ripple {
25 namespace test {
26 namespace jtx {
27 
28 void
29 paths::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>(env.current()),
37  from,
38  to,
39  in_.currency,
40  in_.account,
41  amount,
42  boost::none,
43  env.app());
44  if (!pf.findPaths(depth_))
45  return;
46 
47  STPath fp;
49  auto const found = pf.getBestPaths(limit_, fp, {}, in_.account);
50 
51  // VFALCO TODO API to allow caller to examine the STPathSet
52  // VFALCO isDefault should be renamed to empty()
53  if (!found.isDefault())
54  jv[jss::Paths] = found.getJson(JsonOptions::none);
55 }
56 
57 //------------------------------------------------------------------------------
58 
61 {
63 }
64 
65 void
66 path::append_one(Account const& account)
67 {
68  auto& jv = create();
69  jv["account"] = toBase58(account.id());
70 }
71 
72 void
73 path::append_one(IOU const& iou)
74 {
75  auto& jv = create();
76  jv["currency"] = to_string(iou.issue().currency);
77  jv["account"] = toBase58(iou.issue().account);
78 }
79 
80 void
82 {
83  auto& jv = create();
84  jv["currency"] = to_string(book.currency);
85  jv["issuer"] = toBase58(book.account);
86 }
87 
88 void
89 path::operator()(Env& env, JTx& jt) const
90 {
91  jt.jv["Paths"].append(jv_);
92 }
93 
94 } // namespace jtx
95 } // namespace test
96 } // namespace ripple
ripple::Pathfinder
Calculates payment paths.
Definition: Pathfinder.h:37
ripple::test::jtx::BookSpec::currency
ripple::Currency currency
Definition: amount.h:158
ripple::test::jtx::path::jv_
Json::Value jv_
Definition: paths.h:58
ripple::Issue::currency
Currency currency
Definition: Issue.h:37
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:29
ripple::test::jtx::path::append_one
void append_one(Account const &account)
Definition: paths.cpp:66
ripple::Pathfinder::findPaths
bool findPaths(int searchLevel)
Definition: Pathfinder.cpp:187
ripple::test::jtx::IOU::issue
Issue issue() const
Definition: amount.h:303
ripple::test::jtx::Env::app
Application & app()
Definition: Env.h:240
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:42
ripple::sfAmount
const SF_Amount sfAmount(access, STI_AMOUNT, 1, "Amount")
Definition: SField.h:441
ripple::test::jtx::paths::limit_
unsigned int limit_
Definition: paths.h:37
ripple::test::jtx::BookSpec
Definition: amount.h:155
ripple::test::jtx::paths::depth_
int depth_
Definition: paths.h:36
ripple::Pathfinder::getBestPaths
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer)
Definition: Pathfinder.cpp:566
ripple::test::jtx::paths::operator()
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:29
ripple::test::jtx::paths::in_
Issue in_
Definition: paths.h:35
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:882
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
ripple::Pathfinder::computePathRanks
void computePathRanks(int maxPaths)
Compute the rankings of the paths.
Definition: Pathfinder.cpp:411
ripple::JsonOptions::none
@ none
ripple::test::jtx::JTx
Execution context for applying a JSON transaction.
Definition: JTx.h:41
ripple::test::jtx::JTx::jv
Json::Value jv
Definition: JTx.h:43
ripple::test::jtx::Env::lookup
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
Definition: Env.cpp:156
ripple::amountFromJson
STAmount amountFromJson(SField const &name, Json::Value const &v)
Definition: STAmount.cpp:826
ripple::test::jtx::BookSpec::account
AccountID account
Definition: amount.h:157
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::jtx::IOU
Converts to IOU Issue or STAmount.
Definition: amount.h:291
ripple::STPathSet::getJson
Json::Value getJson(JsonOptions) const override
Definition: STPathSet.cpp:177
ripple::test::jtx::path::create
Json::Value & create()
Definition: paths.cpp:60
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
ripple::STPath
Definition: STPathSet.h:212
ripple::test::jtx::Env::current
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition: Env.h:299
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:115
ripple::Issue::account
AccountID account
Definition: Issue.h:38
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::test::jtx::path::operator()
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:89