Fix levelization

* Move `chooseLedgerEntryType` from protocol to RPC
This commit is contained in:
Edward Hennis
2017-04-06 13:28:09 -04:00
committed by Scott Schurr
parent 46004158a2
commit 96ece1b9f0
6 changed files with 58 additions and 57 deletions

View File

@@ -664,9 +664,58 @@ keypairForSignature(Json::Value const& params, Json::Value& error)
return generateKeyPair (keyType, *seed);
}
beast::SemanticVersion const firstVersion ("1.0.0");
beast::SemanticVersion const goodVersion ("1.0.0");
beast::SemanticVersion const lastVersion ("1.0.0");
std::pair<RPC::Status, LedgerEntryType>
chooseLedgerEntryType(Json::Value const& params)
{
std::pair<RPC::Status, LedgerEntryType> result{ RPC::Status::OK, ltINVALID };
if (params.isMember(jss::type))
{
static
std::array<std::pair<char const *, LedgerEntryType>, 11> const types
{ {
{ jss::account, ltACCOUNT_ROOT },
{ jss::amendments, ltAMENDMENTS },
{ jss::directory, ltDIR_NODE },
{ jss::fee, ltFEE_SETTINGS },
{ jss::hashes, ltLEDGER_HASHES },
{ jss::offer, ltOFFER },
{ jss::signer_list, ltSIGNER_LIST },
{ jss::state, ltRIPPLE_STATE },
{ jss::ticket, ltTICKET },
{ jss::escrow, ltESCROW },
{ jss::payment_channel, ltPAYCHAN }
} };
auto const& p = params[jss::type];
if (!p.isString())
{
result.first = RPC::Status{ rpcINVALID_PARAMS,
"Invalid field 'type', not string." };
assert(result.first.type() == RPC::Status::Type::error_code_i);
return result;
}
auto const filter = p.asString();
auto iter = std::find_if(types.begin(), types.end(),
[&filter](decltype (types.front())& t)
{
return t.first == filter;
});
if (iter == types.end())
{
result.first = RPC::Status{ rpcINVALID_PARAMS,
"Invalid field 'type'." };
assert(result.first.type() == RPC::Status::Type::error_code_i);
return result;
}
result.second = iter->second;
}
return result;
}
beast::SemanticVersion const firstVersion("1.0.0");
beast::SemanticVersion const goodVersion("1.0.0");
beast::SemanticVersion const lastVersion("1.0.0");
} // RPC
} // ripple

View File

@@ -129,6 +129,9 @@ setVersion(Object& parent)
object[jss::last] = lastVersion.print();
}
std::pair<RPC::Status, LedgerEntryType>
chooseLedgerEntryType(Json::Value const& params);
} // RPC
} // ripple