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>
28 #include <date/date.h>
35 isFull(LedgerFill
const& fill)
41 isExpanded(LedgerFill
const& fill)
47 isBinary(LedgerFill
const& fill)
52 template <
class Object>
54 fillJson(Object& json,
bool closed, LedgerInfo
const& info,
bool bFull)
56 json[jss::parent_hash] =
to_string(info.parentHash);
57 json[jss::ledger_index] =
to_string(info.seq);
62 json[jss::closed] =
true;
66 json[jss::closed] =
false;
70 json[jss::ledger_hash] =
to_string(info.hash);
71 json[jss::transaction_hash] =
to_string(info.txHash);
72 json[jss::account_hash] =
to_string(info.accountHash);
73 json[jss::total_coins] =
to_string(info.drops);
77 json[jss::totalCoins] =
to_string(info.drops);
78 json[jss::accepted] = closed;
79 json[jss::close_flags] = info.closeFlags;
82 json[jss::parent_close_time] =
83 info.parentCloseTime.time_since_epoch().count();
84 json[jss::close_time] = info.closeTime.time_since_epoch().count();
85 json[jss::close_time_resolution] = info.closeTimeResolution.count();
89 json[jss::close_time_human] =
to_string(info.closeTime);
91 json[jss::close_time_estimated] =
true;
95 template <
class Object>
97 fillJsonBinary(Object& json,
bool closed, LedgerInfo
const& info)
100 json[jss::closed] =
false;
103 json[jss::closed] =
true;
107 json[jss::ledger_data] =
strHex(s.peekData());
113 LedgerFill
const& fill,
139 auto txMeta = std::make_shared<TxMeta>(
142 txJson[jss::metaData],
fill.ledger, txn, *txMeta);
155 if (account != amount.getIssuer())
163 txJson[jss::owner_funds] = ownerFunds.getText();
170 template <
class Object>
172 fillJsonTx(Object& json, LedgerFill
const& fill)
174 auto&& txns =
setArray(json, jss::transactions);
175 auto bBinary = isBinary(fill);
176 auto bExpanded = isExpanded(fill);
180 auto appendAll = [&](
auto const& txs) {
184 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
188 if (
fill.context &&
fill.context->app.config().reporting())
194 appendAll(
fill.ledger.txs);
203 template <
class Object>
205 fillJsonState(Object& json, LedgerFill
const& fill)
207 auto& ledger =
fill.ledger;
210 auto binary = isBinary(fill);
212 for (
auto const& sle : ledger.sles)
230 template <
class Object>
232 fillJsonQueue(Object& json, LedgerFill
const& fill)
235 auto bBinary = isBinary(fill);
236 auto bExpanded = isExpanded(fill);
238 for (
auto const& tx :
fill.txQueue)
241 txJson[jss::fee_level] =
to_string(tx.feeLevel);
243 txJson[jss::LastLedgerSequence] = *tx.lastValid;
245 txJson[jss::fee] =
to_string(tx.consequences.fee());
247 tx.consequences.potentialSpend() + tx.consequences.fee();
248 txJson[jss::max_spend_drops] =
to_string(spend);
249 txJson[jss::auth_change] = tx.consequences.isBlocker();
251 txJson[jss::account] =
to_string(tx.account);
252 txJson[
"retries_remaining"] = tx.retriesRemaining;
253 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
255 txJson[
"last_result"] =
transToken(*tx.lastResult);
257 txJson[jss::tx] = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
261 template <
class Object>
263 fillJson(Object& json, LedgerFill
const& fill)
267 auto bFull = isFull(fill);
269 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.info());
271 fillJson(json, !
fill.ledger.open(),
fill.ledger.info(), bFull);
274 fillJsonTx(json, fill);
277 fillJsonState(json, fill);
286 fillJson(
object, fill);
289 fillJsonQueue(json, fill);
296 fillJson(json, fill);