xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
detail
Status.cpp
1
#include <xrpld/rpc/Status.h>
2
3
#include <xrpl/beast/utility/instrumentation.h>
4
#include <xrpl/json/json_value.h>
5
#include <xrpl/protocol/ErrorCodes.h>
6
#include <xrpl/protocol/TER.h>
7
#include <xrpl/protocol/jss.h>
8
9
#include <
sstream
>
10
#include <
string
>
11
12
namespace
xrpl::rpc
{
13
14
std::string
15
Status::codeString
()
const
16
{
17
if
(!*
this
)
18
return
""
;
19
20
if
(
type_
==
Type::None
)
21
return
std::to_string
(
code_
);
22
23
if
(
type_
==
Status::Type::TER
)
24
{
25
std::string
s1, s2;
26
27
[[maybe_unused]]
auto
const
success =
transResultInfo
(
toTER
(), s1, s2);
28
XRPL_ASSERT(success,
"xrpl::rpc::codeString : valid TER result"
);
29
30
return
s1 +
": "
+ s2;
31
}
32
33
if
(
type_
==
Status::Type::ErrorCodeI
)
34
{
35
auto
info =
getErrorInfo
(
toErrorCode
());
36
std::ostringstream
sStr;
37
sStr << info.token.cStr() <<
": "
<< info.message.cStr();
38
return
sStr.
str
();
39
}
40
41
// LCOV_EXCL_START
42
UNREACHABLE(
"xrpl::rpc::codeString : invalid type"
);
43
return
""
;
44
// LCOV_EXCL_STOP
45
}
46
47
void
48
Status::fillJson
(
json::Value
& value)
49
{
50
if
(!*
this
)
51
return
;
52
53
auto
& error = value[jss::error];
54
error[jss::code] =
code_
;
55
error[jss::message] =
codeString
();
56
57
// Are there any more messages?
58
if
(!
messages_
.empty())
59
{
60
auto
&
messages
= error[jss::data];
61
for
(
auto
& i :
messages_
)
62
messages
.append(i);
63
}
64
}
65
66
std::string
67
Status::message
()
const
68
{
69
std::string
result;
70
for
(
auto
& m :
messages_
)
71
{
72
if
(!result.
empty
())
73
result +=
'/'
;
74
result += m;
75
}
76
77
return
result;
78
}
79
80
std::string
81
Status::toString
()
const
82
{
83
if
(*
this
)
84
return
codeString
() +
":"
+
message
();
85
return
""
;
86
}
87
88
}
// namespace xrpl::rpc
std::ostringstream
std::string
json::Value
Represents a JSON value.
Definition
json_value.h:117
std::string::empty
T empty(T... args)
xrpl::rpc
API version numbers used in later API versions.
Definition
ApiVersion.h:36
xrpl::rpc::getErrorInfo
ErrorInfo const & getErrorInfo(ErrorCodeI code)
Returns an ErrorInfo that reflects the error code.
Definition
ErrorCodes.cpp:182
xrpl::transResultInfo
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition
TER.cpp:242
sstream
std::ostringstream::str
T str(T... args)
string
xrpl::rpc::Status::Type::TER
@ TER
Definition
Status.h:29
xrpl::rpc::Status::Type::None
@ None
Definition
Status.h:29
xrpl::rpc::Status::Type::ErrorCodeI
@ ErrorCodeI
Definition
Status.h:29
xrpl::rpc::Status::toTER
TER toTER() const
Returns the Status as a TER.
Definition
Status.h:89
xrpl::rpc::Status::messages_
Strings messages_
Definition
Status.h:158
xrpl::rpc::Status::toErrorCode
ErrorCodeI toErrorCode() const
Returns the Status as an error_code_i.
Definition
Status.h:100
xrpl::rpc::Status::type_
Type type_
Definition
Status.h:156
xrpl::rpc::Status::fillJson
void fillJson(json::Value &)
Fill a json::Value with an RPC 2.0 response.
Definition
Status.cpp:48
xrpl::rpc::Status::toString
std::string toString() const
Definition
Status.cpp:81
xrpl::rpc::Status::messages
Strings const & messages() const
Definition
Status.h:127
xrpl::rpc::Status::codeString
std::string codeString() const
If the Status is OK, the result is an empty string.
Definition
Status.cpp:15
xrpl::rpc::Status::code_
Code code_
Definition
Status.h:157
xrpl::rpc::Status::message
std::string message() const
Return the first message, if any.
Definition
Status.cpp:67
std::to_string
T to_string(T... args)
Generated by
1.17.0