20 #include <ripple/app/ledger/LedgerToJson.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/app/misc/DeliverMax.h>
23 #include <ripple/app/misc/TxQ.h>
24 #include <ripple/basics/base_uint.h>
25 #include <ripple/core/Pg.h>
26 #include <ripple/rpc/Context.h>
27 #include <ripple/rpc/DeliveredAmount.h>
34 isFull(LedgerFill
const& fill)
40 isExpanded(LedgerFill
const& fill)
46 isBinary(LedgerFill
const& fill)
51 template <
class Object>
53 fillJson(Object& json,
bool closed,
LedgerInfo const& info,
bool bFull)
55 json[jss::parent_hash] =
to_string(info.parentHash);
56 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);
73 json[jss::close_flags] = info.closeFlags;
76 json[jss::parent_close_time] =
77 info.parentCloseTime.time_since_epoch().count();
78 json[jss::close_time] = info.closeTime.time_since_epoch().count();
79 json[jss::close_time_resolution] = info.closeTimeResolution.count();
83 json[jss::close_time_human] =
to_string(info.closeTime);
85 json[jss::close_time_estimated] =
true;
89 template <
class Object>
91 fillJsonBinary(Object& json,
bool closed,
LedgerInfo const& info)
94 json[jss::closed] =
false;
97 json[jss::closed] =
true;
101 json[jss::ledger_data] =
strHex(s.peekData());
107 LedgerFill
const& fill,
135 txJson[jss::metaData],
138 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
150 if (account != amount.getIssuer())
158 txJson[jss::owner_funds] = ownerFunds.getText();
165 template <
class Object>
167 fillJsonTx(Object& json, LedgerFill
const& fill)
169 auto&& txns =
setArray(json, jss::transactions);
170 auto bBinary = isBinary(fill);
171 auto bExpanded = isExpanded(fill);
175 auto appendAll = [&](
auto const& txs) {
179 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
183 if (
fill.context &&
fill.context->app.config().reporting())
189 appendAll(
fill.ledger.txs);
197 JLOG(
fill.context->j.error())
198 <<
"Exception in " << __func__ <<
": " << ex.
what();
203 template <
class Object>
205 fillJsonState(Object& json, LedgerFill
const& fill)
207 auto& ledger =
fill.ledger;
209 auto expanded = isExpanded(fill);
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);