refactor: output struct (#2456)

fixes #2452
This commit is contained in:
Peter Chen
2025-08-20 11:13:05 -04:00
committed by GitHub
parent d833d36896
commit c780ef8a0b
4 changed files with 25 additions and 71 deletions

View File

@@ -43,6 +43,7 @@
#include <algorithm>
#include <iterator>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
@@ -90,6 +91,17 @@ AccountInfoHandler::process(AccountInfoHandler::Input const& input, Context cons
auto const isClawbackEnabled = isEnabled(Amendments::Clawback);
auto const isTokenEscrowEnabled = isEnabled(Amendments::TokenEscrow);
Output out{
.ledgerIndex = lgrInfo.seq,
.ledgerHash = ripple::strHex(lgrInfo.hash),
.accountData = sle,
.isDisallowIncomingEnabled = isDisallowIncomingEnabled,
.isClawbackEnabled = isClawbackEnabled,
.isTokenEscrowEnabled = isTokenEscrowEnabled,
.apiVersion = ctx.apiVersion,
.signerLists = std::nullopt
};
// Return SignerList(s) if that is requested.
if (input.signerLists) {
// We put the SignerList in an array because of an anticipated
@@ -99,7 +111,6 @@ AccountInfoHandler::process(AccountInfoHandler::Input const& input, Context cons
// This code will need to be revisited if in the future we
// support multiple SignerLists on one account.
auto const signers = sharedPtrBackend_->fetchLedgerObject(signersKey.key, lgrInfo.seq, ctx.yield);
std::vector<ripple::STLedgerEntry> signerList;
if (signers) {
ripple::STLedgerEntry const sleSigners{
@@ -109,30 +120,11 @@ AccountInfoHandler::process(AccountInfoHandler::Input const& input, Context cons
if (!signersKey.check(sleSigners))
return Error{Status{RippledError::rpcDB_DESERIALIZATION}};
signerList.push_back(sleSigners);
out.signerLists = std::vector<ripple::STLedgerEntry>{sleSigners};
}
return Output(
lgrInfo.seq,
ripple::strHex(lgrInfo.hash),
sle,
isDisallowIncomingEnabled,
isClawbackEnabled,
isTokenEscrowEnabled,
ctx.apiVersion,
signerList
);
}
return Output(
lgrInfo.seq,
ripple::strHex(lgrInfo.hash),
sle,
isDisallowIncomingEnabled,
isClawbackEnabled,
isTokenEscrowEnabled,
ctx.apiVersion
);
return out;
}
void

View File

@@ -66,39 +66,6 @@ public:
std::optional<std::vector<ripple::STLedgerEntry>> signerLists;
// 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 isTokenEscrowEnabled Whether token escrow is enabled
* @param version The API version
* @param signerLists The signer lists
*/
Output(
uint32_t ledgerId,
std::string ledgerHash,
ripple::STLedgerEntry sle,
bool isDisallowIncomingEnabled,
bool isClawbackEnabled,
bool isTokenEscrowEnabled,
uint32_t version,
std::optional<std::vector<ripple::STLedgerEntry>> signerLists = std::nullopt
)
: ledgerIndex(ledgerId)
, ledgerHash(std::move(ledgerHash))
, accountData(std::move(sle))
, isDisallowIncomingEnabled(isDisallowIncomingEnabled)
, isClawbackEnabled(isClawbackEnabled)
, isTokenEscrowEnabled(isTokenEscrowEnabled)
, apiVersion(version)
, signerLists(std::move(signerLists))
{
}
};
/**

View File

@@ -124,7 +124,13 @@ GetAggregatePriceHandler::process(GetAggregatePriceHandler::Input const& input,
auto const latestTime = timestampPricesBiMap.left.begin()->first;
Output out(latestTime, ripple::to_string(lgrInfo.hash), lgrInfo.seq);
Output out{
.time = latestTime,
.trimStats = std::nullopt,
.ledgerHash = ripple::to_string(lgrInfo.hash),
.ledgerIndex = lgrInfo.seq,
.median = ""
};
if (input.timeThreshold) {
auto const oldestTime = timestampPricesBiMap.left.rbegin()->first;

View File

@@ -43,7 +43,6 @@
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
namespace rpc {
@@ -59,8 +58,9 @@ public:
* @brief A struct to hold the statistics
*/
struct Stats {
ripple::STAmount avg;
ripple::Number sd; // standard deviation
ripple::STAmount avg{}; // NOLINT(readability-redundant-member-init)
// standard deviation
ripple::Number sd{}; // NOLINT(readability-redundant-member-init)
uint32_t size{0};
};
@@ -69,23 +69,12 @@ public:
*/
struct Output {
uint32_t time;
Stats extireStats;
Stats extireStats{};
std::optional<Stats> trimStats;
std::string ledgerHash;
uint32_t ledgerIndex;
std::string median;
bool validated = true;
/**
* @brief Construct a new Output object
* @param time The time of the latest oracle data
* @param ledgerHash The hash of the ledger
* @param ledgerIndex The index of the ledger
*/
Output(uint32_t time, std::string ledgerHash, uint32_t ledgerIndex)
: time(time), ledgerHash(std::move(ledgerHash)), ledgerIndex(ledgerIndex)
{
}
};
/**