Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AccountChannels.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/common/SpecBackend.hpp"
5#include "rpc/common/Types.hpp"
6
7#include <boost/json/conversion.hpp>
8#include <boost/json/value.hpp>
9#include <rpcspec/handlers/account_channels/Types.hpp>
10#include <xrpl/protocol/STLedgerEntry.h>
11
12#include <cstdint>
13#include <memory>
14#include <optional>
15#include <string>
16#include <utility>
17#include <vector>
18
19namespace rpc {
20
29 : public rpc::HandlerFor<rpc::spec::handlers::account_channels::Input> {
30 // dependencies
31 std::shared_ptr<BackendInterface> const sharedPtrBackend_;
32
33public:
37 static constexpr auto kLimitMin = rpc::spec::handlers::account_channels::kLimitMin;
41 static constexpr auto kLimitMax = rpc::spec::handlers::account_channels::kLimitMax;
45 static constexpr auto kLimitDefault = rpc::spec::handlers::account_channels::kLimitDefault;
46
53 std::string channelID;
54 std::string account;
55 std::string accountDestination;
56 std::string amount;
57 std::string balance;
58 std::optional<std::string> publicKey;
59 std::optional<std::string> publicKeyHex;
60 uint32_t settleDelay{};
61 std::optional<uint32_t> expiration;
62 std::optional<uint32_t> cancelAfter;
63 std::optional<uint32_t> sourceTag;
64 std::optional<uint32_t> destinationTag;
65 };
66
70 struct Output {
71 std::vector<ChannelResponse> channels;
72 std::string account;
73 std::string ledgerHash;
74 uint32_t ledgerIndex{};
75 // validated should be sent via framework
76 bool validated = true;
77 uint32_t limit{};
78 std::optional<std::string> marker;
79 };
80
85
91 AccountChannelsHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
92 : sharedPtrBackend_(std::move(sharedPtrBackend))
93 {
94 }
95
103 [[nodiscard]] Result
104 process(Input const& input, Context const& ctx) const;
105
106private:
107 static void
108 addChannel(std::vector<ChannelResponse>& jsonChannels, xrpl::SLE const& channelSle);
109
116 friend void
117 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
118
125 friend void
126 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, ChannelResponse const& channel);
127};
128} // namespace rpc
AccountChannelsHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new AccountChannelsHandler object.
Definition AccountChannels.hpp:91
static constexpr auto kLimitMax
Maximum accepted value for the limit request field.
Definition AccountChannels.hpp:41
static constexpr auto kLimitMin
Minimum accepted value for the limit request field.
Definition AccountChannels.hpp:37
Result process(Input const &input, Context const &ctx) const
Process the AccountChannels command.
Definition AccountChannels.cpp:67
HandlerReturnType< Output > Result
The result type of the command: the Output on success or an error Status.
Definition AccountChannels.hpp:84
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition AccountChannels.cpp:131
static constexpr auto kLimitDefault
Value of limit used when the request does not specify one.
Definition AccountChannels.hpp:45
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 data for one channel response.
Definition AccountChannels.hpp:52
std::string account
Source account that owns the channel.
Definition AccountChannels.hpp:54
uint32_t settleDelay
Seconds the source must wait before closing the channel.
Definition AccountChannels.hpp:60
std::string channelID
Unique ID of the payment channel (hex).
Definition AccountChannels.hpp:53
std::optional< std::string > publicKey
Channel public key, base58-encoded.
Definition AccountChannels.hpp:58
std::optional< uint32_t > expiration
Time after which the channel can be closed.
Definition AccountChannels.hpp:61
std::optional< uint32_t > destinationTag
Destination tag of the channel, if any.
Definition AccountChannels.hpp:64
std::string balance
XRP, in drops, already paid out of the channel.
Definition AccountChannels.hpp:57
std::string accountDestination
Destination account of the channel.
Definition AccountChannels.hpp:55
std::optional< uint32_t > sourceTag
Source tag of the channel, if any.
Definition AccountChannels.hpp:63
std::optional< std::string > publicKeyHex
Channel public key, hex-encoded.
Definition AccountChannels.hpp:59
std::string amount
Total XRP, in drops, allocated to the channel.
Definition AccountChannels.hpp:56
std::optional< uint32_t > cancelAfter
Immutable expiration time of the channel.
Definition AccountChannels.hpp:62
A struct to hold the output data of the command.
Definition AccountChannels.hpp:70
std::string account
The account whose channels are returned.
Definition AccountChannels.hpp:72
uint32_t limit
Maximum number of channels requested.
Definition AccountChannels.hpp:77
std::string ledgerHash
Hash of the ledger used for the request.
Definition AccountChannels.hpp:73
std::optional< std::string > marker
Pagination marker to resume from, if more results.
Definition AccountChannels.hpp:78
bool validated
Whether the ledger is validated.
Definition AccountChannels.hpp:76
std::vector< ChannelResponse > channels
Payment channels owned by the account.
Definition AccountChannels.hpp:71
uint32_t ledgerIndex
Sequence of the ledger used for the request.
Definition AccountChannels.hpp:74
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