20 #include <ripple/app/ledger/LedgerToJson.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/app/misc/TxQ.h>
23 #include <ripple/basics/base_uint.h>
24 #include <ripple/core/Pg.h>
25 #include <ripple/rpc/Context.h>
26 #include <ripple/rpc/DeliveredAmount.h>
33 isFull(LedgerFill
const& fill)
39 isExpanded(LedgerFill
const& fill)
45 isBinary(LedgerFill
const& fill)
50 template <
class Object>
52 fillJson(Object& json,
bool closed, LedgerInfo
const& info,
bool bFull)
54 json[jss::parent_hash] =
to_string(info.parentHash);
55 json[jss::ledger_index] =
to_string(info.seq);
59 json[jss::closed] =
true;
63 json[jss::closed] =
false;
67 json[jss::ledger_hash] =
to_string(info.hash);
68 json[jss::transaction_hash] =
to_string(info.txHash);
69 json[jss::account_hash] =
to_string(info.accountHash);
70 json[jss::total_coins] =
to_string(info.drops);
72 json[jss::close_flags] = info.closeFlags;
75 json[jss::parent_close_time] =
76 info.parentCloseTime.time_since_epoch().count();
77 json[jss::close_time] = info.closeTime.time_since_epoch().count();
78 json[jss::close_time_resolution] = info.closeTimeResolution.count();
82 json[jss::close_time_human] =
to_string(info.closeTime);
84 json[jss::close_time_estimated] =
true;
88 template <
class Object>
90 fillJsonBinary(Object& json,
bool closed, LedgerInfo
const& info)
93 json[jss::closed] =
false;
96 json[jss::closed] =
true;
100 json[jss::ledger_data] =
strHex(s.peekData());
106 LedgerFill
const& fill,
133 txJson[jss::metaData],
136 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
148 if (account != amount.getIssuer())
156 txJson[jss::owner_funds] = ownerFunds.getText();
163 template <
class Object>
165 fillJsonTx(Object& json, LedgerFill
const& fill)
167 auto&& txns =
setArray(json, jss::transactions);
168 auto bBinary = isBinary(fill);
169 auto bExpanded = isExpanded(fill);
173 auto appendAll = [&](
auto const& txs) {
177 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
181 if (
fill.context &&
fill.context->app.config().reporting())
187 appendAll(
fill.ledger.txs);
195 JLOG(
fill.context->j.error())
196 <<
"Exception in " << __func__ <<
": " << ex.
what();
201 template <
class Object>
203 fillJsonState(Object& json, LedgerFill
const& fill)
205 auto& ledger =
fill.ledger;
207 auto expanded = isExpanded(fill);
208 auto binary = isBinary(fill);
210 for (
auto const& sle : ledger.sles)
228 template <
class Object>
230 fillJsonQueue(Object& json, LedgerFill
const& fill)
233 auto bBinary = isBinary(fill);
234 auto bExpanded = isExpanded(fill);
236 for (
auto const& tx :
fill.txQueue)
239 txJson[jss::fee_level] =
to_string(tx.feeLevel);
241 txJson[jss::LastLedgerSequence] = *tx.lastValid;
243 txJson[jss::fee] =
to_string(tx.consequences.fee());
245 tx.consequences.potentialSpend() + tx.consequences.fee();
246 txJson[jss::max_spend_drops] =
to_string(spend);
247 txJson[jss::auth_change] = tx.consequences.isBlocker();
249 txJson[jss::account] =
to_string(tx.account);
250 txJson[
"retries_remaining"] = tx.retriesRemaining;
251 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
253 txJson[
"last_result"] =
transToken(*tx.lastResult);
255 txJson[jss::tx] = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
259 template <
class Object>
261 fillJson(Object& json, LedgerFill
const& fill)
265 auto bFull = isFull(fill);
267 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.info());
269 fillJson(json, !
fill.ledger.open(),
fill.ledger.info(), bFull);
272 fillJsonTx(json, fill);
275 fillJsonState(json, fill);
284 fillJson(
object, fill);
287 fillJsonQueue(json, fill);
294 fillJson(json, fill);