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/beast/core/LexicalCast.h>
24
#include <ripple/net/RPCErr.h>
25
#include <ripple/protocol/ErrorCodes.h>
26
#include <ripple/protocol/jss.h>
27
#include <ripple/rpc/Context.h>
28
29
namespace
ripple
{
30
31
// {
32
// feature : <feature>
33
// vetoed : true/false
34
// }
35
Json::Value
36
doFeature
(
RPC::JsonContext
& context)
37
{
38
// Get majority amendment status
39
majorityAmendments_t
majorities;
40
41
if
(
auto
const
valLedger = context.
ledgerMaster
.
getValidatedLedger
())
42
majorities =
getMajorityAmendments
(*valLedger);
43
44
auto
& table = context.
app
.
getAmendmentTable
();
45
46
if
(!context.
params
.
isMember
(jss::feature))
47
{
48
auto
features = table.
getJson
();
49
50
for
(
auto
const
& [h, t] : majorities)
51
{
52
features[
to_string
(h)][jss::majority] =
53
t.time_since_epoch().count();
54
}
55
56
Json::Value
jvReply =
Json::objectValue
;
57
jvReply[jss::features] = features;
58
return
jvReply;
59
}
60
61
auto
feature = table.find(context.
params
[jss::feature].
asString
());
62
63
if
(!feature && !feature.parseHex(context.
params
[jss::feature].
asString
()))
64
return
rpcError
(
rpcBAD_FEATURE
);
65
66
if
(context.
params
.
isMember
(jss::vetoed))
67
{
68
if
(context.
params
[jss::vetoed].
asBool
())
69
table.veto(feature);
70
else
71
table.unVeto(feature);
72
}
73
74
Json::Value
jvReply = table.getJson(feature);
75
76
auto
m = majorities.
find
(feature);
77
if
(m != majorities.
end
())
78
jvReply[jss::majority] = m->second.time_since_epoch().count();
79
80
return
jvReply;
81
}
82
83
}
// namespace ripple
ripple::doFeature
Json::Value doFeature(RPC::JsonContext &context)
Definition:
Feature1.cpp:36
ripple::RPC::JsonContext
Definition:
Context.h:53
ripple::getMajorityAmendments
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition:
View.cpp:550
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::to_string
std::string to_string(ListDisposition disposition)
Definition:
ValidatorList.cpp:42
ripple::AmendmentTable::getJson
virtual Json::Value getJson() const =0
Json::Value::asBool
bool asBool() const
Definition:
json_value.cpp:619
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition:
json_value.h:43
ripple::LedgerMaster::getValidatedLedger
std::shared_ptr< Ledger const > getValidatedLedger()
Definition:
LedgerMaster.h:94
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
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