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);
60 json[jss::closed] =
true;
64 json[jss::closed] =
false;
68 json[jss::ledger_hash] =
to_string(info.hash);
69 json[jss::transaction_hash] =
to_string(info.txHash);
70 json[jss::account_hash] =
to_string(info.accountHash);
71 json[jss::total_coins] =
to_string(info.drops);
75 json[jss::totalCoins] =
to_string(info.drops);
76 json[jss::accepted] = closed;
77 json[jss::close_flags] = info.closeFlags;
80 json[jss::parent_close_time] =
81 info.parentCloseTime.time_since_epoch().count();
82 json[jss::close_time] = info.closeTime.time_since_epoch().count();
83 json[jss::close_time_resolution] = info.closeTimeResolution.count();
87 json[jss::close_time_human] =
to_string(info.closeTime);
89 json[jss::close_time_estimated] =
true;
93 template <
class Object>
95 fillJsonBinary(Object& json,
bool closed, LedgerInfo
const& info)
98 json[jss::closed] =
false;
101 json[jss::closed] =
true;
105 json[jss::ledger_data] =
strHex(s.peekData());
111 LedgerFill
const& fill,
137 auto txMeta = std::make_shared<TxMeta>(
140 txJson[jss::metaData],
fill.ledger, txn, *txMeta);
153 if (account != amount.getIssuer())
161 txJson[jss::owner_funds] = ownerFunds.getText();
168 template <
class Object>
170 fillJsonTx(Object& json, LedgerFill
const& fill)
172 auto&& txns =
setArray(json, jss::transactions);
173 auto bBinary = isBinary(fill);
174 auto bExpanded = isExpanded(fill);
178 auto appendAll = [&](
auto const& txs) {
182 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
186 if (
fill.context &&
fill.context->app.config().reporting())
192 appendAll(
fill.ledger.txs);
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);