More feature RPC support.

This commit is contained in:
JoelKatz
2013-05-31 16:22:38 -07:00
parent 349deba218
commit 6e220cc97e
5 changed files with 68 additions and 34 deletions

View File

@@ -40,6 +40,19 @@ FeatureState* FeatureTable::getCreateFeature(const uint256& featureHash, bool cr
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)
{
uint256 hash;
@@ -317,50 +330,60 @@ Json::Value FeatureTable::getJson(int)
boost::mutex::scoped_lock sl(mMutex);
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())
v["name"] = it.second.mFriendlyName;
void FeatureTable::setJson(Json::Value& v, const FeatureState& fs)
{
if (!fs.mFriendlyName.empty())
v["name"] = fs.mFriendlyName;
v["supported"] = it.second.mSupported;
v["vetoed"] = it.second.mVetoed;
v["supported"] = fs.mSupported;
v["vetoed"] = fs.mVetoed;
if (it.second.mEnabled)
if (fs.mEnabled)
v["enabled"] = true;
else
{
v["enabled"] = false;
if (mLastReport != 0)
{
if (it.second.mLastMajority == 0)
if (fs.mLastMajority == 0)
{
v["majority"] = false;
}
else
{
if (it.second.mFirstMajority != 0)
if (fs.mFirstMajority != 0)
{
if (it.second.mFirstMajority == mFirstReport)
if (fs.mFirstMajority == mFirstReport)
v["majority_start"] = "start";
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";
else
v["majority_until"] = it.second.mLastMajority;
v["majority_until"] = fs.mLastMajority;
}
}
}
}
if (it.second.mVetoed)
if (fs.mVetoed)
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;
}

View File

@@ -63,6 +63,7 @@ protected:
FeatureState* getCreateFeature(const uint256& feature, bool create);
bool shouldEnable (uint32 closeTime, const FeatureState& fs);
void setJson(Json::Value& v, const FeatureState&);
public:
@@ -73,6 +74,7 @@ public:
void addInitialFeatures();
FeatureState* addKnownFeature(const char *featureID, const char *friendlyName, bool veto);
uint256 getFeature(const std::string& name);
bool vetoFeature(const uint256& feature);
bool unVetoFeature(const uint256& feature);
@@ -94,6 +96,7 @@ public:
void reportValidations(const FeatureSet&);
Json::Value getJson(int);
Json::Value getJson(const uint256&);
void doValidation(Ledger::ref lastClosedLedger, STObject& baseValidation);
void doVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition);

View File

@@ -18,6 +18,7 @@ Json::Value rpcError(int iError, Json::Value jvResult)
{ rpcACT_MALFORMED, "actMalformed", "Account malformed." },
{ rpcACT_NOT_FOUND, "actNotFound", "Account not found." },
{ 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_MARKET, "badMarket", "No such market." },
{ rpcBAD_SECRET, "badSecret", "Secret does not match account." },

View File

@@ -47,6 +47,7 @@ enum {
rpcACT_MALFORMED,
rpcQUALITY_MALFORMED,
rpcBAD_BLOB,
rpcBAD_FEATURE,
rpcBAD_ISSUER,
rpcBAD_MARKET,
rpcBAD_SECRET,

View File

@@ -2263,11 +2263,17 @@ Json::Value RPCHandler::doFeature(Json::Value jvRequest, int& cost, ScopedLock&
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
return rpcError(rpcNOT_SUPPORTED);
}