20 #include <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/app/misc/Transaction.h>
23 #include <ripple/core/DatabaseCon.h>
24 #include <ripple/core/Pg.h>
25 #include <ripple/core/SociDB.h>
26 #include <ripple/net/RPCErr.h>
27 #include <ripple/protocol/ErrorCodes.h>
28 #include <ripple/protocol/jss.h>
29 #include <ripple/resource/Fees.h>
30 #include <ripple/rpc/Context.h>
31 #include <ripple/rpc/Role.h>
32 #include <ripple/rpc/Status.h>
33 #include <boost/format.hpp>
41 #ifdef RIPPLED_REPORTING
45 Throw<std::runtime_error>(
46 "called doTxHistoryReporting but not in reporting mode");
53 unsigned int startIndex = context.
params[jss::start].
asUInt();
59 boost::format(
"SELECT nodestore_hash, ledger_seq "
61 " ORDER BY ledger_seq DESC LIMIT 20 "
65 auto res = PgQuery(context.
app.getPgPool())(sql.
data());
70 << __func__ <<
" : Postgres response is null - sql = " << sql;
74 else if (res.status() != PGRES_TUPLES_OK)
78 <<
" : Postgres response should have been "
79 "PGRES_TUPLES_OK but instead was "
80 << res.status() <<
" - msg = " << res.msg() <<
" - sql = " << sql;
86 << __func__ <<
" Postgres result msg : " << res.msg();
88 if (res.isNull() || res.ntuples() == 0)
90 JLOG(context.
j.
debug()) << __func__ <<
" : Empty postgres response";
94 else if (res.ntuples() > 0)
96 if (res.nfields() != 2)
98 JLOG(context.
j.
error()) << __func__
99 <<
" : Wrong number of fields in Postgres "
100 "response. Expected 1, but got "
101 << res.nfields() <<
" . sql = " << sql;
108 << __func__ <<
" : Postgres result = " << res.c_str();
114 for (
size_t i = 0; i < res.ntuples(); ++i)
117 if (!hash.
parseHex(res.c_str(i, 0) + 2))
120 ledgerSequences.
push_back(res.asBigInt(i, 1));
124 for (
size_t i = 0; i < txns.size(); ++i)
126 auto const& [sttx, meta] = txns[i];
130 auto txn = std::make_shared<Transaction>(sttx, reason, context.
app);
131 txn->setLedger(ledgerSequences[i]);
136 ret[jss::index] = startIndex;
138 ret[
"used_postgres"] =
true;
160 unsigned int startIndex = context.
params[jss::start].
asUInt();
168 obj[jss::index] = startIndex;
172 "SELECT LedgerSeq, Status, RawTxn "
173 "FROM Transactions ORDER BY LedgerSeq desc LIMIT %u,20;") %
179 boost::optional<std::uint64_t> ledgerSeq;
180 boost::optional<std::string> status;
181 soci::blob sociRawTxnBlob(*db);
187 soci::into(ledgerSeq),
189 soci::into(sociRawTxnBlob, rti));
194 if (soci::i_ok == rti)
195 convert(sociRawTxnBlob, rawTxn);
200 ledgerSeq, status, rawTxn, context.
app))