xrpld
Loading...
Searching...
No Matches
PeerReservationsDel.cpp
1#include <xrpld/rpc/Context.h>
2#include <xrpld/rpc/handlers/Handlers.h>
3
4#include <xrpl/core/PeerReservationTable.h>
5#include <xrpl/json/json_value.h>
6#include <xrpl/protocol/ErrorCodes.h>
7#include <xrpl/protocol/PublicKey.h>
8#include <xrpl/protocol/RPCErr.h>
9#include <xrpl/protocol/jss.h>
10#include <xrpl/protocol/tokens.h>
11
12#include <optional>
13
14namespace xrpl {
15
16json::Value
18{
19 auto const& params = context.params;
20
21 // We repeat much of the parameter parsing from `doPeerReservationsAdd`.
22 if (!params.isMember(jss::public_key))
23 return rpc::missingFieldError(jss::public_key);
24 if (!params[jss::public_key].isString())
25 return rpc::expectedFieldError(jss::public_key, "a string");
26
28 parseBase58<PublicKey>(TokenType::NodePublic, params[jss::public_key].asString());
29 if (!optPk)
31 PublicKey const& nodeId = *optPk;
32
33 auto const previous = context.app.getPeerReservations().erase(nodeId);
34
36 if (previous)
37 {
38 result[jss::previous] = previous->toJson();
39 }
40 return result;
41}
42
43} // namespace xrpl
Represents a JSON value.
Definition json_value.h:117
std::optional< PeerReservation > erase(PublicKey const &nodeId)
A public key.
Definition PublicKey.h:53
virtual PeerReservationTable & getPeerReservations()=0
@ Object
object value (collection of name/value pairs).
Definition json_value.h:29
json::Value expectedFieldError(std::string const &name, std::string const &type)
Definition ErrorCodes.h:309
json::Value missingFieldError(std::string const &name)
Definition ErrorCodes.h:243
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ RpcPublicMalformed
Definition ErrorCodes.h:100
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
json::Value doPeerReservationsDel(rpc::JsonContext &context)
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
Application & app
Definition Context.h:29
json::Value params
Definition Context.h:51