mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
Ledger entry type filter for account_objects and ledger_data (#1116)
Fix #1109
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "rpc/JS.h"
|
||||
#include "rpc/RPCHelpers.h"
|
||||
#include "rpc/common/Types.h"
|
||||
#include "util/LedgerUtils.h"
|
||||
|
||||
#include <boost/json/array.hpp>
|
||||
#include <boost/json/conversion.hpp>
|
||||
@@ -47,30 +48,6 @@
|
||||
|
||||
namespace rpc {
|
||||
|
||||
// found here : https://xrpl.org/ledger_entry.html#:~:text=valid%20fields%20are%3A-,index,-account_root
|
||||
std::unordered_map<std::string, ripple::LedgerEntryType> const AccountObjectsHandler::TYPES_MAP{
|
||||
{JS(amm), ripple::ltAMM},
|
||||
{JS(state), ripple::ltRIPPLE_STATE},
|
||||
{JS(ticket), ripple::ltTICKET},
|
||||
{JS(signer_list), ripple::ltSIGNER_LIST},
|
||||
{JS(payment_channel), ripple::ltPAYCHAN},
|
||||
{JS(offer), ripple::ltOFFER},
|
||||
{JS(escrow), ripple::ltESCROW},
|
||||
{JS(deposit_preauth), ripple::ltDEPOSIT_PREAUTH},
|
||||
{JS(check), ripple::ltCHECK},
|
||||
{JS(nft_page), ripple::ltNFTOKEN_PAGE},
|
||||
{JS(nft_offer), ripple::ltNFTOKEN_OFFER},
|
||||
{JS(did), ripple::ltDID},
|
||||
};
|
||||
|
||||
std::unordered_set<std::string> const AccountObjectsHandler::TYPES_KEYS = [] {
|
||||
std::unordered_set<std::string> keys;
|
||||
std::transform(TYPES_MAP.begin(), TYPES_MAP.end(), std::inserter(keys, keys.begin()), [](auto const& pair) {
|
||||
return pair.first;
|
||||
});
|
||||
return keys;
|
||||
}();
|
||||
|
||||
AccountObjectsHandler::Result
|
||||
AccountObjectsHandler::process(AccountObjectsHandler::Input input, Context const& ctx) const
|
||||
{
|
||||
@@ -93,16 +70,9 @@ AccountObjectsHandler::process(AccountObjectsHandler::Input input, Context const
|
||||
auto typeFilter = std::optional<std::vector<ripple::LedgerEntryType>>{};
|
||||
|
||||
if (input.deletionBlockersOnly) {
|
||||
static constexpr ripple::LedgerEntryType deletionBlockers[] = {
|
||||
ripple::ltCHECK,
|
||||
ripple::ltESCROW,
|
||||
ripple::ltNFTOKEN_PAGE,
|
||||
ripple::ltPAYCHAN,
|
||||
ripple::ltRIPPLE_STATE,
|
||||
};
|
||||
|
||||
typeFilter.emplace();
|
||||
typeFilter->reserve(std::size(deletionBlockers));
|
||||
auto const& deletionBlockers = util::getDeletionBlockerLedgerTypes();
|
||||
typeFilter->reserve(deletionBlockers.size());
|
||||
|
||||
for (auto type : deletionBlockers) {
|
||||
if (input.type && input.type != type)
|
||||
@@ -189,7 +159,7 @@ tag_invoke(boost::json::value_to_tag<AccountObjectsHandler::Input>, boost::json:
|
||||
}
|
||||
|
||||
if (jsonObject.contains(JS(type)))
|
||||
input.type = AccountObjectsHandler::TYPES_MAP.at(jv.at(JS(type)).as_string().c_str());
|
||||
input.type = util::getLedgerEntryTypeFromStr(jv.at(JS(type)).as_string().c_str());
|
||||
|
||||
if (jsonObject.contains(JS(limit)))
|
||||
input.limit = jv.at(JS(limit)).as_int64();
|
||||
|
||||
@@ -20,12 +20,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "data/BackendInterface.h"
|
||||
#include "rpc/RPCHelpers.h"
|
||||
#include "rpc/JS.h"
|
||||
#include "rpc/common/Modifiers.h"
|
||||
#include "rpc/common/Types.h"
|
||||
#include "rpc/common/Validators.h"
|
||||
#include "util/LedgerUtils.h"
|
||||
|
||||
#include <set>
|
||||
#include <boost/json/conversion.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <ripple/protocol/LedgerFormats.h>
|
||||
#include <ripple/protocol/STLedgerEntry.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace rpc {
|
||||
|
||||
@@ -80,6 +93,7 @@ public:
|
||||
static RpcSpecConstRef
|
||||
spec([[maybe_unused]] uint32_t apiVersion)
|
||||
{
|
||||
auto const& ledgerTypeStrs = util::getLedgerEntryTypeStrs();
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
@@ -90,7 +104,7 @@ public:
|
||||
modifiers::Clamp<int32_t>(LIMIT_MIN, LIMIT_MAX)},
|
||||
{JS(type),
|
||||
validation::Type<std::string>{},
|
||||
validation::OneOf<std::string>(TYPES_KEYS.cbegin(), TYPES_KEYS.cend())},
|
||||
validation::OneOf<std::string>(ledgerTypeStrs.cbegin(), ledgerTypeStrs.cend())},
|
||||
{JS(marker), validation::AccountMarkerValidator},
|
||||
{JS(deletion_blockers_only), validation::Type<bool>{}},
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "rpc/common/Modifiers.h"
|
||||
#include "rpc/common/Types.h"
|
||||
#include "rpc/common/Validators.h"
|
||||
#include "util/TxUtil.h"
|
||||
#include "util/TxUtils.h"
|
||||
#include "util/log/Logger.h"
|
||||
|
||||
#include <boost/json/array.hpp>
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "rpc/JS.h"
|
||||
#include "rpc/RPCHelpers.h"
|
||||
#include "rpc/common/Types.h"
|
||||
#include "util/LedgerUtils.h"
|
||||
#include "util/log/Logger.h"
|
||||
|
||||
#include <boost/json/conversion.hpp>
|
||||
@@ -42,45 +43,13 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace rpc {
|
||||
|
||||
std::unordered_map<std::string, ripple::LedgerEntryType> const LedgerDataHandler::TYPES_MAP{
|
||||
{JS(account), ripple::ltACCOUNT_ROOT},
|
||||
{JS(did), ripple::ltDID},
|
||||
{JS(amendments), ripple::ltAMENDMENTS},
|
||||
{JS(check), ripple::ltCHECK},
|
||||
{JS(deposit_preauth), ripple::ltDEPOSIT_PREAUTH},
|
||||
{JS(directory), ripple::ltDIR_NODE},
|
||||
{JS(escrow), ripple::ltESCROW},
|
||||
{JS(fee), ripple::ltFEE_SETTINGS},
|
||||
{JS(hashes), ripple::ltLEDGER_HASHES},
|
||||
{JS(offer), ripple::ltOFFER},
|
||||
{JS(payment_channel), ripple::ltPAYCHAN},
|
||||
{JS(signer_list), ripple::ltSIGNER_LIST},
|
||||
{JS(state), ripple::ltRIPPLE_STATE},
|
||||
{JS(ticket), ripple::ltTICKET},
|
||||
{JS(nft_offer), ripple::ltNFTOKEN_OFFER},
|
||||
{JS(nft_page), ripple::ltNFTOKEN_PAGE},
|
||||
{JS(amm), ripple::ltAMM}
|
||||
};
|
||||
|
||||
// TODO: should be std::views::keys when clang supports it
|
||||
std::unordered_set<std::string> const LedgerDataHandler::TYPES_KEYS = [] {
|
||||
std::unordered_set<std::string> keys;
|
||||
std::transform(TYPES_MAP.begin(), TYPES_MAP.end(), std::inserter(keys, keys.begin()), [](auto const& pair) {
|
||||
return pair.first;
|
||||
});
|
||||
return keys;
|
||||
}();
|
||||
|
||||
LedgerDataHandler::Result
|
||||
LedgerDataHandler::process(Input input, Context const& ctx) const
|
||||
{
|
||||
@@ -246,7 +215,7 @@ tag_invoke(boost::json::value_to_tag<LedgerDataHandler::Input>, boost::json::val
|
||||
}
|
||||
|
||||
if (jsonObject.contains(JS(type)))
|
||||
input.type = LedgerDataHandler::TYPES_MAP.at(jsonObject.at(JS(type)).as_string().c_str());
|
||||
input.type = util::getLedgerEntryTypeFromStr(jsonObject.at(JS(type)).as_string().c_str());
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "data/BackendInterface.h"
|
||||
#include "rpc/RPCHelpers.h"
|
||||
#include "rpc/Errors.h"
|
||||
#include "rpc/JS.h"
|
||||
#include "rpc/common/MetaProcessors.h"
|
||||
#include "rpc/common/Types.h"
|
||||
#include "rpc/common/Validators.h"
|
||||
#include "util/LedgerUtils.h"
|
||||
#include "util/log/Logger.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <boost/json/array.hpp>
|
||||
#include <boost/json/conversion.hpp>
|
||||
#include <boost/json/object.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <ripple/basics/base_uint.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/LedgerFormats.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace rpc {
|
||||
@@ -41,10 +56,6 @@ class LedgerDataHandler {
|
||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||
util::Logger log_{"RPC"};
|
||||
|
||||
static std::unordered_map<std::string, ripple::LedgerEntryType> const TYPES_MAP;
|
||||
|
||||
static std::unordered_set<std::string> const TYPES_KEYS;
|
||||
|
||||
public:
|
||||
// constants
|
||||
static uint32_t constexpr LIMITBINARY = 2048;
|
||||
@@ -84,6 +95,7 @@ public:
|
||||
static RpcSpecConstRef
|
||||
spec([[maybe_unused]] uint32_t apiVersion)
|
||||
{
|
||||
auto const& ledgerTypeStrs = util::getLedgerEntryTypeStrs();
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(binary), validation::Type<bool>{}},
|
||||
{"out_of_order", validation::Type<bool>{}},
|
||||
@@ -97,7 +109,7 @@ public:
|
||||
meta::WithCustomError{
|
||||
validation::Type<std::string>{}, Status{ripple::rpcINVALID_PARAMS, "Invalid field 'type', not string."}
|
||||
},
|
||||
validation::OneOf<std::string>(TYPES_KEYS.cbegin(), TYPES_KEYS.cend())},
|
||||
validation::OneOf<std::string>(ledgerTypeStrs.cbegin(), ledgerTypeStrs.cend())},
|
||||
|
||||
};
|
||||
return rpcSpec;
|
||||
|
||||
Reference in New Issue
Block a user