xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
jtx
rpc.h
1
#pragma once
2
3
#include <test/jtx/Env.h>
4
#include <test/jtx/JTx.h>
5
6
#include <xrpl/protocol/ErrorCodes.h>
7
#include <xrpl/protocol/TER.h>
8
9
#include <
optional
>
10
#include <
string
>
11
#include <
utility
>
12
13
namespace
xrpl::test::jtx
{
14
19
class
Rpc
20
{
21
private
:
22
std::optional<ErrorCodeI>
code_
;
23
std::optional<std::string>
errorMessage_
;
24
std::optional<std::string>
error_
;
25
std::optional<std::string>
errorException_
;
26
27
public
:
31
explicit
Rpc
(
ErrorCodeI
code,
std::optional<std::string>
m = {})
32
:
code_
(code),
errorMessage_
(
std
::move(m))
33
{
34
}
35
39
explicit
Rpc
(
std::string
error,
std::optional<std::string>
exceptionMessage = {})
40
:
error_
(error),
errorException_
(
std
::move(exceptionMessage))
41
{
42
}
43
44
void
45
operator()
(
Env
&,
JTx
& jt)
const
46
{
47
// The RPC request should fail. RPC errors result in telENV_RPC_FAILED.
48
jt.
ter
=
telENV_RPC_FAILED
;
49
if
(
code_
)
50
{
51
auto
const
& errorInfo =
rpc::getErrorInfo
(*
code_
);
52
// When an RPC request returns an error code ('error_code'), it
53
// always includes an error message ('error_message'), and sometimes
54
// includes an error token ('error'). If it does, the error token is
55
// always obtained from the lookup into the ErrorInfo lookup table.
56
//
57
// Take advantage of that fact to populate jt.rpcException. The
58
// check will be aware of whether the rpcException can be safely
59
// ignored.
60
jt.
rpcCode
= {*
code_
,
errorMessage_
? *
errorMessage_
: errorInfo.message.cStr()};
61
jt.
rpcException
= {errorInfo.token.cStr(), std::nullopt};
62
}
63
if
(
error_
)
64
jt.
rpcException
= {*
error_
,
errorException_
};
65
}
66
};
67
68
}
// namespace xrpl::test::jtx
std::string
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
xrpl::test::jtx::Rpc::code_
std::optional< ErrorCodeI > code_
Definition
rpc.h:22
xrpl::test::jtx::Rpc::errorMessage_
std::optional< std::string > errorMessage_
Definition
rpc.h:23
xrpl::test::jtx::Rpc::errorException_
std::optional< std::string > errorException_
Definition
rpc.h:25
xrpl::test::jtx::Rpc::Rpc
Rpc(std::string error, std::optional< std::string > exceptionMessage={})
If there is not a code, we expect an exception message.
Definition
rpc.h:39
xrpl::test::jtx::Rpc::error_
std::optional< std::string > error_
Definition
rpc.h:24
xrpl::test::jtx::Rpc::Rpc
Rpc(ErrorCodeI code, std::optional< std::string > m={})
If there's an error code, we expect an error message.
Definition
rpc.h:31
xrpl::test::jtx::Rpc::operator()
void operator()(Env &, JTx &jt) const
Definition
rpc.h:45
std
STL namespace.
xrpl::rpc::getErrorInfo
ErrorInfo const & getErrorInfo(ErrorCodeI code)
Returns an ErrorInfo that reflects the error code.
Definition
ErrorCodes.cpp:182
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::telENV_RPC_FAILED
@ telENV_RPC_FAILED
Definition
TER.h:54
xrpl::ErrorCodeI
ErrorCodeI
Definition
ErrorCodes.h:23
optional
string
xrpl::test::jtx::JTx
Execution context for applying a JSON transaction.
Definition
JTx.h:27
xrpl::test::jtx::JTx::ter
std::optional< TER > ter
Definition
JTx.h:30
xrpl::test::jtx::JTx::rpcCode
std::optional< std::pair< ErrorCodeI, std::string > > rpcCode
Definition
JTx.h:31
xrpl::test::jtx::JTx::rpcException
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition
JTx.h:32
utility
Generated by
1.17.0