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