rippled
ripple
rpc
handlers
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
// }
34
Json::Value
35
doFeature
(
RPC::JsonContext
& context)
36
{
37
if
(context.
app
.
config
().
reporting
())
38
return
rpcError
(
rpcREPORTING_UNSUPPORTED
);
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
58
Json::Value
jvReply =
Json::objectValue
;
59
jvReply[jss::features] = features;
60
return
jvReply;
61
}
62
63
auto
feature = table.find(context.
params
[jss::feature].
asString
());
64
65
if
(!feature && !feature.parseHex(context.
params
[jss::feature].
asString
()))
66
return
rpcError
(
rpcBAD_FEATURE
);
67
68
if
(context.
params
.
isMember
(jss::vetoed))
69
{
70
if
(context.
params
[jss::vetoed].
asBool
())
71
table.veto(feature);
72
else
73
table.unVeto(feature);
74
}
75
76
Json::Value
jvReply = table.getJson(feature);
77
78
auto
m = majorities.
find
(feature);
79
if
(m != majorities.
end
())
80
jvReply[jss::majority] = m->second.time_since_epoch().count();
81
82
return
jvReply;
83
}
84
85
}
// 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:554
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::AmendmentTable::getJson
virtual Json::Value getJson() const =0
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:276
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::rpcError
Json::Value rpcError(int iError, Json::Value jvResult)
Definition:
RPCErr.cpp:29
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:1612
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:39
std::map::end
T end(T... args)
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
Generated by
1.8.17