mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-20 03:35:55 +00:00
clean up ledger page interface. wire up account_tx
This commit is contained in:
@@ -18,8 +18,8 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <handlers/RPCHelpers.h>
|
||||
#include <reporting/BackendInterface.h>
|
||||
#include <reporting/Pg.h>
|
||||
#include <reporting/ReportingBackend.h>
|
||||
|
||||
std::vector<std::pair<
|
||||
std::shared_ptr<ripple::STTx const>,
|
||||
@@ -27,7 +27,7 @@ std::vector<std::pair<
|
||||
doAccountTxStoredProcedure(
|
||||
ripple::AccountID const& account,
|
||||
std::shared_ptr<PgPool>& pgPool,
|
||||
CassandraFlatMapBackend const& backend)
|
||||
BackendInterface const& backend)
|
||||
{
|
||||
pg_params dbParams;
|
||||
|
||||
@@ -129,7 +129,7 @@ doAccountTxStoredProcedure(
|
||||
boost::json::object
|
||||
doAccountTx(
|
||||
boost::json::object const& request,
|
||||
CassandraFlatMapBackend const& backend,
|
||||
BackendInterface const& backend,
|
||||
std::shared_ptr<PgPool>& pgPool)
|
||||
{
|
||||
boost::json::object response;
|
||||
@@ -148,16 +148,43 @@ doAccountTx(
|
||||
return response;
|
||||
}
|
||||
|
||||
std::optional<BackendInterface::AccountTransactionsCursor> cursor;
|
||||
if (request.contains("cursor"))
|
||||
{
|
||||
auto const& obj = request.at("cursor").as_object();
|
||||
std::optional<uint32_t> ledgerSequence;
|
||||
if (obj.contains("ledger_sequence"))
|
||||
{
|
||||
ledgerSequence = (uint32_t)obj.at("ledger_sequence").as_int64();
|
||||
}
|
||||
std::optional<uint32_t> transactionIndex;
|
||||
if (obj.contains("transaction_index"))
|
||||
{
|
||||
transactionIndex = (uint32_t)obj.at("transaction_index").as_int64();
|
||||
}
|
||||
if (!ledgerSequence || !transactionIndex)
|
||||
{
|
||||
response["error"] =
|
||||
"malformed cursor. include transaction_index and "
|
||||
"ledger_sequence in an object named \"cursor\"";
|
||||
return response;
|
||||
}
|
||||
cursor = {*ledgerSequence, *transactionIndex};
|
||||
}
|
||||
|
||||
boost::json::array txns;
|
||||
auto res = doAccountTxStoredProcedure(*account, pgPool, backend);
|
||||
for (auto const& [sttx, meta] : res)
|
||||
auto [blobs, retCursor] =
|
||||
backend.fetchAccountTransactions(*account, cursor);
|
||||
for (auto const& txnPlusMeta : blobs)
|
||||
{
|
||||
boost::json::object obj;
|
||||
obj["transaction"] = getJson(*sttx);
|
||||
auto [txn, meta] = deserializeTxPlusMeta(txnPlusMeta);
|
||||
obj["transaction"] = getJson(*txn);
|
||||
obj["metadata"] = getJson(*meta);
|
||||
txns.push_back(obj);
|
||||
}
|
||||
response["transactions"] = txns;
|
||||
response["cursor"] = {};
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user