xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
server_info
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
14
namespace
xrpl
{
15
16
// {
17
// feature : <feature>
18
// vetoed : true/false
19
// }
20
json::Value
21
doFeature
(
rpc::JsonContext
& context)
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
{
28
return
rpcError
(
RpcInvalidParams
);
29
}
30
}
31
32
bool
const
isAdmin
= context.
role
==
Role::ADMIN
;
33
// Get majority amendment status
34
MajorityAmendmentsT
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
50
json::Value
jvReply =
json::ValueType::Object
;
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
)
65
return
rpcError
(
RpcNoPermission
);
66
67
if
(!context.
params
[jss::vetoed].
isBool
())
68
{
69
return
rpcError
(
RpcInvalidParams
);
70
}
71
72
if
(context.
params
[jss::vetoed].
asBool
())
73
{
74
table.veto(feature);
75
}
76
else
77
{
78
table.unVeto(feature);
79
}
80
}
81
82
json::Value
jvReply = table.getJson(feature,
isAdmin
);
83
if
(!jvReply)
84
return
rpcError
(
RpcBadFeature
);
85
86
auto
m = majorities.
find
(feature);
87
if
(m != majorities.
end
())
88
jvReply[jss::majority] = m->second.time_since_epoch().count();
89
90
return
jvReply;
91
}
92
93
}
// namespace xrpl
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::asBool
bool asBool() const
Definition
json_value.cpp:708
json::Value::isBool
bool isBool() const
Definition
json_value.cpp:1098
json::Value::isString
bool isString() const
Definition
json_value.cpp:1134
json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition
json_value.cpp:494
json::Value::isMember
bool isMember(char const *key) const
Return true if the object has a member named key.
Definition
json_value.cpp:1049
xrpl::AmendmentTable::find
virtual UInt256 find(std::string const &name) const =0
xrpl::LedgerMaster::getValidatedLedger
std::shared_ptr< Ledger const > getValidatedLedger()
The validated ledger is the last fully validated ledger.
Definition
LedgerMaster.cpp:1600
xrpl::ServiceRegistry::getAmendmentTable
virtual AmendmentTable & getAmendmentTable()=0
std::map::end
T end(T... args)
std::map::find
T find(T... args)
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::RpcBadFeature
@ RpcBadFeature
Definition
ErrorCodes.h:78
xrpl::RpcInvalidParams
@ RpcInvalidParams
Definition
ErrorCodes.h:67
xrpl::RpcNoPermission
@ RpcNoPermission
Definition
ErrorCodes.h:36
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::rpcError
json::Value rpcError(ErrorCodeI iError)
Definition
RPCErr.cpp:13
xrpl::Role::ADMIN
@ ADMIN
Definition
Role.h:27
xrpl::doFeature
json::Value doFeature(rpc::JsonContext &)
Definition
xrpld/rpc/handlers/server_info/Feature.cpp:21
xrpl::isAdmin
bool isAdmin(Port const &port, json::Value const ¶ms, beast::ip::Address const &remoteIp)
Definition
Role.cpp:81
xrpl::MajorityAmendmentsT
std::map< UInt256, NetClock::time_point > MajorityAmendmentsT
Definition
View.h:121
xrpl::getMajorityAmendments
MajorityAmendmentsT getMajorityAmendments(ReadView const &view)
Definition
View.cpp:317
xrpl::rpc::Context::role
Role role
Definition
Context.h:34
xrpl::rpc::Context::app
Application & app
Definition
Context.h:29
xrpl::rpc::Context::ledgerMaster
LedgerMaster & ledgerMaster
Definition
Context.h:32
xrpl::rpc::JsonContext
Definition
Context.h:41
xrpl::rpc::JsonContext::params
json::Value params
Definition
Context.h:51
Generated by
1.17.0