rippled
Loading...
Searching...
No Matches
CanDelete.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 <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/main/Application.h>
22#include <xrpld/app/misc/NetworkOPs.h>
23#include <xrpld/app/misc/SHAMapStore.h>
24#include <xrpld/rpc/Context.h>
25#include <xrpl/beast/core/LexicalCast.h>
26#include <xrpl/protocol/ErrorCodes.h>
27#include <xrpl/protocol/jss.h>
28#include <boost/algorithm/string/case_conv.hpp>
29#include <boost/format.hpp>
30
31namespace ripple {
32
33// can_delete [<ledgerid>|<ledgerhash>|now|always|never]
36{
37 if (!context.app.getSHAMapStore().advisoryDelete())
39
41
42 if (context.params.isMember(jss::can_delete))
43 {
44 Json::Value canDelete = context.params.get(jss::can_delete, 0);
45 std::uint32_t canDeleteSeq = 0;
46
47 if (canDelete.isUInt())
48 {
49 canDeleteSeq = canDelete.asUInt();
50 }
51 else
52 {
53 std::string canDeleteStr = canDelete.asString();
54 boost::to_lower(canDeleteStr);
55
56 if (canDeleteStr.find_first_not_of("0123456789") ==
57 std::string::npos)
58 {
59 canDeleteSeq = beast::lexicalCast<std::uint32_t>(canDeleteStr);
60 }
61 else if (canDeleteStr == "never")
62 {
63 canDeleteSeq = 0;
64 }
65 else if (canDeleteStr == "always")
66 {
68 }
69 else if (canDeleteStr == "now")
70 {
71 canDeleteSeq = context.app.getSHAMapStore().getLastRotated();
72 if (!canDeleteSeq)
74 }
75 else if (uint256 lh; lh.parseHex(canDeleteStr))
76 {
77 auto ledger = context.ledgerMaster.getLedgerByHash(lh);
78
79 if (!ledger)
80 return RPC::make_error(rpcLGR_NOT_FOUND, "ledgerNotFound");
81
82 canDeleteSeq = ledger->info().seq;
83 }
84 else
85 {
87 }
88 }
89
90 ret[jss::can_delete] =
91 context.app.getSHAMapStore().setCanDelete(canDeleteSeq);
92 }
93 else
94 {
95 ret[jss::can_delete] = context.app.getSHAMapStore().getCanDelete();
96 }
97
98 return ret;
99}
100
101} // namespace ripple
Represents a JSON value.
Definition: json_value.h:147
Value get(UInt index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
Definition: json_value.cpp:841
UInt asUInt() const
Definition: json_value.cpp:545
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:469
bool isUInt() const
Definition: json_value.cpp:998
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:943
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:502
T find_first_not_of(T... args)
T max(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Definition: ErrorCodes.cpp:181
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
@ rpcNOT_READY
Definition: ErrorCodes.h:60
@ rpcINVALID_PARAMS
Definition: ErrorCodes.h:84
@ rpcLGR_NOT_FOUND
Definition: ErrorCodes.h:72
@ rpcNOT_ENABLED
Definition: ErrorCodes.h:59
Json::Value doCanDelete(RPC::JsonContext &context)
Definition: CanDelete.cpp:35
Application & app
Definition: Context.h:42
LedgerMaster & ledgerMaster
Definition: Context.h:45
Json::Value params
Definition: Context.h:64