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/common/SpecBackend.hpp"
6#include "rpc/common/Types.hpp"
7#include "util/log/Logger.hpp"
8
9#include <boost/json/array.hpp>
10#include <boost/json/conversion.hpp>
11#include <boost/json/object.hpp>
12#include <boost/json/value.hpp>
13#include <rpcspec/handlers/account_tx/Types.hpp>
14
15#include <cstdint>
16#include <expected>
17#include <memory>
18#include <optional>
19#include <string>
20#include <utility>
21
22namespace rpc {
23
30class AccountTxHandler : public rpc::HandlerFor<rpc::spec::handlers::account_tx::Input> {
31 util::Logger log_{"RPC"};
32 std::shared_ptr<BackendInterface> sharedPtrBackend_;
33 std::shared_ptr<etl::ETLServiceInterface const> etl_;
34
35public:
39 static constexpr auto kLimitMin = rpc::spec::handlers::account_tx::kLimitMin;
43 static constexpr auto kLimitMax = rpc::spec::handlers::account_tx::kLimitMax;
47 static constexpr auto kLimitDefault = rpc::spec::handlers::account_tx::kLimitDefault;
48
52 using Marker = rpc::spec::handlers::account_tx::Marker;
53
57 struct Output {
58 std::string account;
59 uint32_t ledgerIndexMin{0};
60 uint32_t ledgerIndexMax{0};
61 std::optional<uint32_t> limit;
62 std::optional<Marker> marker;
63 // TODO: use a better type than json
64 boost::json::array transactions;
65 // validated should be sent via framework
66 bool validated = true;
67 };
68
73
81 std::shared_ptr<BackendInterface> sharedPtrBackend,
82 std::shared_ptr<etl::ETLServiceInterface const> const& etl
83 )
84 : sharedPtrBackend_(std::move(sharedPtrBackend)), etl_{etl}
85 {
86 }
87
95 [[nodiscard]] Result
96 process(Input const& input, Context const& ctx) const;
97
98private:
105 friend void
106 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
107};
108
109} // namespace rpc
110
115
122void
123tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Marker const& marker);
124
125} // namespace rpc::spec::handlers::account_tx
Result process(Input const &input, Context const &ctx) const
Process the AccountTx command.
Definition AccountTx.cpp:39
AccountTxHandler(std::shared_ptr< BackendInterface > sharedPtrBackend, std::shared_ptr< etl::ETLServiceInterface const > const &etl)
Construct a new AccountTxHandler object.
Definition AccountTx.hpp:80
rpc::spec::handlers::account_tx::Marker Marker
Pagination marker identifying a transaction by ledger sequence and transaction index.
Definition AccountTx.hpp:52
static constexpr auto kLimitDefault
Value of limit used when the request does not specify one.
Definition AccountTx.hpp:47
HandlerReturnType< Output > Result
The result type of the command: the Output on success or an error Status.
Definition AccountTx.hpp:72
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:244
static constexpr auto kLimitMax
Maximum accepted value for the limit request field.
Definition AccountTx.hpp:43
static constexpr auto kLimitMin
Minimum accepted value for the limit request field.
Definition AccountTx.hpp:39
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
This namespace contains everything to do with the ETL and ETL sources.
Definition AmendmentBlockHandlerInterface.hpp:6
JSON conversions for the account_tx spec types used by AccountTxHandler.
Definition AccountTx.cpp:267
void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Marker const &marker)
Convert the Marker to a JSON object.
Definition AccountTx.cpp:270
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:17
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:63
spec::HandlerFor< InputT, boost::json::value > HandlerFor
The spec-driven base every typed handler inherits.
Definition SpecBackend.hpp:24
A struct to hold the output data of the command.
Definition AccountTx.hpp:57
std::string account
The account whose transactions are returned.
Definition AccountTx.hpp:58
uint32_t ledgerIndexMin
Lowest ledger sequence that was searched.
Definition AccountTx.hpp:59
std::optional< uint32_t > limit
Maximum number of transactions requested.
Definition AccountTx.hpp:61
boost::json::array transactions
Transactions affecting the account.
Definition AccountTx.hpp:64
bool validated
Whether the ledger range is validated.
Definition AccountTx.hpp:66
std::optional< Marker > marker
Pagination marker to resume from, if more results.
Definition AccountTx.hpp:62
uint32_t ledgerIndexMax
Highest ledger sequence that was searched.
Definition AccountTx.hpp:60
Context of an RPC call.
Definition Types.hpp:102
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:132