rippled
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 <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/app/misc/AmendmentTable.h>
23 #include <ripple/net/RPCErr.h>
24 #include <ripple/protocol/ErrorCodes.h>
25 #include <ripple/protocol/jss.h>
26 #include <ripple/rpc/Context.h>
27 
28 namespace ripple {
29 
30 // {
31 // feature : <feature>
32 // vetoed : true/false
33 // }
36 {
37  if (context.app.config().reporting())
39 
40  // Get majority amendment status
41  majorityAmendments_t majorities;
42 
43  if (auto const valLedger = context.ledgerMaster.getValidatedLedger())
44  majorities = getMajorityAmendments(*valLedger);
45 
46  auto& table = context.app.getAmendmentTable();
47 
48  if (!context.params.isMember(jss::feature))
49  {
50  auto features = table.getJson();
51 
52  for (auto const& [h, t] : majorities)
53  {
54  features[to_string(h)][jss::majority] =
55  t.time_since_epoch().count();
56  }
57 
59  jvReply[jss::features] = features;
60  return jvReply;
61  }
62 
63  auto feature = table.find(context.params[jss::feature].asString());
64 
65  // If the feature is not found by name, try to parse the `feature` param as
66  // a feature ID. If that fails, return an error.
67  if (!feature && !feature.parseHex(context.params[jss::feature].asString()))
68  return rpcError(rpcBAD_FEATURE);
69 
70  if (context.params.isMember(jss::vetoed))
71  {
72  if (context.params[jss::vetoed].asBool())
73  table.veto(feature);
74  else
75  table.unVeto(feature);
76  }
77 
78  Json::Value jvReply = table.getJson(feature);
79 
80  auto m = majorities.find(feature);
81  if (m != majorities.end())
82  jvReply[jss::majority] = m->second.time_since_epoch().count();
83 
84  return jvReply;
85 }
86 
87 } // namespace ripple
ripple::doFeature
Json::Value doFeature(RPC::JsonContext &context)
Definition: Feature1.cpp:35
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::getMajorityAmendments
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:621
ripple::rpcError
Json::Value rpcError(int iError)
Definition: RPCErr.cpp:29
ripple::Application::getAmendmentTable
virtual AmendmentTable & getAmendmentTable()=0
std::map::find
T find(T... args)
ripple::RPC::Context::ledgerMaster
LedgerMaster & ledgerMaster
Definition: Context.h:45
ripple::rpcREPORTING_UNSUPPORTED
@ rpcREPORTING_UNSUPPORTED
Definition: ErrorCodes.h:141
Json::Value::asBool
bool asBool() const
Definition: json_value.cpp:619
ripple::Config::reporting
bool reporting() const
Definition: Config.h:337
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
ripple::Application::config
virtual Config & config()=0
ripple::RPC::Context::app
Application & app
Definition: Context.h:42
Json::Value::isMember
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:932
std::map
STL class.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerMaster::getValidatedLedger
std::shared_ptr< Ledger const > getValidatedLedger()
Definition: LedgerMaster.cpp:1664
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:41
std::map::end
T end(T... args)
ripple::base_uint::parseHex
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition: base_uint.h:496
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:64
ripple::rpcBAD_FEATURE
@ rpcBAD_FEATURE
Definition: ErrorCodes.h:95
Json::Value
Represents a JSON value.
Definition: json_value.h:145
Json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:469