mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-23 04:25:51 +00:00
More feature RPC support.
This commit is contained in:
@@ -40,6 +40,19 @@ FeatureState* FeatureTable::getCreateFeature(const uint256& featureHash, bool cr
|
|||||||
return &(it->second);
|
return &(it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 FeatureTable::getFeature(const std::string& name)
|
||||||
|
{
|
||||||
|
if (!name.empty())
|
||||||
|
{
|
||||||
|
BOOST_FOREACH(featureMap_t::value_type& it, mFeatureMap)
|
||||||
|
{
|
||||||
|
if (name == it.second.mFriendlyName)
|
||||||
|
return it.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uint256();
|
||||||
|
}
|
||||||
|
|
||||||
FeatureState* FeatureTable::addKnownFeature(const char *featureID, const char *friendlyName, bool veto)
|
FeatureState* FeatureTable::addKnownFeature(const char *featureID, const char *friendlyName, bool veto)
|
||||||
{
|
{
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
@@ -317,50 +330,60 @@ Json::Value FeatureTable::getJson(int)
|
|||||||
boost::mutex::scoped_lock sl(mMutex);
|
boost::mutex::scoped_lock sl(mMutex);
|
||||||
BOOST_FOREACH(const featureIt_t& it, mFeatureMap)
|
BOOST_FOREACH(const featureIt_t& it, mFeatureMap)
|
||||||
{
|
{
|
||||||
Json::Value& v(ret[it.first.GetHex()] = Json::objectValue);
|
setJson(ret[it.first.GetHex()] = Json::objectValue, it.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (!it.second.mFriendlyName.empty())
|
void FeatureTable::setJson(Json::Value& v, const FeatureState& fs)
|
||||||
v["name"] = it.second.mFriendlyName;
|
{
|
||||||
|
if (!fs.mFriendlyName.empty())
|
||||||
|
v["name"] = fs.mFriendlyName;
|
||||||
|
|
||||||
v["supported"] = it.second.mSupported;
|
v["supported"] = fs.mSupported;
|
||||||
v["vetoed"] = it.second.mVetoed;
|
v["vetoed"] = fs.mVetoed;
|
||||||
|
|
||||||
if (it.second.mEnabled)
|
if (fs.mEnabled)
|
||||||
v["enabled"] = true;
|
v["enabled"] = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
v["enabled"] = false;
|
v["enabled"] = false;
|
||||||
if (mLastReport != 0)
|
if (mLastReport != 0)
|
||||||
{
|
{
|
||||||
if (it.second.mLastMajority == 0)
|
if (fs.mLastMajority == 0)
|
||||||
{
|
{
|
||||||
v["majority"] = false;
|
v["majority"] = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (it.second.mFirstMajority != 0)
|
if (fs.mFirstMajority != 0)
|
||||||
{
|
{
|
||||||
if (it.second.mFirstMajority == mFirstReport)
|
if (fs.mFirstMajority == mFirstReport)
|
||||||
v["majority_start"] = "start";
|
v["majority_start"] = "start";
|
||||||
else
|
else
|
||||||
v["majority_start"] = it.second.mFirstMajority;
|
v["majority_start"] = fs.mFirstMajority;
|
||||||
}
|
}
|
||||||
if (it.second.mLastMajority != 0)
|
if (fs.mLastMajority != 0)
|
||||||
{
|
{
|
||||||
if (it.second.mLastMajority == mLastReport)
|
if (fs.mLastMajority == mLastReport)
|
||||||
v["majority_until"] = "now";
|
v["majority_until"] = "now";
|
||||||
else
|
else
|
||||||
v["majority_until"] = it.second.mLastMajority;
|
v["majority_until"] = fs.mLastMajority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it.second.mVetoed)
|
if (fs.mVetoed)
|
||||||
v["veto"] = true;
|
v["veto"] = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
Json::Value FeatureTable::getJson(const uint256& feature)
|
||||||
|
{
|
||||||
|
Json::Value ret = Json::objectValue;
|
||||||
|
boost::mutex::scoped_lock sl(mMutex);
|
||||||
|
setJson(ret[feature.GetHex()] = Json::objectValue, *getCreateFeature(feature, true));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ protected:
|
|||||||
|
|
||||||
FeatureState* getCreateFeature(const uint256& feature, bool create);
|
FeatureState* getCreateFeature(const uint256& feature, bool create);
|
||||||
bool shouldEnable (uint32 closeTime, const FeatureState& fs);
|
bool shouldEnable (uint32 closeTime, const FeatureState& fs);
|
||||||
|
void setJson(Json::Value& v, const FeatureState&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -73,6 +74,7 @@ public:
|
|||||||
void addInitialFeatures();
|
void addInitialFeatures();
|
||||||
|
|
||||||
FeatureState* addKnownFeature(const char *featureID, const char *friendlyName, bool veto);
|
FeatureState* addKnownFeature(const char *featureID, const char *friendlyName, bool veto);
|
||||||
|
uint256 getFeature(const std::string& name);
|
||||||
|
|
||||||
bool vetoFeature(const uint256& feature);
|
bool vetoFeature(const uint256& feature);
|
||||||
bool unVetoFeature(const uint256& feature);
|
bool unVetoFeature(const uint256& feature);
|
||||||
@@ -94,6 +96,7 @@ public:
|
|||||||
void reportValidations(const FeatureSet&);
|
void reportValidations(const FeatureSet&);
|
||||||
|
|
||||||
Json::Value getJson(int);
|
Json::Value getJson(int);
|
||||||
|
Json::Value getJson(const uint256&);
|
||||||
|
|
||||||
void doValidation(Ledger::ref lastClosedLedger, STObject& baseValidation);
|
void doValidation(Ledger::ref lastClosedLedger, STObject& baseValidation);
|
||||||
void doVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition);
|
void doVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ Json::Value rpcError(int iError, Json::Value jvResult)
|
|||||||
{ rpcACT_MALFORMED, "actMalformed", "Account malformed." },
|
{ rpcACT_MALFORMED, "actMalformed", "Account malformed." },
|
||||||
{ rpcACT_NOT_FOUND, "actNotFound", "Account not found." },
|
{ rpcACT_NOT_FOUND, "actNotFound", "Account not found." },
|
||||||
{ rpcBAD_BLOB, "badBlob", "Blob must be a non-empty hex string." },
|
{ rpcBAD_BLOB, "badBlob", "Blob must be a non-empty hex string." },
|
||||||
|
{ rpcBAD_FEATURE, "badFeature", "Feature unknown or invalid." },
|
||||||
{ rpcBAD_ISSUER, "badIssuer", "Issuer account malformed." },
|
{ rpcBAD_ISSUER, "badIssuer", "Issuer account malformed." },
|
||||||
{ rpcBAD_MARKET, "badMarket", "No such market." },
|
{ rpcBAD_MARKET, "badMarket", "No such market." },
|
||||||
{ rpcBAD_SECRET, "badSecret", "Secret does not match account." },
|
{ rpcBAD_SECRET, "badSecret", "Secret does not match account." },
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ enum {
|
|||||||
rpcACT_MALFORMED,
|
rpcACT_MALFORMED,
|
||||||
rpcQUALITY_MALFORMED,
|
rpcQUALITY_MALFORMED,
|
||||||
rpcBAD_BLOB,
|
rpcBAD_BLOB,
|
||||||
|
rpcBAD_FEATURE,
|
||||||
rpcBAD_ISSUER,
|
rpcBAD_ISSUER,
|
||||||
rpcBAD_MARKET,
|
rpcBAD_MARKET,
|
||||||
rpcBAD_SECRET,
|
rpcBAD_SECRET,
|
||||||
|
|||||||
@@ -2263,11 +2263,17 @@ Json::Value RPCHandler::doFeature(Json::Value jvRequest, int& cost, ScopedLock&
|
|||||||
return jvReply;
|
return jvReply;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!jvRequest.isMember("vote"))
|
uint256 uFeature = theApp->getFeatureTable().getFeature(jvRequest["feature"].asString());
|
||||||
|
if (uFeature.isZero())
|
||||||
{
|
{
|
||||||
// WRITEME
|
uFeature.SetHex(jvRequest["feature"].asString());
|
||||||
|
if (uFeature.isZero())
|
||||||
|
return rpcError(rpcBAD_FEATURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!jvRequest.isMember("vote"))
|
||||||
|
return theApp->getFeatureTable().getJson(uFeature);
|
||||||
|
|
||||||
// WRITEME
|
// WRITEME
|
||||||
return rpcError(rpcNOT_SUPPORTED);
|
return rpcError(rpcNOT_SUPPORTED);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user