Skip to content

Commit

Permalink
update API changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Oct 23, 2023
1 parent 5026cbd commit 02f14b0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
1 change: 1 addition & 0 deletions API-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The `network_id` field was added in the `server_info` response in version 1.5.0
Additions are intended to be non-breaking (because they are purely additive).

- `server_definitions`: A new RPC that generates a `definitions.json`-like output that can be used in XRPL libraries.
- `feature`: A non-admin mode that decodes the hex version of amendment names.

## XRP Ledger version 1.12.0

Expand Down
23 changes: 23 additions & 0 deletions src/ripple/rpc/handlers/Feature1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ripple/app/misc/AmendmentTable.h>
#include <ripple/net/RPCErr.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/jss.h>
#include <ripple/rpc/Context.h>

Expand All @@ -37,6 +38,28 @@ doFeature(RPC::JsonContext& context)
if (context.app.config().reporting())
return rpcError(rpcREPORTING_UNSUPPORTED);

if (context.role != Role::ADMIN)
{
if (!context.params.isMember(jss::feature))
{
return RPC::missing_field_error(jss::feature);
}
std::string const& featureStr = context.params[jss::feature].asString();
uint256 feature;
if (!feature.parseHex(featureStr))
{
return rpcError(rpcBAD_FEATURE);
}
std::string const& featureName = featureToName(feature);
if (featureName == featureStr)
{
return rpcError(rpcBAD_FEATURE);
}
Json::Value jvReply = Json::objectValue;
jvReply[jss::feature] = featureName;
return jvReply;
}

// Get majority amendment status
majorityAmendments_t majorities;

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/impl/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Handler const handlerArray[]{
{"gateway_balances", byRef(&doGatewayBalances), Role::USER, NO_CONDITION},
#endif
{"get_counts", byRef(&doGetCounts), Role::ADMIN, NO_CONDITION},
{"feature", byRef(&doFeature), Role::ADMIN, NO_CONDITION},
{"feature", byRef(&doFeature), Role::USER, NO_CONDITION},
{"fee", byRef(&doFee), Role::USER, NEEDS_CURRENT_LEDGER},
{"fetch_info", byRef(&doFetchInfo), Role::ADMIN, NO_CONDITION},
{"ledger_accept",
Expand Down
38 changes: 33 additions & 5 deletions src/test/rpc/Feature_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,39 @@ class Feature_test : public beast::unit_test::suite
return cfg;
})};

auto jrr = env.rpc("feature")[jss::result];
// The current HTTP/S ServerHandler returns an HTTP 403 error code here
// rather than a noPermission JSON error. The JSONRPCClient just eats
// that error and returns an null result.
BEAST_EXPECT(jrr.isNull());
{
auto result = env.rpc("feature")[jss::result];
BEAST_EXPECT(result[jss::error] == "invalidParams");
BEAST_EXPECT(
result[jss::error_message] == "Missing field 'feature'.");
}

{
Json::Value params;
// invalid feature
params[jss::feature] =
"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCD"
"EF";
auto const result = env.rpc(
"json",
"feature",
boost::lexical_cast<std::string>(params))[jss::result];
BEAST_EXPECT(result[jss::error] == "badFeature");
BEAST_EXPECT(
result[jss::error_message] == "Feature unknown or invalid.");
}

{
Json::Value params;
params[jss::feature] =
"93E516234E35E08CA689FA33A6D38E103881F8DCB53023F728C307AA89D515"
"A7";
auto const result = env.rpc(
"json",
"feature",
boost::lexical_cast<std::string>(params))[jss::result];
BEAST_EXPECT(result[jss::feature] == "XRPFees");
}
}

void
Expand Down

0 comments on commit 02f14b0

Please sign in to comment.