xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
jtx
impl
paths.cpp
1
#include <test/jtx/paths.h>
2
3
#include <test/jtx/Env.h>
4
#include <test/jtx/JTx.h>
5
#include <test/jtx/amount.h>
6
7
#include <xrpld/rpc/detail/AssetCache.h>
8
#include <xrpld/rpc/detail/Pathfinder.h>
9
10
#include <xrpl/basics/base_uint.h>
11
#include <xrpl/json/json_value.h>
12
#include <xrpl/protocol/AccountID.h>
13
#include <xrpl/protocol/Issue.h>
14
#include <xrpl/protocol/MPTIssue.h>
15
#include <xrpl/protocol/SField.h>
16
#include <xrpl/protocol/STAmount.h>
17
#include <xrpl/protocol/UintTypes.h>
18
#include <xrpl/protocol/jss.h>
19
20
#include <
memory
>
21
#include <
optional
>
22
23
namespace
xrpl::test::jtx
{
24
25
void
26
Paths::operator()
(
Env
& env,
JTx
& jt)
const
27
{
28
auto
& jv = jt.
jv
;
29
auto
const
from = env.
lookup
(jv[jss::Account].asString());
30
auto
const
to = env.
lookup
(jv[jss::Destination].asString());
31
auto
const
amount =
amountFromJson
(sfAmount, jv[jss::Amount]);
32
33
std::optional<UInt256>
domain;
34
if
(jv.isMember(sfDomainID.jsonName))
35
{
36
if
(!jv[sfDomainID.jsonName].isString())
37
return
;
38
UInt256
num;
39
auto
const
s = jv[sfDomainID.jsonName].asString();
40
if
(num.
parseHex
(s))
41
domain = num;
42
}
43
44
Pathfinder
pf(
45
std::make_shared<AssetCache>
(env.
current
(), env.
app
().
getJournal
(
"AssetCache"
)),
46
from,
47
to,
48
in_
,
49
in_
.getIssuer(),
50
amount,
51
std::nullopt,
52
domain,
53
env.
app
());
54
if
(!pf.
findPaths
(
depth_
))
55
return
;
56
57
STPath
fp;
58
pf.
computePathRanks
(
limit_
);
59
auto
const
found = pf.
getBestPaths
(
limit_
, fp, {},
in_
.getIssuer());
60
61
// VFALCO TODO API to allow caller to examine the STPathSet
62
// VFALCO isDefault should be renamed to empty()
63
if
(!found.isDefault())
64
jv[jss::Paths] = found.
getJson
(
JsonOptions::Values::None
);
65
}
66
67
//------------------------------------------------------------------------------
68
69
Path::Path
(
STPath
const
& p)
70
{
71
jv_
= p.
getJson
(
JsonOptions::Values::None
);
72
}
73
74
json::Value
&
75
Path::create
()
76
{
77
return
jv_
.append(
json::ValueType::Object
);
78
}
79
80
void
81
Path::appendOne
(
Account
const
& account)
82
{
83
appendOne
(account.id());
84
}
85
86
void
87
Path::appendOne
(
AccountID
const
& account)
88
{
89
auto
& jv =
create
();
90
jv[
"account"
] =
toBase58
(account);
91
}
92
93
void
94
Path::appendOne
(
IOU
const
& iou)
95
{
96
auto
& jv =
create
();
97
jv[
"currency"
] =
to_string
(iou.
currency
);
98
jv[
"account"
] =
toBase58
(iou.
account
);
99
}
100
101
void
102
Path::appendOne
(
BookSpec
const
& book)
103
{
104
auto
& jv =
create
();
105
book.asset.visit(
106
[&](
Issue
const
& issue) {
107
jv[
"currency"
] =
to_string
(issue.
currency
);
108
jv[
"issuer"
] =
toBase58
(issue.
account
);
109
},
110
[&](
MPTIssue
const
& issue) { jv[
"mpt_issuance_id"
] =
to_string
(issue.getMptID()); });
111
}
112
113
void
114
Path::operator()
(
Env
& env,
JTx
& jt)
const
115
{
116
jt.
jv
[
"Paths"
].
append
(
jv_
);
117
}
118
119
}
// namespace xrpl::test::jtx
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::append
Value & append(Value const &value)
Append value to array at the end.
Definition
json_value.cpp:997
xrpl::BaseUInt::parseHex
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition
base_uint.h:525
xrpl::Issue
A currency issued by an account.
Definition
Issue.h:18
xrpl::Issue::currency
Currency currency
Definition
Issue.h:20
xrpl::Issue::account
AccountID account
Definition
Issue.h:21
xrpl::MPTIssue
Definition
MPTIssue.h:23
xrpl::Pathfinder
Calculates payment paths.
Definition
Pathfinder.h:37
xrpl::Pathfinder::getBestPaths
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
Definition
Pathfinder.cpp:604
xrpl::Pathfinder::findPaths
bool findPaths(int searchLevel, std::function< bool(void)> const &continueCallback={})
Definition
Pathfinder.cpp:241
xrpl::Pathfinder::computePathRanks
void computePathRanks(int maxPaths, std::function< bool(void)> const &continueCallback={})
Compute the rankings of the paths.
Definition
Pathfinder.cpp:451
xrpl::STPathSet::getJson
json::Value getJson(JsonOptions) const override
Definition
STPathSet.cpp:246
xrpl::STPath
Definition
STPathSet.h:134
xrpl::STPath::getJson
json::Value getJson(JsonOptions) const
Definition
STPathSet.cpp:212
xrpl::ServiceRegistry::getJournal
virtual beast::Journal getJournal(std::string const &name)=0
xrpl::test::jtx::Account
Immutable cryptographic account descriptor.
Definition
jtx/Account.h:21
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
xrpl::test::jtx::Env::app
Application & app()
Definition
Env.h:300
xrpl::test::jtx::Env::lookup
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
Definition
Env.cpp:180
xrpl::test::jtx::Env::current
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition
Env.h:377
xrpl::test::jtx::IOU
Converts to IOU Issue or STAmount.
Definition
src/test/jtx/amount.h:404
xrpl::test::jtx::IOU::account
Account account
Definition
src/test/jtx/amount.h:406
xrpl::test::jtx::IOU::currency
xrpl::Currency currency
Definition
src/test/jtx/amount.h:407
xrpl::test::jtx::Path::jv_
json::Value jv_
Definition
paths.h:49
xrpl::test::jtx::Path::operator()
void operator()(Env &, JTx &jt) const
Definition
paths.cpp:114
xrpl::test::jtx::Path::Path
Path()
xrpl::test::jtx::Path::create
json::Value & create()
Definition
paths.cpp:75
xrpl::test::jtx::Path::appendOne
void appendOne(Account const &account)
Definition
paths.cpp:81
xrpl::test::jtx::Paths::in_
Asset in_
Definition
paths.h:25
xrpl::test::jtx::Paths::depth_
int depth_
Definition
paths.h:26
xrpl::test::jtx::Paths::limit_
unsigned int limit_
Definition
paths.h:27
xrpl::test::jtx::Paths::operator()
void operator()(Env &, JTx &jt) const
Definition
paths.cpp:26
std::make_shared
T make_shared(T... args)
memory
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition
AccountID.cpp:95
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::amountFromJson
STAmount amountFromJson(SField const &name, json::Value const &v)
Definition
STAmount.cpp:917
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
optional
xrpl::JsonOptions::Values::None
@ None
Definition
STBase.h:27
xrpl::test::jtx::BookSpec
Definition
src/test/jtx/amount.h:245
xrpl::test::jtx::JTx
Execution context for applying a JSON transaction.
Definition
JTx.h:27
xrpl::test::jtx::JTx::jv
json::Value jv
Definition
JTx.h:28
Generated by
1.17.0