rippled
ripple
rpc
handlers
PathFind.cpp
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of rippled: https://github.com/ripple/rippled
4
Copyright (c) 2012-2014 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/ledger/LedgerMaster.h>
21
#include <ripple/app/main/Application.h>
22
#include <ripple/app/misc/NetworkOPs.h>
23
#include <ripple/app/paths/PathRequests.h>
24
#include <ripple/net/RPCErr.h>
25
#include <ripple/protocol/ErrorCodes.h>
26
#include <ripple/protocol/jss.h>
27
#include <ripple/resource/Fees.h>
28
#include <ripple/rpc/Context.h>
29
30
namespace
ripple
{
31
32
Json::Value
33
doPathFind
(
RPC::JsonContext
& context)
34
{
35
if
(context.
app
.
config
().
PATH_SEARCH_MAX
== 0)
36
return
rpcError
(
rpcNOT_SUPPORTED
);
37
38
auto
lpLedger = context.
ledgerMaster
.
getClosedLedger
();
39
40
if
(!context.
params
.
isMember
(jss::subcommand) ||
41
!context.
params
[jss::subcommand].
isString
())
42
{
43
return
rpcError
(
rpcINVALID_PARAMS
);
44
}
45
46
if
(!context.
infoSub
)
47
return
rpcError
(
rpcNO_EVENTS
);
48
49
auto
sSubCommand = context.
params
[jss::subcommand].
asString
();
50
51
if
(sSubCommand ==
"create"
)
52
{
53
context.
loadType
=
Resource::feeHighBurdenRPC
;
54
context.
infoSub
->
clearRequest
();
55
return
context.
app
.
getPathRequests
().
makePathRequest
(
56
context.
infoSub
, lpLedger, context.
params
);
57
}
58
59
if
(sSubCommand ==
"close"
)
60
{
61
InfoSubRequest::pointer
request = context.
infoSub
->
getRequest
();
62
63
if
(!request)
64
return
rpcError
(
rpcNO_PF_REQUEST
);
65
66
context.
infoSub
->
clearRequest
();
67
return
request->doClose();
68
}
69
70
if
(sSubCommand ==
"status"
)
71
{
72
InfoSubRequest::pointer
request = context.
infoSub
->
getRequest
();
73
74
if
(!request)
75
return
rpcError
(
rpcNO_PF_REQUEST
);
76
77
return
request->doStatus(context.
params
);
78
}
79
80
return
rpcError
(
rpcINVALID_PARAMS
);
81
}
82
83
}
// namespace ripple
ripple::RPC::Context::infoSub
InfoSub::pointer infoSub
Definition:
Context.h:49
ripple::InfoSub::getRequest
std::shared_ptr< InfoSubRequest > const & getRequest()
Definition:
InfoSub.cpp:134
ripple::RPC::JsonContext
Definition:
Context.h:53
ripple::rpcNOT_SUPPORTED
@ rpcNOT_SUPPORTED
Definition:
ErrorCodes.h:132
std::shared_ptr
STL class.
ripple::PathRequests::makePathRequest
Json::Value makePathRequest(std::shared_ptr< InfoSub > const &subscriber, std::shared_ptr< ReadView const > const &ledger, Json::Value const &request)
Definition:
PathRequests.cpp:245
ripple::doPathFind
Json::Value doPathFind(RPC::JsonContext &)
Definition:
PathFind.cpp:33
ripple::rpcINVALID_PARAMS
@ rpcINVALID_PARAMS
Definition:
ErrorCodes.h:84
Json::Value::isString
bool isString() const
Definition:
json_value.cpp:1009
ripple::rpcError
Json::Value rpcError(int iError)
Definition:
RPCErr.cpp:29
ripple::RPC::Context::loadType
Resource::Charge & loadType
Definition:
Context.h:43
ripple::RPC::Context::ledgerMaster
LedgerMaster & ledgerMaster
Definition:
Context.h:45
ripple::InfoSub::clearRequest
void clearRequest()
Definition:
InfoSub.cpp:122
ripple::Config::PATH_SEARCH_MAX
int PATH_SEARCH_MAX
Definition:
Config.h:203
ripple::Application::config
virtual Config & config()=0
ripple::RPC::Context::app
Application & app
Definition:
Context.h:42
ripple::rpcNO_EVENTS
@ rpcNO_EVENTS
Definition:
ErrorCodes.h:54
Json::Value::isMember
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition:
json_value.cpp:932
ripple::Application::getPathRequests
virtual PathRequests & getPathRequests()=0
ripple::LedgerMaster::getClosedLedger
std::shared_ptr< Ledger const > getClosedLedger()
Definition:
LedgerMaster.h:98
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::RPC::JsonContext::params
Json::Value params
Definition:
Context.h:64
ripple::Resource::feeHighBurdenRPC
const Charge feeHighBurdenRPC
ripple::rpcNO_PF_REQUEST
@ rpcNO_PF_REQUEST
Definition:
ErrorCodes.h:86
Json::Value
Represents a JSON value.
Definition:
json_value.h:145
Json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition:
json_value.cpp:469
Generated by
1.8.17