xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
utility
Random.cpp
1
#include <xrpl/basics/base_uint.h>
2
#include <xrpl/beast/utility/rngfill.h>
3
#include <xrpl/crypto/csprng.h>
4
#include <xrpl/json/json_value.h>
5
#include <xrpl/protocol/ErrorCodes.h>
6
#include <xrpl/protocol/RPCErr.h>
7
#include <xrpl/protocol/jss.h>
8
9
#include <
exception
>
10
11
namespace
xrpl
{
12
13
namespace
rpc
{
14
struct
JsonContext
;
15
}
// namespace rpc
16
17
// Result:
18
// {
19
// random: <UInt256>
20
// }
21
json::Value
22
doRandom
(
rpc::JsonContext
& context)
23
{
24
// TODO(tom): the try/catch is almost certainly redundant, we catch at the
25
// top level too.
26
try
27
{
28
UInt256
rand;
29
beast::rngfill
(rand.begin(), rand.size(),
cryptoPrng
());
30
31
json::Value
jvResult;
32
jvResult[jss::random] =
to_string
(rand);
33
return
jvResult;
34
}
35
catch
(
std::exception
const
&)
36
{
37
return
rpcError
(
RpcInternal
);
// LCOV_EXCL_LINE
38
}
39
}
40
41
}
// namespace xrpl
json::Value
Represents a JSON value.
Definition
json_value.h:117
exception
beast::rngfill
void rngfill(void *const buffer, std::size_t const bytes, Generator &g)
Definition
rngfill.h:11
xrpl::rpc
API version numbers used in later API versions.
Definition
ApiVersion.h:36
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::RpcInternal
@ RpcInternal
Definition
ErrorCodes.h:113
xrpl::doRandom
json::Value doRandom(rpc::JsonContext &)
Definition
Random.cpp:22
xrpl::cryptoPrng
CsprngEngine & cryptoPrng()
The default cryptographically secure PRNG.
Definition
libxrpl/crypto/csprng.cpp:81
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::rpcError
json::Value rpcError(ErrorCodeI iError)
Definition
RPCErr.cpp:13
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::rpc::JsonContext
Definition
Context.h:41
Generated by
1.17.0