rippled
Loading...
Searching...
No Matches
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 <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/main/Application.h>
22#include <xrpld/app/paths/PathRequests.h>
23#include <xrpld/rpc/Context.h>
24
25#include <xrpl/protocol/ErrorCodes.h>
26#include <xrpl/protocol/RPCErr.h>
27#include <xrpl/protocol/jss.h>
28#include <xrpl/resource/Fees.h>
29
30namespace ripple {
31
34{
35 if (context.app.config().PATH_SEARCH_MAX == 0)
37
38 auto lpLedger = context.ledgerMaster.getClosedLedger();
39
40 if (!context.params.isMember(jss::subcommand) ||
41 !context.params[jss::subcommand].isString())
42 {
44 }
45
46 if (!context.infoSub)
47 return rpcError(rpcNO_EVENTS);
48
49 context.infoSub->setApiVersion(context.apiVersion);
50
51 auto sSubCommand = context.params[jss::subcommand].asString();
52
53 if (sSubCommand == "create")
54 {
56 context.infoSub->clearRequest();
57 return context.app.getPathRequests().makePathRequest(
58 context.infoSub, lpLedger, context.params);
59 }
60
61 if (sSubCommand == "close")
62 {
63 InfoSubRequest::pointer request = context.infoSub->getRequest();
64
65 if (!request)
67
68 context.infoSub->clearRequest();
69 return request->doClose();
70 }
71
72 if (sSubCommand == "status")
73 {
74 InfoSubRequest::pointer request = context.infoSub->getRequest();
75
76 if (!request)
78
79 return request->doStatus(context.params);
80 }
81
83}
84
85} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
bool isString() const
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
virtual Config & config()=0
virtual PathRequests & getPathRequests()=0
int PATH_SEARCH_MAX
Definition Config.h:198
std::shared_ptr< InfoSubRequest > const & getRequest()
Definition InfoSub.cpp:133
void setApiVersion(unsigned int apiVersion)
Definition InfoSub.cpp:139
void clearRequest()
Definition InfoSub.cpp:121
std::shared_ptr< Ledger const > getClosedLedger()
Json::Value makePathRequest(std::shared_ptr< InfoSub > const &subscriber, std::shared_ptr< ReadView const > const &ledger, Json::Value const &request)
Charge const feeHeavyBurdenRPC
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ rpcNO_EVENTS
Definition ErrorCodes.h:54
@ rpcNOT_SUPPORTED
Definition ErrorCodes.h:132
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:84
@ rpcNO_PF_REQUEST
Definition ErrorCodes.h:86
Json::Value rpcError(int iError)
Definition RPCErr.cpp:31
Json::Value doPathFind(RPC::JsonContext &)
Definition PathFind.cpp:33
unsigned int apiVersion
Definition Context.h:49
Resource::Charge & loadType
Definition Context.h:42
Application & app
Definition Context.h:41
InfoSub::pointer infoSub
Definition Context.h:48
LedgerMaster & ledgerMaster
Definition Context.h:44