3#include "data/BackendInterface.hpp"
6#include "rpc/common/Specs.hpp"
7#include "rpc/common/Types.hpp"
8#include "rpc/common/Validators.hpp"
9#include "util/AccountUtils.hpp"
11#include <boost/json/array.hpp>
12#include <boost/json/conversion.hpp>
13#include <boost/json/value.hpp>
14#include <xrpl/protocol/AccountID.h>
15#include <xrpl/protocol/ErrorCodes.h>
16#include <xrpl/protocol/PublicKey.h>
17#include <xrpl/protocol/STAmount.h>
18#include <xrpl/protocol/UintTypes.h>
19#include <xrpl/protocol/jss.h>
20#include <xrpl/protocol/tokens.h>
42 std::shared_ptr<BackendInterface> sharedPtrBackend_;
49 std::string ledgerHash;
51 std::string accountID;
52 bool overflow =
false;
53 std::map<ripple::Currency, ripple::STAmount> sums;
54 std::map<ripple::AccountID, std::vector<ripple::STAmount>> hotBalances;
55 std::map<ripple::AccountID, std::vector<ripple::STAmount>> assets;
56 std::map<ripple::AccountID, std::vector<ripple::STAmount>> frozenBalances;
57 std::map<ripple::Currency, ripple::STAmount> locked;
59 bool validated =
true;
67 std::set<ripple::AccountID> hotWallets;
68 std::optional<std::string> ledgerHash;
69 std::optional<uint32_t> ledgerIndex;
80 : sharedPtrBackend_(std::move(sharedPtrBackend))
91 spec([[maybe_unused]] uint32_t apiVersion)
93 auto const getHotWalletValidator = [](
RippledError errCode) {
95 [errCode](boost::json::value
const& value, std::string_view key) ->
MaybeError {
96 if (!value.is_string() && !value.is_array())
97 return Error{
Status{errCode, std::string(key) +
"NotStringOrArray"}};
101 value.is_array() ? value.as_array() : boost::json::array{value};
102 auto const getAccountID =
103 [](
auto const& j) -> std::optional<ripple::AccountID> {
106 ripple::TokenType::AccountPublic,
107 boost::json::value_to<std::string>(j)
111 return ripple::calcAccountID(*pk);
114 boost::json::value_to<std::string>(j)
121 for (
auto const& wallet : wallets) {
122 if (!getAccountID(wallet))
123 return Error{
Status{errCode, std::string(key) +
"Malformed"}};
131 static auto const kSPEC_COMMON =
RpcSpec{
137 static auto const kSPEC_V1 =
RpcSpec{
138 kSPEC_COMMON, {{JS(hotwallet), getHotWalletValidator(ripple::rpcINVALID_HOTWALLET)}}
140 static auto const kSPEC_V2 =
RpcSpec{
141 kSPEC_COMMON, {{JS(hotwallet), getHotWalletValidator(ripple::rpcINVALID_PARAMS)}}
144 return apiVersion == 1 ? kSPEC_V1 : kSPEC_V2;
165 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output
const& output);
174 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value
const& jv);
GatewayBalancesHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new GatewayBalancesHandler object.
Definition GatewayBalances.hpp:79
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:170
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition GatewayBalances.hpp:91
Result process(Input const &input, Context const &ctx) const
Process the GatewayBalances command.
Definition GatewayBalances.cpp:40
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: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
ripple::error_code_i RippledError
Clio uses compatible Rippled error codes for most RPC errors.
Definition Errors.hpp:54
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:36
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition Types.hpp:56
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:24
Context of an RPC call.
Definition Types.hpp:99
A struct to hold the output data of the command.
Definition GatewayBalances.hpp:48
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
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