xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
admin
data
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/basics/StringUtilities.h>
7
#include <xrpl/basics/base_uint.h>
8
#include <xrpl/beast/core/LexicalCast.h>
9
#include <xrpl/json/json_value.h>
10
#include <xrpl/protocol/ErrorCodes.h>
11
#include <xrpl/protocol/jss.h>
12
13
#include <
cstdint
>
14
#include <
limits
>
15
#include <
string
>
16
17
namespace
xrpl
{
18
19
// can_delete [<ledgerid>|<ledgerhash>|now|always|never]
20
json::Value
21
doCanDelete
(
rpc::JsonContext
& context)
22
{
23
if
(!context.
app
.
getSHAMapStore
().
advisoryDelete
())
24
return
rpc::makeError
(
RpcNotEnabled
);
25
26
json::Value
ret(
json::ValueType::Object
);
27
28
if
(context.
params
.
isMember
(jss::can_delete))
29
{
30
json::Value
const
canDelete = context.
params
.
get
(jss::can_delete, 0);
31
std::uint32_t
canDeleteSeq = 0;
32
33
if
(canDelete.
isUInt
())
34
{
35
canDeleteSeq = canDelete.
asUInt
();
36
}
37
else
38
{
39
std::string
canDeleteStr = canDelete.
asString
();
40
canDeleteStr =
toLower
(canDeleteStr);
41
42
if
(canDeleteStr.
find_first_not_of
(
"0123456789"
) == std::string::npos)
43
{
44
canDeleteSeq =
beast::lexicalCast<std::uint32_t>
(canDeleteStr);
45
}
46
else
if
(canDeleteStr ==
"never"
)
47
{
48
canDeleteSeq = 0;
49
}
50
else
if
(canDeleteStr ==
"always"
)
51
{
52
canDeleteSeq =
std::numeric_limits<std::uint32_t>::max
();
53
}
54
else
if
(canDeleteStr ==
"now"
)
55
{
56
canDeleteSeq = context.
app
.
getSHAMapStore
().
getLastRotated
();
57
if
(canDeleteSeq == 0u)
58
return
rpc::makeError
(
RpcNotReady
);
59
}
60
else
if
(
UInt256
lh; lh.parseHex(canDeleteStr))
61
{
62
auto
ledger = context.
ledgerMaster
.
getLedgerByHash
(lh);
63
64
if
(!ledger)
65
return
rpc::makeError
(
RpcLgrNotFound
,
"ledgerNotFound"
);
66
67
canDeleteSeq = ledger->header().seq;
68
}
69
else
70
{
71
return
rpc::makeError
(
RpcInvalidParams
);
72
}
73
}
74
75
ret[jss::can_delete] = context.
app
.
getSHAMapStore
().
setCanDelete
(canDeleteSeq);
76
}
77
else
78
{
79
ret[jss::can_delete] = context.
app
.
getSHAMapStore
().
getCanDelete
();
80
}
81
82
return
ret;
83
}
84
85
}
// namespace xrpl
std::string
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::get
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
Definition
json_value.cpp:941
json::Value::isUInt
bool isUInt() const
Definition
json_value.cpp:1110
json::Value::asUInt
UInt asUInt() const
Definition
json_value.cpp:631
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::LedgerMaster::getLedgerByHash
std::shared_ptr< Ledger const > getLedgerByHash(UInt256 const &hash)
Definition
LedgerMaster.cpp:1798
xrpl::SHAMapStore::getCanDelete
virtual LedgerIndex getCanDelete()=0
Highest ledger that may be deleted.
xrpl::SHAMapStore::advisoryDelete
virtual bool advisoryDelete() const =0
Whether advisory delete is enabled.
xrpl::SHAMapStore::getLastRotated
virtual LedgerIndex getLastRotated()=0
Maximum ledger that has been deleted, or will be deleted if currently in the act of online deletion.
xrpl::SHAMapStore::setCanDelete
virtual LedgerIndex setCanDelete(LedgerIndex canDelete)=0
Highest ledger that may be deleted.
xrpl::ServiceRegistry::getSHAMapStore
virtual SHAMapStore & getSHAMapStore()=0
cstdint
std::string::find_first_not_of
T find_first_not_of(T... args)
std::uint32_t
limits
std::numeric_limits::max
T max(T... args)
beast::lexicalCast
constexpr Out lexicalCast(In in, Out defaultValue=Out())
Convert from one type to another.
Definition
LexicalCast.h:211
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl::rpc::makeError
json::Value makeError(ErrorCodeI code)
Returns a new json object that reflects the error code.
Definition
ErrorCodes.cpp:190
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::RpcLgrNotFound
@ RpcLgrNotFound
Definition
ErrorCodes.h:55
xrpl::RpcNotReady
@ RpcNotReady
Definition
ErrorCodes.h:43
xrpl::RpcNotEnabled
@ RpcNotEnabled
Definition
ErrorCodes.h:42
xrpl::RpcInvalidParams
@ RpcInvalidParams
Definition
ErrorCodes.h:67
xrpl::toLower
std::string toLower(std::string str)
Fold ASCII upper case letters to lower case.
Definition
libxrpl/basics/StringUtilities.cpp:129
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::doCanDelete
json::Value doCanDelete(rpc::JsonContext &context)
Definition
CanDelete.cpp:21
string
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