Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AccountTx.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "etl/ETLServiceInterface.hpp"
5#include "rpc/Errors.hpp"
6#include "rpc/JS.hpp"
7#include "rpc/common/JsonBool.hpp"
8#include "rpc/common/MetaProcessors.hpp"
9#include "rpc/common/Modifiers.hpp"
10#include "rpc/common/Specs.hpp"
11#include "rpc/common/Types.hpp"
12#include "rpc/common/Validators.hpp"
13#include "util/TxUtils.hpp"
14#include "util/log/Logger.hpp"
15
16#include <boost/json/array.hpp>
17#include <boost/json/conversion.hpp>
18#include <boost/json/object.hpp>
19#include <boost/json/value.hpp>
20#include <xrpl/protocol/ErrorCodes.h>
21#include <xrpl/protocol/TxFormats.h>
22#include <xrpl/protocol/jss.h>
23
24#include <cstdint>
25#include <memory>
26#include <optional>
27#include <string>
28#include <unordered_set>
29
30namespace rpc {
31
39 util::Logger log_{"RPC"};
40 std::shared_ptr<BackendInterface> sharedPtrBackend_;
41 std::shared_ptr<etl::ETLServiceInterface const> etl_;
42
43public:
44 static constexpr auto kLIMIT_MIN = 1;
45 static constexpr auto kLIMIT_MAX = 1000;
46 static constexpr auto kLIMIT_DEFAULT = 200;
47
51 struct Marker {
52 uint32_t ledger;
53 uint32_t seq;
54 };
55
59 struct Output {
60 std::string account;
61 uint32_t ledgerIndexMin{0};
62 uint32_t ledgerIndexMax{0};
63 std::optional<uint32_t> limit;
64 std::optional<Marker> marker;
65 // TODO: use a better type than json
66 boost::json::array transactions;
67 // validated should be sent via framework
68 bool validated = true;
69 };
70
74 struct Input {
75 std::string account;
76 // You must use at least one of the following fields in your request:
77 // ledger_index, ledger_hash, ledger_index_min, or ledger_index_max.
78 std::optional<std::string> ledgerHash;
79 std::optional<uint32_t> ledgerIndex;
80 std::optional<int32_t> ledgerIndexMin;
81 std::optional<int32_t> ledgerIndexMax;
82 bool usingValidatedLedger = false;
83 JsonBool binary{false};
84 JsonBool forward{false};
85 std::optional<uint32_t> limit;
86 std::optional<Marker> marker;
87 std::optional<std::string> transactionTypeInLowercase;
88 };
89
90 using Result = HandlerReturnType<Output>;
91
99 std::shared_ptr<BackendInterface> sharedPtrBackend,
100 std::shared_ptr<etl::ETLServiceInterface const> const& etl
101 )
102 : sharedPtrBackend_(std::move(sharedPtrBackend)), etl_{etl}
103 {
104 }
105
112 static RpcSpecConstRef
113 spec([[maybe_unused]] uint32_t apiVersion)
114 {
115 auto const& typesKeysInLowercase = util::getTxTypesInLowercase();
116 static auto const kRPC_SPEC_FOR_V1 = RpcSpec{
120 {JS(ledger_index_min), validation::Type<int32_t>{}},
121 {JS(ledger_index_max), validation::Type<int32_t>{}},
122 {JS(ctid), validation::Type<std::string>{}},
123 {JS(limit),
125 validation::Min(1u),
126 modifiers::Clamp<int32_t>{kLIMIT_MIN, kLIMIT_MAX}},
127 {JS(marker),
130 Status{RippledError::rpcINVALID_PARAMS, "invalidMarker"},
131 },
135 }},
136 {
137 "tx_type",
141 typesKeysInLowercase.cbegin(), typesKeysInLowercase.cend()
142 ),
143 },
144 };
145
146 static auto const kRPC_SPEC = RpcSpec{
147 kRPC_SPEC_FOR_V1,
148 {
149 {JS(binary), validation::Type<bool>{}},
150 {JS(forward), validation::Type<bool>{}},
151 }
152 };
153
154 return apiVersion == 1 ? kRPC_SPEC_FOR_V1 : kRPC_SPEC;
155 }
156
164 Result
165 process(Input const& input, Context const& ctx) const;
166
167private:
174 friend void
175 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
176
183 friend Input
184 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
185
192 friend void
193 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Marker const& marker);
194};
195} // namespace rpc
Result process(Input const &input, Context const &ctx) const
Process the AccountTx command.
Definition AccountTx.cpp:36
AccountTxHandler(std::shared_ptr< BackendInterface > sharedPtrBackend, std::shared_ptr< etl::ETLServiceInterface const > const &etl)
Construct a new AccountTxHandler object.
Definition AccountTx.hpp:98
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition AccountTx.hpp:113
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition AccountTx.cpp:212
A meta-processor that acts as a spec for a sub-object/section.
Definition MetaProcessors.hpp:24
A meta-processor that wraps a validator and produces a custom error in case the wrapped validator fai...
Definition MetaProcessors.hpp:152
Clamp value between min and max.
Definition Modifiers.hpp:23
Validate that value is equal or greater than the specified min.
Definition Validators.hpp:205
Validates that the value is one of the values passed in.
Definition Validators.hpp:364
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:18
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:130
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:62
std::unordered_set< std::string > const & getTxTypesInLowercase()
Get the transaction types in lowercase.
Definition TxUtils.cpp:18
A struct to hold the input data for the command.
Definition AccountTx.hpp:74
A struct to hold the marker data.
Definition AccountTx.hpp:51
A struct to hold the output data of the command.
Definition AccountTx.hpp:59
Context of an RPC call.
Definition Types.hpp:99
A wrapper around bool that allows to convert from any JSON value.
Definition JsonBool.hpp:15
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:110
Represents a Specification of an entire RPC command.
Definition Specs.hpp:82
A status returned from any RPC handler.
Definition Errors.hpp:65
Convert input string to lower case.
Definition Modifiers.hpp:66
static CustomValidator accountValidator
Provides a commonly used validator for accounts.
Definition Validators.hpp:504
static CustomValidator ledgerIndexValidator
Provides a commonly used validator for ledger index.
Definition Validators.hpp:489
static CustomValidator uint256HexStringValidator
Provides a commonly used validator for uint256 hex string.
Definition Validators.hpp:551
A validator that simply requires a field to be present.
Definition Validators.hpp:28
Validates that the type of the value is one of the given types.
Definition Validators.hpp:128