22#include "data/BackendInterface.hpp"
25#include "rpc/common/Specs.hpp"
26#include "rpc/common/Types.hpp"
27#include "rpc/common/Validators.hpp"
28#include "util/AccountUtils.hpp"
30#include <boost/json/array.hpp>
31#include <boost/json/conversion.hpp>
32#include <boost/json/value.hpp>
33#include <xrpl/protocol/AccountID.h>
34#include <xrpl/protocol/ErrorCodes.h>
35#include <xrpl/protocol/PublicKey.h>
36#include <xrpl/protocol/STAmount.h>
37#include <xrpl/protocol/UintTypes.h>
38#include <xrpl/protocol/jss.h>
39#include <xrpl/protocol/tokens.h>
61 std::shared_ptr<BackendInterface> sharedPtrBackend_;
68 std::string ledgerHash;
70 std::string accountID;
71 bool overflow =
false;
72 std::map<ripple::Currency, ripple::STAmount> sums;
73 std::map<ripple::AccountID, std::vector<ripple::STAmount>> hotBalances;
74 std::map<ripple::AccountID, std::vector<ripple::STAmount>> assets;
75 std::map<ripple::AccountID, std::vector<ripple::STAmount>> frozenBalances;
77 bool validated =
true;
85 std::set<ripple::AccountID> hotWallets;
86 std::optional<std::string> ledgerHash;
87 std::optional<uint32_t> ledgerIndex;
98 : sharedPtrBackend_(sharedPtrBackend)
109 spec([[maybe_unused]] uint32_t apiVersion)
111 auto const getHotWalletValidator = [](
RippledError errCode) {
113 [errCode](boost::json::value
const& value, std::string_view key) ->
MaybeError {
114 if (!value.is_string() && !value.is_array())
115 return Error{
Status{errCode, std::string(key) +
"NotStringOrArray"}};
118 auto const wallets = value.is_array() ? value.as_array() : boost::json::array{value};
119 auto const getAccountID = [](
auto const& j) -> std::optional<ripple::AccountID> {
122 ripple::TokenType::AccountPublic, boost::json::value_to<std::string>(j)
126 return ripple::calcAccountID(*pk);
134 for (
auto const& wallet : wallets) {
135 if (!getAccountID(wallet))
136 return Error{
Status{errCode, std::string(key) +
"Malformed"}};
144 static auto const kSPEC_COMMON =
RpcSpec{
150 auto static const kSPEC_V1 =
151 RpcSpec{kSPEC_COMMON, {{JS(hotwallet), getHotWalletValidator(ripple::rpcINVALID_HOTWALLET)}}};
152 auto static const kSPEC_V2 =
153 RpcSpec{kSPEC_COMMON, {{JS(hotwallet), getHotWalletValidator(ripple::rpcINVALID_PARAMS)}}};
155 return apiVersion == 1 ? kSPEC_V1 : kSPEC_V2;
176 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output
const& output);
185 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value
const& jv);
Handles the gateway_balances command.
Definition GatewayBalances.hpp:60
GatewayBalancesHandler(std::shared_ptr< BackendInterface > const &sharedPtrBackend)
Construct a new GatewayBalancesHandler object.
Definition GatewayBalances.hpp:97
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition GatewayBalances.cpp:156
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition GatewayBalances.hpp:109
Result process(Input input, Context const &ctx) const
Process the GatewayBalances command.
Definition GatewayBalances.cpp:59
A meta-validator that allows to specify a custom validation function.
Definition Validators.hpp:423
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:36
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:145
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:81
ripple::error_code_i RippledError
Clio uses compatible Rippled error codes for most RPC errors.
Definition Errors.hpp:71
std::expected< void, Status > MaybeError
Return type used for Validators that can return error but don't have specific value to return.
Definition Types.hpp:55
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition Types.hpp:75
std::optional< T > parseBase58Wrapper(std::string const &str)
A wrapper of parseBase58 function. It adds the check if all characters in the input string are alphan...
Definition AccountUtils.hpp:42
Context of an RPC call.
Definition Types.hpp:118
A struct to hold the output data of the command.
Definition GatewayBalances.hpp:67
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:129
Represents a Specification of an entire RPC command.
Definition Specs.hpp:98
A status returned from any RPC handler.
Definition Errors.hpp:82
static CustomValidator accountValidator
Provides a commonly used validator for accounts.
Definition Validators.hpp:491
static CustomValidator ledgerIndexValidator
Provides a commonly used validator for ledger index.
Definition Validators.hpp:484
static CustomValidator uint256HexStringValidator
Provides a commonly used validator for uint256 hex string.
Definition Validators.hpp:530
A validator that simply requires a field to be present.
Definition Validators.hpp:47