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