rippled
Loading...
Searching...
No Matches
CanDelete.cpp
1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/main/Application.h>
3#include <xrpld/app/misc/SHAMapStore.h>
4#include <xrpld/rpc/Context.h>
5
6#include <xrpl/beast/core/LexicalCast.h>
7#include <xrpl/protocol/ErrorCodes.h>
8#include <xrpl/protocol/jss.h>
9
10#include <boost/algorithm/string/case_conv.hpp>
11
12namespace ripple {
13
14// can_delete [<ledgerid>|<ledgerhash>|now|always|never]
17{
18 if (!context.app.getSHAMapStore().advisoryDelete())
20
22
23 if (context.params.isMember(jss::can_delete))
24 {
25 Json::Value canDelete = context.params.get(jss::can_delete, 0);
26 std::uint32_t canDeleteSeq = 0;
27
28 if (canDelete.isUInt())
29 {
30 canDeleteSeq = canDelete.asUInt();
31 }
32 else
33 {
34 std::string canDeleteStr = canDelete.asString();
35 boost::to_lower(canDeleteStr);
36
37 if (canDeleteStr.find_first_not_of("0123456789") ==
38 std::string::npos)
39 {
40 canDeleteSeq = beast::lexicalCast<std::uint32_t>(canDeleteStr);
41 }
42 else if (canDeleteStr == "never")
43 {
44 canDeleteSeq = 0;
45 }
46 else if (canDeleteStr == "always")
47 {
49 }
50 else if (canDeleteStr == "now")
51 {
52 canDeleteSeq = context.app.getSHAMapStore().getLastRotated();
53 if (!canDeleteSeq)
55 }
56 else if (uint256 lh; lh.parseHex(canDeleteStr))
57 {
58 auto ledger = context.ledgerMaster.getLedgerByHash(lh);
59
60 if (!ledger)
61 return RPC::make_error(rpcLGR_NOT_FOUND, "ledgerNotFound");
62
63 canDeleteSeq = ledger->info().seq;
64 }
65 else
66 {
68 }
69 }
70
71 ret[jss::can_delete] =
72 context.app.getSHAMapStore().setCanDelete(canDeleteSeq);
73 }
74 else
75 {
76 ret[jss::can_delete] = context.app.getSHAMapStore().getCanDelete();
77 }
78
79 return ret;
80}
81
82} // namespace ripple
Represents a JSON value.
Definition json_value.h:131
UInt asUInt() const
std::string asString() const
Returns the unquoted string value.
bool isUInt() const
bool isMember(char const *key) const
Return true if the object has a member named key.
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
virtual SHAMapStore & getSHAMapStore()=0
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
virtual LedgerIndex setCanDelete(LedgerIndex canDelete)=0
Highest ledger that may be deleted.
virtual bool advisoryDelete() const =0
Whether advisory delete is enabled.
virtual LedgerIndex getLastRotated()=0
Maximum ledger that has been deleted, or will be deleted if currently in the act of online deletion.
virtual LedgerIndex getCanDelete()=0
Highest ledger that may be deleted.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:484
T find_first_not_of(T... args)
T max(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:27
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ rpcNOT_READY
Definition ErrorCodes.h:41
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:65
@ rpcLGR_NOT_FOUND
Definition ErrorCodes.h:53
@ rpcNOT_ENABLED
Definition ErrorCodes.h:40
Json::Value doCanDelete(RPC::JsonContext &context)
Definition CanDelete.cpp:16
Application & app
Definition Context.h:22
LedgerMaster & ledgerMaster
Definition Context.h:25