rippled
Loading...
Searching...
No Matches
Feature1.cpp
1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/main/Application.h>
3#include <xrpld/app/misc/AmendmentTable.h>
4#include <xrpld/rpc/Context.h>
5
6#include <xrpl/protocol/ErrorCodes.h>
7#include <xrpl/protocol/RPCErr.h>
8#include <xrpl/protocol/jss.h>
9
10namespace ripple {
11
12// {
13// feature : <feature>
14// vetoed : true/false
15// }
18{
19 if (context.params.isMember(jss::feature))
20 {
21 // ensure that the `feature` param is a string
22 if (!context.params[jss::feature].isString())
23 {
25 }
26 }
27
28 bool const isAdmin = context.role == Role::ADMIN;
29 // Get majority amendment status
30 majorityAmendments_t majorities;
31
32 if (auto const valLedger = context.ledgerMaster.getValidatedLedger())
33 majorities = getMajorityAmendments(*valLedger);
34
35 auto& table = context.app.getAmendmentTable();
36
37 if (!context.params.isMember(jss::feature))
38 {
39 auto features = table.getJson(isAdmin);
40
41 for (auto const& [h, t] : majorities)
42 {
43 features[to_string(h)][jss::majority] =
44 t.time_since_epoch().count();
45 }
46
48 jvReply[jss::features] = features;
49 return jvReply;
50 }
51
52 auto feature = table.find(context.params[jss::feature].asString());
53
54 // If the feature is not found by name, try to parse the `feature` param as
55 // a feature ID. If that fails, return an error.
56 if (!feature && !feature.parseHex(context.params[jss::feature].asString()))
58
59 if (context.params.isMember(jss::vetoed))
60 {
61 if (!isAdmin)
63
64 if (context.params[jss::vetoed].asBool())
65 table.veto(feature);
66 else
67 table.unVeto(feature);
68 }
69
70 Json::Value jvReply = table.getJson(feature, isAdmin);
71 if (!jvReply)
73
74 auto m = majorities.find(feature);
75 if (m != majorities.end())
76 jvReply[jss::majority] = m->second.time_since_epoch().count();
77
78 return jvReply;
79}
80
81} // namespace ripple
Represents a JSON value.
Definition json_value.h:131
bool isString() const
std::string asString() const
Returns the unquoted string value.
bool asBool() const
bool isMember(char const *key) const
Return true if the object has a member named key.
virtual AmendmentTable & getAmendmentTable()=0
std::shared_ptr< Ledger const > getValidatedLedger()
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:484
T end(T... args)
T find(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:27
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ rpcBAD_FEATURE
Definition ErrorCodes.h:76
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:65
@ rpcNO_PERMISSION
Definition ErrorCodes.h:34
bool isAdmin(Port const &port, Json::Value const &params, beast::IP::Address const &remoteIp)
Definition Role.cpp:66
Json::Value rpcError(int iError)
Definition RPCErr.cpp:12
Json::Value doFeature(RPC::JsonContext &context)
Definition Feature1.cpp:17
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition View.cpp:919
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
Application & app
Definition Context.h:22
LedgerMaster & ledgerMaster
Definition Context.h:25