mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 07:25:51 +00:00
Some new PF API support.
This commit is contained in:
@@ -66,6 +66,21 @@ public:
|
||||
|
||||
mSubAccountInfo.insert(addr);
|
||||
}
|
||||
|
||||
void clearPFRequest()
|
||||
{
|
||||
mPFRequest.reset();
|
||||
}
|
||||
|
||||
void setPFRequest(const boost::shared_ptr<PFRequest>& req)
|
||||
{
|
||||
mPFRequest = req;
|
||||
}
|
||||
|
||||
const boost::shared_ptr<PFRequest>& getPFRequest()
|
||||
{
|
||||
return mPFRequest;
|
||||
}
|
||||
};
|
||||
|
||||
class NetworkOPs
|
||||
|
||||
@@ -1,21 +1,93 @@
|
||||
#include "PFRequest.h"
|
||||
|
||||
#include "NetworkOPs.h"
|
||||
#include "RPCErr.h"
|
||||
|
||||
PFRequest::PFRequest(const boost::shared_ptr<InfoSub>& subscriber, Json::Value request) :
|
||||
boost::recursive_mutex PFRequest::sLock;
|
||||
std::set<PFRequest::wptr> PFRequest::sRequests;
|
||||
|
||||
PFRequest::PFRequest(const boost::shared_ptr<InfoSub>& subscriber) :
|
||||
wpSubscriber(subscriber), jvStatus(Json::objectValue), bValid(false)
|
||||
{
|
||||
if (parseJson(request) == PFR_PJ_COMPLETE)
|
||||
bValid = true;
|
||||
;
|
||||
}
|
||||
|
||||
bool PFRequest::isValid()
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
bValid = raSrcAccount.isSet() && raDstAccount.isSet() && saDstAmount.isPositive();
|
||||
return bValid;
|
||||
}
|
||||
|
||||
int PFRequest::parseJson(const Json::Value& jvParams)
|
||||
Json::Value PFRequest::doCreate(const Json::Value& value)
|
||||
{
|
||||
return 0;
|
||||
Json::Value status;
|
||||
bool mValid;
|
||||
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
parseJson(value, true);
|
||||
status = jvStatus;
|
||||
mValid = isValid();
|
||||
}
|
||||
|
||||
if (mValid)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(sLock);
|
||||
sRequests.insert(shared_from_this());
|
||||
}
|
||||
|
||||
return jvStatus;
|
||||
}
|
||||
|
||||
int PFRequest::parseJson(const Json::Value& jvParams, bool complete)
|
||||
{
|
||||
int ret = PFR_PJ_NOCHANGE;
|
||||
|
||||
if (jvParams.isMember("source_account"))
|
||||
{
|
||||
}
|
||||
else if (complete)
|
||||
{
|
||||
jvStatus = rpcSRC_ACT_MISSING;
|
||||
return PFR_PJ_INVALID;
|
||||
}
|
||||
|
||||
if (jvParams.isMember("destination_account"))
|
||||
{
|
||||
}
|
||||
else if (complete)
|
||||
{
|
||||
jvStatus = rpcDST_ACT_MISSING;
|
||||
return PFR_PJ_INVALID;
|
||||
}
|
||||
|
||||
if (jvParams.isMember("destination_amount"))
|
||||
{
|
||||
}
|
||||
else if (complete)
|
||||
{
|
||||
}
|
||||
|
||||
if (jvParams.isMember("source_currencies"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Json::Value PFRequest::doClose(const Json::Value&)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
return jvStatus;
|
||||
}
|
||||
|
||||
Json::Value PFRequest::doStatus(const Json::Value&)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
return jvStatus;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
@@ -21,13 +22,12 @@ class Ledger;
|
||||
class InfoSub;
|
||||
class STAmount;
|
||||
|
||||
// Return values from parseJson
|
||||
#define PFR_PJ_COMPLETE 0
|
||||
#define PFR_PJ_NOCHANGE 1
|
||||
#define PFR_PJ_CHANGE 2
|
||||
#define PFR_PJ_INVALID 3
|
||||
// Return values from parseJson <0 = invalid, >0 = valid
|
||||
#define PFR_PJ_INVALID -1
|
||||
#define PFR_PJ_NOCHANGE 0
|
||||
#define PFR_PJ_CHANGE 1
|
||||
|
||||
class PFRequest
|
||||
class PFRequest : public boost::enable_shared_from_this<PFRequest>
|
||||
{
|
||||
public:
|
||||
typedef boost::weak_ptr<PFRequest> wptr;
|
||||
@@ -54,11 +54,12 @@ protected:
|
||||
static std::set<wptr> sRequests;
|
||||
static boost::recursive_mutex sLock;
|
||||
|
||||
int parseJson(const Json::Value&);
|
||||
void setValid();
|
||||
int parseJson(const Json::Value&, bool complete);
|
||||
|
||||
public:
|
||||
|
||||
PFRequest(const boost::shared_ptr<InfoSub>& subscriber, Json::Value request);
|
||||
PFRequest(const boost::shared_ptr<InfoSub>& subscriber);
|
||||
|
||||
bool isValid();
|
||||
Json::Value getStatus();
|
||||
@@ -67,9 +68,12 @@ public:
|
||||
Json::Value doClose(const Json::Value&);
|
||||
Json::Value doStatus(const Json::Value&);
|
||||
|
||||
void doUpdate();
|
||||
void doUpdate(); // do an update
|
||||
void trigger(); // schedule an update
|
||||
|
||||
static void updateAll(const boost::shared_ptr<Ledger> &);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -54,6 +54,7 @@ Json::Value rpcError(int iError, Json::Value jvResult)
|
||||
{ rpcNO_NETWORK, "noNetwork", "Network not available." },
|
||||
{ rpcNO_PATH, "noPath", "Unable to find a ripple path." },
|
||||
{ rpcNO_PERMISSION, "noPermission", "You don't have permission for this command." },
|
||||
{ rpcNO_PF_REQUEST, "noPathRequest", "No pathfinding request in progress." },
|
||||
{ rpcNOT_STANDALONE, "notStandAlone", "Operation valid in debug mode only." },
|
||||
{ rpcNOT_SUPPORTED, "notSupported", "Operation not supported." },
|
||||
{ rpcPASSWD_CHANGED, "passwdChanged", "Wrong key, password changed." },
|
||||
|
||||
@@ -42,6 +42,7 @@ enum {
|
||||
// Malformed command
|
||||
rpcINVALID_PARAMS,
|
||||
rpcUNKNOWN_COMMAND,
|
||||
rpcNO_PF_REQUEST,
|
||||
|
||||
// Bad parameter
|
||||
rpcACT_BITCOIN,
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "NicknameState.h"
|
||||
#include "InstanceCounter.h"
|
||||
#include "Offer.h"
|
||||
#include "PFRequest.h"
|
||||
|
||||
SETUP_LOG();
|
||||
|
||||
@@ -1174,17 +1175,29 @@ Json::Value RPCHandler::doPathFind(Json::Value jvRequest, int& cost, ScopedLock&
|
||||
|
||||
if (sSubCommand == "create")
|
||||
{
|
||||
// WRITEME
|
||||
mInfoSub->clearPFRequest();
|
||||
PFRequest::pointer request = boost::make_shared<PFRequest>(mInfoSub);
|
||||
Json::Value result = request->doCreate(jvRequest);
|
||||
if (request->isValid())
|
||||
mInfoSub->setPFRequest(request);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (sSubCommand == "close")
|
||||
{
|
||||
// WRITEME
|
||||
PFRequest::pointer request = mInfoSub->getPFRequest();
|
||||
if (!request)
|
||||
return rpcNO_PF_REQUEST;
|
||||
mInfoSub->clearPFRequest();
|
||||
return request->doClose(jvRequest);
|
||||
}
|
||||
|
||||
if (sSubCommand == "status")
|
||||
{
|
||||
// WRITEME
|
||||
PFRequest::pointer request = mInfoSub->getPFRequest();
|
||||
if (!request)
|
||||
return rpcNO_PF_REQUEST;
|
||||
return request->doStatus(jvRequest);
|
||||
}
|
||||
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
|
||||
Reference in New Issue
Block a user