Add missing doxygen comments (#1223)

Fixes #1218
This commit is contained in:
Alex Kremer
2024-03-01 15:58:18 +00:00
committed by GitHub
parent b3e63b2491
commit a74970b81e
125 changed files with 2755 additions and 365 deletions

View File

@@ -34,7 +34,16 @@
namespace rpc {
/**
* @brief getAmmPoolHolds returns the balances of the amm asset pair.
* @brief getAmmPoolHolds returns the balances of the amm asset pair
*
* @param backend The backend to use
* @param sequence The sequence number to use
* @param ammAccountID The amm account
* @param issue1 The first issue
* @param issue2 The second issue
* @param freezeHandling Whether to return zeroes for frozen accounts
* @param yield The coroutine context
* @return The balances of the amm asset pair
*/
std::pair<ripple::STAmount, ripple::STAmount>
getAmmPoolHolds(
@@ -48,7 +57,16 @@ getAmmPoolHolds(
);
/**
* @brief getAmmLpHolds returns the lp token balance.
* @brief getAmmLpHolds returns the liquidity provider token balance
*
* @param backend The backend to use
* @param sequence The sequence number to use
* @param cur1 The first currency
* @param cur2 The second currency
* @param ammAccount The amm account
* @param lpAccount The lp account
* @param yield The coroutine context
* @return The lp token balance
*/
ripple::STAmount
getAmmLpHolds(
@@ -62,7 +80,14 @@ getAmmLpHolds(
);
/**
* @brief getAmmLpHolds returns the lp token balance.
* @brief getAmmLpHolds returns the liquidity provider token balance
*
* @param backend The backend to use
* @param sequence The sequence number to use
* @param ammSle The amm ledger entry
* @param lpAccount The lp account
* @param yield The coroutine context
* @return The lp token balance
*/
ripple::STAmount
getAmmLpHolds(

View File

@@ -75,7 +75,7 @@ public:
* @brief Computes all book_changes for the given transactions.
*
* @param transactions The transactions to compute book changes for
* @return std::vector<BookChange> Book changes
* @return Book changes
*/
[[nodiscard]] static std::vector<BookChange>
compute(std::vector<data::TransactionAndMetadata> const& transactions)
@@ -261,6 +261,7 @@ tag_invoke(boost::json::value_from_tag, boost::json::value& jv, BookChange const
*
* @param lgrInfo The ledger header
* @param transactions The vector of transactions with heir metadata
* @return The book changes
*/
[[nodiscard]] boost::json::object
computeBookChanges(ripple::LedgerHeader const& lgrInfo, std::vector<data::TransactionAndMetadata> const& transactions);

View File

@@ -109,6 +109,7 @@ public:
* @brief Increments the completed count for a particular RPC method.
*
* @param method The method to increment the count for
* @param rpcDuration The duration of the RPC call
*/
void
rpcComplete(std::string const& method, std::chrono::microseconds const& rpcDuration);

View File

@@ -37,13 +37,13 @@
using namespace std;
namespace {
template <class... Ts>
template <typename... Ts>
struct overloadSet : Ts... {
using Ts::operator()...;
};
// explicit deduction guide (not needed as of C++20, but clang be clang)
template <class... Ts>
template <typename... Ts>
overloadSet(Ts...) -> overloadSet<Ts...>;
} // namespace
@@ -107,7 +107,7 @@ getErrorInfo(ClioError code)
}
boost::json::object
makeError(RippledError err, optional<string_view> customError, optional<string_view> customMessage)
makeError(RippledError err, std::optional<std::string_view> customError, std::optional<std::string_view> customMessage)
{
boost::json::object json;
auto const& info = ripple::RPC::get_error_info(err);
@@ -122,7 +122,7 @@ makeError(RippledError err, optional<string_view> customError, optional<string_v
}
boost::json::object
makeError(ClioError err, optional<string_view> customError, optional<string_view> customMessage)
makeError(ClioError err, std::optional<std::string_view> customError, std::optional<std::string_view> customMessage)
{
boost::json::object json;
auto const& info = getErrorInfo(err);

View File

@@ -77,25 +77,61 @@ struct Status {
std::optional<boost::json::object> extraInfo;
Status() = default;
/**
* @brief Construct a new Status object
*
* @param code The error code
*/
/* implicit */ Status(CombinedError code) : code(code){};
/**
* @brief Construct a new Status object
*
* @param code The error code
* @param extraInfo The extra info
*/
Status(CombinedError code, boost::json::object&& extraInfo) : code(code), extraInfo(std::move(extraInfo)){};
// HACK. Some rippled handlers explicitly specify errors.
// This means that we have to be able to duplicate this functionality.
/**
* @brief Construct a new Status object with a custom message
*
* @note HACK. Some rippled handlers explicitly specify errors. This means that we have to be able to duplicate this
* functionality.
*
* @param message The message
*/
explicit Status(std::string message) : code(ripple::rpcUNKNOWN), message(std::move(message))
{
}
/**
* @brief Construct a new Status object
*
* @param code The error code
* @param message The message
*/
Status(CombinedError code, std::string message) : code(code), message(std::move(message))
{
}
/**
* @brief Construct a new Status object
*
* @param code The error code
* @param error The error
* @param message The message
*/
Status(CombinedError code, std::string error, std::string message)
: code(code), error(std::move(error)), message(std::move(message))
{
}
/** @brief Returns true if the Status is *not* OK. */
/**
* @brief Check if the status is not OK
*
* @return true if the status is not OK; false otherwise
*/
operator bool() const
{
if (auto err = std::get_if<RippledError>(&code))
@@ -141,6 +177,13 @@ enum WarningCode { warnUNKNOWN = -1, warnRPC_CLIO = 2001, warnRPC_OUTDATED = 200
/** @brief Holds information about a clio warning. */
struct WarningInfo {
constexpr WarningInfo() = default;
/**
* @brief Construct a new Warning Info object
*
* @param code The warning code
* @param message The warning message
*/
constexpr WarningInfo(WarningCode code, char const* message) : code(code), message(message)
{
}
@@ -154,10 +197,20 @@ class InvalidParamsError : public std::exception {
std::string msg;
public:
/**
* @brief Construct a new Invalid Params Error object
*
* @param msg The error message
*/
explicit InvalidParamsError(std::string msg) : msg(std::move(msg))
{
}
/**
* @brief Get the error message as a C string
*
* @return The error message
*/
char const*
what() const throw() override
{
@@ -170,10 +223,20 @@ class AccountNotFoundError : public std::exception {
std::string account;
public:
/**
* @brief Construct a new Account Not Found Error object
*
* @param acct The account
*/
explicit AccountNotFoundError(std::string acct) : account(std::move(acct))
{
}
/**
* @brief Get the error message as a C string
*
* @return The error message
*/
char const*
what() const throw() override
{
@@ -224,6 +287,8 @@ makeError(Status const& status);
* @brief Generate JSON from a @ref rpc::RippledError.
*
* @param err The rippled error
* @param customError A custom error
* @param customMessage A custom message
* @return The JSON output
*/
boost::json::object
@@ -237,6 +302,8 @@ makeError(
* @brief Generate JSON from a @ref rpc::ClioError.
*
* @param err The clio's custom error
* @param customError A custom error
* @param customMessage A custom message
* @return The JSON output
*/
boost::json::object

View File

@@ -47,10 +47,10 @@ util::Expected<web::Context, Status>
make_WsContext(
boost::asio::yield_context yc,
boost::json::object const& request,
shared_ptr<web::ConnectionBase> const& session,
TagDecoratorFactory const& tagFactory,
std::shared_ptr<web::ConnectionBase> const& session,
util::TagDecoratorFactory const& tagFactory,
data::LedgerRange const& range,
string const& clientIp,
std::string const& clientIp,
std::reference_wrapper<APIVersionParser const> apiVersionParser
)
{
@@ -76,9 +76,9 @@ Expected<web::Context, Status>
make_HttpContext(
boost::asio::yield_context yc,
boost::json::object const& request,
TagDecoratorFactory const& tagFactory,
util::TagDecoratorFactory const& tagFactory,
data::LedgerRange const& range,
string const& clientIp,
std::string const& clientIp,
std::reference_wrapper<APIVersionParser const> apiVersionParser,
bool const isAdmin
)

View File

@@ -54,6 +54,7 @@ namespace rpc {
* @param range The ledger range that is available at request time
* @param clientIp The IP address of the connected client
* @param apiVersionParser A parser that is used to parse out the "api_version" field
* @return A Websocket context or error Status
*/
util::Expected<web::Context, Status>
make_WsContext(
@@ -76,6 +77,7 @@ make_WsContext(
* @param clientIp The IP address of the connected client
* @param apiVersionParser A parser that is used to parse out the "api_version" field
* @param isAdmin Whether the connection has admin privileges
* @return A HTTP context or error Status
*/
util::Expected<web::Context, Status>
make_HttpContext(

View File

@@ -73,6 +73,16 @@ class RPCEngine {
impl::ForwardingProxy<etl::LoadBalancer, Counters, HandlerProvider> forwardingProxy_;
public:
/**
* @brief Construct a new RPCEngine object
*
* @param backend The backend to use
* @param balancer The load balancer to use
* @param dosGuard The DOS guard to use
* @param workQueue The work queue to use
* @param counters The counters to use
* @param handlerProvider The handler provider to use
*/
RPCEngine(
std::shared_ptr<BackendInterface> const& backend,
std::shared_ptr<etl::LoadBalancer> const& balancer,
@@ -90,6 +100,17 @@ public:
{
}
/**
* @brief Factory function to create a new instance of the RPC engine.
*
* @param backend The backend to use
* @param balancer The load balancer to use
* @param dosGuard The DOS guard to use
* @param workQueue The work queue to use
* @param counters The counters to use
* @param handlerProvider The handler provider to use
* @return A new instance of the RPC engine
*/
static std::shared_ptr<RPCEngine>
make_RPCEngine(
std::shared_ptr<BackendInterface> const& backend,
@@ -159,6 +180,7 @@ public:
* @tparam FnType The type of function
* @param func The lambda to execute when this request is handled
* @param ip The ip address for which this request is being executed
* @return true if the request was successfully scheduled; false otherwise
*/
template <typename FnType>
bool

View File

@@ -795,105 +795,6 @@ parseRippleLibSeed(boost::json::value const& value)
return {};
}
std::variant<Status, std::pair<ripple::PublicKey, ripple::SecretKey>>
keypairFromRequst(boost::json::object const& request)
{
bool const has_key_type = request.contains("key_type");
// All of the secret types we allow, but only one at a time.
// The array should be constexpr, but that makes Visual Studio unhappy.
static std::string const secretTypes[]{"passphrase", "secret", "seed", "seed_hex"};
// Identify which secret type is in use.
std::string secretType;
int count = 0;
for (auto const& t : secretTypes) {
if (request.contains(t)) {
++count;
secretType = t;
}
}
if (count == 0)
return Status{RippledError::rpcINVALID_PARAMS, "missing field secret"};
if (count > 1) {
return Status{
RippledError::rpcINVALID_PARAMS,
"Exactly one of the following must be specified: passphrase, secret, seed, or seed_hex"
};
}
std::optional<ripple::KeyType> keyType;
std::optional<ripple::Seed> seed;
if (has_key_type) {
if (!request.at("key_type").is_string())
return Status{RippledError::rpcINVALID_PARAMS, "keyTypeNotString"};
auto const key_type = boost::json::value_to<std::string>(request.at("key_type"));
keyType = ripple::keyTypeFromString(key_type);
if (!keyType)
return Status{RippledError::rpcINVALID_PARAMS, "invalidFieldKeyType"};
if (secretType == "secret")
return Status{RippledError::rpcINVALID_PARAMS, "The secret field is not allowed if key_type is used."};
}
// ripple-lib encodes seed used to generate an Ed25519 wallet in a
// non-standard way. While we never encode seeds that way, we try
// to detect such keys to avoid user confusion.
if (secretType != "seed_hex") {
seed = parseRippleLibSeed(request.at(secretType));
if (seed) {
// If the user passed in an Ed25519 seed but *explicitly*
// requested another key type, return an error.
if (keyType.value_or(ripple::KeyType::ed25519) != ripple::KeyType::ed25519)
return Status{RippledError::rpcINVALID_PARAMS, "Specified seed is for an Ed25519 wallet."};
keyType = ripple::KeyType::ed25519;
}
}
if (!keyType)
keyType = ripple::KeyType::secp256k1;
if (!seed) {
if (has_key_type) {
if (!request.at(secretType).is_string())
return Status{RippledError::rpcINVALID_PARAMS, "secret value must be string"};
auto const key = boost::json::value_to<std::string>(request.at(secretType));
if (secretType == "seed") {
seed = ripple::parseBase58<ripple::Seed>(key);
} else if (secretType == "passphrase") {
seed = ripple::parseGenericSeed(key);
} else if (secretType == "seed_hex") {
ripple::uint128 s;
if (s.parseHex(key))
seed.emplace(ripple::Slice(s.data(), ripple::uint128::size()));
}
} else {
if (!request.at("secret").is_string())
return Status{RippledError::rpcINVALID_PARAMS, "field secret should be a string"};
auto const secret = boost::json::value_to<std::string>(request.at("secret"));
seed = ripple::parseGenericSeed(secret);
}
}
if (!seed)
return Status{RippledError::rpcBAD_SEED, "Bad Seed: invalid field message secretType"};
if (keyType != ripple::KeyType::secp256k1 && keyType != ripple::KeyType::ed25519)
return Status{RippledError::rpcINVALID_PARAMS, "keypairForSignature: invalid key type"};
return generateKeyPair(*keyType, *seed);
}
std::vector<ripple::AccountID>
getAccountsFromTransaction(boost::json::object const& transaction)
{

View File

@@ -75,34 +75,76 @@
namespace rpc {
/** @brief Enum for NFT json manipulation */
enum class NFTokenjson { ENABLE, DISABLE };
/**
* @brief Get a ripple::AccountID from its string representation
*
* @param account The string representation of the account
* @return The account ID or std::nullopt if the string is not a valid account
*/
std::optional<ripple::AccountID>
accountFromStringStrict(std::string const& account);
/**
* @brief Check whether the SLE is owned by the account
*
* @param sle The ledger entry
* @param accountID The account ID
* @return true if the SLE is owned by the account
*/
bool
isOwnedByAccount(ripple::SLE const& sle, ripple::AccountID const& accountID);
/**
* @brief Get the start hint for the account
*
* @param sle The ledger entry
* @param accountID The account ID
* @return The start hint
*/
std::uint64_t
getStartHint(ripple::SLE const& sle, ripple::AccountID const& accountID);
/**
* @brief Parse the account cursor from the JSON
*
* @param jsonCursor The JSON cursor
* @return The parsed account cursor
*/
std::optional<AccountCursor>
parseAccountCursor(std::optional<std::string> jsonCursor);
// TODO this function should probably be in a different file and namespace
/**
* @brief Deserialize a TransactionAndMetadata into a pair of STTx and STObject
*
* @param blobs The TransactionAndMetadata to deserialize
* @return The deserialized objects
*/
std::pair<std::shared_ptr<ripple::STTx const>, std::shared_ptr<ripple::STObject const>>
deserializeTxPlusMeta(data::TransactionAndMetadata const& blobs);
// TODO this function should probably be in a different file and namespace
/**
* @brief Deserialize a TransactionAndMetadata into a pair of STTx and TxMeta
*
* @param blobs The TransactionAndMetadata to deserialize
* @param seq The sequence number to set
* @return The deserialized objects
*/
std::pair<std::shared_ptr<ripple::STTx const>, std::shared_ptr<ripple::TxMeta const>>
deserializeTxPlusMeta(data::TransactionAndMetadata const& blobs, std::uint32_t seq);
/**
* @brief Convert a TransactionAndMetadata to two JSON objects.
* @brief Convert a TransactionAndMetadata to two JSON objects
*
* @param blobs The TransactionAndMetadata to convert.
* @param nftEnabled Whether to include NFT information in the JSON.
* @param networkId The network ID to use for ctid, not include ctid if nullopt.
* @param blobs The TransactionAndMetadata to convert
* @param apiVersion The api version to generate the JSON for
* @param nftEnabled Whether to include NFT information in the JSON
* @param networkId The network ID to use for ctid, not include ctid if nullopt
* @return The JSON objects
*/
std::pair<boost::json::object, boost::json::object>
toExpandedJson(
@@ -131,6 +173,15 @@ toJsonWithBinaryTx(data::TransactionAndMetadata const& txnPlusMeta, std::uint32_
void
insertDeliverMaxAlias(boost::json::object& txJson, std::uint32_t apiVersion);
/**
* @brief Add "DeliveredAmount" to the transaction json object
*
* @param metaJson The metadata json object to add "DeliveredAmount"
* @param txn The transaction object
* @param meta The metadata object
* @param date The date of the ledger
* @return true if the "DeliveredAmount" is added to the metadata json object
*/
bool
insertDeliveredAmount(
boost::json::object& metaJson,
@@ -139,9 +190,21 @@ insertDeliveredAmount(
uint32_t date
);
/**
* @brief Convert STBase object to JSON
*
* @param obj The object to convert
* @return The JSON object
*/
boost::json::object
toJson(ripple::STBase const& obj);
/**
* @brief Convert SLE to JSON
*
* @param sle The ledger entry to convert
* @return The JSON object
*/
boost::json::object
toJson(ripple::SLE const& sle);
@@ -156,13 +219,35 @@ toJson(ripple::SLE const& sle);
boost::json::object
toJson(ripple::LedgerHeader const& info, bool binary, std::uint32_t apiVersion);
/**
* @brief Convert a TxMeta to JSON object.
*
* @param meta The TxMeta to convert.
* @return The JSON object.
*/
boost::json::object
toJson(ripple::TxMeta const& meta);
using RippledJson = Json::Value;
/**
* @brief Convert a RippledJson to boost::json::value
*
* @param value The RippledJson to convert
* @return The JSON value
*/
boost::json::value
toBoostJson(RippledJson const& value);
/**
* @brief Generate a JSON object to publish ledger message
*
* @param lgrInfo The ledger header
* @param fees The fees
* @param ledgerRange The ledger range
* @param txnCount The transaction count
* @return The JSON object
*/
boost::json::object
generatePubLedgerMessage(
ripple::LedgerHeader const& lgrInfo,
@@ -171,9 +256,26 @@ generatePubLedgerMessage(
std::uint32_t txnCount
);
/**
* @brief Get ledger info from the request
*
* @param backend The backend to use
* @param ctx The context of the request
* @return The ledger info or an error status
*/
std::variant<Status, ripple::LedgerHeader>
ledgerInfoFromRequest(std::shared_ptr<data::BackendInterface const> const& backend, web::Context const& ctx);
/**
* @brief Get ledger info from hash or sequence
*
* @param backend The backend to use
* @param yield The coroutine context
* @param ledgerHash The optional ledger hash
* @param ledgerIndex The optional ledger index
* @param maxSeq The maximum sequence to search
* @return The ledger info or an error status
*/
std::variant<Status, ripple::LedgerHeader>
getLedgerInfoFromHashOrSeq(
BackendInterface const& backend,
@@ -183,6 +285,19 @@ getLedgerInfoFromHashOrSeq(
uint32_t maxSeq
);
/**
* @brief Traverse nodes owned by an account
*
* @param backend The backend to use
* @param owner The keylet of the owner
* @param hexMarker The marker
* @param startHint The start hint
* @param sequence The sequence
* @param limit The limit of nodes to traverse
* @param yield The coroutine context
* @param atOwnedNode The function to call for each owned node
* @return The status or the account cursor
*/
std::variant<Status, AccountCursor>
traverseOwnedNodes(
BackendInterface const& backend,
@@ -195,8 +310,21 @@ traverseOwnedNodes(
std::function<void(ripple::SLE)> atOwnedNode
);
// Remove the account check from traverseOwnedNodes
// Account check has been done by framework,remove it from internal function
/**
* @brief Traverse nodes owned by an account
*
* @note Like the other one but removes the account check
*
* @param backend The backend to use
* @param accountID The account ID
* @param sequence The sequence
* @param limit The limit of nodes to traverse
* @param jsonCursor The optional JSON cursor
* @param yield The coroutine context
* @param atOwnedNode The function to call for each owned node
* @param nftIncluded Whether to include NFTs
* @return The status or the account cursor
*/
std::variant<Status, AccountCursor>
traverseOwnedNodes(
BackendInterface const& backend,
@@ -209,6 +337,15 @@ traverseOwnedNodes(
bool nftIncluded = false
);
/**
* @brief Read SLE from the backend
*
* @param backend The backend to use
* @param keylet The keylet to read
* @param lgrInfo The ledger header
* @param context The context of the request
* @return The SLE or nullptr if not found
*/
std::shared_ptr<ripple::SLE const>
read(
std::shared_ptr<data::BackendInterface const> const& backend,
@@ -217,15 +354,34 @@ read(
web::Context const& context
);
std::variant<Status, std::pair<ripple::PublicKey, ripple::SecretKey>>
keypairFromRequst(boost::json::object const& request);
/**
* @brief Get the account associated with a transaction
*
* @param transaction The transaction
* @return A vector of accounts associated with the transaction
*/
std::vector<ripple::AccountID>
getAccountsFromTransaction(boost::json::object const& transaction);
/**
* @brief Convert a ledger header to a blob
*
* @param info The ledger header
* @param includeHash Whether to include the hash
* @return The blob
*/
std::vector<unsigned char>
ledgerInfoToBlob(ripple::LedgerHeader const& info, bool includeHash = false);
/**
* @brief Whether global frozen is set
*
* @param backend The backend to use
* @param seq The ledger sequence
* @param issuer The issuer
* @param yield The coroutine context
* @return true if the global frozen is set; false otherwise
*/
bool
isGlobalFrozen(
BackendInterface const& backend,
@@ -234,6 +390,17 @@ isGlobalFrozen(
boost::asio::yield_context yield
);
/**
* @brief Whether the account is frozen
*
* @param backend The backend to use
* @param sequence The sequence
* @param account The account
* @param currency The currency
* @param issuer The issuer
* @param yield The coroutine context
* @return true if the account is frozen; false otherwise
*/
bool
isFrozen(
BackendInterface const& backend,
@@ -244,6 +411,16 @@ isFrozen(
boost::asio::yield_context yield
);
/**
* @brief Get the account funds
*
* @param backend The backend to use
* @param sequence The sequence
* @param amount The amount
* @param id The account ID
* @param yield The coroutine context
* @return The account funds
*/
ripple::STAmount
accountFunds(
BackendInterface const& backend,
@@ -253,6 +430,18 @@ accountFunds(
boost::asio::yield_context yield
);
/**
* @brief Get the amount that an account holds
*
* @param backend The backend to use
* @param sequence The sequence
* @param account The account
* @param currency The currency
* @param issuer The issuer
* @param zeroIfFrozen Whether to return zero if frozen
* @param yield The coroutine context
* @return The amount account holds
*/
ripple::STAmount
accountHolds(
BackendInterface const& backend,
@@ -264,6 +453,15 @@ accountHolds(
boost::asio::yield_context yield
);
/**
* @brief Get the transfer rate
*
* @param backend The backend to use
* @param sequence The sequence
* @param issuer The issuer
* @param yield The coroutine context
* @return The transfer rate
*/
ripple::Rate
transferRate(
BackendInterface const& backend,
@@ -272,6 +470,15 @@ transferRate(
boost::asio::yield_context yield
);
/**
* @brief Get the XRP liquidity
*
* @param backend The backend to use
* @param sequence The sequence
* @param id The account ID
* @param yield The coroutine context
* @return The XRP liquidity
*/
ripple::XRPAmount
xrpLiquid(
BackendInterface const& backend,
@@ -280,6 +487,17 @@ xrpLiquid(
boost::asio::yield_context yield
);
/**
* @brief Post process an order book
*
* @param offers The offers
* @param book The book
* @param takerID The taker ID
* @param backend The backend to use
* @param ledgerSequence The ledger sequence
* @param yield The coroutine context
* @return The post processed order book
*/
boost::json::array
postProcessOrderBook(
std::vector<data::LedgerObject> const& offers,
@@ -290,12 +508,33 @@ postProcessOrderBook(
boost::asio::yield_context yield
);
/**
* @brief Parse the book from the request
*
* @param pays The currency to pay
* @param payIssuer The issuer of the currency to pay
* @param gets The currency to get
* @param getIssuer The issuer of the currency to get
* @return The book or an error status
*/
std::variant<Status, ripple::Book>
parseBook(ripple::Currency pays, ripple::AccountID payIssuer, ripple::Currency gets, ripple::AccountID getIssuer);
/**
* @brief Parse the book from the request
*
* @param request The request
* @return The book or an error status
*/
std::variant<Status, ripple::Book>
parseBook(boost::json::object const& request);
/**
* @brief Parse the taker from the request
*
* @param taker The taker as json
* @return The taker account or an error status
*/
std::variant<Status, ripple::AccountID>
parseTaker(boost::json::value const& taker);
@@ -309,12 +548,32 @@ parseTaker(boost::json::value const& taker);
ripple::Issue
parseIssue(boost::json::object const& issue);
/**
* @brief Check whethe the request specifies the `current` or `closed` ledger
* @param request The request to check
* @return true if the request specifies the `current` or `closed` ledger
*/
bool
specifiesCurrentOrClosedLedger(boost::json::object const& request);
/**
* @brief Get the NFTID from the request
*
* @param request The request
* @return The NFTID or an error status
*/
std::variant<ripple::uint256, Status>
getNFTID(boost::json::object const& request);
/**
* @brief Check if the amendment is enabled
*
* @param backend The backend to use
* @param yield The yield context
* @param seq The ledger sequence
* @param amendmentId The amendment ID
* @return true if the amendment is enabled
*/
bool
isAmendmentEnabled(
std::shared_ptr<data::BackendInterface const> const& backend,
@@ -323,9 +582,24 @@ isAmendmentEnabled(
ripple::uint256 amendmentId
);
/**
* @brief Encode CTID as string
*
* @param ledgerSeq The ledger sequence
* @param txnIndex The transaction index
* @param networkId The network ID
* @return The encoded CTID or std::nullopt if the input is invalid
*/
std::optional<std::string>
encodeCTID(uint32_t ledgerSeq, uint16_t txnIndex, uint16_t networkId) noexcept;
/**
* @brief Decode the CTID from a string or a uint64_t
*
* @tparam T The type of the CTID
* @param ctid The CTID to decode
* @return The decoded CTID
*/
template <typename T>
inline std::optional<std::tuple<uint32_t, uint16_t, uint16_t>>
decodeCTID(T const ctid) noexcept
@@ -363,7 +637,14 @@ decodeCTID(T const ctid) noexcept
return {{ledgerSeq, txnIndex, networkId}};
}
template <class T>
/**
* @brief Log the duration of the request processing
*
* @tparam T The type of the duration
* @param ctx The context of the request
* @param dur The duration to log
*/
template <typename T>
void
logDuration(web::Context const& ctx, T const& dur)
{
@@ -386,4 +667,75 @@ logDuration(web::Context const& ctx, T const& dur)
LOG(log.info()) << ctx.tag() << msg;
}
/**
* @brief Parse a ripple-lib seed
*
* @param value JSON value to parse from
* @return The parsed seed if successful; std::nullopt otherwise
*/
std::optional<ripple::Seed>
parseRippleLibSeed(boost::json::value const& value);
/**
* @brief Traverse NFT objects and call the callback for each owned node
*
* @param backend The backend to use
* @param sequence The sequence
* @param accountID The account ID
* @param nextPage The next page
* @param limit The limit
* @param yield The coroutine context
* @param atOwnedNode The function to call for each owned node
* @return The account cursor or an error status
*/
std::variant<Status, AccountCursor>
traverseNFTObjects(
BackendInterface const& backend,
std::uint32_t sequence,
ripple::AccountID const& accountID,
ripple::uint256 nextPage,
std::uint32_t limit,
boost::asio::yield_context yield,
std::function<void(ripple::SLE)> atOwnedNode
);
/**
* @brief Parse the string as a uint32_t
*
* @param value The string to parse
* @return The parsed value or std::nullopt if the string is not a valid uint32_t
*/
std::optional<std::uint32_t>
parseStringAsUInt(std::string const& value); // TODO: move to string utils or something?
/**
* @brief Whether the transaction can have a delivered amount
*
* @param txn The transaction
* @param meta The metadata
* @return true if the transaction can have a delivered amount
*/
bool
canHaveDeliveredAmount(
std::shared_ptr<ripple::STTx const> const& txn,
std::shared_ptr<ripple::TxMeta const> const& meta
);
/**
* @brief Get the delivered amount
*
* @param txn The transaction
* @param meta The metadata
* @param ledgerSequence The sequence
* @param date The date of the ledger
* @return The delivered amount or std::nullopt if not available
*/
std::optional<ripple::STAmount>
getDeliveredAmount(
std::shared_ptr<ripple::STTx const> const& txn,
std::shared_ptr<ripple::TxMeta const> const& meta,
std::uint32_t const ledgerSequence,
uint32_t date
);
} // namespace rpc

View File

@@ -66,6 +66,7 @@ public:
* @brief A factory function that creates the work queue based on a config.
*
* @param config The Clio config to use
* @return The work queue
*/
static WorkQueue
make_WorkQueue(util::Config const& config)

View File

@@ -51,6 +51,7 @@ public:
{
}
/** @cond */
~AnyHandler() = default;
AnyHandler(AnyHandler const& other) : pimpl_{other.pimpl_->clone()}
{
@@ -67,6 +68,7 @@ public:
AnyHandler(AnyHandler&&) = default;
AnyHandler&
operator=(AnyHandler&&) = default;
/** @endcond */
/**
* @brief Process incoming JSON by the stored handler

View File

@@ -33,12 +33,30 @@ class HandlerProvider {
public:
virtual ~HandlerProvider() = default;
/**
* @brief Check if the provider contains a handler for a given method
*
* @param command The method to check for
* @return true if the provider contains a handler for the method, false otherwise
*/
virtual bool
contains(std::string const& method) const = 0;
contains(std::string const& command) const = 0;
/**
* @brief Get the handler for a given method
*
* @param command The method to get the handler for
* @return The handler for the method, or std::nullopt if the method is not found
*/
virtual std::optional<AnyHandler>
getHandler(std::string const& command) const = 0;
/**
* @brief Check if a given method is Clio-only
*
* @param command The method to check
* @return true if the method is Clio-only, false otherwise
*/
virtual bool
isClioOnly(std::string const& command) const = 0;
};

View File

@@ -34,12 +34,20 @@ namespace rpc {
struct JsonBool {
bool value = false;
/** @cond */
operator bool() const
{
return value;
}
/** @endcond */
};
/**
* @brief Convert a JSON value to a JsonBool
*
* @param jsonValue The JSON value to convert
* @return The converted JsonBool
*/
inline JsonBool
tag_invoke(boost::json::value_to_tag<JsonBool> const&, boost::json::value const& jsonValue)
{

View File

@@ -168,6 +168,9 @@ public:
/**
* @brief Constructs a validator that calls the given validator `req` and returns a custom error `err` in case `req`
* fails.
*
* @param req The requirement to validate against
* @param err The custom error to return in case `req` fails
*/
WithCustomError(SomeRequirement req, Status err) : requirement{std::move(req)}, error{std::move(err)}
{

View File

@@ -106,12 +106,22 @@ struct AccountCursor {
ripple::uint256 index;
std::uint32_t hint{};
/**
* @brief Convert the cursor to a string
*
* @return The string representation of the cursor
*/
std::string
toString() const
{
return ripple::strHex(index) + "," + std::to_string(hint);
}
/**
* @brief Check if the cursor is non-zero
*
* @return true if the cursor is non-zero, false otherwise
*/
bool
isNonZero() const
{
@@ -119,6 +129,13 @@ struct AccountCursor {
}
};
/**
* @brief Convert an empty output to a JSON object
*
* @note Always generates empty JSON object
*
* @param [out] jv The JSON object to convert to
*/
inline void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, VoidOutput const&)
{

View File

@@ -81,6 +81,13 @@ template <typename Expected>
* @brief A validator that simply requires a field to be present.
*/
struct Required final {
/**
* @brief Verify that the JSON value is present and not null.
*
* @param value The JSON value representing the outer object
* @param key The key used to retrieve the tested value from the outer object
* @return An error if validation failed; otherwise no error is returned
*/
[[nodiscard]] static MaybeError
verify(boost::json::value const& value, std::string_view key);
};
@@ -386,7 +393,7 @@ public:
*
* @param begin,end the range to copy the elements from
*/
template <class InputIt>
template <typename InputIt>
explicit OneOf(InputIt begin, InputIt end) : options_{begin, end}
{
}

View File

@@ -63,7 +63,7 @@ public:
);
bool
contains(std::string const& method) const override;
contains(std::string const& command) const override;
std::optional<AnyHandler>
getHandler(std::string const& command) const override;

View File

@@ -44,6 +44,9 @@ class AMMInfoHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
// todo: use better type than json types
boost::json::value amount1;
@@ -61,6 +64,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::optional<ripple::AccountID> accountID;
std::optional<ripple::AccountID> ammAccount;
@@ -72,20 +78,50 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AMMInfoHandler object
*
* @param sharedPtrBackend The backend to use
*/
AMMInfoHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion);
/**
* @brief Process the AMMInfo command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -55,7 +55,11 @@ public:
static constexpr auto LIMIT_MAX = 400;
static constexpr auto LIMIT_DEFAULT = 200;
// type align with SField.h
/**
* @brief A struct to hold data for one channel response
*
* @note type aligned with SField.h
*/
struct ChannelResponse {
std::string channelID;
std::string account;
@@ -71,6 +75,9 @@ public:
std::optional<uint32_t> destinationTag;
};
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::vector<ChannelResponse> channels;
std::string account;
@@ -82,6 +89,9 @@ public:
std::optional<std::string> marker;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
std::optional<std::string> destinationAccount;
@@ -93,11 +103,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AccountChannelsHandler object
*
* @param sharedPtrBackend The backend to use
*/
AccountChannelsHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -116,6 +137,13 @@ public:
return rpcSpec;
}
/**
* @brief Process the AccountChannels command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
@@ -123,12 +151,30 @@ private:
static void
addChannel(std::vector<ChannelResponse>& jsonChannels, ripple::SLE const& channelSle);
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
/**
* @brief Convert the ChannelResponse to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param channel The channel response to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, ChannelResponse const& channel);
};

View File

@@ -48,6 +48,9 @@ class AccountCurrenciesHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string ledgerHash;
uint32_t ledgerIndex{};
@@ -57,6 +60,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
std::optional<std::string> ledgerHash;
@@ -65,11 +71,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AccountCurrenciesHandler object
*
* @param sharedPtrBackend The backend to use
*/
AccountCurrenciesHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -82,13 +99,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the AccountCurrencies command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -49,6 +49,9 @@ class AccountInfoHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
uint32_t ledgerIndex;
std::string ledgerHash;
@@ -60,6 +63,17 @@ public:
// validated should be sent via framework
bool validated = true;
/**
* @brief Construct a new Output object
*
* @param ledgerId The ledger index
* @param ledgerHash The ledger hash
* @param sle The account data
* @param isDisallowIncomingEnabled Whether disallow incoming is enabled
* @param isClawbackEnabled Whether clawback is enabled
* @param version The API version
* @param signerLists The signer lists
*/
Output(
uint32_t ledgerId,
std::string ledgerHash,
@@ -80,8 +94,12 @@ public:
}
};
// "queue" is not available in Reporting mode
// "ident" is deprecated, keep it for now, in line with rippled
/**
* @brief A struct to hold the input data for the command
*
* `queue` is not available in Reporting mode
* `ident` is deprecated, keep it for now, in line with rippled
*/
struct Input {
std::optional<std::string> account;
std::optional<std::string> ident;
@@ -92,10 +110,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AccountInfoHandler object
*
* @param sharedPtrBackend The backend to use
*/
AccountInfoHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -111,13 +140,32 @@ public:
return apiVersion == 1 ? rpcSpecV1 : rpcSpec;
}
/**
* @brief Process the AccountInfo command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -57,6 +57,9 @@ public:
static auto constexpr LIMIT_MAX = 400;
static auto constexpr LIMIT_DEFAULT = 200;
/**
* @brief A struct to hold data for one line response
*/
struct LineResponse {
std::string account;
std::string balance;
@@ -73,6 +76,9 @@ public:
std::optional<bool> freezePeer;
};
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string account;
std::vector<LineResponse> lines;
@@ -83,6 +89,9 @@ public:
uint32_t limit{};
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
std::optional<std::string> ledgerHash;
@@ -96,10 +105,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AccountLinesHandler object
*
* @param sharedPtrBackend The backend to use
*/
AccountLinesHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -121,6 +141,13 @@ public:
return rpcSpec;
}
/**
* @brief Process the AccountLines command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
@@ -134,12 +161,30 @@ private:
);
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
/**
* @brief Convert the LineResponse to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param line The line response to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, LineResponse const& line);
};

View File

@@ -51,6 +51,9 @@ public:
static auto constexpr LIMIT_MAX = 400;
static auto constexpr LIMIT_DEFAULT = 100;
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string account;
std::string ledgerHash;
@@ -62,6 +65,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
std::optional<std::string> ledgerHash;
@@ -72,10 +78,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AccountNFTsHandler object
*
* @param sharedPtrBackend The backend to use
*/
AccountNFTsHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -93,13 +110,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the AccountNFTs command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -64,6 +64,9 @@ public:
static auto constexpr LIMIT_MAX = 400;
static auto constexpr LIMIT_DEFAULT = 200;
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string account;
std::string ledgerHash;
@@ -74,6 +77,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
std::optional<std::string> ledgerHash;
@@ -86,11 +92,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AccountObjectsHandler object
*
* @param sharedPtrBackend The backend to use
*/
AccountObjectsHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -113,13 +130,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the AccountObjects command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -53,6 +53,9 @@ public:
static auto constexpr LIMIT_MAX = 400;
static auto constexpr LIMIT_DEFAULT = 200;
/**
* @brief A struct to hold data for one offer response
*/
struct Offer {
uint32_t flags{};
uint32_t seq{};
@@ -62,6 +65,9 @@ public:
std::optional<uint32_t> expiration;
};
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string account;
std::string ledgerHash;
@@ -72,6 +78,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
std::optional<std::string> ledgerHash;
@@ -82,11 +91,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AccountOffersHandler object
*
* @param sharedPtrBackend The backend to use
*/
AccountOffersHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -104,6 +124,13 @@ public:
return rpcSpec;
}
/**
* @brief Process the AccountOffers command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
@@ -111,12 +138,30 @@ private:
static void
addOffer(std::vector<Offer>& offers, ripple::SLE const& offerSle);
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
/**
* @brief Convert the Offer to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param offer The offer to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Offer const& offer);
};

View File

@@ -61,11 +61,17 @@ public:
static auto constexpr LIMIT_MIN = 1;
static auto constexpr LIMIT_DEFAULT = 200;
/**
* @brief A struct to hold the marker data
*/
struct Marker {
uint32_t ledger;
uint32_t seq;
};
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string account;
uint32_t ledgerIndexMin{0};
@@ -78,6 +84,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
// You must use at least one of the following fields in your request:
@@ -96,10 +105,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new AccountTxHandler object
*
* @param sharedPtrBackend The backend to use
*/
AccountTxHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -142,16 +162,41 @@ public:
return apiVersion == 1 ? rpcSpecForV1 : rpcSpec;
}
/**
* @brief Process the AccountTx command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
/**
* @brief Convert the Marker to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param marker The marker to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Marker const& marker);
};

View File

@@ -47,6 +47,9 @@ class BookChangesHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string ledgerHash;
uint32_t ledgerIndex{};
@@ -55,7 +58,11 @@ public:
bool validated = true;
};
// Clio does not implement deletion_blockers_only
/**
* @brief A struct to hold the input data for the command
*
* @note Clio does not implement `deletion_blockers_only`
*/
struct Input {
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
@@ -63,10 +70,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new BookChangesHandler object
*
* @param sharedPtrBackend The backend to use
*/
BookChangesHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -78,13 +96,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the BookChanges command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -57,6 +57,9 @@ public:
static auto constexpr LIMIT_MAX = 100;
static auto constexpr LIMIT_DEFAULT = 60;
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string ledgerHash;
uint32_t ledgerIndex;
@@ -64,8 +67,12 @@ public:
bool validated = true;
};
// the taker is not really used in both clio and rippled, both of them return all the offers regardless the funding
// status
/**
* @brief A struct to hold the input data for the command
*
* @note The taker is not really used in both Clio and `rippled`, both of them return all the offers regardless of
* the funding status
*/
struct Input {
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
@@ -80,10 +87,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new BookOffersHandler object
*
* @param sharedPtrBackend The backend to use
*/
BookOffersHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -124,13 +142,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the BookOffers command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -37,7 +37,9 @@
namespace rpc {
/**
* @brief The deposit_authorized command indicates whether one account is authorized to send payments directly to
* @brief Handles the `deposit_authorized` command
*
* The deposit_authorized command indicates whether one account is authorized to send payments directly to
* another. See Deposit Authorization for information on how to require authorization to deliver money to your account.
*
* For more details see: https://xrpl.org/deposit_authorized.html
@@ -48,6 +50,9 @@ class DepositAuthorizedHandler {
public:
// Note: `ledger_current_index` is omitted because it only makes sense for rippled
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
bool depositAuthorized = true;
std::string sourceAccount;
@@ -58,6 +63,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string sourceAccount;
std::string destinationAccount;
@@ -67,11 +75,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new DepositAuthorizedHandler object
*
* @param sharedPtrBackend The backend to use
*/
DepositAuthorizedHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -85,13 +104,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the DepositAuthorized command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -49,6 +49,8 @@
namespace rpc {
/**
* @brief Handles the `gateway_balances` command
*
* The gateway_balances command calculates the total balances issued by a given account, optionally excluding amounts
* held by operational addresses.
*
@@ -58,6 +60,9 @@ class GatewayBalancesHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string ledgerHash;
uint32_t ledgerIndex;
@@ -71,6 +76,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
std::set<ripple::AccountID> hotWallets;
@@ -80,11 +88,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new GatewayBalancesHandler object
*
* @param sharedPtrBackend The backend to use
*/
GatewayBalancesHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -128,13 +147,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the GatewayBalances command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -46,6 +46,9 @@ class LedgerHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
uint32_t ledgerIndex{};
std::string ledgerHash;
@@ -54,9 +57,19 @@ public:
bool validated = true;
};
// clio not support : accounts/full/owner_finds/queue/type
// clio will throw error when accounts/full/owner_funds/queue is set to true
// https://github.com/XRPLF/clio/issues/603
/**
* @brief A struct to hold the input data for the command
*
* Clio does not support:
* - accounts
* - full
* - owner_finds
* - queue
* - type
*
* Clio will throw an error when any of `accounts`/`full`/`owner_funds`/`queue` are set to `true`
* @see https://github.com/XRPLF/clio/issues/603
*/
struct Input {
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
@@ -69,10 +82,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new LedgerHandler object
*
* @param sharedPtrBackend The backend to use
*/
LedgerHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -92,13 +116,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the Ledger command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -62,6 +62,9 @@ public:
static uint32_t constexpr LIMITBINARY = 2048;
static uint32_t constexpr LIMITJSON = 256;
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
uint32_t ledgerIndex{};
std::string ledgerHash;
@@ -73,9 +76,12 @@ public:
bool validated = true;
};
// TODO: Clio does not implement "type" filter
// outOfOrder only for clio, there is no document, traverse via seq diff
// outOfOrder implementation is copied from old rpc handler
/**
* @brief A struct to hold the input data for the command
*
* @note `outOfOrder` is only for Clio, there is no document, traverse via seq diff (outOfOrder implementation is
* copied from old rpc handler)
*/
struct Input {
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
@@ -89,10 +95,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new LedgerDataHandler object
*
* @param sharedPtrBackend The backend to use
*/
LedgerDataHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -116,13 +133,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the LedgerData command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -58,6 +58,9 @@ class LedgerEntryHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string index;
uint32_t ledgerIndex;
@@ -67,6 +70,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::optional<std::string> ledgerHash;
std::optional<uint32_t> ledgerIndex;
@@ -96,10 +102,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new LedgerEntryHandler object
*
* @param sharedPtrBackend The backend to use
*/
LedgerEntryHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -266,6 +283,13 @@ public:
return rpcSpec;
}
/**
* @brief Process the LedgerEntry command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
@@ -275,9 +299,21 @@ private:
static std::variant<ripple::uint256, Status>
composeKeyFromDirectory(boost::json::object const& directory) noexcept;
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -40,20 +40,40 @@ class LedgerRangeHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
data::LedgerRange range;
};
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new LedgerRangeHandler object
*
* @param sharedPtrBackend The backend to use
*/
LedgerRangeHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Process the LedgerRange command
*
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
};

View File

@@ -34,11 +34,23 @@ namespace rpc {
*/
class NFTBuyOffersHandler : public NFTOffersHandlerBase {
public:
/**
* @brief Construct a new NFTBuyOffersHandler object
*
* @param sharedPtrBackend The backend to use
*/
NFTBuyOffersHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: NFTOffersHandlerBase(sharedPtrBackend)
{
}
/**
* @brief Process the NFTBuyOffers command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
};

View File

@@ -57,12 +57,18 @@ public:
static auto constexpr LIMIT_MAX = 100;
static auto constexpr LIMIT_DEFAULT = 50;
/**
* @brief A struct to hold the marker data
*/
// TODO: this marker is same as account_tx, reuse in future
struct Marker {
uint32_t ledger;
uint32_t seq;
};
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string nftID;
uint32_t ledgerIndexMin{0};
@@ -75,6 +81,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string nftID;
// You must use at least one of the following fields in your request:
@@ -91,10 +100,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new NFTHistoryHandler object
*
* @param sharedPtrBackend The backend to use
*/
NFTHistoryHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -123,16 +143,41 @@ public:
return rpcSpec;
}
/**
* @brief Process the NFTHistory command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
/**
* @brief Convert the Marker to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param marker The marker to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Marker const& marker);
};

View File

@@ -45,6 +45,9 @@ class NFTInfoHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string nftID;
uint32_t ledgerIndex;
@@ -62,6 +65,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string nftID;
std::optional<std::string> ledgerHash;
@@ -70,10 +76,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new NFTInfoHandler object
*
* @param sharedPtrBackend The backend to use
*/
NFTInfoHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -86,13 +103,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the NFTInfo command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -42,6 +42,9 @@
namespace rpc {
/**
* @brief Contains common functionality for handling the `nft_offers` command
*/
class NFTOffersHandlerBase {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
@@ -50,6 +53,9 @@ public:
static auto constexpr LIMIT_MAX = 500;
static auto constexpr LIMIT_DEFAULT = 250;
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string nftID = {};
std::vector<ripple::SLE> offers = {};
@@ -60,6 +66,9 @@ public:
std::optional<std::string> marker = {};
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string nftID;
std::optional<std::string> ledgerHash;
@@ -70,11 +79,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new NFTOffersHandlerBase object
*
* @param sharedPtrBackend The backend to use
*/
NFTOffersHandlerBase(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -93,6 +113,15 @@ public:
}
protected:
/**
* @brief Iterate the NFT offer directory
*
* @param input The input data for the command
* @param tokenID The tokenID of the NFT
* @param directory The directory to iterate
* @param yield The coroutine context
* @return The result of the iteration
*/
Result
iterateOfferDirectory(
Input input,
@@ -102,9 +131,21 @@ protected:
) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -34,11 +34,23 @@ namespace rpc {
*/
class NFTSellOffersHandler : public NFTOffersHandlerBase {
public:
/**
* @brief Construct a new NFTSellOffersHandler object
*
* @param sharedPtrBackend The backend to use
*/
NFTSellOffersHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: NFTOffersHandlerBase(sharedPtrBackend)
{
}
/**
* @brief Process the NFTSellOffers command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
};

View File

@@ -37,6 +37,10 @@
#include <string>
namespace rpc {
/**
* @brief Handler for the `nfts_by_issuer` command
*/
class NFTsByIssuerHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
@@ -45,6 +49,9 @@ public:
static auto constexpr LIMIT_MAX = 100;
static auto constexpr LIMIT_DEFAULT = 50;
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
boost::json::array nfts;
uint32_t ledgerIndex;
@@ -55,6 +62,9 @@ public:
std::optional<std::string> marker;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string issuer;
std::optional<uint32_t> nftTaxon;
@@ -66,10 +76,21 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new NFTsByIssuerHandler object
*
* @param sharedPtrBackend The backend to use
*/
NFTsByIssuerHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -88,13 +109,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the NFTsByIssuer command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -44,7 +44,9 @@
namespace rpc {
/**
* @brief The noripple_check command provides a quick way to check the status of the Default Ripple field for an account
* @brief Handles the `noripple_check` command
*
* The noripple_check command provides a quick way to check the status of the Default Ripple field for an account
* and the No Ripple flag of its trust lines, compared with the recommended settings.
*
* For more details see: https://xrpl.org/noripple_check.html
@@ -57,6 +59,9 @@ public:
static auto constexpr LIMIT_MAX = 500;
static auto constexpr LIMIT_DEFAULT = 300;
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string ledgerHash;
uint32_t ledgerIndex{};
@@ -66,6 +71,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string account;
bool roleGateway = false;
@@ -77,11 +85,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new NoRippleCheckHandler object
*
* @param sharedPtrBackend The backend to use
*/
NoRippleCheckHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -110,13 +129,32 @@ public:
return apiVersion == 1 ? rpcSpecV1 : rpcSpec;
}
/**
* @brief Process the NoRippleCheck command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -33,6 +33,12 @@ public:
using Output = VoidOutput;
using Result = HandlerReturnType<Output>;
/**
* @brief Process the Ping command
*
* @param ctx The context of the request
* @return The result of the operation
*/
static Result
process([[maybe_unused]] Context const& ctx)
{

View File

@@ -36,16 +36,31 @@ namespace rpc {
*/
class RandomHandler {
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::string random;
};
using Result = HandlerReturnType<Output>;
/**
* @brief Process the Random command
*
* @param ctx The context of the request
* @return The result of the operation
*/
static Result
process(Context const& ctx);
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
};

View File

@@ -60,6 +60,14 @@ class Counters;
namespace rpc {
/**
* @brief Contains common functionality for handling the `server_info` command
*
* @tparam SubscriptionManagerType The type of the subscription manager
* @tparam LoadBalancerType The type of the load balancer
* @tparam ETLServiceType The type of the ETL service
* @tparam CountersType The type of the counters
*/
template <typename SubscriptionManagerType, typename LoadBalancerType, typename ETLServiceType, typename CountersType>
class BaseServerInfoHandler {
static constexpr auto BACKEND_COUNTERS_KEY = "backend_counters";
@@ -71,10 +79,16 @@ class BaseServerInfoHandler {
std::reference_wrapper<CountersType const> counters_;
public:
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
bool backendCounters = false;
};
/**
* @brief A struct to hold the admin section of the output
*/
struct AdminSection {
boost::json::object counters = {};
std::optional<boost::json::object> backendCounters = {};
@@ -82,6 +96,9 @@ public:
boost::json::object etl = {};
};
/**
* @brief A struct to hold the validated ledger section of the output
*/
struct ValidatedLedgerSection {
uint32_t age = 0;
std::string hash = {};
@@ -89,6 +106,9 @@ public:
std::optional<ripple::Fees> fees = std::nullopt;
};
/**
* @brief A struct to hold the cache section of the output
*/
struct CacheSection {
std::size_t size = 0;
bool isFull = false;
@@ -97,6 +117,9 @@ public:
float successorHitRate = 1.0;
};
/**
* @brief A struct to hold the info section of the output
*/
struct InfoSection {
std::optional<AdminSection> adminSection = std::nullopt;
std::string completeLedgers = {};
@@ -111,6 +134,9 @@ public:
bool isAmendmentBlocked = false;
};
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
InfoSection info = {};
@@ -120,6 +146,15 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new BaseServerInfoHandler object
*
* @param backend The backend to use
* @param subscriptions The subscription manager to use
* @param balancer The load balancer to use
* @param etl The ETL service to use
* @param counters The counters to use
*/
BaseServerInfoHandler(
std::shared_ptr<BackendInterface> const& backend,
std::shared_ptr<SubscriptionManagerType> const& subscriptions,
@@ -135,6 +170,12 @@ public:
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -142,6 +183,13 @@ public:
return rpcSpec;
}
/**
* @brief Process the ServerInfo command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const
{

View File

@@ -52,12 +52,21 @@ class SubscriptionManager;
} // namespace feed
namespace rpc {
/**
* @brief Contains functionality for handling the `subscribe` command
*
* @tparam SubscriptionManagerType The type of the subscription manager to use
*/
template <typename SubscriptionManagerType>
class BaseSubscribeHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
std::shared_ptr<SubscriptionManagerType> subscriptions_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
// response of stream "ledger"
// TODO: use better type than json, this type will be used in the stream as well
@@ -71,6 +80,9 @@ public:
std::optional<boost::json::array> bids;
};
/**
* @brief A struct to hold the data for one order book
*/
struct OrderBook {
ripple::Book book;
std::optional<std::string> taker;
@@ -78,6 +90,9 @@ public:
bool both = false;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::optional<std::vector<std::string>> accounts;
std::optional<std::vector<std::string>> streams;
@@ -87,6 +102,12 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new BaseSubscribeHandler object
*
* @param sharedPtrBackend The backend to use
* @param subscriptions The subscription manager to use
*/
BaseSubscribeHandler(
std::shared_ptr<BackendInterface> const& sharedPtrBackend,
std::shared_ptr<SubscriptionManagerType> const& subscriptions
@@ -95,6 +116,12 @@ public:
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion) const
{
@@ -141,6 +168,13 @@ public:
return rpcSpec;
}
/**
* @brief Process the Subscribe command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const
{

View File

@@ -49,6 +49,9 @@ class TransactionEntryHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
std::optional<ripple::LedgerHeader> ledgerHeader;
// TODO: use a better type for this
@@ -59,6 +62,9 @@ public:
uint32_t apiVersion;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::string txHash;
std::optional<std::string> ledgerHash;
@@ -67,11 +73,22 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new Transaction Entry Handler object
*
* @param sharedPtrBackend The backend to use
*/
TransactionEntryHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend)
: sharedPtrBackend_(sharedPtrBackend)
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion)
{
@@ -86,13 +103,32 @@ public:
return rpcSpec;
}
/**
* @brief Process the transaction_entry command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the command
*/
Result
process(Input input, Context const& ctx) const;
private:
/**
* @brief Convert the Output to a JSON object
*
* @param [out] jv The JSON object to convert to
* @param output The output to convert
*/
friend void
tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
/**
* @brief Convert a JSON object to Input type
*
* @param jv The JSON object to convert
* @return Input parsed from the JSON object
*/
friend Input
tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
};

View File

@@ -50,12 +50,20 @@
namespace rpc {
/**
* @brief Contains common functionality for handling the `tx` command
*
* @tparam ETLServiceType The type of the ETL service to use
*/
template <typename ETLServiceType>
class BaseTxHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
std::shared_ptr<ETLServiceType const> etl_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
uint32_t date = 0u;
std::string hash{};
@@ -70,6 +78,9 @@ public:
bool validated = true;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::optional<std::string> transaction;
std::optional<std::string> ctid;
@@ -80,6 +91,12 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new BaseTxHandler object
*
* @param sharedPtrBackend The backend to use
* @param etl The ETL service to use
*/
BaseTxHandler(
std::shared_ptr<BackendInterface> const& sharedPtrBackend,
std::shared_ptr<ETLServiceType const> const& etl
@@ -88,6 +105,12 @@ public:
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
static RpcSpecConstRef
spec(uint32_t apiVersion)
{
@@ -103,6 +126,13 @@ public:
return apiVersion == 1 ? rpcSpecForV1 : rpcSpec;
}
/**
* @brief Process the Tx command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const
{

View File

@@ -48,17 +48,26 @@ class SubscriptionManager;
namespace rpc {
/**
* @brief Handles the `unsubscribe` command which is used to disconnect a subscriber from a feed
*/
template <typename SubscriptionManagerType>
class BaseUnsubscribeHandler {
std::shared_ptr<BackendInterface> sharedPtrBackend_;
std::shared_ptr<SubscriptionManagerType> subscriptions_;
public:
/**
* @brief A struct to hold one order book
*/
struct OrderBook {
ripple::Book book;
bool both = false;
};
/**
* @brief A struct to hold the input data for the command
*/
struct Input {
std::optional<std::vector<std::string>> accounts;
std::optional<std::vector<std::string>> streams;
@@ -69,6 +78,12 @@ public:
using Output = VoidOutput;
using Result = HandlerReturnType<Output>;
/**
* @brief Construct a new BaseUnsubscribeHandler object
*
* @param sharedPtrBackend The backend to use
* @param subscriptions The subscription manager to use
*/
BaseUnsubscribeHandler(
std::shared_ptr<BackendInterface> const& sharedPtrBackend,
std::shared_ptr<SubscriptionManagerType> const& subscriptions
@@ -77,6 +92,12 @@ public:
{
}
/**
* @brief Returns the API specification for the command
*
* @param apiVersion The api version to return the spec for
* @return The spec for the given apiVersion
*/
RpcSpecConstRef
spec([[maybe_unused]] uint32_t apiVersion) const
{
@@ -110,6 +131,13 @@ public:
return rpcSpec;
}
/**
* @brief Process the Unsubscribe command
*
* @param input The input data for the command
* @param ctx The context of the request
* @return The result of the operation
*/
Result
process(Input input, Context const& ctx) const
{

View File

@@ -39,12 +39,20 @@ class VersionHandler {
rpc::impl::ProductionAPIVersionParser apiVersionParser_;
public:
/**
* @brief A struct to hold the output data of the command
*/
struct Output {
uint32_t minVersion;
uint32_t maxVersion;
uint32_t currVersion;
};
/**
* @brief Construct a new Version Handler object
*
* @param config The configuration to use
*/
explicit VersionHandler(util::Config const& config)
: apiVersionParser_(
config.valueOr("default", API_VERSION_DEFAULT),
@@ -56,6 +64,12 @@ public:
using Result = HandlerReturnType<Output>;
/**
* @brief Process the version command
*
* @param ctx The context of the request
* @return The result of the command
*/
Result
process([[maybe_unused]] Context const& ctx) const
{