xrpld
Loading...
Searching...
No Matches
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
13namespace xrpl::test::jtx {
14
19class Rpc
20{
21private:
26
27public:
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.
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_)
65 }
66};
67
68} // namespace xrpl::test::jtx
A transaction testing environment.
Definition Env.h:161
std::optional< ErrorCodeI > code_
Definition rpc.h:22
std::optional< std::string > errorMessage_
Definition rpc.h:23
std::optional< std::string > errorException_
Definition rpc.h:25
Rpc(std::string error, std::optional< std::string > exceptionMessage={})
If there is not a code, we expect an exception message.
Definition rpc.h:39
std::optional< std::string > error_
Definition rpc.h:24
Rpc(ErrorCodeI code, std::optional< std::string > m={})
If there's an error code, we expect an error message.
Definition rpc.h:31
void operator()(Env &, JTx &jt) const
Definition rpc.h:45
STL namespace.
ErrorInfo const & getErrorInfo(ErrorCodeI code)
Returns an ErrorInfo that reflects the error code.
@ telENV_RPC_FAILED
Definition TER.h:54
ErrorCodeI
Definition ErrorCodes.h:23
Execution context for applying a JSON transaction.
Definition JTx.h:27
std::optional< TER > ter
Definition JTx.h:30
std::optional< std::pair< ErrorCodeI, std::string > > rpcCode
Definition JTx.h:31
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition JTx.h:32