rippled
Loading...
Searching...
No Matches
Feature1.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/main/Application.h>
22#include <xrpld/app/misc/AmendmentTable.h>
23#include <xrpld/rpc/Context.h>
24
25#include <xrpl/protocol/ErrorCodes.h>
26#include <xrpl/protocol/RPCErr.h>
27#include <xrpl/protocol/jss.h>
28
29namespace ripple {
30
31// {
32// feature : <feature>
33// vetoed : true/false
34// }
37{
38 if (context.params.isMember(jss::feature))
39 {
40 // ensure that the `feature` param is a string
41 if (!context.params[jss::feature].isString())
42 {
44 }
45 }
46
47 bool const isAdmin = context.role == Role::ADMIN;
48 // Get majority amendment status
49 majorityAmendments_t majorities;
50
51 if (auto const valLedger = context.ledgerMaster.getValidatedLedger())
52 majorities = getMajorityAmendments(*valLedger);
53
54 auto& table = context.app.getAmendmentTable();
55
56 if (!context.params.isMember(jss::feature))
57 {
58 auto features = table.getJson(isAdmin);
59
60 for (auto const& [h, t] : majorities)
61 {
62 features[to_string(h)][jss::majority] =
63 t.time_since_epoch().count();
64 }
65
67 jvReply[jss::features] = features;
68 return jvReply;
69 }
70
71 auto feature = table.find(context.params[jss::feature].asString());
72
73 // If the feature is not found by name, try to parse the `feature` param as
74 // a feature ID. If that fails, return an error.
75 if (!feature && !feature.parseHex(context.params[jss::feature].asString()))
77
78 if (context.params.isMember(jss::vetoed))
79 {
80 if (!isAdmin)
82
83 if (context.params[jss::vetoed].asBool())
84 table.veto(feature);
85 else
86 table.unVeto(feature);
87 }
88
89 Json::Value jvReply = table.getJson(feature, isAdmin);
90 if (!jvReply)
92
93 auto m = majorities.find(feature);
94 if (m != majorities.end())
95 jvReply[jss::majority] = m->second.time_since_epoch().count();
96
97 return jvReply;
98}
99
100} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
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:503
T end(T... args)
T find(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ rpcBAD_FEATURE
Definition ErrorCodes.h:95
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:84
@ rpcNO_PERMISSION
Definition ErrorCodes.h:53
bool isAdmin(Port const &port, Json::Value const &params, beast::IP::Address const &remoteIp)
Definition Role.cpp:85
Json::Value rpcError(int iError)
Definition RPCErr.cpp:31
Json::Value doFeature(RPC::JsonContext &context)
Definition Feature1.cpp:36
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition View.cpp:938
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
Application & app
Definition Context.h:41
LedgerMaster & ledgerMaster
Definition Context.h:44